ActionObjectType.php 1.8 KB

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