Files
2026-01-26 14:30:59 +01:00

68 lines
3.1 KiB
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class SubTaskResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
*
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
$data = [
'id' => $this->id,
'is_draft' => $this->is_draft,
'type' => $this->type,
'created_by' => $this->created_by,
'master_task' => $this->mastertask->title,
'master_task_description' => $this->mastertask->description,
'master_task_deadline' => $this->mastertask->deadline,
'master_task_id' => $this->mastertask->id,
'description' => $this->description,
'project_code' => ($this->mastertask->project) ? $this->mastertask->project->code . ' ' . $this->mastertask->project->name : null,
'title' => $this->title,
'team_id' => ($this->mastertask->team) ? $this->mastertask->team->id : null,
'team' => $this->mastertask->team,
'employee_id' => $this->user->id,
'duration' => $this->estimated_time,
'spent_time' => $this->tracked_time,
'deadline' => $this->deadline,
'office365_location' => $this->office365_location,
'is_finished' => $this->is_finished,
'timeblocks' => TimeblockResource::collection($this->timeblocks),
'timesheets' => TimesheetResource::collection($this->timesheets),
'files' => AttachmentResource::collection($this->attachments->isNotEmpty() ? $this->attachments : $this->mastertask->attachments),
'color' => $this->mastertask->color,
];
// Pre drafty pridáme employees dáta
if ($this->is_draft && $this->draft_data) {
$data['employees'] = $this->draft_data;
// Agregované timeblocks zo všetkých zamestnancov pre kalendárne zobrazenie
$allDraftTimeblocks = [];
foreach ($this->draft_data as $employee) {
if (isset($employee['timeblocks']) && is_array($employee['timeblocks'])) {
foreach ($employee['timeblocks'] as $timeblock) {
$allDraftTimeblocks[] = [
'employee_id' => $employee['id'],
'start' => $timeblock['start'] ?? null,
'end' => $timeblock['end'] ?? null,
'is_finished' => $timeblock['is_finished'] ?? false,
];
}
}
}
$data['all_draft_timeblocks'] = $allDraftTimeblocks;
}
return $data;
}
}