ApprovalObjectType.php 1.8 KB

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