FileByObjectResource.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Http\Resources\API;
  3. use App\Libraries\BIM\BIMFactory;
  4. use App\Models\Enums\BimFileConvertStatus;
  5. use App\Models\Enums\ObjectApprovalStatus;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Http\Resources\Json\JsonResource;
  8. use Illuminate\Support\Facades\Storage;
  9. class FileByObjectResource extends JsonResource
  10. {
  11. /**
  12. * Transform the resource into an array.
  13. *
  14. * @return array<string, mixed>
  15. */
  16. public function toArray(Request $request): array
  17. {
  18. $data = [
  19. 'id' => $this->id,
  20. 'title' => $this->title,
  21. 'extension' => $this->extension,
  22. 'download_url' => Storage::url($this->pathname),
  23. 'size' => $this->size,
  24. 'created_by' => $this->createdBy ? new UserProfileResource($this->createdBy) : null,
  25. 'updated_by' => $this->updatedBy ? new UserProfileResource($this->updatedBy) : null,
  26. 'created_at' => (string) $this->created_at,
  27. 'updated_at' => (string) $this->updated_at,
  28. 'version' => $this->version,
  29. 'display_id'=>(string)$this->display_id,
  30. 'object_type'=>$this->object_type,
  31. 'object_id'=>$this->object_id,
  32. 'approval_status'=> ObjectApprovalStatus::getStatus($this->approval_status),
  33. 'naming_rule' => $this->namingRule ? new NamingRuleSimpleResource($this->namingRule) : null,
  34. 'naming_rules' => $this->naming_rules,
  35. 'doc_stage' => $this->doc_stage,
  36. 'doc_type' => $this->doc_type,
  37. "custom_fields" => $this->custom_fields,
  38. 'bim_file' => $this->bimFile ? new BimFileResource($this->bimFile) : null,
  39. ];
  40. if ($this->is_bim == 1 && $this->bimFile && $this->bimFile->convert_status == BimFileConvertStatus::DONE->value) {
  41. $data['model_preview'] = true;
  42. }
  43. return $data;
  44. }
  45. }