2017-03-10 22:08:59 -08:00
|
|
|
<?php
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-03-10 22:08:59 -08:00
|
|
|
namespace App\Http\Transformers;
|
|
|
|
|
2019-03-13 20:12:03 -07:00
|
|
|
use App\Helpers\Helper;
|
2017-03-10 22:08:59 -08:00
|
|
|
use App\Models\Manufacturer;
|
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-03-10 22:08:59 -08:00
|
|
|
|
|
|
|
class ManufacturersTransformer
|
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
public function transformManufacturers(Collection $manufacturers, $total)
|
2017-03-10 22:08:59 -08:00
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
$array = [];
|
2017-03-10 22:08:59 -08:00
|
|
|
foreach ($manufacturers as $manufacturer) {
|
|
|
|
$array[] = self::transformManufacturer($manufacturer);
|
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-03-10 22:08:59 -08:00
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
public function transformManufacturer(Manufacturer $manufacturer = null)
|
2017-03-10 22:08:59 -08:00
|
|
|
{
|
|
|
|
if ($manufacturer) {
|
|
|
|
$array = [
|
2017-07-25 23:40:30 -07:00
|
|
|
'id' => (int) $manufacturer->id,
|
2017-03-10 22:08:59 -08:00
|
|
|
'name' => e($manufacturer->name),
|
|
|
|
'url' => e($manufacturer->url),
|
2018-09-29 21:33:52 -07:00
|
|
|
'image' => ($manufacturer->image) ? Storage::disk('public')->url('manufacturers/'.e($manufacturer->image)) : null,
|
2017-03-10 22:08:59 -08:00
|
|
|
'support_url' => e($manufacturer->support_url),
|
2023-04-26 16:39:15 -07:00
|
|
|
'warranty_lookup_url' => e($manufacturer->warranty_lookup_url),
|
2017-03-10 22:08:59 -08:00
|
|
|
'support_phone' => e($manufacturer->support_phone),
|
|
|
|
'support_email' => e($manufacturer->support_email),
|
2017-07-25 23:40:30 -07:00
|
|
|
'assets_count' => (int) $manufacturer->assets_count,
|
|
|
|
'licenses_count' => (int) $manufacturer->licenses_count,
|
|
|
|
'consumables_count' => (int) $manufacturer->consumables_count,
|
|
|
|
'accessories_count' => (int) $manufacturer->accessories_count,
|
2024-09-19 10:04:50 -07:00
|
|
|
'created_by' => ($manufacturer->adminuser) ? [
|
|
|
|
'id' => (int) $manufacturer->adminuser->id,
|
|
|
|
'name'=> e($manufacturer->adminuser->present()->fullName()),
|
|
|
|
] : null,
|
2017-03-10 22:08:59 -08:00
|
|
|
'created_at' => Helper::getFormattedDateObject($manufacturer->created_at, 'datetime'),
|
|
|
|
'updated_at' => Helper::getFormattedDateObject($manufacturer->updated_at, 'datetime'),
|
2018-03-03 18:46:19 -08:00
|
|
|
'deleted_at' => Helper::getFormattedDateObject($manufacturer->deleted_at, 'datetime'),
|
2017-03-10 22:08:59 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
$permissions_array['available_actions'] = [
|
2021-06-10 13:15:52 -07:00
|
|
|
'update' => (($manufacturer->deleted_at == '') && (Gate::allows('update', Manufacturer::class))),
|
|
|
|
'restore' => (($manufacturer->deleted_at != '') && (Gate::allows('create', Manufacturer::class))),
|
2020-05-23 10:36:02 -07:00
|
|
|
'delete' => $manufacturer->isDeletable(),
|
2017-03-10 22:08:59 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
$array += $permissions_array;
|
|
|
|
|
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|