2017-07-07 17:10:06 -07:00
|
|
|
<?php
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-07-07 17:10:06 -07:00
|
|
|
namespace App\Http\Transformers;
|
|
|
|
|
2019-03-13 20:12:03 -07:00
|
|
|
use App\Helpers\Helper;
|
2017-07-07 17:10:06 -07:00
|
|
|
use App\Models\Company;
|
2023-03-18 11:58:09 -07:00
|
|
|
use Illuminate\Support\Facades\Gate;
|
2019-03-13 20:12:03 -07:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2018-09-29 21:33:52 -07:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2017-07-07 17:10:06 -07:00
|
|
|
|
|
|
|
class CompaniesTransformer
|
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
public function transformCompanies(Collection $companies, $total)
|
2017-07-07 17:10:06 -07:00
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
$array = [];
|
2017-07-07 17:10:06 -07:00
|
|
|
foreach ($companies as $company) {
|
|
|
|
$array[] = self::transformCompany($company);
|
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-07-07 17:10:06 -07:00
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
public function transformCompany(Company $company = null)
|
2017-07-07 17:10:06 -07:00
|
|
|
{
|
|
|
|
if ($company) {
|
|
|
|
$array = [
|
2017-08-22 14:53:48 -07:00
|
|
|
'id' => (int) $company->id,
|
2017-07-07 17:10:06 -07:00
|
|
|
'name' => e($company->name),
|
2023-07-10 11:44:21 -07:00
|
|
|
'phone' => ($company->phone!='') ? e($company->phone): null,
|
|
|
|
'fax' => ($company->phone!='') ? e($company->fax): null,
|
2018-09-29 21:33:52 -07:00
|
|
|
'image' => ($company->image) ? Storage::disk('public')->url('companies/'.e($company->image)) : null,
|
2021-06-10 13:15:52 -07:00
|
|
|
'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,
|
2017-07-07 17:10:06 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
$permissions_array['available_actions'] = [
|
2020-05-23 10:36:02 -07:00
|
|
|
'update' => Gate::allows('update', Company::class),
|
2021-06-10 13:15:52 -07:00
|
|
|
'delete' => $company->isDeletable(),
|
2017-07-07 17:10:06 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
$array += $permissions_array;
|
|
|
|
|
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|