mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-10 23:54:12 -08:00
54 lines
1.6 KiB
PHP
54 lines
1.6 KiB
PHP
|
<?php
|
||
|
namespace App\Http\Transformers;
|
||
|
|
||
|
use App\Models\Company;
|
||
|
use Illuminate\Database\Eloquent\Collection;
|
||
|
use Gate;
|
||
|
use App\Helpers\Helper;
|
||
|
|
||
|
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' => e($company->id),
|
||
|
'name' => e($company->name),
|
||
|
"created_at" => Helper::getFormattedDateObject($company->created_at, 'datetime'),
|
||
|
"updated_at" => Helper::getFormattedDateObject($company->updated_at, 'datetime'),
|
||
|
"assets_count" => $company->assets_count,
|
||
|
"licenses_count" => $company->licenses_count,
|
||
|
"accessories_count" => $company->accessories_count,
|
||
|
"consumables_count" => $company->consumables_count,
|
||
|
"components_count" => $company->components_count,
|
||
|
"users_count" => $company->users_count
|
||
|
];
|
||
|
|
||
|
$permissions_array['available_actions'] = [
|
||
|
'update' => Gate::allows('update', Company::class) ? true : false,
|
||
|
'delete' => Gate::allows('delete', Company::class) ? true : false,
|
||
|
];
|
||
|
|
||
|
$array += $permissions_array;
|
||
|
|
||
|
return $array;
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
}
|