1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 16:13:20 +01:00
invoiceninja/app/Transformers/TaskTransformer.php

74 lines
2.5 KiB
PHP
Raw Normal View History

2020-01-21 01:32:34 +01:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
2020-01-21 01:32:34 +01:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2020-01-21 01:32:34 +01:00
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Transformers;
2020-10-11 23:36:59 +02:00
use App\Models\Document;
2020-01-21 01:32:34 +01:00
use App\Models\Task;
use App\Utils\Traits\MakesHash;
/**
* class TaskTransformer.
2020-01-21 01:32:34 +01:00
*/
class TaskTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [
2020-10-11 23:36:59 +02:00
'documents'
2020-01-21 01:32:34 +01:00
];
/**
* @var array
*/
protected $availableIncludes = [
2020-10-11 23:36:59 +02:00
'documents'
2020-01-21 01:32:34 +01:00
];
2020-10-12 01:27:38 +02:00
public function includeDocuments(Task $task)
2020-10-11 23:36:59 +02:00
{
$transformer = new DocumentTransformer($this->serializer);
return $this->includeCollection($task->documents, $transformer, Document::class);
}
2020-01-21 01:32:34 +01:00
public function transform(Task $task)
{
return [
'id' => (string) $this->encodePrimaryKey($task->id),
2020-10-12 22:42:02 +02:00
'user_id' => (string) $this->encodePrimaryKey($task->user_id),
'assigned_user_id' => (string) $this->encodePrimaryKey($task->assigned_user_id),
'number' => (string) $task->number ?: '',
// 'start_time' => (int) $task->start_time,
2020-10-26 22:54:59 +01:00
'description' => (string) $task->description ?: '',
'duration' => (int) $task->duration ?: 0,
2020-10-26 20:10:04 +01:00
'rate' => (float) $task->rate ?: 0,
'created_at' => (int) $task->created_at,
'updated_at' => (int) $task->updated_at,
'archived_at' => (int) $task->deleted_at,
2020-10-26 22:54:59 +01:00
'invoice_id' => $this->encodePrimaryKey($task->invoice_id) ?: '',
'client_id' => $this->encodePrimaryKey($task->client_id) ?: '',
'project_id' => $this->encodePrimaryKey($task->project_id) ?: '',
2020-01-21 01:32:34 +01:00
'is_deleted' => (bool) $task->is_deleted,
'time_log' => $task->time_log ?: '',
2021-01-15 12:01:44 +01:00
'is_running' => (bool) $task->is_running, //@deprecate
2020-01-21 01:32:34 +01:00
'custom_value1' => $task->custom_value1 ?: '',
'custom_value2' => $task->custom_value2 ?: '',
'custom_value3' => $task->custom_value3 ?: '',
'custom_value4' => $task->custom_value4 ?: '',
2020-10-26 22:54:59 +01:00
'status_id' => $this->encodePrimaryKey($task->status_id) ?: '',
2021-01-06 00:36:20 +01:00
'status_sort_order' => (int) $task->status_sort_order, //deprecated 5.0.34
2020-12-14 22:52:14 +01:00
'is_date_based' => (bool) $task->is_date_based,
2021-01-22 11:55:03 +01:00
'status_order' => is_null($task->status_order) ? null : (int)$task->status_order,
2020-01-21 01:32:34 +01:00
];
}
}