mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 06:17:28 -08:00
Added new seats transformer
This commit is contained in:
parent
7f1a535b30
commit
3d5545494e
57
app/Http/Transformers/LicenseSeatsTransformer.php
Normal file
57
app/Http/Transformers/LicenseSeatsTransformer.php
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
namespace App\Http\Transformers;
|
||||
|
||||
use App\Models\LicenseSeat;
|
||||
use Gate;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use App\Helpers\Helper;
|
||||
|
||||
class LicenseSeatsTransformer
|
||||
{
|
||||
|
||||
public function transformLicenseSeats (Collection $seats, $total)
|
||||
{
|
||||
$array = array();
|
||||
$seat_count = 0;
|
||||
foreach ($seats as $seat) {
|
||||
$seat_count++;
|
||||
$array[] = self::transformLicenseSeat($seat, $seat_count);
|
||||
}
|
||||
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
||||
}
|
||||
|
||||
public function transformLicenseSeat (LicenseSeat $seat, $seat_count)
|
||||
{
|
||||
$array = [
|
||||
'id' => (int) $seat->license->id,
|
||||
'name' => 'Seat '.$seat_count,
|
||||
'assigned_user' => ($seat->user) ? [
|
||||
'id' => (int) $seat->user->id,
|
||||
'name'=> e($seat->user->present()->fullName)
|
||||
] : null,
|
||||
'assigned_asset' => ($seat->asset) ? [
|
||||
'id' => (int) $seat->asset->id,
|
||||
'name'=> e($seat->asset->present()->fullName)
|
||||
] : null,
|
||||
'reassignable' => (bool) $seat->license->reassignable,
|
||||
'user_can_checkout' => (($seat->assigned_to=='') && ($seat->asset_id=='')) ? true : false,
|
||||
];
|
||||
|
||||
$permissions_array['available_actions'] = [
|
||||
'checkout' => Gate::allows('checkout', License::class) ? true : false,
|
||||
'checkin' => Gate::allows('checkin', License::class) ? true : false,
|
||||
'clone' => Gate::allows('create', License::class) ? true : false,
|
||||
'update' => Gate::allows('update', License::class) ? true : false,
|
||||
'delete' => Gate::allows('delete', License::class) ? true : false,
|
||||
];
|
||||
|
||||
$array += $permissions_array;
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue