Files
laravel-manager-packagist/src/Modules/Posts/PostsModule.php
T

82 lines
2.8 KiB
PHP

<?php
namespace IriksIT\Manager\Modules\Posts;
use IriksIT\Manager\Models\Post;
use IriksIT\Manager\Modules\BaseModule;
use IriksIT\Manager\Support\MediaUsage;
use IriksIT\Manager\Support\Names;
use IriksIT\Manager\Support\Permission;
class PostsModule extends BaseModule
{
public function key(): string
{
return 'posts';
}
public function label(): string
{
return 'Posts';
}
public function enabledByDefault(): bool
{
return false;
}
public function tables(): array
{
return ['posts', 'post_labels'];
}
public function permissions(): array
{
return [
new Permission('posts.view', 'See the posts, drafts included', 'Posts'),
new Permission('posts.write', 'Write posts: create drafts and change them', 'Posts', needs: ['posts.view']),
new Permission('posts.publish', 'Publish, schedule and unpublish posts, and change posts that are live', 'Posts', needs: ['posts.view', 'posts.write']),
new Permission('posts.delete', 'Delete posts (one that is live only together with publishing)', 'Posts', needs: ['posts.view']),
new Permission('posts.labels', 'Manage the categories and tags: make them, and rename, merge and remove them on all posts', 'Posts', needs: ['posts.view']),
];
}
public function navigation(): array
{
return [
['label' => 'Posts', 'route' => Names::route('posts.index'), 'permission' => 'posts.view'],
['label' => 'Categories and tags', 'route' => Names::route('labels.index'), 'permission' => 'posts.labels'],
];
}
public function actions(): array
{
return [
'posts.store' => ['Created a post'],
'posts.update' => ['Changed a post'],
'posts.online' => ['Put a post on the site, or took it off', ['online']],
'posts.destroy' => ['Deleted a post'],
'labels.store' => ['Made a category or tag', ['type', 'name']],
'labels.update' => ['Renamed a category or tag', ['type', 'name', 'new_name']],
'labels.destroy' => ['Removed a category or tag', ['type', 'name']],
];
}
public function views(): array
{
return [
'posts.index' => 'Opened the posts',
'posts.create' => 'Opened the form for a new post',
'posts.edit' => 'Opened a post',
'posts.preview' => 'Opened the preview of a post',
'labels.index' => 'Opened the categories and tags',
];
}
/** Where the media library looks for the use of a file: the texts of the posts. */
public function boot(): void
{
app(MediaUsage::class)->register(fn () => Post::query()->get(['body', 'excerpt', 'cover_image'])->flatMap(fn (Post $row) => array_values($row->only(['body', 'excerpt', 'cover_image']))));
}
}