2017-01-24 18:57:33 -08:00
|
|
|
<?php
|
|
|
|
namespace App\Http\Transformers;
|
|
|
|
|
2019-03-13 20:12:03 -07:00
|
|
|
use App\Helpers\Helper;
|
2017-01-24 18:57:33 -08:00
|
|
|
use App\Models\License;
|
2017-02-08 18:24:55 -08:00
|
|
|
use Gate;
|
2017-01-24 18:57:33 -08:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
|
|
|
|
class LicensesTransformer
|
|
|
|
{
|
|
|
|
|
|
|
|
public function transformLicenses (Collection $licenses, $total)
|
|
|
|
{
|
|
|
|
$array = array();
|
|
|
|
foreach ($licenses as $license) {
|
|
|
|
$array[] = self::transformLicense($license);
|
|
|
|
}
|
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function transformLicense (License $license)
|
|
|
|
{
|
|
|
|
$array = [
|
2017-07-25 23:40:30 -07:00
|
|
|
'id' => (int) $license->id,
|
2017-01-24 19:24:47 -08:00
|
|
|
'name' => e($license->name),
|
2017-07-25 23:40:30 -07:00
|
|
|
'company' => ($license->company) ? ['id' => (int) $license->company->id,'name'=> e($license->company->name)] : null,
|
|
|
|
'manufacturer' => ($license->manufacturer) ? ['id' => (int) $license->manufacturer->id,'name'=> e($license->manufacturer->name)] : null,
|
2017-12-05 16:26:23 -08:00
|
|
|
'product_key' => (Gate::allows('viewKeys', License::class)) ? e($license->serial) : '------------',
|
2017-02-10 18:43:30 -08:00
|
|
|
'order_number' => e($license->order_number),
|
|
|
|
'purchase_order' => e($license->purchase_order),
|
2017-03-03 17:53:42 -08:00
|
|
|
'purchase_date' => Helper::getFormattedDateObject($license->purchase_date, 'date'),
|
2017-01-24 19:24:47 -08:00
|
|
|
'purchase_cost' => e($license->purchase_cost),
|
|
|
|
'notes' => e($license->notes),
|
2017-03-03 17:53:42 -08:00
|
|
|
'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'),
|
2017-11-02 19:37:30 -07:00
|
|
|
'seats' => (int) $license->seats,
|
2017-11-02 20:23:04 -07:00
|
|
|
'free_seats_count' => (int) $license->free_seats_count,
|
2017-03-11 02:52:50 -08:00
|
|
|
'license_name' => e($license->license_name),
|
2017-01-24 19:24:47 -08:00
|
|
|
'license_email' => e($license->license_email),
|
|
|
|
'maintained' => ($license->maintained == 1) ? true : false,
|
2017-07-25 23:40:30 -07:00
|
|
|
'supplier' => ($license->supplier) ? ['id' => (int) $license->supplier->id,'name'=> e($license->supplier->name)] : null,
|
2018-05-04 21:01:38 -07:00
|
|
|
'category' => ($license->category) ? ['id' => (int) $license->category->id,'name'=> e($license->category->name)] : null,
|
2017-03-03 17:53:42 -08:00
|
|
|
'created_at' => Helper::getFormattedDateObject($license->created_at, 'datetime'),
|
|
|
|
'updated_at' => Helper::getFormattedDateObject($license->updated_at, 'datetime'),
|
2017-11-02 19:16:09 -07:00
|
|
|
'user_can_checkout' => (bool) ($license->free_seats_count > 0),
|
2017-01-24 18:57:33 -08:00
|
|
|
];
|
|
|
|
|
2017-02-08 18:24:55 -08:00
|
|
|
$permissions_array['available_actions'] = [
|
|
|
|
'checkout' => Gate::allows('checkout', License::class) ? true : false,
|
|
|
|
'checkin' => Gate::allows('checkin', License::class) ? true : false,
|
2017-07-07 18:45:49 -07:00
|
|
|
'clone' => Gate::allows('create', License::class) ? true : false,
|
2017-02-08 18:24:55 -08:00
|
|
|
'update' => Gate::allows('update', License::class) ? true : false,
|
|
|
|
'delete' => Gate::allows('delete', License::class) ? true : false,
|
|
|
|
];
|
|
|
|
|
|
|
|
$array += $permissions_array;
|
|
|
|
|
2017-01-24 18:57:33 -08:00
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function transformAssetsDatatable($licenses) {
|
|
|
|
return (new DatatablesTransformer)->transformDatatables($licenses);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|