1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace App\Models\Enums;
- use App\Models\Asset;
- use App\Models\Container;
- use App\Models\Plan;
- use App\Models\Project;
- use App\Models\Requirement;
- use App\Models\Task;
- use App\Services\History\Detector\ContainerContentDetector;
- use App\Services\History\Detector\ContainerDetector;
- 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";
- 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(),
- };
- }
- 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),
- };
- }
- public function nameField(): string
- {
- return match ($this) {
- self::ASSET, self::PROJECT, self::TASK => "name",
- self::PLAN => "title", self::REQUIREMENT => "title",
- default => "name",
- };
- }
- public function detectorClassName(): ?string
- {
- return match ($this) {
- ActionObjectType::PROJECT => ProjectDetector::class,
- ActionObjectType::REQUIREMENT => RequirementDetector::class,
- ActionObjectType::TASK => TaskDetector::class,
- ActionObjectType::CONTAINER => ContainerDetector::class,
- ActionObjectType::CONTAINER_CONTENT => ContainerContentDetector::class,
- default => null
- };
- }
- }
|