TaskDetailResource.php 2.8 KB

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