mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Fixed transformer
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
0c2bed605f
commit
56b02df7aa
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Http\Transformers;
|
namespace App\Http\Transformers;
|
||||||
|
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
|
use App\Models\Accessory;
|
||||||
use App\Models\Location;
|
use App\Models\Location;
|
||||||
use Illuminate\Support\Facades\Gate;
|
use Illuminate\Support\Facades\Gate;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
@ -45,9 +46,9 @@ class LocationsTransformer
|
||||||
'zip' => ($location->zip) ? e($location->zip) : null,
|
'zip' => ($location->zip) ? e($location->zip) : null,
|
||||||
'phone' => ($location->phone!='') ? e($location->phone): null,
|
'phone' => ($location->phone!='') ? e($location->phone): null,
|
||||||
'fax' => ($location->fax!='') ? e($location->fax): null,
|
'fax' => ($location->fax!='') ? e($location->fax): null,
|
||||||
'assigned_assets_count' => (int) $location->assigned_assets_count,
|
'accessories_count' => (int) $location->accessories_count,
|
||||||
'accessories_count' => (int) $location->assigned_accessories,
|
|
||||||
'assigned_accessories_count' => (int) $location->assigned_accessories_count,
|
'assigned_accessories_count' => (int) $location->assigned_accessories_count,
|
||||||
|
'assigned_assets_count' => (int) $location->assigned_assets_count,
|
||||||
'assets_count' => (int) $location->assets_count,
|
'assets_count' => (int) $location->assets_count,
|
||||||
'rtd_assets_count' => (int) $location->rtd_assets_count,
|
'rtd_assets_count' => (int) $location->rtd_assets_count,
|
||||||
'users_count' => (int) $location->users_count,
|
'users_count' => (int) $location->users_count,
|
||||||
|
@ -79,6 +80,37 @@ class LocationsTransformer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function transformCheckedoutAccessories($accessory_checkouts, $total)
|
||||||
|
{
|
||||||
|
|
||||||
|
$array = [];
|
||||||
|
foreach ($accessory_checkouts as $checkout) {
|
||||||
|
$array = [
|
||||||
|
'id' => $checkout->id,
|
||||||
|
'accessory' => [
|
||||||
|
'id' => $checkout->accessory->id,
|
||||||
|
'name' => $checkout->accessory->name,
|
||||||
|
],
|
||||||
|
'image' => ($checkout->accessory->image) ? Storage::disk('public')->url('accessories/'.e($checkout->accessory->image)) : null,
|
||||||
|
'note' => $checkout->note ? e($checkout->note) : null,
|
||||||
|
'created_by' => $checkout->admin ? [
|
||||||
|
'id' => (int) $checkout->admin->id,
|
||||||
|
'name'=> e($checkout->admin->present()->fullName),
|
||||||
|
]: null,
|
||||||
|
'created_at' => Helper::getFormattedDateObject($checkout->created_at, 'datetime'),
|
||||||
|
];
|
||||||
|
|
||||||
|
$permissions_array['available_actions'] = [
|
||||||
|
'checkout' => Gate::allows('checkout', Accessory::class),
|
||||||
|
'checkin' => Gate::allows('checkin', Accessory::class),
|
||||||
|
];
|
||||||
|
|
||||||
|
$array += $permissions_array;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This gives a compact view of the location data without any additional relational queries,
|
* This gives a compact view of the location data without any additional relational queries,
|
||||||
* allowing us to 1) deliver a smaller payload and 2) avoid additional queries on relations that
|
* allowing us to 1) deliver a smaller payload and 2) avoid additional queries on relations that
|
||||||
|
|
Loading…
Reference in a new issue