ActionObjectType.php 3.0 KB

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