snipe-it/app/Http/Transformers/LicensesTransformer.php

67 lines
2.8 KiB
PHP
Raw Normal View History

2017-01-24 18:57:33 -08:00
<?php
namespace App\Http\Transformers;
use App\Models\License;
use Gate;
2017-01-24 18:57:33 -08:00
use Illuminate\Database\Eloquent\Collection;
2017-02-10 18:43:30 -08:00
use App\Helpers\Helper;
2017-01-24 18:57:33 -08:00
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 = [
'id' => $license->id,
2017-01-24 19:24:47 -08:00
'name' => e($license->name),
2017-02-10 18:43:30 -08:00
'company' => ($license->company) ? ['id' => $license->company->id,'name'=> e($license->company->name)] : null,
'manufacturer' => ($license->manufacturer) ? ['id' => $license->manufacturer->id,'name'=> e($license->manufacturer->name)] : null,
'product_key' => e($license->serial),
'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),
2017-02-10 18:43:30 -08:00
'depreciation' => ($license->depreciation) ? ['id' => $license->depreciation->id,'name'=> e($license->depreciation->name)] : null,
2017-01-24 19:24:47 -08:00
'notes' => e($license->notes),
2017-03-03 17:53:42 -08:00
'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'),
2017-02-10 18:43:30 -08:00
'total_seats' => e($license->seats),
'remaining_qty' => $license->remaincount(),
'min_qty' => $license->remaincount(),
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-02-10 18:43:30 -08:00
'supplier' => ($license->supplier) ? ['id' => $license->supplier->id,'name'=> e($license->supplier->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'),
'user_can_checkout' => (bool) ($license->remaincount() > 0),
2017-01-24 18:57:33 -08:00
];
$permissions_array['available_actions'] = [
'checkout' => Gate::allows('checkout', License::class) ? true : false,
'checkin' => Gate::allows('checkin', License::class) ? true : false,
'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);
}
}