mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 13:44:06 -08:00
aa8f1378c9
Signed-off-by: snipe <snipe@snipe.net> # Conflicts: # README.md # app/Http/Controllers/Accessories/AccessoriesController.php # app/Http/Controllers/Api/AssetMaintenancesController.php # app/Http/Controllers/Api/AssetModelsController.php # app/Http/Controllers/Api/AssetsController.php # app/Http/Controllers/Api/UsersController.php # app/Http/Controllers/AssetMaintenancesController.php # app/Http/Controllers/Assets/AssetFilesController.php # app/Http/Controllers/Assets/AssetsController.php # app/Http/Controllers/Assets/BulkAssetsController.php # app/Http/Controllers/Components/ComponentsController.php # app/Http/Controllers/Consumables/ConsumablesController.php # app/Http/Controllers/Licenses/LicenseFilesController.php # app/Http/Controllers/Licenses/LicensesController.php # app/Http/Controllers/Users/UserFilesController.php # app/Http/Transformers/AssetsTransformer.php # app/Http/Transformers/LicensesTransformer.php # app/Importer/UserImporter.php # app/Models/Asset.php # config/app.php # config/version.php # package-lock.json # public/js/build/app.js # public/js/dist/all.js # public/js/dist/bootstrap-table.js # public/mix-manifest.json # resources/lang/en/admin/users/message.php # resources/lang/is/button.php # resources/lang/ja/admin/kits/general.php # resources/lang/ro/admin/users/general.php # resources/lang/zh-HK/admin/depreciations/general.php # resources/lang/zh-HK/admin/models/general.php # resources/views/hardware/qr-view.blade.php # resources/views/hardware/view.blade.php # resources/views/partials/bootstrap-table.blade.php # resources/views/users/view.blade.php # routes/web.php # routes/web/hardware.php # routes/web/models.php # routes/web/users.php
73 lines
3.2 KiB
PHP
73 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Transformers;
|
|
|
|
use App\Helpers\Helper;
|
|
use App\Models\License;
|
|
use Gate;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
class LicensesTransformer
|
|
{
|
|
public function transformLicenses(Collection $licenses, $total)
|
|
{
|
|
$array = [];
|
|
foreach ($licenses as $license) {
|
|
$array[] = self::transformLicense($license);
|
|
}
|
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
}
|
|
|
|
public function transformLicense(License $license)
|
|
{
|
|
$array = [
|
|
'id' => (int) $license->id,
|
|
'name' => e($license->name),
|
|
'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,
|
|
'product_key' => (Gate::allows('viewKeys', License::class)) ? e($license->serial) : '------------',
|
|
'order_number' => e($license->order_number),
|
|
'purchase_order' => e($license->purchase_order),
|
|
'purchase_date' => Helper::getFormattedDateObject($license->purchase_date, 'date'),
|
|
'termination_date' => Helper::getFormattedDateObject($license->termination_date, 'date'),
|
|
'depreciation' => ($license->depreciation) ? ['id' => (int) $license->depreciation->id,'name'=> e($license->depreciation->name)] : null,
|
|
'purchase_cost' => Helper::formatCurrencyOutput($license->purchase_cost),
|
|
'purchase_cost_numeric' => $license->purchase_cost,
|
|
'notes' => e($license->notes),
|
|
'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'),
|
|
'seats' => (int) $license->seats,
|
|
'free_seats_count' => (int) $license->free_seats_count,
|
|
'license_name' => e($license->license_name),
|
|
'license_email' => e($license->license_email),
|
|
'reassignable' => ($license->reassignable == 1) ? true : false,
|
|
'maintained' => ($license->maintained == 1) ? true : false,
|
|
'supplier' => ($license->supplier) ? ['id' => (int) $license->supplier->id, 'name'=> e($license->supplier->name)] : null,
|
|
'category' => ($license->category) ? ['id' => (int) $license->category->id, 'name'=> e($license->category->name)] : null,
|
|
'created_at' => Helper::getFormattedDateObject($license->created_at, 'datetime'),
|
|
'updated_at' => Helper::getFormattedDateObject($license->updated_at, 'datetime'),
|
|
'user_can_checkout' => (bool) ($license->free_seats_count > 0),
|
|
];
|
|
|
|
$permissions_array['available_actions'] = [
|
|
'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),
|
|
];
|
|
|
|
$array += $permissions_array;
|
|
|
|
return $array;
|
|
}
|
|
|
|
public function transformAssetsDatatable($licenses)
|
|
{
|
|
return (new DatatablesTransformer)->transformDatatables($licenses);
|
|
}
|
|
|
|
|
|
|
|
}
|