mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-26 14:09:43 -08:00
987536930c
* Fix some n+1 problems * Use route in notification dropdown to make sure we link to correct page * Work on better UI support for checkout to non-user. Fix links on index bootstrap table, work towards eliminating assignedUser * Remove Asset::assigneduser() relationship. Instead add a checkedOutToUser() method and/or port to using assignedTo() * Adjust string to fit new reality * Fix #3780. Move the consumables getDataView method to the ApiController. Not entirely RESTful, but it's a weird method that probably doesn't need its own controller and the functionality would be strange to stack on the userscontroller... * Fix file uploads to assets and restore the delete route. * Add asset maintence edit action to index. * Suppliers asset list should link to the related asset, not to the supplier with same ID. * Asset models page should use polymorphic formatter on assigned to to better handle assorted item types. * Comment out more assigneduser fallacy until we figure out the query builder approach to searching for location text.
55 lines
2.3 KiB
PHP
55 lines
2.3 KiB
PHP
<?php
|
|
namespace App\Http\Transformers;
|
|
|
|
use App\Models\AssetMaintenance;
|
|
use Gate;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use App\Helpers\Helper;
|
|
|
|
class AssetMaintenancesTransformer
|
|
{
|
|
|
|
public function transformAssetMaintenances (Collection $assetmaintenances, $total)
|
|
{
|
|
$array = array();
|
|
foreach ($assetmaintenances as $assetmaintenance) {
|
|
$array[] = self::transformAssetMaintenance($assetmaintenance);
|
|
}
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
}
|
|
|
|
public function transformAssetMaintenance (AssetMaintenance $assetmaintenance)
|
|
{
|
|
$array = [
|
|
'id' => (int) $assetmaintenance->id,
|
|
'asset_name' => ($assetmaintenance->asset) ? ['id' => $assetmaintenance->asset->id,'name'=> e($assetmaintenance->asset->name)] : null,
|
|
'title' => ($assetmaintenance->title) ? e($assetmaintenance->title) : null,
|
|
'notes' => ($assetmaintenance->notes) ? e($assetmaintenance->notes) : null,
|
|
'supplier' => ($assetmaintenance->supplier) ? ['id' => $assetmaintenance->supplier->id,'name'=> e($assetmaintenance->supplier->name)] : null,
|
|
'cost' => Helper::formatCurrencyOutput($assetmaintenance->cost),
|
|
'asset_maintenance_type' => e($assetmaintenance->asset_maintenance_type),
|
|
'start_date' => Helper::getFormattedDateObject($assetmaintenance->start_date, 'datetime'),
|
|
'asset_maintenance_time' => $assetmaintenance->asset_maintenance_time,
|
|
'completion_date' => Helper::getFormattedDateObject($assetmaintenance->completion_date, 'datetime'),
|
|
'user_id' => ($assetmaintenance->admin) ? ['id' => $assetmaintenance->admin->id,'name'=> e($assetmaintenance->admin->getFullNameAttribute())] : null,
|
|
'created_at' => Helper::getFormattedDateObject($assetmaintenance->created_at, 'datetime'),
|
|
'updated_at' => Helper::getFormattedDateObject($assetmaintenance->updated_at, 'datetime'),
|
|
|
|
];
|
|
|
|
$permissions_array['available_actions'] = [
|
|
'update' => (bool) Gate::allows('update', Asset::class),
|
|
'delete' => (bool) Gate::allows('delete', Asset::class),
|
|
];
|
|
|
|
$array += $permissions_array;
|
|
|
|
return $array;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|