2017-01-13 04:50:20 -08:00
|
|
|
<?php
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-01-13 04:50:20 -08:00
|
|
|
namespace App\Http\Transformers;
|
|
|
|
|
2019-03-13 20:12:03 -07:00
|
|
|
use App\Helpers\Helper;
|
2017-01-13 04:50:20 -08:00
|
|
|
use App\Models\Statuslabel;
|
2023-03-18 11:58:09 -07:00
|
|
|
use Illuminate\Support\Facades\Gate;
|
2019-03-13 20:12:03 -07:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2017-01-13 04:50:20 -08:00
|
|
|
|
|
|
|
class StatuslabelsTransformer
|
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
public function transformStatuslabels(Collection $statuslabels, $total)
|
2017-01-13 04:50:20 -08:00
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
$array = [];
|
2017-01-13 04:50:20 -08:00
|
|
|
foreach ($statuslabels as $statuslabel) {
|
|
|
|
$array[] = self::transformStatuslabel($statuslabel);
|
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2018-07-05 14:42:39 -07:00
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
2017-01-13 04:50:20 -08:00
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
public function transformStatuslabel(Statuslabel $statuslabel)
|
2017-01-13 04:50:20 -08:00
|
|
|
{
|
|
|
|
$array = [
|
2017-07-25 23:40:30 -07:00
|
|
|
'id' => (int) $statuslabel->id,
|
2017-01-13 04:50:20 -08:00
|
|
|
'name' => e($statuslabel->name),
|
|
|
|
'type' => $statuslabel->getStatuslabelType(),
|
2017-02-01 17:48:28 -08:00
|
|
|
'color' => ($statuslabel->color) ? e($statuslabel->color) : null,
|
2021-06-10 13:15:52 -07:00
|
|
|
'show_in_nav' => ($statuslabel->show_in_nav == '1') ? true : false,
|
|
|
|
'default_label' => ($statuslabel->default_label == '1') ? true : false,
|
2017-10-19 10:48:15 -07:00
|
|
|
'assets_count' => (int) $statuslabel->assets_count,
|
2017-02-01 17:48:28 -08:00
|
|
|
'notes' => e($statuslabel->notes),
|
2024-09-19 10:22:11 -07:00
|
|
|
'created_by' => ($statuslabel->adminuser) ? [
|
|
|
|
'id' => (int) $statuslabel->adminuser->id,
|
|
|
|
'name'=> e($statuslabel->adminuser->present()->fullName()),
|
|
|
|
] : null,
|
2017-03-03 17:53:42 -08:00
|
|
|
'created_at' => Helper::getFormattedDateObject($statuslabel->created_at, 'datetime'),
|
|
|
|
'updated_at' => Helper::getFormattedDateObject($statuslabel->updated_at, 'datetime'),
|
2017-01-13 04:50:20 -08:00
|
|
|
];
|
|
|
|
|
2017-02-08 18:24:55 -08:00
|
|
|
$permissions_array['available_actions'] = [
|
2017-03-03 17:56:05 -08:00
|
|
|
'update' => Gate::allows('update', Statuslabel::class) ? true : false,
|
2017-10-19 11:41:35 -07:00
|
|
|
'delete' => (Gate::allows('delete', Statuslabel::class) && ($statuslabel->assets_count == 0)) ? true : false,
|
2017-02-08 18:24:55 -08:00
|
|
|
];
|
|
|
|
$array += $permissions_array;
|
|
|
|
|
2017-01-13 04:50:20 -08:00
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
}
|