ActionObjectType.php 3.2 KB

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