117 行
7.3 KiB
PHP
117 行
7.3 KiB
PHP
<?php
|
|
|
|
namespace XXB\CatchTheFish;
|
|
|
|
use XXB\CatchTheFish\Controllers;
|
|
use XXB\CatchTheFish\Api\Resource\FishResource;
|
|
use XXB\CatchTheFish\Api\Resource\RoundResource;
|
|
use Flarum\Api\Context;
|
|
use Flarum\Api\Endpoint;
|
|
use Flarum\Api\Resource;
|
|
use Flarum\Api\Schema;
|
|
use Flarum\Discussion\Discussion;
|
|
use Flarum\Extend;
|
|
use Flarum\Post\Post;
|
|
use Flarum\Settings\SettingsRepositoryInterface;
|
|
use Flarum\User\User;
|
|
|
|
return [
|
|
(new Extend\Frontend('forum'))
|
|
->css(__DIR__ . '/resources/less/forum.less')
|
|
->js(__DIR__ . '/js/dist/forum.js')
|
|
->route('/catch-the-fish', 'catch-the-fish-ranking')
|
|
->route('/catch-the-fish/rounds', 'catch-the-fish-rounds')
|
|
->route('/catch-the-fish/rounds/{id}', 'catch-the-fish-round'),
|
|
(new Extend\Frontend('admin'))
|
|
->css(__DIR__ . '/resources/less/admin.less')
|
|
->js(__DIR__ . '/js/dist/admin.js'),
|
|
|
|
(new Extend\Routes('api'))
|
|
->get('/catch-the-fish/rounds', 'catchthefish.api.rounds.index', Controllers\RoundIndexController::class)
|
|
->post('/catch-the-fish/rounds', 'catchthefish.api.rounds.store', Controllers\RoundStoreController::class)
|
|
->get('/catch-the-fish/rounds/{id:[0-9]+}', 'catchthefish.api.rounds.show', Controllers\RoundShowController::class)
|
|
->patch('/catch-the-fish/rounds/{id:[0-9]+}', 'catchthefish.api.rounds.update', Controllers\RoundUpdateController::class)
|
|
->delete('/catch-the-fish/rounds/{id:[0-9]+}', 'catchthefish.api.rounds.delete', Controllers\RoundDeleteController::class)
|
|
->get('/catch-the-fish/rounds/{id:[0-9]+}/fishes', 'catchthefish.api.fishes.index', Controllers\FishIndexController::class)
|
|
->post('/catch-the-fish/rounds/{id:[0-9]+}/fishes', 'catchthefish.api.fishes.store', Controllers\FishStoreController::class)
|
|
->post('/catch-the-fish/rounds/{id:[0-9]+}/fishes-from-images', 'catchthefish.api.fishes.store-image', Controllers\FishImageBulkController::class)
|
|
->patch('/catch-the-fish/fishes/{id:[0-9]+}', 'catchthefish.api.fishes.update', Controllers\FishUpdateController::class)
|
|
->delete('/catch-the-fish/fishes/{id:[0-9]+}', 'catchthefish.api.fishes.delete', Controllers\FishDeleteController::class)
|
|
->post('/catch-the-fish/fishes/{id:[0-9]+}/catch', 'catchthefish.api.fishes.catch', Controllers\FishCatchController::class)
|
|
->post('/catch-the-fish/fishes/{id:[0-9]+}/place', 'catchthefish.api.fishes.place', Controllers\FishPlaceController::class)
|
|
->post('/catch-the-fish/fishes/{id:[0-9]+}/image', 'catchthefish.api.fishes.image', Controllers\FishImageController::class)
|
|
->get('/catch-the-fish/rounds/{id:[0-9]+}/rankings', 'catchthefish.api.rankings.index', Controllers\RankingIndexController::class),
|
|
|
|
(new Extend\Locales(__DIR__ . '/resources/locale')),
|
|
|
|
new Extend\ApiResource(RoundResource::class),
|
|
new Extend\ApiResource(FishResource::class),
|
|
(new Extend\ApiResource(Resource\ForumResource::class))
|
|
->fields(fn() => [
|
|
Schema\Boolean::make('catchTheFishCanModerate')
|
|
->get(fn(object $forum, Context $context) => $context->getActor()->isAdmin() || $context->getActor()->can('catchthefish.moderate')),
|
|
Schema\Boolean::make('catchTheFishCanSeeRankingsPage')
|
|
->get(fn(object $forum, Context $context) => $context->getActor()->isAdmin() || $context->getActor()->can('catchthefish.list-rankings')),
|
|
Schema\Boolean::make('catchTheFishAlertRound')
|
|
->get(fn(object $forum, Context $context) => resolve(SettingsRepositoryInterface::class)->get('catch-the-fish.alertRound') !== '0'),
|
|
Schema\Boolean::make('catchTheFishAnimateFlip')
|
|
->get(fn(object $forum, Context $context) => resolve(SettingsRepositoryInterface::class)->get('catch-the-fish.animateFlip') !== '0'),
|
|
Schema\Relationship\ToMany::make('catchTheFishActiveRounds')
|
|
->type('catchthefish-rounds')
|
|
->includable()
|
|
->get(fn(object $forum, Context $context) => ($context->getActor()->isAdmin() || $context->getActor()->can('catchthefish.visible')) ? Round::activeRound()->get()->all() : []),
|
|
])
|
|
->endpoint(Endpoint\Show::class, fn(Endpoint\Show $endpoint) => $endpoint->addDefaultInclude(['catchTheFishActiveRounds'])),
|
|
(new Extend\ApiResource(Resource\DiscussionResource::class))
|
|
->fields(fn() => [
|
|
Schema\Relationship\ToMany::make('catchTheFishFishes')
|
|
->type('catchthefish-fishes')
|
|
->includable()
|
|
->get(fn(Discussion $discussion, Context $context) => ($context->getActor()->isAdmin() || $context->getActor()->can('catchthefish.visible')) ? $discussion->catchTheFishFishes()->activeFish()->get()->all() : []),
|
|
])
|
|
->endpoint([Endpoint\Index::class, Endpoint\Show::class], fn(Endpoint\Index|Endpoint\Show $endpoint) => $endpoint->addDefaultInclude(['catchTheFishFishes'])),
|
|
(new Extend\ApiResource(Resource\PostResource::class))
|
|
->fields(fn() => [
|
|
Schema\Relationship\ToMany::make('catchTheFishFishes')
|
|
->type('catchthefish-fishes')
|
|
->includable()
|
|
->get(fn(Post $post, Context $context) => ($context->getActor()->isAdmin() || $context->getActor()->can('catchthefish.visible')) ? $post->catchTheFishFishes()->activeFish()->get()->all() : []),
|
|
])
|
|
->endpoint([Endpoint\Index::class, Endpoint\Show::class], fn(Endpoint\Index|Endpoint\Show $endpoint) => $endpoint->addDefaultInclude(['catchTheFishFishes'])),
|
|
(new Extend\ApiResource(Resource\UserResource::class))
|
|
->fields(fn() => [
|
|
Schema\Relationship\ToMany::make('catchTheFishFishes')
|
|
->type('catchthefish-fishes')
|
|
->includable()
|
|
->get(fn(User $user, Context $context) => ($context->getActor()->isAdmin() || $context->getActor()->can('catchthefish.visible')) ? $user->catchTheFishFishes()->activeFish()->get()->all() : []),
|
|
Schema\Relationship\ToMany::make('catchTheFishBasket')
|
|
->type('catchthefish-fishes')
|
|
->includable()
|
|
->get(fn(User $user, Context $context) => $context->getActor()->id === $user->id ? $user->catchTheFishBasket()->get()->all() : []),
|
|
])
|
|
->endpoint([Endpoint\Index::class, Endpoint\Show::class], fn(Endpoint\Index|Endpoint\Show $endpoint) => $endpoint->addDefaultInclude(['catchTheFishFishes', 'catchTheFishBasket'])),
|
|
|
|
(new Extend\Model(Discussion::class))
|
|
->relationship('catchTheFishFishes', function ($model) {
|
|
return (new ConfigureFishesRelationship('discussion_id_placement'))($model);
|
|
}),
|
|
(new Extend\Model(Post::class))
|
|
->relationship('catchTheFishFishes', function ($model) {
|
|
return (new ConfigureFishesRelationship('post_id_placement'))($model);
|
|
}),
|
|
(new Extend\Model(User::class))
|
|
->relationship('catchTheFishFishes', function ($model) {
|
|
return (new ConfigureFishesRelationship('user_id_placement'))($model);
|
|
})
|
|
->relationship('catchTheFishBasket', function ($model) {
|
|
return (new ConfigureBasketRelationship())($model);
|
|
}),
|
|
|
|
(new Extend\Policy())
|
|
->modelPolicy(Fish::class, Access\FishPolicy::class)
|
|
->modelPolicy(Round::class, Access\RoundPolicy::class),
|
|
|
|
(new Extend\ServiceProvider())
|
|
->register(Providers\StorageServiceProvider::class),
|
|
];
|