forked from flarumite/simple-discussion-views
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extend.php
47 lines (38 loc) · 1.53 KB
/
extend.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/*
* This file is part of flarumite/simple-discussion-views.
*
* Copyright (c) 2020 Flarumite.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Flarum\Api\Controller\ListDiscussionsController;
use Flarum\Api\Controller\ShowDiscussionController;
use Flarum\Api\Serializer\DiscussionSerializer;
use Flarum\Database\AbstractModel;
use Flarum\Discussion\Event\Saving;
use Flarum\Extend;
use Flarum\Extend\Frontend;
use Flarumite\DiscussionViews\AddAttributesBasedOnPermission;
use Flarumite\DiscussionViews\Listeners;
use Flarumite\DiscussionViews\Listeners\AddDiscussionViewHandler;
return [
(new Frontend('forum'))
->css(__DIR__.'/resources/less/forum.less')
->js(__DIR__.'/js/dist/forum.js'),
(new Frontend('admin'))
->js(__DIR__.'/js/dist/admin.js'),
new Extend\Locales(__DIR__.'/resources/locale'),
(new Extend\Event())
->listen(Saving::class, Listeners\SaveDiscussionFromModal::class),
(new Extend\ApiSerializer(DiscussionSerializer::class))
->attribute('views', function (DiscussionSerializer $serializer, AbstractModel $discussion) {
return $discussion->view_count;
})
->attributes(AddAttributesBasedOnPermission::class),
(new Extend\ApiController(ShowDiscussionController::class))
->prepareDataForSerialization(AddDiscussionViewHandler::class),
(new Extend\ApiController(ListDiscussionsController::class))
->addSortField('view_count'),
];