-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextend.php
75 lines (59 loc) · 2.89 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
<?php
/*
* This file is part of foskym/flarum-custom-levels.
*
* Copyright (c) 2024 FoskyM.
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace FoskyM\CustomLevels;
use Flarum\Extend;
use Flarum\User\User;
use Flarum\Api\Controller\ListUsersController;
use Flarum\Api\Serializer\UserSerializer;
use FoskyM\CustomLevels\UserAttributes;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\Extension\ExtensionManager;
return [
(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'),
new Extend\Locales(__DIR__ . '/locale'),
(new Extend\Settings())
->serializeToForum('foskym-custom-levels.levelText', 'foskym-custom-levels.levelText')
->serializeToForum('foskym-custom-levels.expText', 'foskym-custom-levels.expText')
->serializeToForum('foskym-custom-levels.expFormula', 'foskym-custom-levels.expFormula')
->serializeToForum('foskym-custom-levels.levelFormula', 'foskym-custom-levels.levelFormula'),
(new Extend\Console())
->command(Command\RefreshExpCommand::class)
->command(Command\RefreshQuestExpCommand::class)
->command(Command\DeleteExpLogsCommand::class),
(new Extend\Model(User::class))
->cast('exp', 'int'),
(new Extend\ApiSerializer(UserSerializer::class))
->attributes(UserAttributes::class)
->attribute('exp', function (UserSerializer $serializer, User $user) {
return (int) $user->exp;
})
->attribute('canEditExp', function (UserSerializer $serializer, User $user) {
return $serializer->getActor()->can('edit_exp', $user);
}),
(new Extend\ApiController(ListUsersController::class))
->addSortField('exp'),
(new Extend\Routes('api'))
->get('/exp/refresh', 'custom-levels.exp.refresh', Api\Controller\RefreshExpController::class)
->get('/exp-logs', 'custom-levels.exp-logs.list', Api\Controller\ListExpLogsController::class)
->get('/levels', 'custom-levels.levels.list', Api\Controller\ListLevelsController::class)
->post('/levels', 'custom-levels.levels.create', Api\Controller\CreateLevelController::class)
->patch('/levels/{id}', 'custom-levels.levels.update', Api\Controller\UpdateLevelController::class)
->delete('/levels/{id}', 'custom-levels.levels.delete', Api\Controller\DeleteLevelController::class),
(new Extend\Event())
->listen(Event\ExpUpdated::class, Listeners\ExpUpdatedListener::class),
(new Extend\Notification())
->type(Notification\LevelUpdatedNotification::class, Api\Serializer\LevelSerializer::class, ['alert']),
require(__DIR__ . '/src/Integration/Integrations.php')
];