mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 13:44:06 -08:00
e3e0d57f56
* Add IDE Helper files * Cleanup imports - Alphabetises imports - Removes unused imports * Add Platform requirements * Move filling asset into block where asset exists * Remove duplicate array keys
56 lines
1.9 KiB
PHP
56 lines
1.9 KiB
PHP
<?php
|
|
namespace App\Http\Transformers;
|
|
|
|
use App\Helpers\Helper;
|
|
use App\Models\Company;
|
|
use Gate;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class CompaniesTransformer
|
|
{
|
|
|
|
public function transformCompanies (Collection $companies, $total)
|
|
{
|
|
$array = array();
|
|
foreach ($companies as $company) {
|
|
$array[] = self::transformCompany($company);
|
|
}
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
}
|
|
|
|
public function transformCompany (Company $company = null)
|
|
{
|
|
if ($company) {
|
|
|
|
$array = [
|
|
'id' => (int) $company->id,
|
|
'name' => e($company->name),
|
|
'image' => ($company->image) ? Storage::disk('public')->url('companies/'.e($company->image)) : null,
|
|
"created_at" => Helper::getFormattedDateObject($company->created_at, 'datetime'),
|
|
"updated_at" => Helper::getFormattedDateObject($company->updated_at, 'datetime'),
|
|
"assets_count" => (int) $company->assets_count,
|
|
"licenses_count" => (int) $company->licenses_count,
|
|
"accessories_count" => (int) $company->accessories_count,
|
|
"consumables_count" => (int) $company->consumables_count,
|
|
"components_count" => (int) $company->components_count,
|
|
"users_count" => (int) $company->users_count
|
|
];
|
|
|
|
$permissions_array['available_actions'] = [
|
|
'update' => Gate::allows('update', Company::class) ? true : false,
|
|
'delete' => (Gate::allows('delete', Company::class) && ($company->assets_count == 0) && ($company->accessories_count == 0) && ($company->consumables_count == 0) && ($company->components_count == 0) && ($company->users_count == 0)) ? true : false,
|
|
];
|
|
|
|
$array += $permissions_array;
|
|
|
|
return $array;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|