Adopt Laravel coding style
Shift automatically applies the Laravel coding style - which uses the PSR-2 coding style as a base with some minor additions. You may customize the adopted coding style by adding your own [PHP CS Fixer][1] `.php_cs` config file to your project root. Feel free to use [Shift's Laravel ruleset][2] to help you get started. [1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer [2]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Transformers;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
@@ -10,14 +11,14 @@ class AssetsTransformer
|
||||
{
|
||||
public function transformAssets(Collection $assets, $total)
|
||||
{
|
||||
$array = array();
|
||||
$array = [];
|
||||
foreach ($assets as $asset) {
|
||||
$array[] = self::transformAsset($asset);
|
||||
}
|
||||
|
||||
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
||||
}
|
||||
|
||||
|
||||
public function transformAsset(Asset $asset)
|
||||
{
|
||||
$array = [
|
||||
@@ -27,10 +28,10 @@ class AssetsTransformer
|
||||
'serial' => e($asset->serial),
|
||||
'model' => ($asset->model) ? [
|
||||
'id' => (int) $asset->model->id,
|
||||
'name'=> e($asset->model->name)
|
||||
'name'=> e($asset->model->name),
|
||||
] : null,
|
||||
'model_number' => (($asset->model) && ($asset->model->model_number)) ? e($asset->model->model_number) : null,
|
||||
'eol' => ($asset->purchase_date!='') ? Helper::getFormattedDateObject($asset->present()->eol_date(), 'date') : null ,
|
||||
'eol' => ($asset->purchase_date != '') ? Helper::getFormattedDateObject($asset->present()->eol_date(), 'date') : null,
|
||||
'status_label' => ($asset->assetstatus) ? [
|
||||
'id' => (int) $asset->assetstatus->id,
|
||||
'name'=> e($asset->assetstatus->name),
|
||||
@@ -39,34 +40,34 @@ class AssetsTransformer
|
||||
] : null,
|
||||
'category' => (($asset->model) && ($asset->model->category)) ? [
|
||||
'id' => (int) $asset->model->category->id,
|
||||
'name'=> e($asset->model->category->name)
|
||||
] : null,
|
||||
'name'=> e($asset->model->category->name),
|
||||
] : null,
|
||||
'manufacturer' => (($asset->model) && ($asset->model->manufacturer)) ? [
|
||||
'id' => (int) $asset->model->manufacturer->id,
|
||||
'name'=> e($asset->model->manufacturer->name)
|
||||
'name'=> e($asset->model->manufacturer->name),
|
||||
] : null,
|
||||
'supplier' => ($asset->supplier) ? [
|
||||
'id' => (int) $asset->supplier->id,
|
||||
'name'=> e($asset->supplier->name)
|
||||
] : null,
|
||||
'name'=> e($asset->supplier->name),
|
||||
] : null,
|
||||
'notes' => ($asset->notes) ? e($asset->notes) : null,
|
||||
'order_number' => ($asset->order_number) ? e($asset->order_number) : null,
|
||||
'company' => ($asset->company) ? [
|
||||
'id' => (int) $asset->company->id,
|
||||
'name'=> e($asset->company->name)
|
||||
'name'=> e($asset->company->name),
|
||||
] : null,
|
||||
'location' => ($asset->location) ? [
|
||||
'id' => (int) $asset->location->id,
|
||||
'name'=> e($asset->location->name)
|
||||
] : null,
|
||||
'name'=> e($asset->location->name),
|
||||
] : null,
|
||||
'rtd_location' => ($asset->defaultLoc) ? [
|
||||
'id' => (int) $asset->defaultLoc->id,
|
||||
'name'=> e($asset->defaultLoc->name)
|
||||
] : null,
|
||||
'name'=> e($asset->defaultLoc->name),
|
||||
] : null,
|
||||
'image' => ($asset->getImageUrl()) ? $asset->getImageUrl() : null,
|
||||
'assigned_to' => $this->transformAssignedTo($asset),
|
||||
'warranty_months' => ($asset->warranty_months > 0) ? e($asset->warranty_months . ' ' . trans('admin/hardware/form.months')) : null,
|
||||
'warranty_expires' => ($asset->warranty_months > 0) ? Helper::getFormattedDateObject($asset->warranty_expires, 'date') : null,
|
||||
'warranty_months' => ($asset->warranty_months > 0) ? e($asset->warranty_months.' '.trans('admin/hardware/form.months')) : null,
|
||||
'warranty_expires' => ($asset->warranty_months > 0) ? Helper::getFormattedDateObject($asset->warranty_expires, 'date') : null,
|
||||
'created_at' => Helper::getFormattedDateObject($asset->created_at, 'datetime'),
|
||||
'updated_at' => Helper::getFormattedDateObject($asset->updated_at, 'datetime'),
|
||||
'last_audit_date' => Helper::getFormattedDateObject($asset->last_audit_date, 'datetime'),
|
||||
@@ -82,14 +83,12 @@ class AssetsTransformer
|
||||
'user_can_checkout' => (bool) $asset->availableForCheckout(),
|
||||
];
|
||||
|
||||
|
||||
if (($asset->model) && ($asset->model->fieldset) && ($asset->model->fieldset->fields->count() > 0)) {
|
||||
$fields_array = array();
|
||||
$fields_array = [];
|
||||
|
||||
foreach ($asset->model->fieldset->fields as $field) {
|
||||
|
||||
if ($field->isFieldDecryptable($asset->{$field->convertUnicodeDbSlug()})) {
|
||||
$decrypted = \App\Helpers\Helper::gracefulDecrypt($field,$asset->{$field->convertUnicodeDbSlug()});
|
||||
$decrypted = \App\Helpers\Helper::gracefulDecrypt($field, $asset->{$field->convertUnicodeDbSlug()});
|
||||
$value = (Gate::allows('superadmin')) ? $decrypted : strtoupper(trans('admin/custom_fields/general.encrypted'));
|
||||
|
||||
$fields_array[$field->name] = [
|
||||
@@ -97,20 +96,17 @@ class AssetsTransformer
|
||||
'value' => $value,
|
||||
'field_format' => $field->format,
|
||||
];
|
||||
|
||||
} else {
|
||||
$fields_array[$field->name] = [
|
||||
'field' => $field->convertUnicodeDbSlug(),
|
||||
'value' => $asset->{$field->convertUnicodeDbSlug()},
|
||||
'field_format' => $field->format,
|
||||
];
|
||||
|
||||
|
||||
}
|
||||
$array['custom_fields'] = $fields_array;
|
||||
}
|
||||
} else {
|
||||
$array['custom_fields'] = array();
|
||||
$array['custom_fields'] = [];
|
||||
}
|
||||
|
||||
$permissions_array['available_actions'] = [
|
||||
@@ -119,10 +115,10 @@ class AssetsTransformer
|
||||
'clone' => Gate::allows('create', Asset::class),
|
||||
'restore' => false,
|
||||
'update' => (bool) Gate::allows('update', Asset::class),
|
||||
'delete' => ($asset->assigned_to=='' && Gate::allows('delete', Asset::class)),
|
||||
'delete' => ($asset->assigned_to == '' && Gate::allows('delete', Asset::class)),
|
||||
];
|
||||
|
||||
if ($asset->deleted_at!='') {
|
||||
if ($asset->deleted_at != '') {
|
||||
$permissions_array['available_actions'] = [
|
||||
'checkout' => true,
|
||||
'checkin' => false,
|
||||
@@ -133,8 +129,8 @@ class AssetsTransformer
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
$array += $permissions_array;
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
@@ -153,27 +149,29 @@ class AssetsTransformer
|
||||
'first_name'=> e($asset->assigned->first_name),
|
||||
'last_name'=> ($asset->assigned->last_name) ? e($asset->assigned->last_name) : null,
|
||||
'employee_number' => ($asset->assigned->employee_num) ? e($asset->assigned->employee_num) : null,
|
||||
'type' => 'user'
|
||||
'type' => 'user',
|
||||
] : null;
|
||||
}
|
||||
|
||||
return $asset->assigned ? [
|
||||
'id' => $asset->assigned->id,
|
||||
'name' => $asset->assigned->display_name,
|
||||
'type' => $asset->assignedType()
|
||||
'type' => $asset->assignedType(),
|
||||
] : null;
|
||||
}
|
||||
|
||||
|
||||
public function transformRequestedAssets(Collection $assets, $total)
|
||||
{
|
||||
$array = array();
|
||||
$array = [];
|
||||
foreach ($assets as $asset) {
|
||||
$array[] = self::transformRequestedAsset($asset);
|
||||
}
|
||||
|
||||
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
||||
}
|
||||
|
||||
public function transformRequestedAsset(Asset $asset) {
|
||||
public function transformRequestedAsset(Asset $asset)
|
||||
{
|
||||
$array = [
|
||||
'id' => (int) $asset->id,
|
||||
'name' => e($asset->name),
|
||||
@@ -193,8 +191,8 @@ class AssetsTransformer
|
||||
|
||||
];
|
||||
|
||||
$array += $permissions_array;
|
||||
return $array;
|
||||
$array += $permissions_array;
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user