mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-10 23:54:12 -08:00
08f3e78d26
# Conflicts: # app/Http/Controllers/Api/UsersController.php # app/Http/Transformers/LocationsTransformer.php # resources/views/locations/view.blade.php # routes/api.php # tests/_data/dump.sql
70 lines
2.1 KiB
PHP
70 lines
2.1 KiB
PHP
<?php
|
|
namespace App\Http\Transformers;
|
|
|
|
use App\Models\Location;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Gate;
|
|
use App\Helpers\Helper;
|
|
|
|
class LocationsTransformer
|
|
{
|
|
|
|
public function transformLocations(Collection $locations, $total)
|
|
{
|
|
$array = array();
|
|
foreach ($locations as $location) {
|
|
$array[] = self::transformLocation($location);
|
|
}
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
}
|
|
|
|
public function transformLocation(Location $location = null)
|
|
{
|
|
if ($location) {
|
|
|
|
$children_arr = [];
|
|
foreach($location->childLocations as $child) {
|
|
$children_arr[] = [
|
|
'id' => (int) $child->id,
|
|
'name' => $child->name
|
|
];
|
|
}
|
|
|
|
$array = [
|
|
'id' => (int) $location->id,
|
|
'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(),
|
|
'country' => e($location->country),
|
|
'created_at' => Helper::getFormattedDateObject($location->created_at, 'datetime'),
|
|
'updated_at' => Helper::getFormattedDateObject($location->updated_at, 'datetime'),
|
|
'parent' => ($location->parent) ? [
|
|
'id' => (int) $location->parent->id,
|
|
'name'=> e($location->parent->name)
|
|
] : null,
|
|
'manager' => ($location->manager) ? (new UsersTransformer)->transformUser($location->manager) : null,
|
|
|
|
|
|
'children' => $children_arr,
|
|
];
|
|
|
|
$permissions_array['available_actions'] = [
|
|
'update' => Gate::allows('update', Location::class) ? true : false,
|
|
'delete' => Gate::allows('delete', Location::class) ? true : false,
|
|
];
|
|
|
|
$array += $permissions_array;
|
|
|
|
return $array;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|