TaskDetailResource.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Http\Resources\API;
  3. use App\Models\User;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Resources\Json\JsonResource;
  6. class TaskDetailResource extends JsonResource
  7. {
  8. /**
  9. * Transform the resource into an array.
  10. *
  11. * @return array<string, mixed>
  12. */
  13. public function toArray(Request $request): array
  14. {
  15. $whitelist=make_array_list($this->whitelist??'');
  16. $whitelistName=User::query()->whereIn('id',$whitelist)->get();
  17. $mailto=$this->mailto;
  18. $mailtoName=User::query()->whereIn('id',$mailto)->get();
  19. return [
  20. "id" => $this->id,
  21. "name" => $this->name,
  22. "project_id" => $this->project_id,
  23. "project" => new ProjectSimpleResource($this->project),
  24. "requirement_id" => $this->requirement_id,
  25. "requirement" => new RequirementSimpleResource($this->requirement),
  26. "requirement_group_id"=> $this->requirement_group_id,
  27. "naming_rule_id" => $this->naming_rule_id,
  28. "naming_rule" => new NamingRuleSimpleResource($this->namingRule),
  29. "naming_custom_fields" => $this->naming_rules,
  30. "parent_id" => $this->parent_id,
  31. "task_type" => $this->task_type,
  32. "doc_stage" => $this->doc_stage,
  33. "doc_type" => $this->doc_type,
  34. "status" => $this->status,
  35. 'approval_status' => $this->approval_status,
  36. "assign" => $this->assign,
  37. 'description' => $this->description ? (new \App\Services\File\ImageUrlService)->getImageUrl($this->description) : null,
  38. "begin" => $this->begin,
  39. "end" => $this->end,
  40. "mailto" => $mailto,
  41. "mailto_name" =>UserProfileResource::collection($mailtoName),
  42. "email_subject" => $this->email_subject,
  43. "acl" => $this->acl,
  44. "whitelist" => $whitelist,
  45. "whitelist_name"=>UserProfileResource::collection($whitelistName),
  46. "closed_by" => new UserProfileResource($this->closedBy),
  47. "closed_at" => $this->closed_at,
  48. "canceled_by" => new UserProfileResource($this->canceledBy),
  49. "canceled_at" => $this->canceled_at,
  50. "approve_by" => new UserProfileResource($this->approveBy),
  51. "approve_at" => $this->approve_at,
  52. "finished_by" => new UserProfileResource($this->finishedBy),
  53. "finished_at" => $this->finished_at,
  54. "review_by" => new UserProfileResource($this->reviewBy),
  55. "review_at" => $this->review_at,
  56. "created_by" => new UserProfileResource($this->createdBy),
  57. "custom_fields" => $this->custom_fields,
  58. "created_at" => (string)$this->created_at,
  59. "updated_at" => (string)$this->updated_at,
  60. "containers" => ContainerSimpleResource::collection($this->containers),
  61. ];
  62. }
  63. }