1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-06 03:02:34 +01:00
invoiceninja/app/Transformers/ProjectTransformer.php

67 lines
2.1 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) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Transformers;
2020-10-11 23:34:02 +02:00
use App\Models\Document;
2020-01-21 01:32:34 +01:00
use App\Models\Project;
use App\Utils\Traits\MakesHash;
/**
* class ProjectTransformer.
2020-01-21 01:32:34 +01:00
*/
class ProjectTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [
2020-10-11 23:34:02 +02:00
'documents',
2020-01-21 01:32:34 +01:00
];
/**
* @var array
*/
protected $availableIncludes = [
2020-10-11 23:34:02 +02:00
'documents'
2020-01-21 01:32:34 +01:00
];
2020-10-11 23:34:02 +02:00
public function includeDocuments(Project $project)
{
$transformer = new DocumentTransformer($this->serializer);
return $this->includeCollection($project->documents, $transformer, Document::class);
}
2020-01-21 01:32:34 +01:00
public function transform(Project $project)
{
return [
'id' => (string) $this->encodePrimaryKey($project->id),
2020-10-08 00:25:39 +02:00
'user_id' => (string) $this->encodePrimaryKey($project->user_id),
'assigned_user_id' => (string) $this->encodePrimaryKey($project->assigned_user_id),
2020-01-21 01:32:34 +01:00
'client_id' => (string) $this->encodePrimaryKey($project->client_id),
2020-10-08 00:25:39 +02:00
'name' => $project->name ?: '',
'created_at' => (int) $project->created_at,
'updated_at' => (int) $project->updated_at,
'archived_at' => (int) $project->deleted_at,
2020-01-21 01:32:34 +01:00
'is_deleted' => (bool) $project->is_deleted,
'task_rate' => (float) $project->task_rate,
'due_date' => $project->due_date ?: '',
2020-10-08 00:25:39 +02:00
'private_notes' => (string) $project->private_notes ?: '',
'public_notes' => (string) $project->public_notes ?: '',
2020-01-21 01:32:34 +01:00
'budgeted_hours' => (float) $project->budgeted_hours,
2020-10-08 00:25:39 +02:00
'custom_value1' => (string) $project->custom_value1 ?: '',
'custom_value2' => (string) $project->custom_value2 ?: '',
'custom_value3' => (string) $project->custom_value3 ?: '',
'custom_value4' => (string) $project->custom_value4 ?: '',
2020-01-21 01:32:34 +01:00
];
}
}