snipe-it/app/Http/Transformers/StatuslabelsTransformer.php

46 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Transformers;
use App\Models\Statuslabel;
use Illuminate\Database\Eloquent\Collection;
use Gate;
2017-03-03 17:53:42 -08:00
use App\Helpers\Helper;
class StatuslabelsTransformer
{
public function transformStatuslabels (Collection $statuslabels)
{
$array = array();
foreach ($statuslabels as $statuslabel) {
$array[] = self::transformStatuslabel($statuslabel);
}
return (new DatatablesTransformer)->transformDatatables($array);
}
public function transformStatuslabel (Statuslabel $statuslabel)
{
$array = [
'id' => e($statuslabel->id),
'name' => e($statuslabel->name),
'type' => $statuslabel->getStatuslabelType(),
'color' => ($statuslabel->color) ? e($statuslabel->color) : null,
'show_in_nav' => ($statuslabel->show_in_nav=='1') ? true : false,
'notes' => e($statuslabel->notes),
2017-03-03 17:53:42 -08:00
'created_at' => Helper::getFormattedDateObject($statuslabel->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($statuslabel->updated_at, 'datetime'),
];
$permissions_array['available_actions'] = [
'update' => Gate::allows('update', Statuslabel::class) ? true : false,
'delete' => Gate::allows('delete', Statuslabel::class) ? true : false,
];
$array += $permissions_array;
return $array;
}
}