2017-01-13 11:38:25 -08:00
|
|
|
<?php
|
|
|
|
namespace App\Http\Transformers;
|
|
|
|
|
|
|
|
use App\Models\Asset;
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2017-01-24 21:04:38 -08:00
|
|
|
use App\Http\Transformers\UsersTransformer;
|
2017-01-13 11:38:25 -08:00
|
|
|
|
|
|
|
class AssetsTransformer
|
|
|
|
{
|
|
|
|
|
|
|
|
public function transformAssets (Collection $assets, $total)
|
|
|
|
{
|
|
|
|
$array = array();
|
|
|
|
foreach ($assets as $asset) {
|
|
|
|
$array[] = self::transformAsset($asset);
|
|
|
|
}
|
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function transformAsset (Asset $asset)
|
|
|
|
{
|
|
|
|
$array = [
|
|
|
|
'id' => $asset->id,
|
|
|
|
'name' => $asset->name,
|
|
|
|
'asset_tag' => $asset->asset_tag,
|
|
|
|
'serial' => $asset->serial,
|
2017-01-24 17:07:00 -08:00
|
|
|
'model' => ($asset->model) ? $asset->model : '',
|
2017-01-13 11:38:25 -08:00
|
|
|
'model_number' => $asset->model_number,
|
2017-01-24 22:25:17 -08:00
|
|
|
'status_label' => ($asset->assetstatus) ? $asset->assetstatus : null,
|
2017-01-13 11:38:25 -08:00
|
|
|
'last_checkout' => $asset->last_checkout,
|
2017-01-24 22:25:17 -08:00
|
|
|
'category' => ($asset->model->category) ? $asset->model->category : null,
|
|
|
|
'manufacturer' => ($asset->model->manufacturer) ? $asset->model->manufacturer : null,
|
2017-01-13 11:38:25 -08:00
|
|
|
'notes' => $asset->notes,
|
|
|
|
'expected_checkin' => $asset->expected_checkin,
|
|
|
|
'order_number' => $asset->order_number,
|
|
|
|
'companyName' => $asset->companyName,
|
2017-01-24 22:46:07 -08:00
|
|
|
'location' => ($asset->assetLoc) ? $asset->assetLoc : null,
|
|
|
|
'image' => ($asset->getImageUrl()) ? $asset->getImageUrl() : null,
|
2017-01-24 21:04:38 -08:00
|
|
|
'assigned_to' => ($asset->assigneduser) ? (new UsersTransformer)->transformUser($asset->assigneduser) : null,
|
2017-01-13 11:38:25 -08:00
|
|
|
'created_at' => $asset->created_at,
|
|
|
|
'purchase_date' => $asset->purchase_date,
|
|
|
|
'purchase_cost' => $asset->purchase_cost,
|
|
|
|
'company' => ($asset->company) ? $asset->company->name: '',
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
|
2017-01-24 18:57:21 -08:00
|
|
|
public function transformAssetsDatatable($assets) {
|
|
|
|
return (new DatatablesTransformer)->transformDatatables($assets);
|
2017-01-13 11:38:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|