ApprovalFlowObjectType.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Models\Enums;
  3. use App\Models\Asset;
  4. use App\Models\Container;
  5. use App\Models\Plan;
  6. use App\Models\Project;
  7. use App\Models\Requirement;
  8. use App\Models\Task;
  9. use App\Services\History\Detector\AssetDetector;
  10. use App\Services\History\Detector\ContainerContentDetector;
  11. use App\Services\History\Detector\ContainerDetector;
  12. use App\Services\History\Detector\ProjectDetector;
  13. use App\Services\History\Detector\RequirementDetector;
  14. use App\Services\History\Detector\TaskDetector;
  15. enum ApprovalFlowObjectType: string
  16. {
  17. case ASSET = "asset";
  18. case PROJECT = "project";
  19. case REQUIREMENT = "requirement";
  20. case TASK = "task";
  21. case CONTAINER = "container";
  22. public function modelBuilder(): \Illuminate\Database\Eloquent\Builder
  23. {
  24. return match ($this) {
  25. self::ASSET => Asset::query(),
  26. self::PROJECT => Project::query(),
  27. self::TASK => Task::query(),
  28. self::REQUIREMENT => Requirement::query(),
  29. self::CONTAINER => Container::query(),
  30. };
  31. }
  32. public function modelBuilderAllowed(string $id = null): \Illuminate\Database\Eloquent\Builder
  33. {
  34. return match ($this) {
  35. self::ASSET => Asset::query()->allowed(),
  36. self::PROJECT => Project::query()->allowed($id),
  37. self::TASK => Task::query()->allowed($id),
  38. self::REQUIREMENT => Requirement::query(),
  39. self::CONTAINER => Container::query()->allowed($id),
  40. };
  41. }
  42. }