ActionObjectType.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App\Models\Enums;
  3. use App\Models\Asset;
  4. use App\Models\Container;
  5. use App\Models\Plan;
  6. use App\Models\Project;
  7. use App\Models\Requirement;
  8. use App\Models\Task;
  9. use App\Services\History\Detector\ContainerContentDetector;
  10. use App\Services\History\Detector\ContainerDetector;
  11. use App\Services\History\Detector\ProjectDetector;
  12. use App\Services\History\Detector\RequirementDetector;
  13. use App\Services\History\Detector\TaskDetector;
  14. enum ActionObjectType: string
  15. {
  16. case ASSET = "asset";
  17. case PROJECT = "project";
  18. case REQUIREMENT = "requirement";
  19. case TASK = "task";
  20. case PLAN = "plan";
  21. case CONTAINER = "container";
  22. case CONTAINER_CONTENT = "container_content";
  23. public function modelBuilder(): \Illuminate\Database\Eloquent\Builder
  24. {
  25. return match ($this) {
  26. self::ASSET => Asset::query(),
  27. self::PROJECT => Project::query(),
  28. self::TASK => Task::query(),
  29. self::PLAN => Plan::query(),
  30. self::REQUIREMENT => Requirement::query(),
  31. self::CONTAINER => Container::query(),
  32. };
  33. }
  34. public function modelBuilderAllowed(string $id = null): \Illuminate\Database\Eloquent\Builder
  35. {
  36. return match ($this) {
  37. self::ASSET => Asset::query()->allowed(),
  38. self::PROJECT => Project::query()->allowed($id),
  39. self::TASK => Task::query()->allowed($id),
  40. self::PLAN => Plan::query(),
  41. self::REQUIREMENT => Requirement::query(),
  42. self::CONTAINER => Container::query()->allowed($id),
  43. };
  44. }
  45. public function nameField(): string
  46. {
  47. return match ($this) {
  48. self::ASSET, self::PROJECT, self::TASK => "name",
  49. self::PLAN => "title", self::REQUIREMENT => "title",
  50. default => "name",
  51. };
  52. }
  53. public function detectorClassName(): ?string
  54. {
  55. return match ($this) {
  56. ActionObjectType::PROJECT => ProjectDetector::class,
  57. ActionObjectType::REQUIREMENT => RequirementDetector::class,
  58. ActionObjectType::TASK => TaskDetector::class,
  59. ActionObjectType::CONTAINER => ContainerDetector::class,
  60. ActionObjectType::CONTAINER_CONTENT => ContainerContentDetector::class,
  61. default => null
  62. };
  63. }
  64. }