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

52 lines
1.2 KiB
PHP
Raw Normal View History

2017-01-12 23:40:35 -08:00
<?php
namespace App\Http\Transformers;
use App\Models\Location;
use Illuminate\Database\Eloquent\Collection;
class LocationsTransformer
{
public function transformLocations (Collection $locations, $total)
2017-01-12 23:40:35 -08:00
{
$array = array();
foreach ($locations as $location) {
$array[] = self::transformLocation($location);
}
return (new DatatablesTransformer)->transformDatatables($array, $total);
2017-01-12 23:40:35 -08:00
}
2017-01-13 01:45:14 -08:00
public function transformLocation (Location $location = null)
2017-01-12 23:40:35 -08:00
{
if ($location) {
$assets_arr = [];
foreach($location->assets() as $asset) {
$assets_arr = ['id' => $asset->id];
}
$transformed = [
2017-01-12 23:40:35 -08:00
'id' => e($location->id),
2017-01-13 00:13:57 -08:00
'name' => e($location->name),
'address' => e($location->address),
'city' => e($location->city),
'state' => e($location->state),
'assets_checkedout' => $location->assets()->count(),
'assets_default' => $location->assignedassets()->count(),
2017-01-13 00:13:57 -08:00
'country' => e($location->country),
'assets' => $assets_arr,
2017-01-12 23:40:35 -08:00
];
return $transformed;
2017-01-12 23:40:35 -08:00
}
}
}