ActionObjectType.php 2.4 KB

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