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

53 lines
1.7 KiB
PHP
Raw Normal View History

2017-01-24 18:57:33 -08:00
<?php
namespace App\Http\Transformers;
use App\Models\License;
use App\Models\LicenseSeat;
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 = [
'id' => $license->id,
2017-01-24 19:24:47 -08:00
'name' => e($license->name),
2017-01-26 21:05:33 -08:00
'company' => e($license->company->name),
2017-01-24 18:57:33 -08:00
'manufacturer' => ($license->manufacturer) ? $license->manufacturer : null,
2017-01-24 19:24:47 -08:00
'serial' => e($license->name),
'purchase_order' => e($license->order_number),
'purchase_date' => e($license->purchase_date),
'purchase_cost' => e($license->purchase_cost),
2017-01-24 18:57:33 -08:00
'depreciation' => ($license->depreciation) ? $license->depreciation : null,
2017-01-24 19:24:47 -08:00
'notes' => e($license->notes),
'expiration_date' => e($license->expiration_date),
'totalSeats' => e($license->seats),
2017-01-24 18:57:33 -08:00
'remaining' => $license->remaincount(),
2017-01-24 19:24:47 -08:00
'license_name' => e($license->license_name),
'license_email' => e($license->license_email),
'maintained' => ($license->maintained == 1) ? true : false,
2017-01-24 18:57:33 -08:00
'supplier' => ($license->supplier) ? $license->supplier : null,
'created_at' => $license->created_at,
];
return $array;
}
public function transformAssetsDatatable($licenses) {
return (new DatatablesTransformer)->transformDatatables($licenses);
}
}