mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-27 05:31:11 -08:00
5290c47e2a
# Conflicts: # .env.example # .travis.yml # Dockerfile # README.md # app/Console/Commands/LdapSync.php # app/Console/Kernel.php # app/Http/Controllers/AccessoriesController.php # app/Http/Controllers/Api/AccessoriesController.php # app/Http/Controllers/Api/AssetsController.php # app/Http/Controllers/Api/LocationsController.php # app/Http/Controllers/Api/SettingsController.php # app/Http/Controllers/Api/UsersController.php # app/Http/Controllers/AssetModelsController.php # app/Http/Controllers/Assets/AssetFilesController.php # app/Http/Controllers/Assets/AssetsController.php # app/Http/Controllers/CategoriesController.php # app/Http/Controllers/CompaniesController.php # app/Http/Controllers/ComponentsController.php # app/Http/Controllers/ConsumablesController.php # app/Http/Controllers/DepartmentsController.php # app/Http/Controllers/LicensesController.php # app/Http/Controllers/LocationsController.php # app/Http/Controllers/ManufacturersController.php # app/Http/Controllers/ReportsController.php # app/Http/Controllers/SettingsController.php # app/Http/Controllers/SuppliersController.php # app/Http/Controllers/UsersController.php # app/Http/Middleware/EncryptCookies.php # app/Http/Requests/AssetRequest.php # app/Http/Transformers/AssetMaintenancesTransformer.php # app/Importer/AssetImporter.php # app/Models/AssetMaintenance.php # app/Models/Location.php # app/Models/User.php # composer.json # composer.lock # config/backup.php # config/database.php # config/version.php # public/mix-manifest.json # resources/lang/en-ID/general.php # resources/lang/vi/admin/settings/general.php # resources/views/accessories/edit.blade.php # resources/views/hardware/view.blade.php # resources/views/layouts/default.blade.php # tests/api/ApiCategoriesCest.php
76 lines
2.8 KiB
PHP
76 lines
2.8 KiB
PHP
<?php
|
|
namespace App\Http\Transformers;
|
|
|
|
use App\Helpers\Helper;
|
|
use App\Models\Location;
|
|
use Gate;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
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->children as $child) {
|
|
$children_arr[] = [
|
|
'id' => (int) $child->id,
|
|
'name' => $child->name
|
|
];
|
|
}
|
|
|
|
$array = [
|
|
'id' => (int) $location->id,
|
|
'name' => e($location->name),
|
|
'image' => ($location->image) ? Storage::disk('public')->url('locations/'.e($location->image)) : null,
|
|
'address' => ($location->address) ? e($location->address) : null,
|
|
'address2' => ($location->address2) ? e($location->address2) : null,
|
|
'city' => ($location->city) ? e($location->city) : null,
|
|
'state' => ($location->state) ? e($location->state) : null,
|
|
'country' => ($location->country) ? e($location->country) : null,
|
|
'zip' => ($location->zip) ? e($location->zip) : null,
|
|
'assigned_assets_count' => (int) $location->assigned_assets_count,
|
|
'assets_count' => (int) $location->assets_count,
|
|
'users_count' => (int) $location->users_count,
|
|
'currency' => ($location->currency) ? e($location->currency) : null,
|
|
'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) && ($location->assigned_assets_count==0) && ($location->assets_count==0) && ($location->users_count==0) && ($location->deleted_at=='')) ? true : false,
|
|
];
|
|
|
|
$array += $permissions_array;
|
|
|
|
return $array;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|