1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00
invoiceninja/app/Ninja/Transformers/TaskTransformer.php

56 lines
1.7 KiB
PHP
Raw Normal View History

2017-01-30 20:40:43 +01:00
<?php
namespace App\Ninja\Transformers;
2015-11-27 13:55:28 +01:00
use App\Models\Account;
use App\Models\Client;
2017-01-30 20:40:43 +01:00
use App\Models\Task;
2015-11-27 13:55:28 +01:00
/**
* @SWG\Definition(definition="Task", @SWG\Xml(name="Task"))
*/
class TaskTransformer extends EntityTransformer
{
/**
2017-01-30 20:40:43 +01:00
* @SWG\Property(property="id", type="integer", example=1, readOnly=true)
* @SWG\Property(property="amount", type="number", format="float", example=10, readOnly=true)
2017-01-30 20:40:43 +01:00
* @SWG\Property(property="invoice_id", type="integer", example=1)
*/
2015-11-27 13:55:28 +01:00
protected $availableIncludes = [
'client',
];
public function __construct(Account $account)
{
parent::__construct($account);
}
public function includeClient(Task $task)
{
if ($task->client) {
$transformer = new ClientTransformer($this->account, $this->serializer);
2017-01-30 20:40:43 +01:00
2015-11-27 13:55:28 +01:00
return $this->includeItem($task->client, $transformer, 'client');
} else {
return null;
}
}
public function transform(Task $task)
{
2016-05-03 22:02:29 +02:00
return array_merge($this->getDefaults($task), [
2015-11-27 13:55:28 +01:00
'id' => (int) $task->public_id,
'description' => $task->description,
'duration' => $task->getDuration(),
'updated_at' => (int) $this->getTimestamp($task->updated_at),
'archived_at' => (int) $this->getTimestamp($task->deleted_at),
2017-04-11 23:17:01 +02:00
'invoice_id' => $task->invoice ? (int) $task->invoice->public_id : 0,
'client_id' => $task->client ? (int) $task->client->public_id : 0,
'project_id' => $task->project ? (int) $task->project->public_id : 0,
'is_deleted' => (bool) $task->is_deleted,
'time_log' => $task->time_log,
'is_running' => (bool) $task->is_running,
2016-05-03 22:02:29 +02:00
]);
2015-11-27 13:55:28 +01:00
}
2016-11-16 12:12:10 +01:00
}