ActionObjectType.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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\DetectorContact;
  9. use App\Services\History\Detector\ProjectDetector;
  10. use App\Services\History\Detector\RequirementDetector;
  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. public function modelBuilder(): \Illuminate\Database\Eloquent\Builder
  19. {
  20. return match ($this) {
  21. self::ASSET => Asset::query(),
  22. self::PROJECT => Project::query(),
  23. self::TASK => Task::query(),
  24. self::PLAN => Plan::query(),
  25. self::REQUIREMENT => Requirement::query(),
  26. };
  27. }
  28. public function nameField(): string
  29. {
  30. return match ($this) {
  31. self::ASSET, self::PROJECT, self::TASK => "name",
  32. self::PLAN, self::REQUIREMENT => "title",
  33. default => "name",
  34. };
  35. }
  36. public function detectorClassName(): ?string
  37. {
  38. return match ($this) {
  39. ActionObjectType::PROJECT => ProjectDetector::class,
  40. ActionObjectType::REQUIREMENT => RequirementDetector::class,
  41. default => null
  42. };
  43. }
  44. }