forked from afrux/asirem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextend.php
More file actions
82 lines (69 loc) · 2.71 KB
/
extend.php
File metadata and controls
82 lines (69 loc) · 2.71 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/*
* This file is part of afrux/asirem.
*
* Copyright (c) 2021 Sami Ilyes Mazouz.
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace Deltamichael\Asirem;
use Flarum\Extend;
use Flarum\Frontend\Document;
use Flarum\Tags\Api\Serializer\TagSerializer;
use Flarum\Api\Serializer\DiscussionSerializer;
use Flarum\Api\Serializer\UserSerializer;
use Flarum\Tags\Api\Controller\ListTagsController;
use Flarum\Tags\Tag;
use Flarum\Discussion\DiscussionRepository;
use Flarum\Discussion\Discussion;
return [
new \Afrux\ThemeBase\Extend\Init('deltamichael-asirem'),
new \Afrux\ThemeBase\Extend\Footer,
new \Afrux\ThemeBase\Extend\UploadableBanner,
new \Afrux\ThemeBase\Extend\ExposeLaravelVersionToDashboard,
(new \Afrux\ThemeBase\Extend\DashboardLayout)
->splitToNavAndContent()
->normalizeStatusWidgetStructure()
->normalizeAdminHeaderStructure()
->normalizeExtensionPageStructure()
->normalizeUserTable()
->addExtensionsPage(),
(new Extend\Frontend('forum'))
->js(__DIR__.'/js/dist/forum.js')
->css(__DIR__.'/less/forum.less'),
(new Extend\Frontend('admin'))
->js(__DIR__.'/js/dist/admin.js')
->css(__DIR__.'/less/admin.less')
->content(function (Document $document) {
$document->layoutView = "deltamichael-asirem::frontend.admin";
}),
(new Extend\View)
->namespace("deltamichael-asirem", __DIR__."/views"),
new Extend\Locales(__DIR__.'/locale'),
(new Extend\ApiSerializer(TagSerializer::class))
->hasOne('lastPostedDiscussion', DiscussionSerializer::class)
->attribute('unreadCount', function (TagSerializer $serializer, Tag $tag) {
$actor = $serializer->getActor();
if (!$actor || !$actor->exists) {
return 0;
}
$discussionRepository = resolve(DiscussionRepository::class);
$readIdsQuery = $discussionRepository->getReadIdsQuery($actor);
return Discussion::query()
->whereVisibleTo($actor)
->whereHas('tags', function ($q) use ($tag) {
$q->where('id', $tag->id);
})
->where(function ($q) use ($readIdsQuery, $actor) {
$q->whereNotIn('id', $readIdsQuery)
->where('last_posted_at', '>', $actor->marked_all_as_read_at ?: 0);
})
->distinct()
->count('id');
}),
(new Extend\ApiSerializer(DiscussionSerializer::class))
->hasOne('lastPostedUser', UserSerializer::class),
(new Extend\ApiController(ListTagsController::class))
->addInclude('lastPostedDiscussion.lastPostedUser'),
];