1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Ninja/Transformers/EntityTransformer.php
Holger Lösken 0fbda85a59 Code Refactoring
- Removed unused uses
- Type hinting for method parameters
- Removed commented code
- Introduced comments for classes and methods
- Short array syntax
2016-07-03 16:19:22 +00:00

60 lines
1.5 KiB
PHP

<?php namespace App\Ninja\Transformers;
use Auth;
use App\Models\Account;
use League\Fractal\TransformerAbstract;
class EntityTransformer extends TransformerAbstract
{
protected $account;
protected $serializer;
public function __construct(Account $account = null, $serializer = null)
{
$this->account = $account;
$this->serializer = $serializer;
}
protected function includeCollection($data, $transformer, $entityType)
{
if ($this->serializer && $this->serializer != API_SERIALIZER_JSON) {
$entityType = null;
}
return $this->collection($data, $transformer, $entityType);
}
protected function includeItem($data, $transformer, $entityType)
{
if ($this->serializer && $this->serializer != API_SERIALIZER_JSON) {
$entityType = null;
}
return $this->item($data, $transformer, $entityType);
}
protected function getTimestamp($date)
{
return $date ? $date->getTimestamp() : null;
}
public function getDefaultIncludes()
{
return $this->defaultIncludes;
}
protected function getDefaults($entity)
{
$data = [
'account_key' => $this->account->account_key,
'is_owner' => (bool) (Auth::check() && Auth::user()->owns($entity)),
];
if ($entity->relationLoaded('user')) {
$data['user_id'] = (int) $entity->user->public_id + 1;
}
return $data;
}
}