123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace App\Models\Enums;
- use App\Models\Asset;
- use App\Models\Container;
- use App\Models\File;
- use App\Models\Plan;
- use App\Models\Project;
- use App\Models\Requirement;
- use App\Models\Task;
- use App\Services\History\Detector\AssetDetector;
- use App\Services\History\Detector\ContainerContentDetector;
- use App\Services\History\Detector\ContainerDetector;
- use App\Services\History\Detector\FileDetector;
- use App\Services\History\Detector\ProjectDetector;
- use App\Services\History\Detector\RequirementDetector;
- use App\Services\History\Detector\TaskDetector;
- enum ActionObjectType: string
- {
- case ASSET = "asset";
- case PROJECT = "project";
- case REQUIREMENT = "requirement";
- case TASK = "task";
- case PLAN = "plan";
- case CONTAINER = "container";
- case CONTAINER_CONTENT = "container_content";
- case CONTAINER_FILE = "container_file";
- public function modelBuilder(): \Illuminate\Database\Eloquent\Builder
- {
- return match ($this) {
- self::ASSET => Asset::query(),
- self::PROJECT => Project::query(),
- self::TASK => Task::query(),
- self::PLAN => Plan::query(),
- self::REQUIREMENT => Requirement::query(),
- self::CONTAINER => Container::query(),
- self::CONTAINER_FILE => File::query(),
- };
- }
- public function modelBuilderAllowed(string $id = null): \Illuminate\Database\Eloquent\Builder
- {
- return match ($this) {
- self::ASSET => Asset::query()->allowed(),
- self::PROJECT => Project::query()->allowed($id),
- self::TASK => Task::query()->allowed($id),
- self::PLAN => Plan::query(),
- self::REQUIREMENT => Requirement::query(),
- self::CONTAINER => Container::query()->allowed($id),
- self::CONTAINER_FILE => File::query(),
- };
- }
- public function nameField(): string
- {
- return match ($this) {
- self::ASSET,
- self::PROJECT,
- self::TASK => "name",
- self::PLAN => "title",
- self::REQUIREMENT => "title",
- self::CONTAINER_FILE => 'title',
- default => "name",
- };
- }
- public function detectorClassName(): ?string
- {
- return match ($this) {
- ActionObjectType::ASSET => AssetDetector::class,
- ActionObjectType::PROJECT => ProjectDetector::class,
- ActionObjectType::REQUIREMENT => RequirementDetector::class,
- ActionObjectType::TASK => TaskDetector::class,
- ActionObjectType::CONTAINER => ContainerDetector::class,
- ActionObjectType::CONTAINER_CONTENT => ContainerContentDetector::class,
- ActionObjectType::CONTAINER_FILE => FileDetector::class,
- default => null
- };
- }
- }
|