72 lines
3.3 KiB
PHP
72 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class PublicDocumentCollectionResource extends JsonResource
|
|
{
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'slug' => $this->public_uuid,
|
|
'public_uuid' => $this->public_uuid,
|
|
'title' => $this->title,
|
|
'document_number' => $this->document_number,
|
|
'summary' => $this->description,
|
|
'description' => $this->description,
|
|
'status' => $this->status,
|
|
'status_label' => $this->getStatusLabel(),
|
|
'access_level' => $this->access_level,
|
|
'access_level_label' => $this->getAccessLevelLabel(),
|
|
'published_at' => $this->created_at?->toIso8601String(),
|
|
'updated_at' => $this->updated_at?->toIso8601String(),
|
|
'expires_at' => $this->expires_at?->toDateString(),
|
|
'version_count' => $this->version_count,
|
|
'category' => $this->whenLoaded('category', function () {
|
|
return [
|
|
'id' => $this->category->id,
|
|
'name' => $this->category->name,
|
|
'slug' => $this->category->slug,
|
|
'icon' => $this->category->icon,
|
|
];
|
|
}),
|
|
'current_version' => $this->whenLoaded('currentVersion', function () {
|
|
if (! $this->currentVersion) {
|
|
return null;
|
|
}
|
|
|
|
return [
|
|
'id' => $this->currentVersion->id,
|
|
'version_number' => $this->currentVersion->version_number,
|
|
'version_notes' => $this->currentVersion->version_notes,
|
|
'is_current' => (bool) $this->currentVersion->is_current,
|
|
'original_filename' => $this->currentVersion->original_filename,
|
|
'mime_type' => $this->currentVersion->mime_type,
|
|
'file_extension' => $this->currentVersion->getFileExtension(),
|
|
'file_size' => $this->currentVersion->file_size,
|
|
'file_size_human' => $this->currentVersion->getFileSizeHuman(),
|
|
'file_hash' => $this->currentVersion->file_hash,
|
|
'uploaded_by' => $this->currentVersion->uploadedBy?->name,
|
|
'uploaded_at' => $this->currentVersion->uploaded_at?->toIso8601String(),
|
|
'download_url' => route('documents.public.download', $this->public_uuid),
|
|
];
|
|
}),
|
|
'links' => [
|
|
'api_url' => url('/api/v1/public-documents/'.$this->public_uuid),
|
|
'detail_url' => route('documents.public.show', $this->public_uuid),
|
|
'web_url' => route('documents.public.show', $this->public_uuid),
|
|
'download_url' => route('documents.public.download', $this->public_uuid),
|
|
],
|
|
'metadata' => [
|
|
'document_type' => $this->category?->name,
|
|
'expiration_status' => $this->getExpirationStatusLabel(),
|
|
'auto_archive_on_expiry' => (bool) $this->auto_archive_on_expiry,
|
|
'expiry_notice' => $this->expiry_notice,
|
|
],
|
|
];
|
|
}
|
|
}
|