2018-01-10 18:47:40 -08:00
|
|
|
<?php
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2018-01-10 18:47:40 -08:00
|
|
|
namespace App\Http\Transformers;
|
|
|
|
|
2018-07-18 05:31:59 -07:00
|
|
|
use App\Models\License;
|
2019-03-13 20:12:03 -07:00
|
|
|
use App\Models\LicenseSeat;
|
2023-03-18 11:58:09 -07:00
|
|
|
use Illuminate\Support\Facades\Gate;
|
2018-01-10 18:47:40 -08:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
|
|
|
|
class LicenseSeatsTransformer
|
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
public function transformLicenseSeats(Collection $seats, $total)
|
2018-01-10 18:47:40 -08:00
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
$array = [];
|
2018-01-10 18:47:40 -08:00
|
|
|
$seat_count = 0;
|
|
|
|
foreach ($seats as $seat) {
|
|
|
|
$seat_count++;
|
|
|
|
$array[] = self::transformLicenseSeat($seat, $seat_count);
|
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2018-01-10 18:47:40 -08:00
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
public function transformLicenseSeat(LicenseSeat $seat, $seat_count = 0)
|
2018-01-10 18:47:40 -08:00
|
|
|
{
|
|
|
|
$array = [
|
2018-01-10 20:36:27 -08:00
|
|
|
'id' => (int) $seat->id,
|
|
|
|
'license_id' => (int) $seat->license->id,
|
2018-01-10 18:47:40 -08:00
|
|
|
'assigned_user' => ($seat->user) ? [
|
|
|
|
'id' => (int) $seat->user->id,
|
2019-11-21 22:03:56 -08:00
|
|
|
'name'=> e($seat->user->present()->fullName),
|
2023-12-18 17:15:06 -08:00
|
|
|
'email' => e($seat->user->email),
|
2021-06-10 13:15:52 -07:00
|
|
|
'department'=> ($seat->user->department) ?
|
2019-11-21 22:03:56 -08:00
|
|
|
[
|
2021-06-10 13:15:52 -07:00
|
|
|
'id' => (int) $seat->user->department->id,
|
|
|
|
'name' => e($seat->user->department->name),
|
2019-11-21 22:03:56 -08:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
] : null,
|
2018-01-10 18:47:40 -08:00
|
|
|
] : null,
|
|
|
|
'assigned_asset' => ($seat->asset) ? [
|
|
|
|
'id' => (int) $seat->asset->id,
|
2021-06-10 13:15:52 -07:00
|
|
|
'name'=> e($seat->asset->present()->fullName),
|
2018-01-10 18:47:40 -08:00
|
|
|
] : null,
|
2018-01-10 20:36:27 -08:00
|
|
|
'location' => ($seat->location()) ? [
|
|
|
|
'id' => (int) $seat->location()->id,
|
2021-06-10 13:15:52 -07:00
|
|
|
'name'=> e($seat->location()->name),
|
2018-01-10 20:36:27 -08:00
|
|
|
] : null,
|
2018-01-10 18:47:40 -08:00
|
|
|
'reassignable' => (bool) $seat->license->reassignable,
|
2023-09-28 07:40:18 -07:00
|
|
|
'notes' => e($seat->notes),
|
2021-06-10 13:15:52 -07:00
|
|
|
'user_can_checkout' => (($seat->assigned_to == '') && ($seat->asset_id == '')),
|
2018-01-10 18:47:40 -08:00
|
|
|
];
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
if ($seat_count != 0) {
|
2021-03-29 19:41:26 -07:00
|
|
|
$array['name'] = 'Seat '.$seat_count;
|
|
|
|
}
|
|
|
|
|
2018-01-10 18:47:40 -08:00
|
|
|
$permissions_array['available_actions'] = [
|
2020-05-23 10:36:02 -07:00
|
|
|
'checkout' => Gate::allows('checkout', License::class),
|
|
|
|
'checkin' => Gate::allows('checkin', License::class),
|
|
|
|
'clone' => Gate::allows('create', License::class),
|
|
|
|
'update' => Gate::allows('update', License::class),
|
|
|
|
'delete' => Gate::allows('delete', License::class),
|
2018-01-10 18:47:40 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
$array += $permissions_array;
|
|
|
|
|
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
}
|