Skip to content

A free open source IT asset/license management system

Applied pint to Traits and Transformers

snipea613380811f6
diff --git a/app/Http/Traits/ConvertsBase64ToFiles.php b/app/Http/Traits/ConvertsBase64ToFiles.php
index 4e023da267..39d1ce09f9 100644
--- a/app/Http/Traits/ConvertsBase64ToFiles.php
+++ b/app/Http/Traits/ConvertsBase64ToFiles.php
@@ -2,12 +2,12 @@
namespace App\Http\Traits;
-use Illuminate\Validation\ValidationException;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
-use Illuminate\Support\Str;
use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Str;
+use Illuminate\Validation\ValidationException;
trait ConvertsBase64ToFiles
{
@@ -30,13 +30,13 @@ trait ConvertsBase64ToFiles
Collection::make($flattened)->each(function ($filename, $key) {
rescue(function () use ($key, $filename) {
// dont process plain files
- if ( $this->file($key)){
+ if ($this->file($key)) {
return;
}
$base64Contents = $this->input($key);
- if (!$base64Contents) {
+ if (! $base64Contents) {
return;
}
@@ -59,18 +59,18 @@ trait ConvertsBase64ToFiles
$uploadedFile = new UploadedFile($tempFilePath, $filename, null, null, true);
- Log::debug("Trait: uploadedfile ". $tempFilePath);
- $this->offsetUnset($key);
- Log::debug("Trait: encoded field \"$key\" removed" );
-
- //Inserting new file to $this-files does not work so have to deal this after
- $this->offsetSet($key,$uploadedFile);
- Log::debug("Trait: field \"$key\" inserted as UplodedFile" );
-
+ Log::debug('Trait: uploadedfile '.$tempFilePath);
+ $this->offsetUnset($key);
+ Log::debug("Trait: encoded field \"$key\" removed");
+
+ // Inserting new file to $this-files does not work so have to deal this after
+ $this->offsetSet($key, $uploadedFile);
+ Log::debug("Trait: field \"$key\" inserted as UplodedFile");
+
}, null, false);
});
}
}
/**
* Loosely based on idea https://github.com/protonemedia/laravel-mixins/tree/master/src/Request
- * */
\ No newline at end of file
+ * */
diff --git a/app/Http/Traits/MigratesLegacyAssetLocations.php b/app/Http/Traits/MigratesLegacyAssetLocations.php
index ffc08893f9..67e546306f 100644
--- a/app/Http/Traits/MigratesLegacyAssetLocations.php
+++ b/app/Http/Traits/MigratesLegacyAssetLocations.php
@@ -12,23 +12,21 @@ trait MigratesLegacyAssetLocations
* as a location ID, which isn't valid. Later versions of Snipe-IT have stricter validation
* rules, so it's necessary to fix this for long-time users. It's kinda gross, but will help
* people (and their data) in the long run
- * @param Asset $asset
- * @return void
*/
private function migrateLegacyLocations(Asset $asset): void
{
if ($asset->rtd_location_id == '0') {
Log::debug('Manually override the RTD location IDs');
- Log::debug('Original RTD Location ID: ' . $asset->rtd_location_id);
+ Log::debug('Original RTD Location ID: '.$asset->rtd_location_id);
$asset->rtd_location_id = '';
- Log::debug('New RTD Location ID: ' . $asset->rtd_location_id);
+ Log::debug('New RTD Location ID: '.$asset->rtd_location_id);
}
if ($asset->location_id == '0') {
Log::debug('Manually override the location IDs');
- Log::debug('Original Location ID: ' . $asset->location_id);
+ Log::debug('Original Location ID: '.$asset->location_id);
$asset->location_id = '';
- Log::debug('New Location ID: ' . $asset->location_id);
+ Log::debug('New Location ID: '.$asset->location_id);
}
}
}
diff --git a/app/Http/Traits/TwoColumnUniqueUndeletedTrait.php b/app/Http/Traits/TwoColumnUniqueUndeletedTrait.php
index 0cf0edb455..98d509bf70 100644
--- a/app/Http/Traits/TwoColumnUniqueUndeletedTrait.php
+++ b/app/Http/Traits/TwoColumnUniqueUndeletedTrait.php
@@ -8,7 +8,7 @@ trait TwoColumnUniqueUndeletedTrait
* Prepare a unique_ids rule, adding a model identifier if required.
*
* @param array $parameters
- * @param string $field
+ * @param string $field
* @return string
*/
protected function prepareTwoColumnUniqueUndeletedRule($parameters)
diff --git a/app/Http/Traits/UniqueUndeletedTrait.php b/app/Http/Traits/UniqueUndeletedTrait.php
index d4c726bd73..c6b7765a40 100644
--- a/app/Http/Traits/UniqueUndeletedTrait.php
+++ b/app/Http/Traits/UniqueUndeletedTrait.php
@@ -8,7 +8,7 @@ trait UniqueUndeletedTrait
* Prepare a unique_ids rule, adding a model identifier if required.
*
* @param array $parameters
- * @param string $field
+ * @param string $field
* @return string
*/
protected function prepareUniqueUndeletedRule($parameters, $field)
diff --git a/app/Http/Transformers/AccessoriesTransformer.php b/app/Http/Transformers/AccessoriesTransformer.php
index b256917c0e..76b6d1baa1 100644
--- a/app/Http/Transformers/AccessoriesTransformer.php
+++ b/app/Http/Transformers/AccessoriesTransformer.php
@@ -4,8 +4,8 @@ namespace App\Http\Transformers;
use App\Helpers\Helper;
use App\Models\Accessory;
-use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Storage;
class AccessoriesTransformer
@@ -28,29 +28,29 @@ class AccessoriesTransformer
'image' => ($accessory->image) ? Storage::disk('public')->url('accessories/'.e($accessory->image)) : null,
'company' => ($accessory->company) ? [
'id' => $accessory->company->id,
- 'name'=> e($accessory->company->name),
- 'tag_color'=> ($accessory->company->tag_color) ? e($accessory->company->tag_color) : null,
+ 'name' => e($accessory->company->name),
+ 'tag_color' => ($accessory->company->tag_color) ? e($accessory->company->tag_color) : null,
] : null,
'manufacturer' => ($accessory->manufacturer) ? [
'id' => $accessory->manufacturer->id,
- 'name'=> e($accessory->manufacturer->name),
- 'tag_color'=> ($accessory->manufacturer->tag_color) ? e($accessory->manufacturer->tag_color) : null,
+ 'name' => e($accessory->manufacturer->name),
+ 'tag_color' => ($accessory->manufacturer->tag_color) ? e($accessory->manufacturer->tag_color) : null,
] : null,
'supplier' => ($accessory->supplier) ? [
'id' => $accessory->supplier->id,
- 'name'=> e($accessory->supplier->name),
- 'tag_color'=> ($accessory->supplier->tag_color) ? e($accessory->supplier->tag_color) : null,
+ 'name' => e($accessory->supplier->name),
+ 'tag_color' => ($accessory->supplier->tag_color) ? e($accessory->supplier->tag_color) : null,
] : null,
'model_number' => ($accessory->model_number) ? e($accessory->model_number) : null,
'category' => ($accessory->category) ? [
'id' => $accessory->category->id,
- 'name'=> e($accessory->category->name),
- 'tag_color'=> ($accessory->category->tag_color) ? e($accessory->category->tag_color) : null,
+ 'name' => e($accessory->category->name),
+ 'tag_color' => ($accessory->category->tag_color) ? e($accessory->category->tag_color) : null,
] : null,
'location' => ($accessory->location) ? [
'id' => $accessory->location->id,
- 'name'=> e($accessory->location->name),
- 'tag_color'=> ($accessory->location->tag_color) ? e($accessory->location->tag_color) : null,
+ 'name' => e($accessory->location->name),
+ 'tag_color' => ($accessory->location->tag_color) ? e($accessory->location->tag_color) : null,
] : null,
'notes' => ($accessory->notes) ? Helper::parseEscapedMarkedownInline($accessory->notes) : null,
'qty' => ($accessory->qty) ? (int) $accessory->qty : null,
@@ -62,10 +62,10 @@ class AccessoriesTransformer
'min_amt' => ($accessory->min_amt) ? (int) $accessory->min_amt : null,
'remaining_qty' => (int) ($accessory->qty - $accessory->checkouts_count), // Legacy - should phase out - replaced by below, for the bootstrap table formatter
'remaining' => (int) ($accessory->qty - $accessory->checkouts_count),
- 'checkouts_count' => $accessory->checkouts_count,
+ 'checkouts_count' => $accessory->checkouts_count,
'created_by' => ($accessory->adminuser) ? [
'id' => (int) $accessory->adminuser->id,
- 'name'=> e($accessory->adminuser->display_name),
+ 'name' => e($accessory->adminuser->display_name),
] : null,
'created_at' => Helper::getFormattedDateObject($accessory->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($accessory->updated_at, 'datetime'),
@@ -74,11 +74,11 @@ class AccessoriesTransformer
$permissions_array['available_actions'] = [
'checkout' => Gate::allows('checkout', Accessory::class),
- 'checkin' => false,
+ 'checkin' => false,
'update' => Gate::allows('update', Accessory::class),
'delete' => $accessory->checkouts_count === 0 && Gate::allows('delete', Accessory::class),
'clone' => Gate::allows('create', Accessory::class),
-
+
];
$permissions_array['user_can_checkout'] = false;
@@ -103,8 +103,8 @@ class AccessoriesTransformer
'note' => $checkout->note ? e($checkout->note) : null,
'created_by' => $checkout->adminuser ? [
'id' => (int) $checkout->adminuser->id,
- 'name'=> e($checkout->adminuser->present()->fullName),
- ]: null,
+ 'name' => e($checkout->adminuser->present()->fullName),
+ ] : null,
'created_at' => Helper::getFormattedDateObject($checkout->created_at, 'datetime'),
'available_actions' => Gate::allows('checkout', Accessory::class) ? ['checkin' => true] : ['checkin' => false],
];
@@ -122,9 +122,9 @@ class AccessoriesTransformer
if ($accessoryCheckout->checkedOutToUser()) {
return (new UsersTransformer)->transformUserCompact($accessoryCheckout->assigned);
} elseif ($accessoryCheckout->checkedOutToLocation()) {
- return (new LocationsTransformer())->transformLocationCompact($accessoryCheckout->assigned);
+ return (new LocationsTransformer)->transformLocationCompact($accessoryCheckout->assigned);
} elseif ($accessoryCheckout->checkedOutToAsset()) {
- return (new AssetsTransformer())->transformAssetCompact($accessoryCheckout->assigned);
+ return (new AssetsTransformer)->transformAssetCompact($accessoryCheckout->assigned);
}
}
}
diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php
index bc3f044d35..b7adbadb22 100644
--- a/app/Http/Transformers/ActionlogsTransformer.php
+++ b/app/Http/Transformers/ActionlogsTransformer.php
@@ -1,4 +1,5 @@
<?php
+
namespace App\Http\Transformers;
use App\Enums\ActionType;
@@ -6,15 +7,14 @@ use App\Helpers\Helper;
use App\Helpers\StorageHelper;
use App\Models\Actionlog;
use App\Models\Asset;
+use App\Models\AssetModel;
+use App\Models\Company;
use App\Models\CustomField;
+use App\Models\Location;
use App\Models\Setting;
use App\Models\Statuslabel;
-use App\Models\Company;
use App\Models\Supplier;
-use App\Models\Location;
-use App\Models\AssetModel;
use Illuminate\Database\Eloquent\Collection;
-use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Log;
@@ -22,14 +22,14 @@ use Illuminate\Support\Facades\Storage;
class ActionlogsTransformer
{
-
- public function transformActionlogs (Collection $actionlogs, $total)
+ public function transformActionlogs(Collection $actionlogs, $total)
{
- $array = array();
+ $array = [];
$settings = Setting::getSettings();
foreach ($actionlogs as $actionlog) {
$array[] = self::transformActionlog($actionlog, $settings);
}
+
return (new DatatablesTransformer)->transformDatatables($array, $total);
}
@@ -43,19 +43,20 @@ class ActionlogsTransformer
// {"_snipeit_right_sized_fault_tolerant_localareanetwo_1":
// {"old":null,"new":{"value":"1579490695972","_snipeit_new_field_2":2,"_snipeit_new_field_3":"Monday, 20 January 2020 2:24:55 PM"}}
// so we have to walk down that next level
- if(is_object($value) && isset($value->value)) {
+ if (is_object($value) && isset($value->value)) {
return $this->clean_field($value->value);
}
+
return is_scalar($value) || is_null($value) ? e($value) : e(json_encode($value));
}
- public function transformActionlog (Actionlog $actionlog, $settings = null)
+ public function transformActionlog(Actionlog $actionlog, $settings = null)
{
$icon = $actionlog->present()->icon();
- if (($actionlog->filename!='') && ($actionlog->action_type!='upload deleted')) {
- $icon = Helper::filetype_icon($actionlog->filename);
+ if (($actionlog->filename != '') && ($actionlog->action_type != 'upload deleted')) {
+ $icon = Helper::filetype_icon($actionlog->filename);
}
static $custom_fields = false;
@@ -64,10 +65,8 @@ class ActionlogsTransformer
$custom_fields = CustomField::all();
}
-
-
// This is necessary since we can't escape special characters within a JSON object
- if (($actionlog->log_meta) && ($actionlog->log_meta!='')) {
+ if (($actionlog->log_meta) && ($actionlog->log_meta != '')) {
$meta_array = json_decode($actionlog->log_meta);
$clean_meta = [];
@@ -86,7 +85,7 @@ class ActionlogsTransformer
if ($custom_field->db_column == $fieldname) {
- if ($custom_field->field_encrypted == '1') {
+ if ($custom_field->field_encrypted == '1') {
// Unset these fields. We need to decrypt them, since even if the decrypted value
// didn't change, their value in the DB will, so we have to compare the unencrypted version
@@ -97,7 +96,7 @@ class ActionlogsTransformer
$enc_old = '';
$enc_new = '';
- if ($this->clean_field($fieldata->old!='')) {
+ if ($this->clean_field($fieldata->old != '')) {
try {
$enc_old = Crypt::decryptString($this->clean_field($fieldata->old));
} catch (\Exception $e) {
@@ -105,7 +104,7 @@ class ActionlogsTransformer
}
}
- if ($this->clean_field($fieldata->new!='')) {
+ if ($this->clean_field($fieldata->new != '')) {
try {
$enc_new = Crypt::decryptString($this->clean_field($fieldata->new));
} catch (\Exception $e) {
@@ -114,8 +113,8 @@ class ActionlogsTransformer
}
if ($enc_old != $enc_new) {
- $clean_meta[$fieldname]['old'] = "************";
- $clean_meta[$fieldname]['new'] = "************";
+ $clean_meta[$fieldname]['old'] = '************';
+ $clean_meta[$fieldname]['new'] = '************';
// Display the changes if the user is an admin or superadmin
if (Gate::allows('admin')) {
@@ -125,7 +124,6 @@ class ActionlogsTransformer
}
-
}
}
@@ -136,14 +134,13 @@ class ActionlogsTransformer
}
}
- $clean_meta= $this->changedInfo($clean_meta);
+ $clean_meta = $this->changedInfo($clean_meta);
}
-
$array = [
- 'id' => (int) $actionlog->id,
- 'icon' => $icon,
- 'file' => ($actionlog->filename!='')
+ 'id' => (int) $actionlog->id,
+ 'icon' => $icon,
+ 'file' => ($actionlog->filename != '')
?
[
'url' => $actionlog->uploads_file_url(),
@@ -157,29 +154,29 @@ class ActionlogsTransformer
'id' => (int) $actionlog->item->id,
'name' => e($actionlog->item->display_name) ?? null,
'type' => e($actionlog->itemType()),
- 'serial' => e($actionlog->item->serial) ? e($actionlog->item->serial) : null
+ 'serial' => e($actionlog->item->serial) ? e($actionlog->item->serial) : null,
] : null,
'location' => ($actionlog->location) ? [
'id' => (int) $actionlog->location->id,
'name' => e($actionlog->location->name),
- 'tag_color'=> ($actionlog->location->tag_color) ? e($actionlog->location->tag_color) : null,
+ 'tag_color' => ($actionlog->location->tag_color) ? e($actionlog->location->tag_color) : null,
] : null,
- 'created_at' => Helper::getFormattedDateObject($actionlog->created_at, 'datetime'),
- 'updated_at' => Helper::getFormattedDateObject($actionlog->updated_at, 'datetime'),
- 'next_audit_date' => ($actionlog->itemType()=='asset') ? Helper::getFormattedDateObject($actionlog->calcNextAuditDate(null, $actionlog->item), 'date'): null,
+ 'created_at' => Helper::getFormattedDateObject($actionlog->created_at, 'datetime'),
+ 'updated_at' => Helper::getFormattedDateObject($actionlog->updated_at, 'datetime'),
+ 'next_audit_date' => ($actionlog->itemType() == 'asset') ? Helper::getFormattedDateObject($actionlog->calcNextAuditDate(null, $actionlog->item), 'date') : null,
'days_to_next_audit' => $actionlog->daysUntilNextAudit($settings->audit_interval, $actionlog->item),
- 'action_type' => $actionlog->present()->actionType(),
+ 'action_type' => $actionlog->present()->actionType(),
'admin' => ($actionlog->adminuser) ? [
'id' => (int) $actionlog->adminuser->id,
'name' => e($actionlog->adminuser->display_name) ?? null,
- 'first_name'=> e($actionlog->adminuser->first_name),
- 'last_name'=> e($actionlog->adminuser->last_name)
+ 'first_name' => e($actionlog->adminuser->first_name),
+ 'last_name' => e($actionlog->adminuser->last_name),
] : null,
'created_by' => ($actionlog->adminuser) ? [
'id' => (int) $actionlog->adminuser->id,
'name' => e($actionlog->adminuser->display_name),
- 'first_name'=> e($actionlog->adminuser->first_name),
- 'last_name'=> e($actionlog->adminuser->last_name)
+ 'first_name' => e($actionlog->adminuser->first_name),
+ 'last_name' => e($actionlog->adminuser->last_name),
] : null,
'target' => ($actionlog->target) ? [
'id' => (int) $actionlog->target->id,
@@ -187,39 +184,37 @@ class ActionlogsTransformer
'type' => e($actionlog->targetType()),
] : null,
'quantity' => $this->getQuantity($actionlog),
- 'note' => ($actionlog->note) ? Helper::parseEscapedMarkedownInline($actionlog->note): null,
- 'signature_file' => (($actionlog->accept_signature) && Storage::exists('private_uploads/signatures/'.$actionlog->accept_signature)) ? route('log.signature.view', ['filename' => $actionlog->accept_signature ]) : null,
- 'log_meta' => ((isset($clean_meta)) && (is_array($clean_meta))) ? $clean_meta: null,
+ 'note' => ($actionlog->note) ? Helper::parseEscapedMarkedownInline($actionlog->note) : null,
+ 'signature_file' => (($actionlog->accept_signature) && Storage::exists('private_uploads/signatures/'.$actionlog->accept_signature)) ? route('log.signature.view', ['filename' => $actionlog->accept_signature]) : null,
+ 'log_meta' => ((isset($clean_meta)) && (is_array($clean_meta))) ? $clean_meta : null,
'remote_ip' => e($actionlog->remote_ip) ?? null,
'user_agent' => e($actionlog->user_agent) ?? null,
- 'action_source' => ($actionlog->action_source) ?? null,
- 'action_date' => ($actionlog->action_date) ? Helper::getFormattedDateObject($actionlog->action_date, 'datetime'): Helper::getFormattedDateObject($actionlog->created_at, 'datetime'),
+ 'action_source' => ($actionlog->action_source) ?? null,
+ 'action_date' => ($actionlog->action_date) ? Helper::getFormattedDateObject($actionlog->action_date, 'datetime') : Helper::getFormattedDateObject($actionlog->created_at, 'datetime'),
];
-// Log::info("Clean Meta is: ".print_r($clean_meta,true));
- //dd($array);
+ // Log::info("Clean Meta is: ".print_r($clean_meta,true));
+ // dd($array);
return $array;
}
-
-
- public function transformCheckedoutActionlog (Collection $accessories_checkout, $total)
+ public function transformCheckedoutActionlog(Collection $accessories_checkout, $total)
{
- $array = array();
+ $array = [];
foreach ($accessories_checkout as $user) {
$array[] = (new UsersTransformer)->transformUser($user);
}
+
return (new DatatablesTransformer)->transformDatatables($array, $total);
}
+
/**
* This takes the ids of the changed attributes and returns the names instead for the history view of an Asset
*
- * @param array $clean_meta
* @return array
*/
-
public function changedInfo(array $clean_meta)
{
static $location = false;
@@ -228,7 +223,6 @@ class ActionlogsTransformer
static $status = false;
static $company = false;
-
if ($location === false) {
$location = Location::select('id', 'name')->withTrashed()->get();
}
@@ -245,7 +239,7 @@ class ActionlogsTransformer
$company = Company::select('id', 'name')->get();
}
- if(array_key_exists('rtd_location_id',$clean_meta)) {
+ if (array_key_exists('rtd_location_id', $clean_meta)) {
$oldRtd = $location->find($clean_meta['rtd_location_id']['old']);
$oldRtdName = $oldRtd ? e($oldRtd->name) : trans('general.deleted');
@@ -253,13 +247,12 @@ class ActionlogsTransformer
$newRtd = $location->find($clean_meta['rtd_location_id']['new']);
$newRtdName = $newRtd ? e($newRtd->name) : trans('general.deleted');
- $clean_meta['rtd_location_id']['old'] = $clean_meta['rtd_location_id']['old'] ? "[id: ".$clean_meta['rtd_location_id']['old']."] ". $oldRtdName : '';
- $clean_meta['rtd_location_id']['new'] = $clean_meta['rtd_location_id']['new'] ? "[id: ".$clean_meta['rtd_location_id']['new']."] ". $newRtdName : '';
+ $clean_meta['rtd_location_id']['old'] = $clean_meta['rtd_location_id']['old'] ? '[id: '.$clean_meta['rtd_location_id']['old'].'] '.$oldRtdName : '';
+ $clean_meta['rtd_location_id']['new'] = $clean_meta['rtd_location_id']['new'] ? '[id: '.$clean_meta['rtd_location_id']['new'].'] '.$newRtdName : '';
$clean_meta[trans('admin/hardware/form.default_location')] = $clean_meta['rtd_location_id'];
unset($clean_meta['rtd_location_id']);
}
-
if (array_key_exists('location_id', $clean_meta)) {
$oldLocation = $location->find($clean_meta['location_id']['old']);
@@ -268,14 +261,13 @@ class ActionlogsTransformer
$newLocation = $location->find($clean_meta['location_id']['new']);
$newLocationName = $newLocation ? e($newLocation->name) : trans('general.deleted');
-
- $clean_meta['location_id']['old'] = $clean_meta['location_id']['old'] ? "[id: ".$clean_meta['location_id']['old']."] ". $oldLocationName : '';
- $clean_meta['location_id']['new'] = $clean_meta['location_id']['new'] ? "[id: ".$clean_meta['location_id']['new']."] ". $newLocationName : '';
+ $clean_meta['location_id']['old'] = $clean_meta['location_id']['old'] ? '[id: '.$clean_meta['location_id']['old'].'] '.$oldLocationName : '';
+ $clean_meta['location_id']['new'] = $clean_meta['location_id']['new'] ? '[id: '.$clean_meta['location_id']['new'].'] '.$newLocationName : '';
$clean_meta[trans('admin/locations/message.current_location')] = $clean_meta['location_id'];
unset($clean_meta['location_id']);
}
- if(array_key_exists('model_id', $clean_meta)) {
+ if (array_key_exists('model_id', $clean_meta)) {
$oldModel = $model->find($clean_meta['model_id']['old']);
$oldModelName = $oldModel ? e($oldModel->name) : trans('admin/models/message.deleted');
@@ -283,13 +275,12 @@ class ActionlogsTransformer
$newModel = $model->find($clean_meta['model_id']['new']);
$newModelName = $newModel ? e($newModel->name) : trans('admin/models/message.deleted');
- $clean_meta['model_id']['old'] = "[id: ".$clean_meta['model_id']['old']."] ".$oldModelName;
- $clean_meta['model_id']['new'] = "[id: ".$clean_meta['model_id']['new']."] ".$newModelName; /** model is required at asset creation */
-
+ $clean_meta['model_id']['old'] = '[id: '.$clean_meta['model_id']['old'].'] '.$oldModelName;
+ $clean_meta['model_id']['new'] = '[id: '.$clean_meta['model_id']['new'].'] '.$newModelName; /** model is required at asset creation */
$clean_meta[trans('admin/hardware/form.model')] = $clean_meta['model_id'];
unset($clean_meta['model_id']);
}
- if(array_key_exists('company_id', $clean_meta)) {
+ if (array_key_exists('company_id', $clean_meta)) {
$oldCompany = $company->find($clean_meta['company_id']['old']);
$oldCompanyName = $oldCompany ? e($oldCompany->name) : trans('admin/company/message.deleted');
@@ -297,12 +288,12 @@ class ActionlogsTransformer
$newCompany = $company->find($clean_meta['company_id']['new']);
$newCompanyName = $newCompany ? e($newCompany->name) : trans('admin/company/message.deleted');
- $clean_meta['company_id']['old'] = $clean_meta['company_id']['old'] ? "[id: ".$clean_meta['company_id']['old']."] ". $oldCompanyName : trans('general.unassigned');
- $clean_meta['company_id']['new'] = $clean_meta['company_id']['new'] ? "[id: ".$clean_meta['company_id']['new']."] ". $newCompanyName : trans('general.unassigned');
+ $clean_meta['company_id']['old'] = $clean_meta['company_id']['old'] ? '[id: '.$clean_meta['company_id']['old'].'] '.$oldCompanyName : trans('general.unassigned');
+ $clean_meta['company_id']['new'] = $clean_meta['company_id']['new'] ? '[id: '.$clean_meta['company_id']['new'].'] '.$newCompanyName : trans('general.unassigned');
$clean_meta[trans('general.company')] = $clean_meta['company_id'];
unset($clean_meta['company_id']);
}
- if(array_key_exists('supplier_id', $clean_meta)) {
+ if (array_key_exists('supplier_id', $clean_meta)) {
$oldSupplier = $supplier->find($clean_meta['supplier_id']['old']);
$oldSupplierName = $oldSupplier ? e($oldSupplier->name) : trans('admin/suppliers/message.deleted');
@@ -310,12 +301,12 @@ class ActionlogsTransformer
$newSupplier = $supplier->find($clean_meta['supplier_id']['new']);
$newSupplierName = $newSupplier ? e($newSupplier->name) : trans('admin/suppliers/message.deleted');
- $clean_meta['supplier_id']['old'] = $clean_meta['supplier_id']['old'] ? "[id: ".$clean_meta['supplier_id']['old']."] ". $oldSupplierName : trans('general.unassigned');
- $clean_meta['supplier_id']['new'] = $clean_meta['supplier_id']['new'] ? "[id: ".$clean_meta['supplier_id']['new']."] ". $newSupplierName : trans('general.unassigned');
+ $clean_meta['supplier_id']['old'] = $clean_meta['supplier_id']['old'] ? '[id: '.$clean_meta['supplier_id']['old'].'] '.$oldSupplierName : trans('general.unassigned');
+ $clean_meta['supplier_id']['new'] = $clean_meta['supplier_id']['new'] ? '[id: '.$clean_meta['supplier_id']['new'].'] '.$newSupplierName : trans('general.unassigned');
$clean_meta[trans('general.supplier')] = $clean_meta['supplier_id'];
unset($clean_meta['supplier_id']);
}
- if(array_key_exists('status_id', $clean_meta)) {
+ if (array_key_exists('status_id', $clean_meta)) {
$oldStatus = $status->find($clean_meta['status_id']['old']);
$oldStatusName = $oldStatus ? e($oldStatus->name) : trans('admin/statuslabels/message.deleted_label');
@@ -323,12 +314,12 @@ class ActionlogsTransformer
$newStatus = $status->find($clean_meta['status_id']['new']);
$newStatusName = $newStatus ? e($newStatus->name) : trans('admin/statuslabels/message.deleted_label');
- $clean_meta['status_id']['old'] = $clean_meta['status_id']['old'] ? "[id: ".$clean_meta['status_id']['old']."] ". $oldStatusName : trans('general.unassigned');
- $clean_meta['status_id']['new'] = $clean_meta['status_id']['new'] ? "[id: ".$clean_meta['status_id']['new']."] ". $newStatusName : trans('general.unassigned');
+ $clean_meta['status_id']['old'] = $clean_meta['status_id']['old'] ? '[id: '.$clean_meta['status_id']['old'].'] '.$oldStatusName : trans('general.unassigned');
+ $clean_meta['status_id']['new'] = $clean_meta['status_id']['new'] ? '[id: '.$clean_meta['status_id']['new'].'] '.$newStatusName : trans('general.unassigned');
$clean_meta[trans('general.status_label')] = $clean_meta['status_id'];
unset($clean_meta['status_id']);
}
- if(array_key_exists('asset_eol_date', $clean_meta)) {
+ if (array_key_exists('asset_eol_date', $clean_meta)) {
$clean_meta[trans('admin/hardware/form.eol_date')] = $clean_meta['asset_eol_date'];
unset($clean_meta['asset_eol_date']);
}
@@ -339,12 +330,12 @@ class ActionlogsTransformer
private function getQuantity(Actionlog $actionlog): ?int
{
- if (!$actionlog->quantity) {
+ if (! $actionlog->quantity) {
return null;
}
// only a few action types will have a quantity we are interested in.
- if (!in_array($actionlog->action_type, [
+ if (! in_array($actionlog->action_type, [
ActionType::Checkout->value,
ActionType::Accepted->value,
ActionType::Declined->value,
@@ -357,6 +348,4 @@ class ActionlogsTransformer
return (int) $actionlog->quantity;
}
-
-
}
diff --git a/app/Http/Transformers/AssetModelsTransformer.php b/app/Http/Transformers/AssetModelsTransformer.php
index 129e395ed8..82506f5c50 100644
--- a/app/Http/Transformers/AssetModelsTransformer.php
+++ b/app/Http/Transformers/AssetModelsTransformer.php
@@ -4,8 +4,8 @@ namespace App\Http\Transformers;
use App\Helpers\Helper;
use App\Models\AssetModel;
-use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Storage;
class AssetModelsTransformer
@@ -23,16 +23,16 @@ class AssetModelsTransformer
public function transformAssetModel(AssetModel $assetmodel)
{
- $default_field_values = array();
+ $default_field_values = [];
// Reach into the custom fields and models_custom_fields pivot table to find the default values for this model
if ($assetmodel->fieldset) {
- foreach($assetmodel->fieldset->fields AS $field) {
+ foreach ($assetmodel->fieldset->fields as $field) {
$default_field_values[] = [
'name' => e($field->name),
'db_column_name' => e($field->db_column_name()),
'default_value' => ($field->defaultValue($assetmodel->id)) ? e($field->defaultValue($assetmodel->id)) : null,
- 'format' => e($field->format),
+ 'format' => e($field->format),
'required' => ($field->pivot->required == '1') ? true : false,
];
}
@@ -43,16 +43,16 @@ class AssetModelsTransformer
'name' => e($assetmodel->name),
'manufacturer' => ($assetmodel->manufacturer) ? [
'id' => (int) $assetmodel->manufacturer->id,
- 'name'=> e($assetmodel->manufacturer->name),
- 'tag_color'=> ($assetmodel->manufacturer->tag_color) ? e($assetmodel->manufacturer->tag_color) : null,
+ 'name' => e($assetmodel->manufacturer->name),
+ 'tag_color' => ($assetmodel->manufacturer->tag_color) ? e($assetmodel->manufacturer->tag_color) : null,
] : null,
'image' => ($assetmodel->image != '') ? Storage::disk('public')->url('models/'.e($assetmodel->image)) : null,
- 'model_number' => ($assetmodel->model_number ? e($assetmodel->model_number): null),
- 'min_amt' => ($assetmodel->min_amt) ? (int) $assetmodel->min_amt : null,
+ 'model_number' => ($assetmodel->model_number ? e($assetmodel->model_number) : null),
+ 'min_amt' => ($assetmodel->min_amt) ? (int) $assetmodel->min_amt : null,
'depreciation' => ($assetmodel->depreciation) ? [
'id' => (int) $assetmodel->depreciation->id,
- 'name'=> e($assetmodel->depreciation->name),
+ 'name' => e($assetmodel->depreciation->name),
] : null,
'assets_count' => (int) $assetmodel->assets_count,
'assets_assigned_count' => (int) $assetmodel->assets_assigned_count,
@@ -60,12 +60,12 @@ class AssetModelsTransformer
'remaining' => (int) ($assetmodel->assets_count - (int) $assetmodel->assets_assigned_count) - (int) $assetmodel->assets_archived_count,
'category' => ($assetmodel->category) ? [
'id' => (int) $assetmodel->category->id,
- 'name'=> e($assetmodel->category->name),
- 'tag_color'=> ($assetmodel->category->tag_color) ? e($assetmodel->category->tag_color) : null,
+ 'name' => e($assetmodel->category->name),
+ 'tag_color' => ($assetmodel->category->tag_color) ? e($assetmodel->category->tag_color) : null,
] : null,
'fieldset' => ($assetmodel->fieldset) ? [
'id' => (int) $assetmodel->fieldset->id,
- 'name'=> e($assetmodel->fieldset->name),
+ 'name' => e($assetmodel->fieldset->name),
] : null,
'default_fieldset_values' => $default_field_values,
'eol' => ($assetmodel->eol > 0) ? $assetmodel->eol.' months' : 'None',
@@ -74,7 +74,7 @@ class AssetModelsTransformer
'notes' => Helper::parseEscapedMarkedownInline($assetmodel->notes),
'created_by' => ($assetmodel->adminuser) ? [
'id' => (int) $assetmodel->adminuser->id,
- 'name'=> e($assetmodel->adminuser->display_name),
+ 'name' => e($assetmodel->adminuser->display_name),
] : null,
'created_at' => Helper::getFormattedDateObject($assetmodel->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($assetmodel->updated_at, 'datetime'),
@@ -115,7 +115,7 @@ class AssetModelsTransformer
'url' => route('show/modelfile', [$assetmodel->id, $file->id]),
'created_by' => ($file->adminuser) ? [
'id' => (int) $file->adminuser->id,
- 'name'=> e($file->adminuser->display_name),
+ 'name' => e($file->adminuser->display_name),
] : null,
'created_at' => Helper::getFormattedDateObject($file->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($file->updated_at, 'datetime'),
@@ -127,6 +127,7 @@ class AssetModelsTransformer
];
$array += $permissions_array;
+
return $array;
}
diff --git a/app/Http/Transformers/AssetsTransformer.php b/app/Http/Transformers/AssetsTransformer.php
index 4e501da786..f08704039e 100644
--- a/app/Http/Transformers/AssetsTransformer.php
+++ b/app/Http/Transformers/AssetsTransformer.php
@@ -7,9 +7,9 @@ use App\Models\Accessory;
use App\Models\AccessoryCheckout;
use App\Models\Asset;
use App\Models\Setting;
-use Illuminate\Support\Facades\Gate;
-use Illuminate\Database\Eloquent\Collection;
use Carbon\Carbon;
+use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Storage;
class AssetsTransformer
@@ -36,67 +36,67 @@ 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,
'byod' => ($asset->byod ? true : false),
'requestable' => ($asset->requestable ? true : false),
'model_number' => (($asset->model) && ($asset->model->model_number)) ? e($asset->model->model_number) : null,
- 'eol' => (($asset->asset_eol_date != '') && ($asset->purchase_date != '')) ? (int) Carbon::parse($asset->asset_eol_date)->diffInMonths($asset->purchase_date, true) . ' months' : null,
+ 'eol' => (($asset->asset_eol_date != '') && ($asset->purchase_date != '')) ? (int) Carbon::parse($asset->asset_eol_date)->diffInMonths($asset->purchase_date, true).' months' : null,
'asset_eol_date' => ($asset->asset_eol_date != '') ? Helper::getFormattedDateObject($asset->asset_eol_date, 'date') : null,
'status_label' => ($asset->assetstatus) ? [
'id' => (int) $asset->assetstatus->id,
- 'name'=> e($asset->assetstatus->name),
- 'status_type'=> e($asset->assetstatus->getStatuslabelType()),
+ 'name' => e($asset->assetstatus->name),
+ 'status_type' => e($asset->assetstatus->getStatuslabelType()),
'status_meta' => e($asset->present()->statusMeta),
] : null,
'category' => (($asset->model) && ($asset->model->category)) ? [
'id' => (int) $asset->model->category->id,
- 'name'=> e($asset->model->category->name),
- 'tag_color'=> ($asset->model->category->tag_color) ? e($asset->model->category->tag_color) : null,
+ 'name' => e($asset->model->category->name),
+ 'tag_color' => ($asset->model->category->tag_color) ? e($asset->model->category->tag_color) : null,
] : null,
'manufacturer' => (($asset->model) && ($asset->model->manufacturer)) ? [
'id' => (int) $asset->model->manufacturer->id,
- 'name'=> e($asset->model->manufacturer->name),
- 'tag_color'=> ($asset->model->manufacturer->tag_color) ? e($asset->model->manufacturer->tag_color) : null,
+ 'name' => e($asset->model->manufacturer->name),
+ 'tag_color' => ($asset->model->manufacturer->tag_color) ? e($asset->model->manufacturer->tag_color) : null,
] : null,
'depreciation' => (($asset->model) && ($asset->model->depreciation)) ? [
'id' => (int) $asset->model->depreciation->id,
- 'name'=> e($asset->model->depreciation->name),
- 'months'=> (int) $asset->model->depreciation->months,
- 'type'=> e($asset->model->depreciation->depreciation_type),
- 'minimum'=> ($asset->model->depreciation->depreciation_min) ? (int) $asset->model->depreciation->depreciation_min : null,
+ 'name' => e($asset->model->depreciation->name),
+ 'months' => (int) $asset->model->depreciation->months,
+ 'type' => e($asset->model->depreciation->depreciation_type),
+ 'minimum' => ($asset->model->depreciation->depreciation_min) ? (int) $asset->model->depreciation->depreciation_min : null,
] : null,
'supplier' => ($asset->supplier) ? [
'id' => (int) $asset->supplier->id,
- 'name'=> e($asset->supplier->name),
- 'tag_color'=> ($asset->supplier->tag_color) ? e($asset->supplier->tag_color) : null,
+ 'name' => e($asset->supplier->name),
+ 'tag_color' => ($asset->supplier->tag_color) ? e($asset->supplier->tag_color) : null,
] : null,
'notes' => ($asset->notes) ? Helper::parseEscapedMarkedownInline($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),
- 'tag_color'=> ($asset->company->tag_color) ? e($asset->company->tag_color) : null,
+ 'name' => e($asset->company->name),
+ 'tag_color' => ($asset->company->tag_color) ? e($asset->company->tag_color) : null,
] : null,
'location' => ($asset->location) ? [
'id' => (int) $asset->location->id,
- 'name'=> e($asset->location->name),
- 'tag_color'=> ($asset->location->tag_color) ? e($asset->location->tag_color) : null,
+ 'name' => e($asset->location->name),
+ 'tag_color' => ($asset->location->tag_color) ? e($asset->location->tag_color) : null,
] : null,
'rtd_location' => ($asset->defaultLoc) ? [
'id' => (int) $asset->defaultLoc->id,
- 'name'=> e($asset->defaultLoc->name),
- 'tag_color'=> ($asset->defaultLoc->tag_color) ? e($asset->defaultLoc->tag_color) : null,
+ 'name' => e($asset->defaultLoc->name),
+ 'tag_color' => ($asset->defaultLoc->tag_color) ? e($asset->defaultLoc->tag_color) : null,
] : null,
'image' => ($asset->getImageUrl()) ? $asset->getImageUrl() : null,
- 'qr' => ($setting->qr_code=='1') ? config('app.url').'/uploads/barcodes/qr-'.str_slug($asset->asset_tag).'-'.str_slug($asset->id).'.png' : null,
- 'alt_barcode' => ($setting->alt_barcode_enabled=='1') ? config('app.url').'/uploads/barcodes/'.str_slug($setting->alt_barcode).'-'.str_slug($asset->asset_tag).'.png' : null,
+ 'qr' => ($setting->qr_code == '1') ? config('app.url').'/uploads/barcodes/qr-'.str_slug($asset->asset_tag).'-'.str_slug($asset->id).'.png' : null,
+ 'alt_barcode' => ($setting->alt_barcode_enabled == '1') ? config('app.url').'/uploads/barcodes/'.str_slug($setting->alt_barcode).'-'.str_slug($asset->asset_tag).'.png' : null,
'assigned_to' => $this->transformAssignedTo($asset),
- 'warranty_months' => ($asset->warranty_months > 0) ? e($asset->warranty_months.' '.trans('admin/hardware/form.months')) : 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_by' => ($asset->adminuser) ? [
'id' => (int) $asset->adminuser->id,
- 'name'=> e($asset->adminuser->display_name),
+ 'name' => e($asset->adminuser->display_name),
] : null,
'created_at' => Helper::getFormattedDateObject($asset->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($asset->updated_at, 'datetime'),
@@ -104,7 +104,7 @@ class AssetsTransformer
'next_audit_date' => Helper::getFormattedDateObject($asset->next_audit_date, 'date'),
'deleted_at' => Helper::getFormattedDateObject($asset->deleted_at, 'datetime'),
'purchase_date' => Helper::getFormattedDateObject($asset->purchase_date, 'date'),
-// 'first_checkout' => Helper::getFormattedDateObject($asset->first_checkout_at, 'datetime'),
+ // 'first_checkout' => Helper::getFormattedDateObject($asset->first_checkout_at, 'datetime'),
'age' => $asset->purchase_date ? $asset->purchase_date->locale(app()->getLocale())->diffForHumans() : '',
'last_checkout' => Helper::getFormattedDateObject($asset->last_checkout, 'datetime'),
'last_checkin' => Helper::getFormattedDateObject($asset->last_checkin, 'datetime'),
@@ -117,7 +117,6 @@ class AssetsTransformer
'book_value' => Helper::formatCurrencyOutput($asset->getDepreciatedValue()),
];
-
if (($asset->model) && ($asset->model->fieldset) && ($asset->model->fieldset->fields->count() > 0)) {
$fields_array = [];
@@ -126,28 +125,28 @@ class AssetsTransformer
$decrypted = Helper::gracefulDecrypt($field, $asset->{$field->db_column});
$value = (Gate::allows('assets.view.encrypted_custom_fields')) ? $decrypted : strtoupper(trans('admin/custom_fields/general.encrypted'));
- if ($field->format == 'DATE'){
- if (Gate::allows('assets.view.encrypted_custom_fields')){
+ if ($field->format == 'DATE') {
+ if (Gate::allows('assets.view.encrypted_custom_fields')) {
$value = Helper::getFormattedDateObject($value, 'date', false);
} else {
- $value = strtoupper(trans('admin/custom_fields/general.encrypted'));
+ $value = strtoupper(trans('admin/custom_fields/general.encrypted'));
}
}
$fields_array[$field->name] = [
- 'field' => e($field->db_column),
- 'value' => e($value),
- 'field_format' => $field->format,
- 'element' => $field->element,
- ];
+ 'field' => e($field->db_column),
+ 'value' => e($value),
+ 'field_format' => $field->format,
+ 'element' => $field->element,
+ ];
} else {
$value = $asset->{$field->db_column};
- if (($field->format == 'DATE') && (!is_null($value)) && ($value!='')){
+ if (($field->format == 'DATE') && (! is_null($value)) && ($value != '')) {
$value = Helper::getFormattedDateObject($value, 'date', false);
}
-
+
$fields_array[$field->name] = [
'field' => e($field->db_column),
'value' => e($value),
@@ -163,38 +162,37 @@ class AssetsTransformer
}
$permissions_array['available_actions'] = [
- 'checkout' => ($asset->deleted_at=='' && Gate::allows('checkout', Asset::class)) ? true : false,
- 'checkin' => ($asset->deleted_at=='' && Gate::allows('checkin', Asset::class)) ? true : false,
- 'clone' => Gate::allows('create', Asset::class) ? true : false,
- 'restore' => ($asset->deleted_at!='' && Gate::allows('create', Asset::class)) ? true : false,
- 'update' => ($asset->deleted_at=='' && Gate::allows('update', Asset::class)) ? true : false,
- 'audit' => Gate::allows('audit', Asset::class) ? true : false,
- 'delete' => ($asset->deleted_at=='' && $asset->assigned_to =='' && Gate::allows('delete', Asset::class) && ($asset->deleted_at == '')) ? true : false,
- ];
-
-
- if (request('components')=='true') {
-
+ 'checkout' => ($asset->deleted_at == '' && Gate::allows('checkout', Asset::class)) ? true : false,
+ 'checkin' => ($asset->deleted_at == '' && Gate::allows('checkin', Asset::class)) ? true : false,
+ 'clone' => Gate::allows('create', Asset::class) ? true : false,
+ 'restore' => ($asset->deleted_at != '' && Gate::allows('create', Asset::class)) ? true : false,
+ 'update' => ($asset->deleted_at == '' && Gate::allows('update', Asset::class)) ? true : false,
+ 'audit' => Gate::allows('audit', Asset::class) ? true : false,
+ 'delete' => ($asset->deleted_at == '' && $asset->assigned_to == '' && Gate::allows('delete', Asset::class) && ($asset->deleted_at == '')) ? true : false,
+ ];
+
+ if (request('components') == 'true') {
+
if ($asset->components) {
$array['components'] = [];
-
+
foreach ($asset->components as $component) {
$array['components'][] = [
-
- 'id' => $component->id,
- 'pivot_id' => $component->pivot->id,
- 'name' => e($component->name),
- 'qty' => $component->pivot->assigned_qty,
- 'price_cost' => $component->purchase_cost,
- 'purchase_total' => $component->purchase_cost * $component->pivot->assigned_qty,
- 'checkout_date' => Helper::getFormattedDateObject($component->pivot->created_at, 'datetime') ,
-
+
+ 'id' => $component->id,
+ 'pivot_id' => $component->pivot->id,
+ 'name' => e($component->name),
+ 'qty' => $component->pivot->assigned_qty,
+ 'price_cost' => $component->purchase_cost,
+ 'purchase_total' => $component->purchase_cost * $component->pivot->assigned_qty,
+ 'checkout_date' => Helper::getFormattedDateObject($component->pivot->created_at, 'datetime'),
+
];
}
}
}
-
+
$array += $permissions_array;
return $array;
@@ -209,26 +207,25 @@ class AssetsTransformer
{
if ($asset->checkedOutToUser()) {
return $asset->assigned ? [
- 'id' => (int) $asset->assigned->id,
- 'username' => e($asset->assigned->username),
- 'name' => e($asset->assigned->display_name),
- 'first_name'=> e($asset->assigned->first_name),
- 'last_name'=> ($asset->assigned->last_name) ? e($asset->assigned->last_name) : null,
- 'email'=> ($asset->assigned->email) ? e($asset->assigned->email) : null,
- 'employee_number' => ($asset->assigned->employee_num) ? e($asset->assigned->employee_num) : null,
- 'jobtitle' => $asset->assigned->jobtitle ? e($asset->assigned->jobtitle) : null,
- 'type' => 'user',
- ] : null;
+ 'id' => (int) $asset->assigned->id,
+ 'username' => e($asset->assigned->username),
+ 'name' => e($asset->assigned->display_name),
+ 'first_name' => e($asset->assigned->first_name),
+ 'last_name' => ($asset->assigned->last_name) ? e($asset->assigned->last_name) : null,
+ 'email' => ($asset->assigned->email) ? e($asset->assigned->email) : null,
+ 'employee_number' => ($asset->assigned->employee_num) ? e($asset->assigned->employee_num) : null,
+ 'jobtitle' => $asset->assigned->jobtitle ? e($asset->assigned->jobtitle) : null,
+ 'type' => 'user',
+ ] : null;
}
return $asset->assigned ? [
'id' => $asset->assigned->id,
'name' => e($asset->assigned->display_name),
- 'type' => $asset->assignedType()
+ 'type' => $asset->assignedType(),
] : null;
}
-
public function transformRequestedAssets(Collection $assets, $total)
{
$array = [];
@@ -242,7 +239,7 @@ class AssetsTransformer
public function transformRequestedAsset(Asset $asset)
{
$array = [
- 'id' => (int)$asset->id,
+ 'id' => (int) $asset->id,
'name' => e($asset->name),
'asset_tag' => e($asset->asset_tag),
'serial' => e($asset->serial),
@@ -264,7 +261,7 @@ class AssetsTransformer
if (($field->field_encrypted == '0') && ($field->show_in_requestable_list == '1')) {
$value = $asset->{$field->db_column};
- if (($field->format == 'DATE') && (!is_null($value)) && ($value != '')) {
+ if (($field->format == 'DATE') && (! is_null($value)) && ($value != '')) {
$value = Helper::getFormattedDateObject($value, 'date', false);
}
@@ -277,13 +274,13 @@ class AssetsTransformer
$array['custom_fields'] = new \stdClass; // HACK to force generation of empty object instead of empty list
}
-
$permissions_array['available_actions'] = [
'cancel' => ($asset->isRequestedBy(auth()->user())) ? true : false,
'request' => ($asset->isRequestedBy(auth()->user())) ? false : true,
];
$array += $permissions_array;
+
return $array;
}
@@ -314,7 +311,6 @@ class AssetsTransformer
return (new DatatablesTransformer)->transformDatatables($array, $total);
}
-
public function transformCheckedoutAccessory(AccessoryCheckout $accessory_checkout)
{
if ($accessory_checkout->accessory) {
@@ -325,10 +321,10 @@ class AssetsTransformer
'name' => e($accessory_checkout->accessory->display_name),
],
'assigned_to' => $accessory_checkout->assigned_to,
- 'image' => ($accessory_checkout->accessory->image) ? Storage::disk('public')->url('accessories/' . e($accessory_checkout->accessory->image)) : null,
+ 'image' => ($accessory_checkout->accessory->image) ? Storage::disk('public')->url('accessories/'.e($accessory_checkout->accessory->image)) : null,
'note' => $accessory_checkout->note ? e($accessory_checkout->note) : null,
'created_by' => $accessory_checkout->adminuser ? [
- 'id' => (int)$accessory_checkout->adminuser->id,
+ 'id' => (int) $accessory_checkout->adminuser->id,
'name' => e($accessory_checkout->display_name),
] : null,
'created_at' => Helper::getFormattedDateObject($accessory_checkout->created_at, 'datetime'),
@@ -341,8 +337,8 @@ class AssetsTransformer
];
$array += $permissions_array;
+
return $array;
}
}
-
}
diff --git a/app/Http/Transformers/CategoriesTransformer.php b/app/Http/Transformers/CategoriesTransformer.php
index b2e5c4cae9..dc0ec3cfbe 100644
--- a/app/Http/Transformers/CategoriesTransformer.php
+++ b/app/Http/Transformers/CategoriesTransformer.php
@@ -4,8 +4,8 @@ namespace App\Http\Transformers;
use App\Helpers\Helper;
use App\Models\Category;
-use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Storage;
class CategoriesTransformer
@@ -20,7 +20,7 @@ class CategoriesTransformer
return (new DatatablesTransformer)->transformDatatables($array, $total);
}
- public function transformCategory(Category $category = null)
+ public function transformCategory(?Category $category = null)
{
// We only ever use item_count for categories in this transformer, so it makes sense to keep it
@@ -49,10 +49,10 @@ class CategoriesTransformer
$array = [
'id' => (int) $category->id,
'name' => e($category->name),
- 'image' => ($category->image) ? Storage::disk('public')->url('categories/'.e($category->image)) : null,
+ 'image' => ($category->image) ? Storage::disk('public')->url('categories/'.e($category->image)) : null,
'category_type' => Helper::categoryTypeList($category->category_type),
'has_eula' => ($category->getEula() ? true : false),
- 'use_default_eula' => ($category->use_default_eula=='1' ? true : false),
+ 'use_default_eula' => ($category->use_default_eula == '1' ? true : false),
'eula' => ($category->getEula()),
'checkin_email' => ($category->checkin_email == '1'),
'require_acceptance' => ($category->require_acceptance == '1'),
@@ -64,7 +64,7 @@ class CategoriesTransformer
'licenses_count' => (int) $category->licenses_count,
'created_by' => ($category->adminuser) ? [
'id' => (int) $category->adminuser->id,
- 'name'=> e($category->adminuser->display_name),
+ 'name' => e($category->adminuser->display_name),
] : null,
'tag_color' => $category->tag_color ? e($category->tag_color) : null,
'notes' => Helper::parseEscapedMarkedownInline($category->notes),
diff --git a/app/Http/Transformers/CompaniesTransformer.php b/app/Http/Transformers/CompaniesTransformer.php
index b8f2ce757a..bd18474533 100644
--- a/app/Http/Transformers/CompaniesTransformer.php
+++ b/app/Http/Transformers/CompaniesTransformer.php
@@ -4,8 +4,8 @@ namespace App\Http\Transformers;
use App\Helpers\Helper;
use App\Models\Company;
-use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Storage;
class CompaniesTransformer
@@ -20,16 +20,16 @@ class CompaniesTransformer
return (new DatatablesTransformer)->transformDatatables($array, $total);
}
- public function transformCompany(Company $company = null)
+ public function transformCompany(?Company $company = null)
{
if ($company) {
$array = [
'id' => (int) $company->id,
'name' => e($company->name),
- 'phone' => ($company->phone!='') ? e($company->phone): null,
- 'fax' => ($company->fax!='') ? e($company->fax): null,
- 'email' => ($company->email!='') ? e($company->email): null,
- 'image' => ($company->image) ? Storage::disk('public')->url('companies/'.e($company->image)) : null,
+ 'phone' => ($company->phone != '') ? e($company->phone) : null,
+ 'fax' => ($company->fax != '') ? e($company->fax) : null,
+ 'email' => ($company->email != '') ? e($company->email) : null,
+ 'image' => ($company->image) ? Storage::disk('public')->url('companies/'.e($company->image)) : null,
'assets_count' => (int) $company->assets_count,
'licenses_count' => (int) $company->licenses_count,
'accessories_count' => (int) $company->accessories_count,
@@ -38,9 +38,9 @@ class CompaniesTransformer
'users_count' => (int) $company->users_count,
'created_by' => ($company->adminuser) ? [
'id' => (int) $company->adminuser->id,
- 'name'=> e($company->adminuser->display_name),
+ 'name' => e($company->adminuser->display_name),
] : null,
- 'tag_color' => ($company->tag_color!='') ? e($company->tag_color): null,
+ 'tag_color' => ($company->tag_color != '') ? e($company->tag_color) : null,
'notes' => Helper::parseEscapedMarkedownInline($company->notes),
'created_at' => Helper::getFormattedDateObject($company->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($company->updated_at, 'datetime'),
diff --git a/app/Http/Transformers/ComponentsAssetsTransformer.php b/app/Http/Transformers/ComponentsAssetsTransformer.php
index 437d00ca22..a6f9d6f323 100644
--- a/app/Http/Transformers/ComponentsAssetsTransformer.php
+++ b/app/Http/Transformers/ComponentsAssetsTransformer.php
@@ -3,8 +3,8 @@
namespace App\Http\Transformers;
use App\Models\Asset;
-use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\Gate;
class ComponentsAssetsTransformer
{
diff --git a/app/Http/Transformers/ComponentsTransformer.php b/app/Http/Transformers/ComponentsTransformer.php
index bb6ed3a5bc..219e6e6e6f 100644
--- a/app/Http/Transformers/ComponentsTransformer.php
+++ b/app/Http/Transformers/ComponentsTransformer.php
@@ -4,8 +4,8 @@ namespace App\Http\Transformers;
use App\Helpers\Helper;
use App\Models\Component;
-use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Storage;
class ComponentsTransformer
@@ -25,7 +25,7 @@ class ComponentsTransformer
$array = [
'id' => (int) $component->id,
'name' => e($component->name),
- 'image' => ($component->image) ? Storage::disk('public')->url('components/'.e($component->image)) : null,
+ 'image' => ($component->image) ? Storage::disk('public')->url('components/'.e($component->image)) : null,
'serial' => ($component->serial) ? e($component->serial) : null,
'location' => ($component->location) ? [
'id' => (int) $component->location->id,
@@ -41,21 +41,21 @@ class ComponentsTransformer
] : null,
'supplier' => ($component->supplier) ? [
'id' => $component->supplier->id,
- 'name'=> e($component->supplier->name),
+ 'name' => e($component->supplier->name),
'tag_color' => $component->supplier->tag_color ? e($component->supplier->tag_color) : null,
] : null,
'manufacturer' => ($component->manufacturer) ? [
'id' => $component->manufacturer->id,
- 'name'=> e($component->manufacturer->name),
+ 'name' => e($component->manufacturer->name),
'tag_color' => $component->manufacturer->tag_color ? e($component->manufacturer->tag_color) : null,
] : null,
'model_number' => ($component->model_number) ? e($component->model_number) : null,
- 'order_number' => e($component->order_number),
- 'purchase_date' => Helper::getFormattedDateObject($component->purchase_date, 'date'),
+ 'order_number' => e($component->order_number),
+ 'purchase_date' => Helper::getFormattedDateObject($component->purchase_date, 'date'),
'purchase_cost' => Helper::formatCurrencyOutput($component->purchase_cost),
'total_cost' => Helper::formatCurrencyOutput($component->totalCostSum()),
- 'remaining' => (int) $component->numRemaining(),
- 'company' => ($component->company) ? [
+ 'remaining' => (int) $component->numRemaining(),
+ 'company' => ($component->company) ? [
'id' => (int) $component->company->id,
'name' => e($component->company->name),
'tag_color' => $component->company->tag_color ? e($component->company->tag_color) : null,
@@ -63,11 +63,11 @@ class ComponentsTransformer
'notes' => ($component->notes) ? Helper::parseEscapedMarkedownInline($component->notes) : null,
'created_by' => ($component->adminuser) ? [
'id' => (int) $component->adminuser->id,
- 'name'=> e($component->adminuser->display_name),
+ 'name' => e($component->adminuser->display_name),
] : null,
'created_at' => Helper::getFormattedDateObject($component->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($component->updated_at, 'datetime'),
- 'user_can_checkout' => ($component->numRemaining() > 0) ? 1 : 0,
+ 'user_can_checkout' => ($component->numRemaining() > 0) ? 1 : 0,
];
$permissions_array['available_actions'] = [
@@ -89,7 +89,7 @@ class ComponentsTransformer
$array[] = [
'assigned_pivot_id' => $asset->pivot->id,
'id' => (int) $asset->id,
- 'name' => e($asset->model->display_name).' '.e($asset->display_name),
+ 'name' => e($asset->model->display_name).' '.e($asset->display_name),
'qty' => $asset->pivot->assigned_qty,
'note' => e($asset->pivot->note),
'type' => 'asset',
diff --git a/app/Http/Transformers/ConsumablesTransformer.php b/app/Http/Transformers/ConsumablesTransformer.php
index c31754d5b5..33e31304f4 100644
--- a/app/Http/Transformers/ConsumablesTransformer.php
+++ b/app/Http/Transformers/ConsumablesTransformer.php
@@ -4,9 +4,8 @@ namespace App\Http\Transformers;
use App\Helpers\Helper;
use App\Models\Consumable;
-use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
-use Illuminate\Support\Facades\Storage;
+use Illuminate\Support\Facades\Gate;
class ConsumablesTransformer
{
@@ -23,47 +22,47 @@ class ConsumablesTransformer
public function transformConsumable(Consumable $consumable)
{
$array = [
- 'id' => (int) $consumable->id,
- 'name' => e($consumable->name),
- 'image' => ($consumable->getImageUrl()) ? ($consumable->getImageUrl()) : null,
- 'category' => ($consumable->category) ? [
+ 'id' => (int) $consumable->id,
+ 'name' => e($consumable->name),
+ 'image' => ($consumable->getImageUrl()) ? ($consumable->getImageUrl()) : null,
+ 'category' => ($consumable->category) ? [
'id' => $consumable->category->id,
'name' => e($consumable->category->name),
'tag_color' => $consumable->category->tag_color ? e($consumable->category->tag_color) : null,
- ] : null,
- 'company' => ($consumable->company) ? [
+ ] : null,
+ 'company' => ($consumable->company) ? [
'id' => (int) $consumable->company->id,
'name' => e($consumable->company->name),
'tag_color' => $consumable->company->tag_color ? e($consumable->company->tag_color) : null,
] : null,
- 'item_no' => e($consumable->item_no),
- 'location' => ($consumable->location) ? [
+ 'item_no' => e($consumable->item_no),
+ 'location' => ($consumable->location) ? [
'id' => (int) $consumable->location->id,
'name' => e($consumable->location->name),
'tag_color' => $consumable->location->tag_color ? e($consumable->location->tag_color) : null,
] : null,
- 'manufacturer' => ($consumable->manufacturer) ? [
+ 'manufacturer' => ($consumable->manufacturer) ? [
'id' => (int) $consumable->manufacturer->id,
'name' => e($consumable->manufacturer->name),
'tag_color' => $consumable->manufacturer->tag_color ? e($consumable->manufacturer->tag_color) : null,
] : null,
'supplier' => ($consumable->supplier) ? [
'id' => $consumable->supplier->id,
- 'name'=> e($consumable->supplier->name),
+ 'name' => e($consumable->supplier->name),
'tag_color' => $consumable->supplier->tag_color ? e($consumable->supplier->tag_color) : null,
] : null,
- 'min_amt' => (int) $consumable->min_amt,
- 'model_number' => ($consumable->model_number != '') ? e($consumable->model_number) : null,
- 'remaining' => $consumable->numRemaining(),
- 'order_number' => e($consumable->order_number),
- 'purchase_cost' => Helper::formatCurrencyOutput($consumable->purchase_cost),
+ 'min_amt' => (int) $consumable->min_amt,
+ 'model_number' => ($consumable->model_number != '') ? e($consumable->model_number) : null,
+ 'remaining' => $consumable->numRemaining(),
+ 'order_number' => e($consumable->order_number),
+ 'purchase_cost' => Helper::formatCurrencyOutput($consumable->purchase_cost),
'total_cost' => Helper::formatCurrencyOutput($consumable->totalCostSum()),
- 'purchase_date' => Helper::getFormattedDateObject($consumable->purchase_date, 'date'),
- 'qty' => (int) $consumable->qty,
- 'notes' => ($consumable->notes) ? Helper::parseEscapedMarkedownInline($consumable->notes) : null,
+ 'purchase_date' => Helper::getFormattedDateObject($consumable->purchase_date, 'date'),
+ 'qty' => (int) $consumable->qty,
+ 'notes' => ($consumable->notes) ? Helper::parseEscapedMarkedownInline($consumable->notes) : null,
'created_by' => ($consumable->adminuser) ? [
'id' => (int) $consumable->adminuser->id,
- 'name'=> e($consumable->adminuser->display_name),
+ 'name' => e($consumable->adminuser->display_name),
] : null,
'created_at' => Helper::getFormattedDateObject($consumable->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($consumable->updated_at, 'datetime'),
diff --git a/app/Http/Transformers/CustomFieldsTransformer.php b/app/Http/Transformers/CustomFieldsTransformer.php
index 2b1ef566c1..0afaf88112 100644
--- a/app/Http/Transformers/CustomFieldsTransformer.php
+++ b/app/Http/Transformers/CustomFieldsTransformer.php
@@ -20,9 +20,9 @@ class CustomFieldsTransformer
/**
* Builds up an array of formatted custom fields
- * @param Collection $fields
- * @param int $modelId
- * @param int $total
+ *
+ * @param int $modelId
+ * @param int $total
* @return array
*/
public function transformCustomFieldsWithDefaultValues(Collection $fields, $modelId, $total)
@@ -42,18 +42,18 @@ class CustomFieldsTransformer
'id' => $field->id,
'name' => e($field->name),
'db_column_name' => e($field->db_column_name()),
- 'format' => e($field->format),
- 'field_values' => ($field->field_values) ? e($field->field_values) : null,
- 'field_encrypted' => ($field->field_encrypted =='1') ? true : false,
- 'field_values_array' => ($field->field_values) ? explode("\r\n", e($field->field_values)) : null,
- 'type' => e($field->element),
- 'required' => (($field->pivot) && ($field->pivot->required=='1')) ? true : false,
- 'display_in_user_view' => ($field->display_in_user_view =='1') ? true : false,
- 'auto_add_to_fieldsets' => ($field->auto_add_to_fieldsets == '1') ? true : false,
- 'show_in_listview' => ($field->show_in_listview == '1') ? true : false,
- 'display_checkin' => ($field->display_checkin == '1') ? true : false,
- 'display_checkout' => ($field->display_checkout == '1') ? true : false,
- 'display_audit' => ($field->display_audit == '1') ? true : false,
+ 'format' => e($field->format),
+ 'field_values' => ($field->field_values) ? e($field->field_values) : null,
+ 'field_encrypted' => ($field->field_encrypted == '1') ? true : false,
+ 'field_values_array' => ($field->field_values) ? explode("\r\n", e($field->field_values)) : null,
+ 'type' => e($field->element),
+ 'required' => (($field->pivot) && ($field->pivot->required == '1')) ? true : false,
+ 'display_in_user_view' => ($field->display_in_user_view == '1') ? true : false,
+ 'auto_add_to_fieldsets' => ($field->auto_add_to_fieldsets == '1') ? true : false,
+ 'show_in_listview' => ($field->show_in_listview == '1') ? true : false,
+ 'display_checkin' => ($field->display_checkin == '1') ? true : false,
+ 'display_checkout' => ($field->display_checkout == '1') ? true : false,
+ 'display_audit' => ($field->display_audit == '1') ? true : false,
'created_at' => Helper::getFormattedDateObject($field->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($field->updated_at, 'datetime'),
];
@@ -65,8 +65,7 @@ class CustomFieldsTransformer
* Returns the core data for a field, including the default value it has
* when attributed to a certain model
*
- * @param CustomField $field
- * @param int $modelId
+ * @param int $modelId
* @return array
*/
public function transformCustomFieldWithDefaultValue(CustomField $field, $modelId)
@@ -74,8 +73,8 @@ class CustomFieldsTransformer
return [
'id' => $field->id,
'name' => e($field->name),
- 'type' => e($field->element),
- 'field_values_array' => ($field->field_values) ? explode("\r\n", e($field->field_values)) : null,
+ 'type' => e($field->element),
+ 'field_values_array' => ($field->field_values) ? explode("\r\n", e($field->field_values)) : null,
'default_value' => $field->defaultValue($modelId),
];
}
diff --git a/app/Http/Transformers/CustomFieldsetsTransformer.php b/app/Http/Transformers/CustomFieldsetsTransformer.php
index 61e42486ab..f46b75deda 100644
--- a/app/Http/Transformers/CustomFieldsetsTransformer.php
+++ b/app/Http/Transformers/CustomFieldsetsTransformer.php
@@ -26,8 +26,8 @@ class CustomFieldsetsTransformer
foreach ($models as $model) {
$modelsArray[] = [
- 'id' => $model->id,
- 'name' => e($model->name),
+ 'id' => $model->id,
+ 'name' => e($model->name),
];
}
diff --git a/app/Http/Transformers/DatatablesTransformer.php b/app/Http/Transformers/DatatablesTransformer.php
index 2ec993536d..cd187c95d9 100644
--- a/app/Http/Transformers/DatatablesTransformer.php
+++ b/app/Http/Transformers/DatatablesTransformer.php
@@ -4,7 +4,6 @@ namespace App\Http\Transformers;
class DatatablesTransformer
{
-
/**
* Transform data for bootstrap tables and API responses for lists of things
**/
@@ -26,4 +25,4 @@ class DatatablesTransformer
return $objects_array;
}
-}
\ No newline at end of file
+}
diff --git a/app/Http/Transformers/DepartmentsTransformer.php b/app/Http/Transformers/DepartmentsTransformer.php
index d230180184..defa08e600 100644
--- a/app/Http/Transformers/DepartmentsTransformer.php
+++ b/app/Http/Transformers/DepartmentsTransformer.php
@@ -4,8 +4,8 @@ namespace App\Http\Transformers;
use App\Helpers\Helper;
use App\Models\Department;
-use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Storage;
class DepartmentsTransformer
@@ -20,25 +20,25 @@ class DepartmentsTransformer
return (new DatatablesTransformer)->transformDatatables($array, $total);
}
- public function transformDepartment(Department $department = null)
+ public function transformDepartment(?Department $department = null)
{
if ($department) {
$array = [
'id' => (int) $department->id,
'name' => e($department->name),
- 'phone' => ($department->phone!='') ? e($department->phone): null,
- 'fax' => ($department->fax!='') ? e($department->fax): null,
- 'image' => ($department->image) ? Storage::disk('public')->url(app('departments_upload_url').e($department->image)) : null,
+ 'phone' => ($department->phone != '') ? e($department->phone) : null,
+ 'fax' => ($department->fax != '') ? e($department->fax) : null,
+ 'image' => ($department->image) ? Storage::disk('public')->url(app('departments_upload_url').e($department->image)) : null,
'company' => ($department->company) ? [
'id' => (int) $department->company->id,
- 'name'=> e($department->company->name),
+ 'name' => e($department->company->name),
'tag_color' => $department->company->tag_color ? e($department->company->tag_color) : null,
] : null,
'manager' => ($department->manager) ? [
'id' => (int) $department->manager->id,
'name' => e($department->manager->display_name),
- 'first_name'=> e($department->manager->first_name),
- 'last_name'=> e($department->manager->last_name),
+ 'first_name' => e($department->manager->first_name),
+ 'last_name' => e($department->manager->last_name),
] : null,
'location' => ($department->location) ? [
'id' => (int) $department->location->id,
diff --git a/app/Http/Transformers/DepreciationReportTransformer.php b/app/Http/Transformers/DepreciationReportTransformer.php
index 0c272b784f..5fd3da712d 100644
--- a/app/Http/Transformers/DepreciationReportTransformer.php
+++ b/app/Http/Transformers/DepreciationReportTransformer.php
@@ -1,32 +1,35 @@
<?php
+
namespace App\Http\Transformers;
use App\Helpers\Helper;
use App\Models\Asset;
+use App\Models\Setting;
use Illuminate\Database\Eloquent\Collection;
/**
* This tranformer looks like it's extraneous, since we return as much or more
- * info in the AssetsTransformer, but we want to flatten these results out so that they
- * don't dislose more information than we want. Folks with depreciation powers don't necessaily
- * have the right to see additional info, and inspecting the API call here could disclose
+ * info in the AssetsTransformer, but we want to flatten these results out so that they
+ * don't dislose more information than we want. Folks with depreciation powers don't necessaily
+ * have the right to see additional info, and inspecting the API call here could disclose
* info they're not supposed to see.
- *
+ *
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v5.2.0]
*/
class DepreciationReportTransformer
{
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)
{
@@ -45,28 +48,26 @@ class DepreciationReportTransformer
if ($asset->location && $asset->location->currency) {
$purchase_cost_currency = $asset->location->currency;
} else {
- $purchase_cost_currency = \App\Models\Setting::getSettings()->default_currency;
+ $purchase_cost_currency = Setting::getSettings()->default_currency;
}
/**
* If there is a NOT an empty purchase cost (meaning not null or '' but it *could* be zero),
- * format the purchase cost. We coould do this inline in the transformer, but we need that value
+ * format the purchase cost. We coould do this inline in the transformer, but we need that value
* for the other calculations that come after, like diff, etc.
*/
- if ($asset->purchase_cost!='') {
+ if ($asset->purchase_cost != '') {
$purchase_cost = $asset->purchase_cost;
}
-
/**
* Override the previously set null values if there is a valid model and associated depreciation
*/
if (($asset->model) && ($asset->model->depreciation) && ($asset->model->depreciation->months !== 0)) {
$depreciated_value = Helper::formatCurrencyOutput($asset->getDepreciatedValue());
- $monthly_depreciation =Helper::formatCurrencyOutput($asset->getMonthlyDepreciation());
+ $monthly_depreciation = Helper::formatCurrencyOutput($asset->getMonthlyDepreciation());
$diff = Helper::formatCurrencyOutput(($asset->purchase_cost - $asset->getDepreciatedValue()));
- }
- else if($asset->model->eol !== null) {
+ } elseif ($asset->model->eol !== null) {
$monthly_depreciation = Helper::formatCurrencyOutput(($asset->model->eol > 0 ? ($asset->purchase_cost / $asset->model->eol) : 0));
}
@@ -74,40 +75,38 @@ class DepreciationReportTransformer
$checkout_target = $asset->assigned->name;
if ($asset->checkedOutToUser()) {
$checkout_target = $asset->assigned->getFullNameAttribute();
- }
+ }
}
-
+
$array = [
-
+
'company' => ($asset->company) ? e($asset->company->name) : null,
'name' => e($asset->name),
'asset_tag' => e($asset->asset_tag),
'serial' => e($asset->serial),
- 'model' => ($asset->model) ? e($asset->model->name) : null,
+ 'model' => ($asset->model) ? 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) ? e($asset->assetstatus->name) : null,
- 'status' => ($asset->assetstatus) ? e($asset->present()->statusMeta) : null,
+ 'status' => ($asset->assetstatus) ? e($asset->present()->statusMeta) : null,
'category' => (($asset->model) && ($asset->model->category)) ? e($asset->model->category->name) : null,
'manufacturer' => (($asset->model) && ($asset->model->manufacturer)) ? e($asset->model->manufacturer->name) : null,
'supplier' => ($asset->supplier) ? e($asset->supplier->name) : null,
'notes' => ($asset->notes) ? e($asset->notes) : null,
'order_number' => ($asset->order_number) ? e($asset->order_number) : null,
'location' => ($asset->location) ? e($asset->location->name) : null,
- 'warranty_expires' => ($asset->warranty_months > 0) ? Helper::getFormattedDateObject($asset->warranty_expires, 'date') : null,
+ 'warranty_expires' => ($asset->warranty_months > 0) ? Helper::getFormattedDateObject($asset->warranty_expires, 'date') : null,
'currency' => $purchase_cost_currency,
'purchase_date' => Helper::getFormattedDateObject($asset->purchase_date, 'date'),
'purchase_cost' => Helper::formatCurrencyOutput($asset->purchase_cost),
'book_value' => Helper::formatCurrencyOutput($depreciated_value),
'monthly_depreciation' => $monthly_depreciation,
'checked_out_to' => ($checkout_target) ? e($checkout_target) : null,
- 'diff' => Helper::formatCurrencyOutput($diff),
- 'number_of_months' => ($asset->model && $asset->model->depreciation) ? e($asset->model->depreciation->months) : null,
- 'depreciation' => (($asset->model) && ($asset->model->depreciation)) ? e($asset->model->depreciation->name) : null,
-
+ 'diff' => Helper::formatCurrencyOutput($diff),
+ 'number_of_months' => ($asset->model && $asset->model->depreciation) ? e($asset->model->depreciation->months) : null,
+ 'depreciation' => (($asset->model) && ($asset->model->depreciation)) ? e($asset->model->depreciation->name) : null,
-
];
return $array;
@@ -117,7 +116,4 @@ class DepreciationReportTransformer
{
return (new DatatablesTransformer)->transformDatatables($assets);
}
-
-
-
}
diff --git a/app/Http/Transformers/DepreciationsTransformer.php b/app/Http/Transformers/DepreciationsTransformer.php
index 3b0d68392c..9aa2ed7123 100644
--- a/app/Http/Transformers/DepreciationsTransformer.php
+++ b/app/Http/Transformers/DepreciationsTransformer.php
@@ -3,11 +3,9 @@
namespace App\Http\Transformers;
use App\Helpers\Helper;
-use App\Models\Depreciable;
use App\Models\Depreciation;
-use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
-use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Gate;
class DepreciationsTransformer
{
@@ -33,10 +31,10 @@ class DepreciationsTransformer
'licenses_count' => ($depreciation->licenses_count > 0) ? (int) $depreciation->licenses_count : 0,
'created_by' => ($depreciation->adminuser) ? [
'id' => (int) $depreciation->adminuser->id,
- 'name'=> e($depreciation->adminuser->display_name),
+ 'name' => e($depreciation->adminuser->display_name),
] : null,
'created_at' => Helper::getFormattedDateObject($depreciation->created_at, 'datetime'),
- 'updated_at' => Helper::getFormattedDateObject($depreciation->updated_at, 'datetime')
+ 'updated_at' => Helper::getFormattedDateObject($depreciation->updated_at, 'datetime'),
];
$permissions_array['available_actions'] = [
@@ -48,4 +46,4 @@ class DepreciationsTransformer
return $array;
}
-}
\ No newline at end of file
+}
diff --git a/app/Http/Transformers/GroupsTransformer.php b/app/Http/Transformers/GroupsTransformer.php
index 7593926155..c9122aa11a 100644
--- a/app/Http/Transformers/GroupsTransformer.php
+++ b/app/Http/Transformers/GroupsTransformer.php
@@ -4,12 +4,12 @@ namespace App\Http\Transformers;
use App\Helpers\Helper;
use App\Models\Group;
-use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\Gate;
class GroupsTransformer
{
- public function transformGroups (Collection $groups, $total = null)
+ public function transformGroups(Collection $groups, $total = null)
{
$array = [];
foreach ($groups as $group) {
@@ -29,7 +29,7 @@ class GroupsTransformer
'notes' => Helper::parseEscapedMarkedownInline($group->notes),
'created_by' => ($group->adminuser) ? [
'id' => (int) $group->adminuser->id,
- 'name'=> e($group->adminuser->display_name),
+ 'name' => e($group->adminuser->display_name),
] : null,
'created_at' => Helper::getFormattedDateObject($group->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($group->updated_at, 'datetime'),
diff --git a/app/Http/Transformers/ImportsTransformer.php b/app/Http/Transformers/ImportsTransformer.php
index 486c18f28c..3bc3a5f587 100644
--- a/app/Http/Transformers/ImportsTransformer.php
+++ b/app/Http/Transformers/ImportsTransformer.php
@@ -27,8 +27,8 @@ class ImportsTransformer
'import_type' => e($import->import_type),
'created_at' => $import->created_at->diffForHumans(),
'header_row' => $import->header_row,
- 'first_row' => $import->first_row,
- 'field_map' => $import->field_map,
+ 'first_row' => $import->first_row,
+ 'field_map' => $import->field_map,
];
return $array;
diff --git a/app/Http/Transformers/LabelsTransformer.php b/app/Http/Transformers/LabelsTransformer.php
index 0ed5a09686..b37b655751 100644
--- a/app/Http/Transformers/LabelsTransformer.php
+++ b/app/Http/Transformers/LabelsTransformer.php
@@ -2,10 +2,9 @@
namespace App\Http\Transformers;
-use App\Helpers\Helper;
use App\Models\Labels\Label;
-use App\Models\Labels\Sheet;
use App\Models\Labels\RectangleSheet;
+use App\Models\Labels\Sheet;
use Illuminate\Support\Collection;
class LabelsTransformer
@@ -26,31 +25,31 @@ class LabelsTransformer
'name' => $label->getName(),
'unit' => $label->getUnit(),
- 'width' => number_format($label->getWidth(), 2),
+ 'width' => number_format($label->getWidth(), 2),
'height' => number_format($label->getHeight(), 2),
- 'margin_top' => $label->getMarginTop(),
+ 'margin_top' => $label->getMarginTop(),
'margin_bottom' => $label->getMarginBottom(),
- 'margin_left' => $label->getMarginLeft(),
- 'margin_right' => $label->getMarginRight(),
+ 'margin_left' => $label->getMarginLeft(),
+ 'margin_right' => $label->getMarginRight(),
- 'support_asset_tag' => $label->getSupportAssetTag(),
+ 'support_asset_tag' => $label->getSupportAssetTag(),
'support_1d_barcode' => $label->getSupport1DBarcode(),
'support_2d_barcode' => $label->getSupport2DBarcode(),
- 'support_fields' => $label->getSupportFields(),
- 'support_logo' => $label->getSupportLogo(),
- 'support_title' => $label->getSupportTitle(),
+ 'support_fields' => $label->getSupportFields(),
+ 'support_logo' => $label->getSupportLogo(),
+ 'support_title' => $label->getSupportTitle(),
];
if ($label instanceof Sheet) {
$array['sheet_info'] = [
- 'label_width' => $label->getLabelWidth(),
+ 'label_width' => $label->getLabelWidth(),
'label_height' => $label->getLabelHeight(),
- 'label_margin_top' => $label->getLabelMarginTop(),
+ 'label_margin_top' => $label->getLabelMarginTop(),
'label_margin_bottom' => $label->getLabelMarginBottom(),
- 'label_margin_left' => $label->getLabelMarginLeft(),
- 'label_margin_right' => $label->getLabelMarginRight(),
+ 'label_margin_left' => $label->getLabelMarginLeft(),
+ 'label_margin_right' => $label->getLabelMarginRight(),
'labels_per_page' => $label->getLabelsPerPage(),
'label_border' => $label->getLabelBorder(),
@@ -60,9 +59,9 @@ class LabelsTransformer
if ($label instanceof RectangleSheet) {
$array['rectanglesheet_info'] = [
'columns' => $label->getColumns(),
- 'rows' => $label->getRows(),
+ 'rows' => $label->getRows(),
'column_spacing' => $label->getLabelColumnSpacing(),
- 'row_spacing' => $label->getLabelRowSpacing(),
+ 'row_spacing' => $label->getLabelRowSpacing(),
];
}
diff --git a/app/Http/Transformers/LicenseSeatsTransformer.php b/app/Http/Transformers/LicenseSeatsTransformer.php
index f06536da20..f218b0631e 100644
--- a/app/Http/Transformers/LicenseSeatsTransformer.php
+++ b/app/Http/Transformers/LicenseSeatsTransformer.php
@@ -5,8 +5,9 @@ namespace App\Http\Transformers;
use App\Helpers\Helper;
use App\Models\License;
use App\Models\LicenseSeat;
-use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\Gate;
+
class LicenseSeatsTransformer
{
public function transformLicenseSeats(Collection $seats, $total)
@@ -28,16 +29,16 @@ class LicenseSeatsTransformer
'updated_at' => Helper::getFormattedDateObject($seat->updated_at, 'datetime'), // we use updated_at here because the record gets updated when it's checked in or out
'assigned_user' => ($seat->user) ? [
'id' => (int) $seat->user->id,
- 'name'=> e($seat->user->present()->fullName),
+ 'name' => e($seat->user->present()->fullName),
'email' => e($seat->user->email),
- 'department'=> ($seat->user->department) ?
+ 'department' => ($seat->user->department) ?
[
'id' => (int) $seat->user->department->id,
'name' => e($seat->user->department->name),
'tag_color' => $seat->user->department->tag_color ? e($seat->user->department->tag_color) : null,
] : null,
- 'company'=> ($seat->user->company) ?
+ 'company' => ($seat->user->company) ?
[
'id' => (int) $seat->user->company->id,
'name' => e($seat->user->company->name),
@@ -48,12 +49,12 @@ class LicenseSeatsTransformer
] : null,
'assigned_asset' => ($seat->asset) ? [
'id' => (int) $seat->asset->id,
- 'name'=> e($seat->asset->present()->fullName),
+ 'name' => e($seat->asset->present()->fullName),
'created_at' => Helper::getFormattedDateObject($seat->created_at, 'datetime'),
] : null,
'location' => ($seat->location()) ? [
'id' => (int) $seat->location()->id,
- 'name'=> e($seat->location()->name),
+ 'name' => e($seat->location()->name),
'tag_color' => $seat->location()->tag_color ? e($seat->location()->tag_color) : null,
'created_at' => Helper::getFormattedDateObject($seat->created_at, 'datetime'),
] : null,
diff --git a/app/Http/Transformers/LicensesTransformer.php b/app/Http/Transformers/LicensesTransformer.php
index 5c71390929..120f870eb1 100644
--- a/app/Http/Transformers/LicensesTransformer.php
+++ b/app/Http/Transformers/LicensesTransformer.php
@@ -4,8 +4,8 @@ namespace App\Http\Transformers;
use App\Helpers\Helper;
use App\Models\License;
-use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\Gate;
class LicensesTransformer
{
@@ -24,11 +24,11 @@ class LicensesTransformer
$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) ? [
+ '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),
- 'tag_color'=> ($license->manufacturer->tag_color) ? e($license->manufacturer->tag_color) : null,
+ 'name' => e($license->manufacturer->name),
+ 'tag_color' => ($license->manufacturer->tag_color) ? e($license->manufacturer->tag_color) : null,
] : null,
'product_key' => (Gate::allows('viewKeys', License::class)) ? e($license->serial) : '------------',
'order_number' => ($license->order_number) ? e($license->order_number) : null,
@@ -36,7 +36,7 @@ class LicensesTransformer
'purchase_date' => Helper::getFormattedDateObject($license->purchase_date, 'date'),
'termination_date' => Helper::getFormattedDateObject($license->termination_date, 'date'),
'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'),
- 'depreciation' => ($license->depreciation) ? ['id' => (int) $license->depreciation->id,'name'=> e($license->depreciation->name)] : null,
+ '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' => Helper::parseEscapedMarkedownInline($license->notes),
@@ -44,23 +44,23 @@ class LicensesTransformer
'free_seats_count' => (int) $license->free_seats_count - License::unReassignableCount($license),
'remaining' => (int) $license->free_seats_count,
'min_amt' => ($license->min_amt) ? (int) ($license->min_amt) : null,
- 'license_name' => ($license->license_name) ? e($license->license_name) : null,
+ 'license_name' => ($license->license_name) ? e($license->license_name) : null,
'license_email' => ($license->license_email) ? e($license->license_email) : null,
'reassignable' => ($license->reassignable == 1) ? true : false,
'maintained' => ($license->maintained == 1) ? true : false,
- 'supplier' => ($license->supplier) ? [
+ 'supplier' => ($license->supplier) ? [
'id' => (int) $license->supplier->id,
- 'name'=> e($license->supplier->name),
- 'tag_color'=> ($license->supplier->tag_color) ? e($license->supplier->tag_color) : null,
+ 'name' => e($license->supplier->name),
+ 'tag_color' => ($license->supplier->tag_color) ? e($license->supplier->tag_color) : null,
] : null,
- 'category' => ($license->category) ? [
+ 'category' => ($license->category) ? [
'id' => (int) $license->category->id,
- 'name'=> e($license->category->name),
- 'tag_color'=> ($license->category->tag_color) ? e($license->category->tag_color) : null,
+ 'name' => e($license->category->name),
+ 'tag_color' => ($license->category->tag_color) ? e($license->category->tag_color) : null,
] : null,
'created_by' => ($license->adminuser) ? [
'id' => (int) $license->adminuser->id,
- 'name'=> e($license->adminuser->display_name),
+ 'name' => e($license->adminuser->display_name),
] : null,
'created_at' => Helper::getFormattedDateObject($license->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($license->updated_at, 'datetime'),
@@ -86,7 +86,4 @@ class LicensesTransformer
{
return (new DatatablesTransformer)->transformDatatables($licenses);
}
-
-
-
}
diff --git a/app/Http/Transformers/LocationsTransformer.php b/app/Http/Transformers/LocationsTransformer.php
index 28fdc9ae79..7137362bcf 100644
--- a/app/Http/Transformers/LocationsTransformer.php
+++ b/app/Http/Transformers/LocationsTransformer.php
@@ -6,8 +6,8 @@ use App\Helpers\Helper;
use App\Models\Accessory;
use App\Models\AccessoryCheckout;
use App\Models\Location;
-use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Storage;
class LocationsTransformer
@@ -22,7 +22,7 @@ class LocationsTransformer
return (new DatatablesTransformer)->transformDatatables($array, $total);
}
- public function transformLocation(Location $location = null)
+ public function transformLocation(?Location $location = null)
{
if ($location) {
$children_arr = [];
@@ -38,43 +38,43 @@ class LocationsTransformer
$array = [
'id' => (int) $location->id,
'name' => e($location->name),
- 'image' => ($location->image) ? Storage::disk('public')->url('locations/'.e($location->image)) : null,
- 'address' => ($location->address) ? e($location->address) : null,
- 'address2' => ($location->address2) ? e($location->address2) : null,
- 'city' => ($location->city) ? e($location->city) : null,
- 'state' => ($location->state) ? e($location->state) : null,
+ 'image' => ($location->image) ? Storage::disk('public')->url('locations/'.e($location->image)) : null,
+ 'address' => ($location->address) ? e($location->address) : null,
+ 'address2' => ($location->address2) ? e($location->address2) : null,
+ 'city' => ($location->city) ? e($location->city) : null,
+ 'state' => ($location->state) ? e($location->state) : null,
'country' => ($location->country) ? e($location->country) : null,
'zip' => ($location->zip) ? e($location->zip) : null,
- 'phone' => ($location->phone!='') ? e($location->phone): null,
- 'fax' => ($location->fax!='') ? e($location->fax): null,
+ 'phone' => ($location->phone != '') ? e($location->phone) : null,
+ 'fax' => ($location->fax != '') ? e($location->fax) : null,
'accessories_count' => (int) $location->accessories_count,
'assigned_accessories_count' => (int) $location->assigned_accessories_count,
'assigned_assets_count' => (int) $location->assigned_assets_count,
- 'assets_count' => (int) $location->assets_count,
- 'rtd_assets_count' => (int) $location->rtd_assets_count,
- 'users_count' => (int) $location->users_count,
- 'consumables_count' => (int) $location->consumables_count,
- 'components_count' => (int) $location->components_count,
- 'children_count' => (int) $location->children_count,
- 'currency' => ($location->currency) ? e($location->currency) : null,
- 'ldap_ou' => ($location->ldap_ou) ? e($location->ldap_ou) : null,
+ 'assets_count' => (int) $location->assets_count,
+ 'rtd_assets_count' => (int) $location->rtd_assets_count,
+ 'users_count' => (int) $location->users_count,
+ 'consumables_count' => (int) $location->consumables_count,
+ 'components_count' => (int) $location->components_count,
+ 'children_count' => (int) $location->children_count,
+ 'currency' => ($location->currency) ? e($location->currency) : null,
+ 'ldap_ou' => ($location->ldap_ou) ? e($location->ldap_ou) : null,
'tag_color' => $location->tag_color ? e($location->tag_color) : null,
'notes' => Helper::parseEscapedMarkedownInline($location->notes),
'created_at' => Helper::getFormattedDateObject($location->created_at, 'datetime'),
'created_by' => $location->adminuser ? [
'id' => (int) $location->adminuser->id,
- 'name'=> e($location->adminuser->present()->fullName),
- ]: null,
+ 'name' => e($location->adminuser->present()->fullName),
+ ] : null,
'updated_at' => Helper::getFormattedDateObject($location->updated_at, 'datetime'),
'parent' => ($location->parent) ? [
'id' => (int) $location->parent->id,
- 'name'=> e($location->parent->name),
+ 'name' => e($location->parent->name),
'tag_color' => $location->parent->tag_color ? e($location->parent->tag_color) : null,
] : null,
'manager' => ($location->manager) ? (new UsersTransformer)->transformUser($location->manager) : null,
'company' => ($location->company) ? [
'id' => (int) $location->company->id,
- 'name'=> e($location->company->name),
+ 'name' => e($location->company->name),
'tag_color' => $location->company->tag_color ? e($location->company->tag_color) : null,
] : null,
@@ -85,7 +85,7 @@ class LocationsTransformer
'update' => (Gate::allows('update', Location::class) && ($location->deleted_at == '')),
'delete' => $location->isDeletable(),
'bulk_selectable' => [
- 'delete' => $location->isDeletable()
+ 'delete' => $location->isDeletable(),
],
'clone' => (Gate::allows('create', Location::class) && ($location->deleted_at == '')),
'restore' => (Gate::allows('create', Location::class) && ($location->deleted_at != '')),
@@ -97,7 +97,6 @@ class LocationsTransformer
}
}
-
public function transformCheckedoutAccessories($accessory_checkouts, $total)
{
@@ -109,56 +108,54 @@ class LocationsTransformer
return (new DatatablesTransformer)->transformDatatables($array, $total);
}
-
public function transformCheckedoutAccessory(AccessoryCheckout $accessory_checkout)
{
- $array = [
- 'id' => $accessory_checkout->id,
- 'assigned_to' => $accessory_checkout->assigned_to,
- 'accessory' => $this->transformAccessory($accessory_checkout->accessory),
- 'image' => ($accessory_checkout?->accessory?->image) ? Storage::disk('public')->url('accessories/' . e($accessory_checkout->accessory->image)) : null,
- 'note' => $accessory_checkout->note ? e($accessory_checkout->note) : null,
- 'created_by' => $accessory_checkout->adminuser ? [
- 'id' => (int) $accessory_checkout->adminuser->id,
- 'name'=> e($accessory_checkout->adminuser->present()->fullName),
- ]: null,
- 'created_at' => Helper::getFormattedDateObject($accessory_checkout->created_at, 'datetime'),
- ];
+ $array = [
+ 'id' => $accessory_checkout->id,
+ 'assigned_to' => $accessory_checkout->assigned_to,
+ 'accessory' => $this->transformAccessory($accessory_checkout->accessory),
+ 'image' => ($accessory_checkout?->accessory?->image) ? Storage::disk('public')->url('accessories/'.e($accessory_checkout->accessory->image)) : null,
+ 'note' => $accessory_checkout->note ? e($accessory_checkout->note) : null,
+ 'created_by' => $accessory_checkout->adminuser ? [
+ 'id' => (int) $accessory_checkout->adminuser->id,
+ 'name' => e($accessory_checkout->adminuser->present()->fullName),
+ ] : null,
+ 'created_at' => Helper::getFormattedDateObject($accessory_checkout->created_at, 'datetime'),
+ ];
+
+ $permissions_array['available_actions'] = [
+ 'checkout' => false,
+ 'checkin' => Gate::allows('checkin', Accessory::class),
+ ];
+
+ $array += $permissions_array;
- $permissions_array['available_actions'] = [
- 'checkout' => false,
- 'checkin' => Gate::allows('checkin', Accessory::class),
- ];
-
- $array += $permissions_array;
return $array;
}
-
-
/**
* This gives a compact view of the location data without any additional relational queries,
* allowing us to 1) deliver a smaller payload and 2) avoid additional queries on relations that
* have not been easy/lazy loaded already
*
- * @param Location $location
* @return array
+ *
* @throws \Exception
*/
- public function transformLocationCompact(Location $location = null)
+ public function transformLocationCompact(?Location $location = null)
{
if ($location) {
$array = [
'id' => (int) $location->id,
- 'image' => ($location->image) ? Storage::disk('public')->url('locations/'.e($location->image)) : null,
- 'type' => "location",
+ 'image' => ($location->image) ? Storage::disk('public')->url('locations/'.e($location->image)) : null,
+ 'type' => 'location',
'name' => e($location->name),
'created_by' => $location->adminuser ? [
'id' => (int) $location->adminuser->id,
- 'name'=> e($location->adminuser->display_name),
- ]: null,
+ 'name' => e($location->adminuser->display_name),
+ ] : null,
'created_at' => Helper::getFormattedDateObject($location->created_at, 'datetime'),
];
diff --git a/app/Http/Transformers/MaintenancesTransformer.php b/app/Http/Transformers/MaintenancesTransformer.php
index 389640a277..dfadcd968e 100644
--- a/app/Http/Transformers/MaintenancesTransformer.php
+++ b/app/Http/Transformers/MaintenancesTransformer.php
@@ -5,8 +5,8 @@ namespace App\Http\Transformers;
use App\Helpers\Helper;
use App\Models\Asset;
use App\Models\Maintenance;
-use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Storage;
class MaintenancesTransformer
@@ -24,71 +24,71 @@ class MaintenancesTransformer
public function transformMaintenance(Maintenance $assetmaintenance)
{
$array = [
- 'id' => (int) $assetmaintenance->id,
+ 'id' => (int) $assetmaintenance->id,
'asset' => ($assetmaintenance->asset) ? [
'id' => (int) $assetmaintenance->asset->id,
- 'name'=> ($assetmaintenance->asset->name) ? e($assetmaintenance->asset->name) : null,
- 'asset_tag'=> e($assetmaintenance->asset->asset_tag),
- 'serial'=> e($assetmaintenance->asset->serial),
- 'deleted_at'=> Helper::getFormattedDateObject($assetmaintenance->asset->deleted_at, 'datetime'),
+ 'name' => ($assetmaintenance->asset->name) ? e($assetmaintenance->asset->name) : null,
+ 'asset_tag' => e($assetmaintenance->asset->asset_tag),
+ 'serial' => e($assetmaintenance->asset->serial),
+ 'deleted_at' => Helper::getFormattedDateObject($assetmaintenance->asset->deleted_at, 'datetime'),
'created_at' => Helper::getFormattedDateObject($assetmaintenance->asset->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($assetmaintenance->asset->updated_at, 'datetime'),
] : null,
'image' => ($assetmaintenance->image != '') ? Storage::disk('public')->url('maintenances/'.e($assetmaintenance->image)) : null,
'model' => (($assetmaintenance->asset) && ($assetmaintenance->asset->model)) ? [
'id' => (int) $assetmaintenance->asset->model->id,
- 'name'=> ($assetmaintenance->asset->model->name) ? e($assetmaintenance->asset->model->name) : null,
- 'model_number'=> ($assetmaintenance->asset->model->model_number) ? e($assetmaintenance->asset->model->model_number) : null,
+ 'name' => ($assetmaintenance->asset->model->name) ? e($assetmaintenance->asset->model->name) : null,
+ 'model_number' => ($assetmaintenance->asset->model->model_number) ? e($assetmaintenance->asset->model->model_number) : null,
] : null,
'status_label' => (($assetmaintenance->asset) && ($assetmaintenance->asset->assetstatus)) ? [
'id' => (int) $assetmaintenance->asset->assetstatus->id,
- 'name'=> e($assetmaintenance->asset->assetstatus->name),
- 'status_type'=> e($assetmaintenance->asset->assetstatus->getStatuslabelType()),
+ 'name' => e($assetmaintenance->asset->assetstatus->name),
+ 'status_type' => e($assetmaintenance->asset->assetstatus->getStatuslabelType()),
'status_meta' => e($assetmaintenance->asset->present()->statusMeta),
] : null,
'company' => (($assetmaintenance->asset) && ($assetmaintenance->asset->company)) ? [
'id' => (int) $assetmaintenance->asset->company->id,
- 'name'=> ($assetmaintenance->asset->company->name) ? e($assetmaintenance->asset->company->name) : null,
+ 'name' => ($assetmaintenance->asset->company->name) ? e($assetmaintenance->asset->company->name) : null,
] : null,
- 'name' => ($assetmaintenance->name) ? e($assetmaintenance->name) : null,
- 'title' => ($assetmaintenance->name) ? e($assetmaintenance->name) : null, // legacy to not change the shape of the API
+ 'name' => ($assetmaintenance->name) ? e($assetmaintenance->name) : null,
+ 'title' => ($assetmaintenance->name) ? e($assetmaintenance->name) : null, // legacy to not change the shape of the API
'location' => (($assetmaintenance->asset) && ($assetmaintenance->asset->location)) ? [
'id' => (int) $assetmaintenance->asset->location->id,
- 'name'=> e($assetmaintenance->asset->location->name),
+ 'name' => e($assetmaintenance->asset->location->name),
] : null,
'rtd_location' => (($assetmaintenance->asset) && ($assetmaintenance->asset->defaultLoc)) ? [
'id' => (int) $assetmaintenance->asset->defaultLoc->id,
- 'name'=> e($assetmaintenance->asset->defaultLoc->name),
+ 'name' => e($assetmaintenance->asset->defaultLoc->name),
+ ] : null,
+ 'notes' => ($assetmaintenance->notes) ? Helper::parseEscapedMarkedownInline($assetmaintenance->notes) : null,
+ 'supplier' => ($assetmaintenance->supplier) ? [
+ 'id' => $assetmaintenance->supplier->id,
+ 'name' => e($assetmaintenance->supplier->name),
] : null,
- 'notes' => ($assetmaintenance->notes) ? Helper::parseEscapedMarkedownInline($assetmaintenance->notes) : null,
- 'supplier' => ($assetmaintenance->supplier) ? [
- 'id' => $assetmaintenance->supplier->id,
- 'name'=> e($assetmaintenance->supplier->name)
- ] : null,
- 'url' => ($assetmaintenance->url) ? e($assetmaintenance->url) : null,
- 'cost' => Helper::formatCurrencyOutput($assetmaintenance->cost),
- 'asset_maintenance_type' => e($assetmaintenance->asset_maintenance_type),
- 'start_date' => Helper::getFormattedDateObject($assetmaintenance->start_date, 'date'),
- 'asset_maintenance_time' => $assetmaintenance->asset_maintenance_time,
- 'completion_date' => Helper::getFormattedDateObject($assetmaintenance->completion_date, 'date'),
- 'user_id' => ($assetmaintenance->adminuser) ? [
+ 'url' => ($assetmaintenance->url) ? e($assetmaintenance->url) : null,
+ 'cost' => Helper::formatCurrencyOutput($assetmaintenance->cost),
+ 'asset_maintenance_type' => e($assetmaintenance->asset_maintenance_type),
+ 'start_date' => Helper::getFormattedDateObject($assetmaintenance->start_date, 'date'),
+ 'asset_maintenance_time' => $assetmaintenance->asset_maintenance_time,
+ 'completion_date' => Helper::getFormattedDateObject($assetmaintenance->completion_date, 'date'),
+ 'user_id' => ($assetmaintenance->adminuser) ? [
'id' => $assetmaintenance->adminuser->id,
- 'name'=> e($assetmaintenance->adminuser->display_name)
+ 'name' => e($assetmaintenance->adminuser->display_name),
] : null, // legacy to not change the shape of the API
'created_by' => ($assetmaintenance->adminuser) ? [
'id' => (int) $assetmaintenance->adminuser->id,
- 'name'=> e($assetmaintenance->adminuser->display_name),
+ 'name' => e($assetmaintenance->adminuser->display_name),
] : null,
'created_at' => Helper::getFormattedDateObject($assetmaintenance->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($assetmaintenance->updated_at, 'datetime'),
- 'is_warranty'=> $assetmaintenance->is_warranty,
+ 'is_warranty' => $assetmaintenance->is_warranty,
];
$permissions_array['available_actions'] = [
- 'update' => (Gate::allows('update', Asset::class) && ((($assetmaintenance->asset) && $assetmaintenance->asset->deleted_at==''))) ? true : false,
+ 'update' => (Gate::allows('update', Asset::class) && ((($assetmaintenance->asset) && $assetmaintenance->asset->deleted_at == ''))) ? true : false,
'delete' => Gate::allows('delete', Asset::class),
];
diff --git a/app/Http/Transformers/ManufacturersTransformer.php b/app/Http/Transformers/ManufacturersTransformer.php
index 5f05c62e05..1e793439a4 100644
--- a/app/Http/Transformers/ManufacturersTransformer.php
+++ b/app/Http/Transformers/ManufacturersTransformer.php
@@ -4,8 +4,8 @@ namespace App\Http\Transformers;
use App\Helpers\Helper;
use App\Models\Manufacturer;
-use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Storage;
class ManufacturersTransformer
@@ -20,14 +20,14 @@ class ManufacturersTransformer
return (new DatatablesTransformer)->transformDatatables($array, $total);
}
- public function transformManufacturer(Manufacturer $manufacturer = null)
+ public function transformManufacturer(?Manufacturer $manufacturer = null)
{
if ($manufacturer) {
$array = [
'id' => (int) $manufacturer->id,
'name' => e($manufacturer->name),
'url' => e($manufacturer->url),
- 'image' => ($manufacturer->image) ? Storage::disk('public')->url('manufacturers/'.e($manufacturer->image)) : null,
+ 'image' => ($manufacturer->image) ? Storage::disk('public')->url('manufacturers/'.e($manufacturer->image)) : null,
'support_url' => e($manufacturer->support_url),
'warranty_lookup_url' => e($manufacturer->warranty_lookup_url),
'support_phone' => e($manufacturer->support_phone),
@@ -41,7 +41,7 @@ class ManufacturersTransformer
'notes' => Helper::parseEscapedMarkedownInline($manufacturer->notes),
'created_by' => ($manufacturer->adminuser) ? [
'id' => (int) $manufacturer->adminuser->id,
- 'name'=> e($manufacturer->adminuser->display_name),
+ 'name' => e($manufacturer->adminuser->display_name),
] : null,
'created_at' => Helper::getFormattedDateObject($manufacturer->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($manufacturer->updated_at, 'datetime'),
diff --git a/app/Http/Transformers/PieChartTransformer.php b/app/Http/Transformers/PieChartTransformer.php
index e5f48644a5..c2c818e47e 100644
--- a/app/Http/Transformers/PieChartTransformer.php
+++ b/app/Http/Transformers/PieChartTransformer.php
@@ -2,16 +2,19 @@
namespace App\Http\Transformers;
-
use App\Helpers\Helper;
+use Illuminate\Http\Response;
+
/**
* Class PieChartTransformer
*
* This handles the standardized formatting of the API response we need to provide for
* the pie charts
*
- * @return \Illuminate\Http\Response
+ * @return Response
+ *
* @since [v6.0.11]
+ *
* @author [A. Gianotto] [<[email protected]>]
*/
class PieChartTransformer
@@ -28,7 +31,7 @@ class PieChartTransformer
if ($total['count'] > 0) {
- $labels[] = $total['label']." (".$total['count'].")";
+ $labels[] = $total['label'].' ('.$total['count'].')';
$counts[] = $total['count'];
if (isset($total['color'])) {
@@ -45,11 +48,10 @@ class PieChartTransformer
'datasets' => [[
'data' => $counts,
'backgroundColor' => $colors_array,
- 'hoverBackgroundColor' => $colors_array,
+ 'hoverBackgroundColor' => $colors_array,
]],
];
-
return $results;
}
}
diff --git a/app/Http/Transformers/PredefinedKitsTransformer.php b/app/Http/Transformers/PredefinedKitsTransformer.php
index 3660ff269e..7031264b14 100644
--- a/app/Http/Transformers/PredefinedKitsTransformer.php
+++ b/app/Http/Transformers/PredefinedKitsTransformer.php
@@ -6,13 +6,14 @@ use App\Helpers\Helper;
use App\Models\Asset;
use App\Models\PredefinedKit;
use App\Models\SnipeModel;
-use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\Gate;
/**
* transforms collection of models to array with simple typres
*
* @author [D. Minaev] [<[email protected]>]
+ *
* @return array
*/
class PredefinedKitsTransformer
@@ -34,7 +35,7 @@ class PredefinedKitsTransformer
'name' => e($kit->name),
'created_by' => ($kit->adminuser) ? [
'id' => (int) $kit->adminuser->id,
- 'name'=> e($kit->adminuser->display_name),
+ 'name' => e($kit->adminuser->display_name),
] : null,
'created_at' => Helper::getFormattedDateObject($kit->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($kit->updated_at, 'datetime'),
@@ -55,6 +56,7 @@ class PredefinedKitsTransformer
/**
* transform collection of any elemets attached to kit
+ *
* @return array
*/
public function transformElements(Collection $elements, $total)
diff --git a/app/Http/Transformers/ProfileTransformer.php b/app/Http/Transformers/ProfileTransformer.php
index 3b8e58e133..10db6d6bec 100644
--- a/app/Http/Transformers/ProfileTransformer.php
+++ b/app/Http/Transformers/ProfileTransformer.php
@@ -18,7 +18,6 @@ class ProfileTransformer
return (new DatatablesTransformer)->transformDatatables($array, $total);
}
-
public function transformFile(Actionlog $file)
{
$array = [
@@ -29,7 +28,7 @@ class ProfileTransformer
'type' => e($file->itemType()),
] : null,
'filename' => e($file->filename),
- 'signature_file' => ($file->accept_signature) ? route('profile.signature.view', ['filename' => $file->accept_signature ]) : null,
+ 'signature_file' => ($file->accept_signature) ? route('profile.signature.view', ['filename' => $file->accept_signature]) : null,
'note' => e($file->note),
'url' => route('profile.storedeula.download', ['filename' => $file->filename]),
'file' => route('profile.storedeula.download', ['filename' => $file->filename]),
@@ -38,5 +37,4 @@ class ProfileTransformer
return $array;
}
-
}
diff --git a/app/Http/Transformers/SelectlistTransformer.php b/app/Http/Transformers/SelectlistTransformer.php
index 6972be262c..2b025662cc 100644
--- a/app/Http/Transformers/SelectlistTransformer.php
+++ b/app/Http/Transformers/SelectlistTransformer.php
@@ -2,6 +2,7 @@
namespace App\Http\Transformers;
+use Illuminate\Http\Response;
use Illuminate\Pagination\LengthAwarePaginator;
/**
@@ -11,8 +12,10 @@ use Illuminate\Pagination\LengthAwarePaginator;
* the rich (text and images) Select2 javascript.
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0.16]
- * @return \Illuminate\Http\Response
+ *
+ * @return Response
*/
class SelectlistTransformer
{
@@ -34,9 +37,9 @@ class SelectlistTransformer
$results = [
'results' => $items_array,
'pagination' => [
- 'more' => ($select_items->currentPage() >= $select_items->lastPage()) ? false : true,
- 'per_page' => $select_items->perPage(),
- ],
+ 'more' => ($select_items->currentPage() >= $select_items->lastPage()) ? false : true,
+ 'per_page' => $select_items->perPage(),
+ ],
'total_count' => $select_items->total(),
'page' => $select_items->currentPage(),
'page_count' => $select_items->lastPage(),
diff --git a/app/Http/Transformers/StatuslabelsTransformer.php b/app/Http/Transformers/StatuslabelsTransformer.php
index 255cddcb04..f394518612 100644
--- a/app/Http/Transformers/StatuslabelsTransformer.php
+++ b/app/Http/Transformers/StatuslabelsTransformer.php
@@ -4,8 +4,8 @@ namespace App\Http\Transformers;
use App\Helpers\Helper;
use App\Models\Statuslabel;
-use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\Gate;
class StatuslabelsTransformer
{
@@ -32,7 +32,7 @@ class StatuslabelsTransformer
'notes' => e($statuslabel->notes),
'created_by' => ($statuslabel->adminuser) ? [
'id' => (int) $statuslabel->adminuser->id,
- 'name'=> e($statuslabel->adminuser->display_name),
+ 'name' => e($statuslabel->adminuser->display_name),
] : null,
'created_at' => Helper::getFormattedDateObject($statuslabel->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($statuslabel->updated_at, 'datetime'),
diff --git a/app/Http/Transformers/SuppliersTransformer.php b/app/Http/Transformers/SuppliersTransformer.php
index 6313529e4d..f4b6bfaaa0 100644
--- a/app/Http/Transformers/SuppliersTransformer.php
+++ b/app/Http/Transformers/SuppliersTransformer.php
@@ -4,8 +4,8 @@ namespace App\Http\Transformers;
use App\Helpers\Helper;
use App\Models\Supplier;
-use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Storage;
class SuppliersTransformer
@@ -20,13 +20,13 @@ class SuppliersTransformer
return (new DatatablesTransformer)->transformDatatables($array, $total);
}
- public function transformSupplier(Supplier $supplier = null)
+ public function transformSupplier(?Supplier $supplier = null)
{
if ($supplier) {
$array = [
'id' => (int) $supplier->id,
'name' => e($supplier->name),
- 'image' => ($supplier->image) ? Storage::disk('public')->url('suppliers/'.e($supplier->image)) : null,
+ 'image' => ($supplier->image) ? Storage::disk('public')->url('suppliers/'.e($supplier->image)) : null,
'url' => e($supplier->url),
'address' => e($supplier->address),
'address2' => e($supplier->address2),
@@ -48,8 +48,8 @@ class SuppliersTransformer
'created_at' => Helper::getFormattedDateObject($supplier->created_at, 'datetime'),
'created_by' => $supplier->adminuser ? [
'id' => (int) $supplier->adminuser->id,
- 'name'=> e($supplier->adminuser->present()->fullName),
- ]: null,
+ 'name' => e($supplier->adminuser->present()->fullName),
+ ] : null,
'updated_at' => Helper::getFormattedDateObject($supplier->updated_at, 'datetime'),
];
diff --git a/app/Http/Transformers/UploadedFilesTransformer.php b/app/Http/Transformers/UploadedFilesTransformer.php
index b072506781..4983de03fc 100644
--- a/app/Http/Transformers/UploadedFilesTransformer.php
+++ b/app/Http/Transformers/UploadedFilesTransformer.php
@@ -21,7 +21,6 @@ class UploadedFilesTransformer
return (new DatatablesTransformer)->transformDatatables($array, $total);
}
-
public function transformFile(Actionlog $file)
{
$snipeModel = $file->item_type;
@@ -38,10 +37,10 @@ class UploadedFilesTransformer
'filetype' => StorageHelper::getFiletype($file->uploads_file_path()),
'mediatype' => StorageHelper::getMediaType($file->uploads_file_path()),
'url' => $file->uploads_file_url(),
- 'note' => ($file->note) ? e($file->note) : null,
+ 'note' => ($file->note) ? e($file->note) : null,
'created_by' => ($file->adminuser) ? [
'id' => (int) $file->adminuser->id,
- 'name'=> e($file->adminuser->display_name),
+ 'name' => e($file->adminuser->display_name),
] : null,
'created_at' => Helper::getFormattedDateObject($file->created_at, 'datetime'),
'deleted_at' => Helper::getFormattedDateObject($file->deleted_at, 'datetime'),
@@ -54,8 +53,7 @@ class UploadedFilesTransformer
];
$array += $permissions_array;
+
return $array;
}
-
-
-}
\ No newline at end of file
+}
diff --git a/app/Http/Transformers/UsersTransformer.php b/app/Http/Transformers/UsersTransformer.php
index 9843e839ff..7d295356a5 100644
--- a/app/Http/Transformers/UsersTransformer.php
+++ b/app/Http/Transformers/UsersTransformer.php
@@ -29,75 +29,75 @@ class UsersTransformer
$role = 'admin';
}
$array = [
- 'id' => (int) $user->id,
- 'avatar' => e($user->present()->gravatar) ?? null,
- 'name' => e($user->getFullNameAttribute()) ?? null,
- 'first_name' => e($user->first_name) ?? null,
- 'last_name' => e($user->last_name) ?? null,
- 'display_name' => ($user->getRawOriginal('display_name')) ? e($user->getRawOriginal('display_name')) : null,
- 'username' => e($user->username) ?? null,
- 'remote' => ($user->remote == '1') ? true : false,
- 'locale' => ($user->locale) ? e($user->locale) : null,
- 'employee_num' => ($user->employee_num) ? e($user->employee_num) : null,
- 'manager' => ($user->manager) ? [
- 'id' => (int) $user->manager->id,
- 'name'=> e($user->manager->display_name),
- ] : null,
- 'jobtitle' => ($user->jobtitle) ? e($user->jobtitle) : null,
- 'vip' => ($user->vip == '1') ? true : false,
- 'phone' => ($user->phone) ? e($user->phone) : null,
- 'mobile' => ($user->mobile) ? e($user->mobile) : null,
- 'website' => ($user->website) ? e($user->website) : null,
- 'address' => ($user->address) ? e($user->address) : null,
- 'city' => ($user->city) ? e($user->city) : null,
- 'state' => ($user->state) ? e($user->state) : null,
- 'country' => ($user->country) ? e($user->country) : null,
- 'zip' => ($user->zip) ? e($user->zip) : null,
- 'email' => ($user->email) ? e($user->email) : null,
- 'department' => ($user->department) ? [
- 'id' => (int) $user->department->id,
- 'name'=> e($user->department->name),
- 'tag_color' => ($user->department->tag_color) ? e($user->department->tag_color) : null,
- ] : null,
- 'department_manager' => ($user->department?->manager) ? [
- 'id' => (int) $user->department->manager->id,
- 'name'=> e($user->department->manager->display_name),
- ] : null,
- 'location' => ($user->userloc) ? [
- 'id' => (int) $user->userloc->id,
- 'name'=> e($user->userloc->name),
- 'tag_color'=> ($user->userloc->tag_color) ? e($user->userloc->tag_color) : null,
- ] : null,
- 'notes'=> Helper::parseEscapedMarkedownInline($user->notes),
- 'role' => $role,
- 'permissions' => $user->decodePermissions(),
- 'activated' => ($user->activated == '1') ? true : false,
- 'autoassign_licenses' => ($user->autoassign_licenses == '1') ? true : false,
- 'ldap_import' => ($user->ldap_import == '1') ? true : false,
- 'two_factor_enrolled' => ($user->two_factor_active_and_enrolled()) ? true : false,
- 'two_factor_optin' => ($user->two_factor_active()) ? true : false,
- 'assets_count' => (int) $user->assets_count,
- 'licenses_count' => (int) $user->licenses_count,
- 'accessories_count' => (int) $user->accessories_count,
- 'consumables_count' => (int) $user->consumables_count,
- 'manages_users_count' => (int) $user->manages_users_count,
- 'manages_locations_count' => (int) $user->manages_locations_count,
- 'company' => ($user->company) ? [
- 'id' => (int) $user->company->id,
- 'name'=> e($user->company->name),
- 'tag_color'=> ($user->company->tag_color) ? e($user->company->tag_color) : null,
- ] : null,
- 'created_by' => ($user->createdBy) ? [
- 'id' => (int) $user->createdBy->id,
- 'name'=> e($user->createdBy->display_name),
- ] : null,
- 'created_at' => Helper::getFormattedDateObject($user->created_at, 'datetime'),
- 'updated_at' => Helper::getFormattedDateObject($user->updated_at, 'datetime'),
- 'start_date' => Helper::getFormattedDateObject($user->start_date, 'date'),
- 'end_date' => Helper::getFormattedDateObject($user->end_date, 'date'),
- 'last_login' => Helper::getFormattedDateObject($user->last_login, 'datetime'),
- 'deleted_at' => ($user->deleted_at) ? Helper::getFormattedDateObject($user->deleted_at, 'datetime') : null,
- ];
+ 'id' => (int) $user->id,
+ 'avatar' => e($user->present()->gravatar) ?? null,
+ 'name' => e($user->getFullNameAttribute()) ?? null,
+ 'first_name' => e($user->first_name) ?? null,
+ 'last_name' => e($user->last_name) ?? null,
+ 'display_name' => ($user->getRawOriginal('display_name')) ? e($user->getRawOriginal('display_name')) : null,
+ 'username' => e($user->username) ?? null,
+ 'remote' => ($user->remote == '1') ? true : false,
+ 'locale' => ($user->locale) ? e($user->locale) : null,
+ 'employee_num' => ($user->employee_num) ? e($user->employee_num) : null,
+ 'manager' => ($user->manager) ? [
+ 'id' => (int) $user->manager->id,
+ 'name' => e($user->manager->display_name),
+ ] : null,
+ 'jobtitle' => ($user->jobtitle) ? e($user->jobtitle) : null,
+ 'vip' => ($user->vip == '1') ? true : false,
+ 'phone' => ($user->phone) ? e($user->phone) : null,
+ 'mobile' => ($user->mobile) ? e($user->mobile) : null,
+ 'website' => ($user->website) ? e($user->website) : null,
+ 'address' => ($user->address) ? e($user->address) : null,
+ 'city' => ($user->city) ? e($user->city) : null,
+ 'state' => ($user->state) ? e($user->state) : null,
+ 'country' => ($user->country) ? e($user->country) : null,
+ 'zip' => ($user->zip) ? e($user->zip) : null,
+ 'email' => ($user->email) ? e($user->email) : null,
+ 'department' => ($user->department) ? [
+ 'id' => (int) $user->department->id,
+ 'name' => e($user->department->name),
+ 'tag_color' => ($user->department->tag_color) ? e($user->department->tag_color) : null,
+ ] : null,
+ 'department_manager' => ($user->department?->manager) ? [
+ 'id' => (int) $user->department->manager->id,
+ 'name' => e($user->department->manager->display_name),
+ ] : null,
+ 'location' => ($user->userloc) ? [
+ 'id' => (int) $user->userloc->id,
+ 'name' => e($user->userloc->name),
+ 'tag_color' => ($user->userloc->tag_color) ? e($user->userloc->tag_color) : null,
+ ] : null,
+ 'notes' => Helper::parseEscapedMarkedownInline($user->notes),
+ 'role' => $role,
+ 'permissions' => $user->decodePermissions(),
+ 'activated' => ($user->activated == '1') ? true : false,
+ 'autoassign_licenses' => ($user->autoassign_licenses == '1') ? true : false,
+ 'ldap_import' => ($user->ldap_import == '1') ? true : false,
+ 'two_factor_enrolled' => ($user->two_factor_active_and_enrolled()) ? true : false,
+ 'two_factor_optin' => ($user->two_factor_active()) ? true : false,
+ 'assets_count' => (int) $user->assets_count,
+ 'licenses_count' => (int) $user->licenses_count,
+ 'accessories_count' => (int) $user->accessories_count,
+ 'consumables_count' => (int) $user->consumables_count,
+ 'manages_users_count' => (int) $user->manages_users_count,
+ 'manages_locations_count' => (int) $user->manages_locations_count,
+ 'company' => ($user->company) ? [
+ 'id' => (int) $user->company->id,
+ 'name' => e($user->company->name),
+ 'tag_color' => ($user->company->tag_color) ? e($user->company->tag_color) : null,
+ ] : null,
+ 'created_by' => ($user->createdBy) ? [
+ 'id' => (int) $user->createdBy->id,
+ 'name' => e($user->createdBy->display_name),
+ ] : null,
+ 'created_at' => Helper::getFormattedDateObject($user->created_at, 'datetime'),
+ 'updated_at' => Helper::getFormattedDateObject($user->updated_at, 'datetime'),
+ 'start_date' => Helper::getFormattedDateObject($user->start_date, 'date'),
+ 'end_date' => Helper::getFormattedDateObject($user->end_date, 'date'),
+ 'last_login' => Helper::getFormattedDateObject($user->last_login, 'datetime'),
+ 'deleted_at' => ($user->deleted_at) ? Helper::getFormattedDateObject($user->deleted_at, 'datetime') : null,
+ ];
$permissions_array['available_actions'] = [
'update' => (Gate::allows('update', User::class) && ($user->deleted_at == '')),
@@ -130,11 +130,9 @@ class UsersTransformer
* allowing us to 1) deliver a smaller payload and 2) avoid additional queries on relations that
* have not been easy/lazy loaded already
*
- * @param User $user
- * @return array
* @throws \Exception
*/
- public function transformUserCompact(User $user) : array
+ public function transformUserCompact(User $user): array
{
$array = [
@@ -148,8 +146,8 @@ class UsersTransformer
'display_name' => e($user->display_name),
'created_by' => $user->adminuser ? [
'id' => (int) $user->adminuser->id,
- 'name'=> e($user->adminuser->present()->fullName),
- ]: null,
+ 'name' => e($user->adminuser->present()->fullName),
+ ] : null,
'created_at' => Helper::getFormattedDateObject($user->created_at, 'datetime'),
'deleted_at' => ($user->deleted_at) ? Helper::getFormattedDateObject($user->deleted_at, 'datetime') : null,
];