mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-30 07:59:50 -08:00
934afa036f
Shift automatically applies the Laravel coding style - which uses the PSR-2 coding style as a base with some minor additions. You may customize the adopted coding style by adding your own [PHP CS Fixer][1] `.php_cs` config file to your project root. Feel free to use [Shift's Laravel ruleset][2] to help you get started. [1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer [2]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200
51 lines
1.7 KiB
PHP
51 lines
1.7 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 = [];
|
|
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),
|
|
'delete' => $company->isDeletable(),
|
|
];
|
|
|
|
$array += $permissions_array;
|
|
|
|
return $array;
|
|
}
|
|
}
|
|
}
|