forked from FriendsOfFlarum/polls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extend.php
executable file
·78 lines (61 loc) · 2.95 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
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
<?php
/*
* This file is part of fof/polls.
*
* Copyright (c) FriendsOfFlarum.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FoF\Polls;
use Flarum\Api\Controller;
use Flarum\Api\Serializer\DiscussionSerializer;
use Flarum\Api\Serializer\UserSerializer;
use Flarum\Discussion\Discussion;
use Flarum\Discussion\Event\Saving;
use Flarum\Extend;
use FoF\Polls\Api\Controllers;
use FoF\Polls\Api\Serializers\PollSerializer;
return [
(new Extend\Frontend('forum'))
->js(__DIR__.'/js/dist/forum.js')
->css(__DIR__.'/resources/less/forum.less'),
(new Extend\Frontend('admin'))
->js(__DIR__.'/js/dist/admin.js')
->css(__DIR__.'/resources/less/admin.less'),
new Extend\Locales(__DIR__.'/resources/locale'),
(new Extend\Routes('api'))
->patch('/fof/polls/{id}', 'fof.polls.edit', Controllers\EditPollController::class)
->delete('/fof/polls/{id}', 'fof.polls.delete', Controllers\DeletePollController::class)
->patch('/fof/polls/{id}/vote', 'fof.polls.vote', Controllers\VotePollController::class),
(new Extend\Model(Discussion::class))
->hasOne('poll', Poll::class, 'discussion_id', 'id'),
(new Extend\Event())
->listen(Saving::class, Listeners\SavePollsToDatabase::class),
(new Extend\ApiSerializer(DiscussionSerializer::class))
->hasOne('poll', PollSerializer::class),
(new Extend\ApiSerializer(UserSerializer::class))
->attributes(function (UserSerializer $serializer): array {
return [
'canEditPolls' => $serializer->getActor()->can('discussion.polls'),
'canStartPolls' => $serializer->getActor()->can('startPolls'),
'canSelfEditPolls' => $serializer->getActor()->can('selfEditPolls'),
'canVotePolls' => $serializer->getActor()->can('votePolls'),
];
}),
(new Extend\ApiController(Controller\ListDiscussionsController::class))
->addInclude('poll'),
(new Extend\ApiController(Controller\ShowDiscussionController::class))
->addInclude(['poll', 'poll.options', 'poll.myVotes', 'poll.myVotes.option'])
->addOptionalInclude(['poll.votes', 'poll.votes.user', 'poll.votes.option']),
(new Extend\ApiController(Controller\CreateDiscussionController::class))
->addInclude(['poll', 'poll.options', 'poll.myVotes', 'poll.myVotes.option'])
->addOptionalInclude(['poll.votes', 'poll.votes.user', 'poll.votes.option']),
(new Extend\ApiController(Controller\UpdateDiscussionController::class))
->addInclude(['poll', 'poll.options', 'poll.myVotes', 'poll.myVotes.option'])
->addOptionalInclude(['poll.votes', 'poll.votes.user', 'poll.votes.option']),
(new Extend\Console())
->command(Console\RefreshVoteCountCommand::class),
(new Extend\Policy())
->modelPolicy(Poll::class, Access\PollPolicy::class),
];