ActionObjectType.php 2.7 KB

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