framework/extensions/mentions/src/MentionsServiceProvider.php

61 lines
2.6 KiB
PHP
Raw Normal View History

2015-05-14 20:31:03 +08:00
<?php namespace Flarum\Mentions;
use Flarum\Support\ServiceProvider;
2015-05-17 08:50:18 +08:00
use Flarum\Extend\EventSubscribers;
use Flarum\Extend\ForumAssets;
use Flarum\Extend\Relationship;
use Flarum\Extend\SerializeRelationship;
use Flarum\Extend\ApiInclude;
use Flarum\Extend\Formatter;
use Flarum\Extend\NotificationType;
2015-05-14 20:31:03 +08:00
class MentionsServiceProvider extends ServiceProvider
{
2015-05-17 08:50:18 +08:00
public function boot()
2015-05-14 20:31:03 +08:00
{
2015-05-17 08:50:18 +08:00
$this->extend(
new EventSubscribers([
'Flarum\Mentions\Handlers\PostMentionsMetadataUpdater',
'Flarum\Mentions\Handlers\UserMentionsMetadataUpdater'
]),
2015-05-14 20:31:03 +08:00
2015-05-17 08:50:18 +08:00
new ForumAssets([
__DIR__.'/../js/dist/extension.js',
__DIR__.'/../less/mentions.less'
]),
2015-05-14 20:31:03 +08:00
2015-05-17 08:50:18 +08:00
new Relationship('Flarum\Core\Models\Post', function ($model) {
return $model->belongsToMany('Flarum\Core\Models\Post', 'mentions_posts', 'mentions_id');
}, 'mentionedBy'),
2015-05-14 20:31:03 +08:00
2015-05-17 08:50:18 +08:00
new Relationship('Flarum\Core\Models\Post', function ($model) {
return $model->belongsToMany('Flarum\Core\Models\Post', 'mentions_posts', 'post_id', 'mentions_id');
}, 'mentionsPosts'),
2015-05-14 20:31:03 +08:00
2015-05-17 08:50:18 +08:00
new Relationship('Flarum\Core\Models\Post', function ($model) {
return $model->belongsToMany('Flarum\Core\Models\User', 'mentions_users', 'post_id', 'mentions_id');
}, 'mentionsUsers'),
2015-05-14 20:31:03 +08:00
2015-05-17 08:50:18 +08:00
new SerializeRelationship('Flarum\Api\Serializers\PostSerializer', 'hasMany', 'mentionedBy', 'Flarum\Api\Serializers\PostBasicSerializer'),
2015-05-14 20:31:03 +08:00
2015-05-17 08:50:18 +08:00
new SerializeRelationship('Flarum\Api\Serializers\PostSerializer', 'hasMany', 'mentionsPosts', 'Flarum\Api\Serializers\PostBasicSerializer'),
2015-05-14 20:31:03 +08:00
2015-05-17 08:50:18 +08:00
new SerializeRelationship('Flarum\Api\Serializers\PostSerializer', 'hasMany', 'mentionsUsers', 'Flarum\Api\Serializers\UserBasicSerializer'),
2015-05-14 20:31:03 +08:00
2015-05-17 08:50:18 +08:00
new ApiInclude('discussions.show', ['posts.mentionedBy', 'posts.mentionedBy.user', 'posts.mentionsPosts', 'posts.mentionsPosts.user', 'posts.mentionsUsers'], true),
2015-05-14 20:31:03 +08:00
2015-05-17 08:50:18 +08:00
new ApiInclude(['posts.index', 'posts.show'], ['mentionedBy', 'mentionedBy.user'], true),
2015-05-14 20:31:03 +08:00
2015-05-17 08:50:18 +08:00
new ApiInclude(['posts.create'], ['mentionsPosts', 'mentionsPosts.mentionedBy'], true),
2015-05-14 20:31:03 +08:00
2015-05-17 08:50:18 +08:00
new Formatter('postMentions', 'Flarum\Mentions\PostMentionsFormatter'),
2015-05-14 20:31:03 +08:00
2015-05-17 08:50:18 +08:00
new Formatter('userMentions', 'Flarum\Mentions\UserMentionsFormatter'),
2015-05-14 20:31:03 +08:00
2015-05-17 08:50:18 +08:00
(new NotificationType('Flarum\Mentions\PostMentionedNotification'))->enableByDefault('alert'),
2015-05-14 20:31:03 +08:00
2015-05-17 08:50:18 +08:00
(new NotificationType('Flarum\Mentions\UserMentionedNotification'))->enableByDefault('alert')
);
2015-05-14 20:31:03 +08:00
}
}