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-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-01-24 22:25:17 -08:00
|
|
|
'id' => $assetmodel->id,
|
|
|
|
'name' => e($assetmodel->name),
|
|
|
|
'manufacturer' => ($assetmodel->manufacturer_id) ? $assetmodel->manufacturer : null,
|
2017-01-24 22:46:07 -08:00
|
|
|
'image' => ($assetmodel->image!='') ? url('/').'/uploads/models/'.e($assetmodel->image) : '',
|
2017-01-24 22:25:17 -08:00
|
|
|
'model_number' => e($assetmodel->model_number),
|
|
|
|
'depreciation' => ($assetmodel->depreciation) ? $assetmodel->depreciation : 'No',
|
|
|
|
'assets_count' => $assetmodel->assets_count,
|
|
|
|
'category' => ($assetmodel->category_id) ? $assetmodel->category : null,
|
|
|
|
'fieldset' => ($assetmodel->fieldset) ? $assetmodel->fieldset : null,
|
|
|
|
'eol' => ($assetmodel->eol > 0) ? $assetmodel->eol .' months': 'None',
|
2017-01-26 21:02:59 -08:00
|
|
|
'notes' => e($assetmodel->notes)
|
2017-01-24 22:25:17 -08:00
|
|
|
|
|
|
|
];
|
2017-02-08 18:24:55 -08:00
|
|
|
|
|
|
|
$permissions_array['available_actions'] = [
|
2017-07-07 18:45:49 -07:00
|
|
|
'update' => Gate::allows('update', AssetModel::class) ? true : false,
|
|
|
|
'delete' => Gate::allows('delete', AssetModel::class) ? true : false,
|
|
|
|
'clone' => Gate::allows('create', AssetModel::class) ? 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|