57 lines
1.9 KiB
PHP
57 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Transformers\Registries;
|
|
|
|
use App\Models\Registries\Entry;
|
|
use App\Services\PermissionsService;
|
|
use App\Transformers\Assets\AssetTransformer;
|
|
use App\Transformers\Objects\ObjectTransformer;
|
|
use League\Fractal\Resource\Collection;
|
|
use League\Fractal\Resource\Item;
|
|
use League\Fractal\Resource\Primitive;
|
|
use League\Fractal\TransformerAbstract;
|
|
|
|
class EntryTransformer extends TransformerAbstract {
|
|
protected array $defaultIncludes = [
|
|
|
|
];
|
|
|
|
protected array $availableIncludes = [
|
|
'registry', 'category', 'asset', 'operations'
|
|
];
|
|
|
|
public function transform(Entry $model): array {
|
|
return [
|
|
'id' => $model->uuid,
|
|
'number' => $model->number,
|
|
'name' => $model->name,
|
|
'active_since' => $model->active_since ? $model->active_since->toIso8601String() : null,
|
|
'active_till' => $model->active_till ? $model->active_till->toIso8601String() : null,
|
|
'created_at' => $model->created_at ? $model->created_at->toIso8601String() : null,
|
|
'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : null
|
|
];
|
|
}
|
|
|
|
public function includeRegistry(Entry $model): ?Item {
|
|
return $model->registry ? $this->item($model->registry, new RegistryTransformer()) : null;
|
|
}
|
|
|
|
public function includeCategory(Entry $model): ?Item {
|
|
return $model->category ? $this->item($model->category, new CategoryTransformer()) : null;
|
|
}
|
|
|
|
public function includeAsset(Entry $model): ?Item {
|
|
return $model->asset ? $this->item($model->asset, new AssetTransformer()) : null;
|
|
}
|
|
|
|
public function includeOperations(Entry $model): Collection {
|
|
return $this->collection($model->operations, new ObjectTransformer());
|
|
}
|
|
|
|
public function includePermissions(Entry $model): Primitive {
|
|
return $this->primitive((new PermissionsService($model))->get());
|
|
}
|
|
|
|
|
|
}
|