2017-01-24 22:25:17 -08:00
|
|
|
<?php
|
|
|
|
namespace App\Http\Transformers;
|
|
|
|
|
|
|
|
use App\Models\AssetModel;
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2017-02-08 18:24:55 -08:00
|
|
|
use Gate;
|
2017-07-29 17:01:03 -07:00
|
|
|
use App\Helpers\Helper;
|
2017-01-24 22:25:17 -08:00
|
|
|
|
|
|
|
class AssetModelsTransformer
|
|
|
|
{
|
|
|
|
|
|
|
|
public function transformAssetModels (Collection $assetmodels, $total)
|
|
|
|
{
|
|
|
|
$array = array();
|
|
|
|
foreach ($assetmodels as $assetmodel) {
|
|
|
|
$array[] = self::transformAssetModel($assetmodel);
|
|
|
|
}
|
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function transformAssetModel (AssetModel $assetmodel)
|
|
|
|
{
|
2017-01-26 21:02:59 -08:00
|
|
|
|
2017-02-08 18:24:55 -08:00
|
|
|
$array = [
|
2017-07-25 23:40:30 -07:00
|
|
|
'id' => (int) $assetmodel->id,
|
2017-01-24 22:25:17 -08:00
|
|
|
'name' => e($assetmodel->name),
|
2017-07-29 17:01:03 -07:00
|
|
|
'manufacturer' => ($assetmodel->manufacturer) ? [
|
|
|
|
'id' => (int) $assetmodel->manufacturer->id,
|
|
|
|
'name'=> e($assetmodel->manufacturer->name)
|
|
|
|
] : null,
|
2017-07-25 23:40:30 -07:00
|
|
|
'image' => ($assetmodel->image!='') ? url('/').'/uploads/models/'.e($assetmodel->image) : null,
|
2017-01-24 22:25:17 -08:00
|
|
|
'model_number' => e($assetmodel->model_number),
|
2017-07-29 17:01:03 -07:00
|
|
|
'depreciation' => ($assetmodel->depreciation) ? [
|
|
|
|
'id' => (int) $assetmodel->depreciation->id,
|
|
|
|
'name'=> e($assetmodel->depreciation->name)
|
|
|
|
] : null,
|
2017-01-24 22:25:17 -08:00
|
|
|
'assets_count' => $assetmodel->assets_count,
|
2017-07-29 17:01:03 -07:00
|
|
|
'category' => ($assetmodel->category) ? [
|
|
|
|
'id' => (int) $assetmodel->category->id,
|
|
|
|
'name'=> e($assetmodel->category->name)
|
|
|
|
] : null,
|
|
|
|
'fieldset' => ($assetmodel->fieldset) ? [
|
|
|
|
'id' => (int) $assetmodel->fieldset->id,
|
|
|
|
'name'=> e($assetmodel->fieldset->name)
|
|
|
|
] : null,
|
2017-01-24 22:25:17 -08:00
|
|
|
'eol' => ($assetmodel->eol > 0) ? $assetmodel->eol .' months': 'None',
|
2017-07-29 17:01:03 -07:00
|
|
|
'notes' => e($assetmodel->notes),
|
|
|
|
'created_at' => Helper::getFormattedDateObject($assetmodel->created_at, 'datetime'),
|
|
|
|
'updated_at' => Helper::getFormattedDateObject($assetmodel->updated_at, 'datetime'),
|
2017-10-03 17:53:08 -07:00
|
|
|
'deleted_at' => Helper::getFormattedDateObject($assetmodel->deleted_at, 'datetime'),
|
2017-01-24 22:25:17 -08:00
|
|
|
|
|
|
|
];
|
2017-02-08 18:24:55 -08:00
|
|
|
|
|
|
|
$permissions_array['available_actions'] = [
|
2017-10-03 17:53:08 -07:00
|
|
|
'update' => (Gate::allows('update', AssetModel::class) && ($assetmodel->deleted_at=='')) ? true : false,
|
|
|
|
'delete' => (Gate::allows('delete', AssetModel::class) && ($assetmodel->deleted_at=='')) ? true : false,
|
|
|
|
'clone' => (Gate::allows('create', AssetModel::class) && ($assetmodel->deleted_at=='')) ,
|
|
|
|
'restore' => (Gate::allows('create', AssetModel::class) && ($assetmodel->deleted_at!='')) ? true : false,
|
2017-02-08 18:24:55 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
$array += $permissions_array;
|
|
|
|
return $array;
|
2017-01-24 22:25:17 -08:00
|
|
|
}
|
|
|
|
|
2017-01-26 21:02:59 -08:00
|
|
|
|
2017-01-24 22:25:17 -08:00
|
|
|
public function transformAssetModelsDatatable($assetmodels) {
|
|
|
|
return (new DatatablesTransformer)->transformDatatables($assetmodels);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|