2017-05-23 14:31:04 -07:00
|
|
|
<?php
|
|
|
|
namespace App\Http\Transformers;
|
|
|
|
|
2019-03-13 20:12:03 -07:00
|
|
|
use App\Helpers\Helper;
|
2017-05-23 14:31:04 -07:00
|
|
|
use App\Models\Actionlog;
|
2017-08-25 18:40:20 -07:00
|
|
|
use App\Models\Setting;
|
2017-05-23 14:31:04 -07:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
|
|
|
|
class ActionlogsTransformer
|
|
|
|
{
|
|
|
|
|
|
|
|
public function transformActionlogs (Collection $actionlogs, $total)
|
|
|
|
{
|
|
|
|
$array = array();
|
2017-08-25 18:40:20 -07:00
|
|
|
$settings = Setting::getSettings();
|
2017-05-23 14:31:04 -07:00
|
|
|
foreach ($actionlogs as $actionlog) {
|
2017-08-25 18:40:20 -07:00
|
|
|
$array[] = self::transformActionlog($actionlog, $settings);
|
2017-05-23 14:31:04 -07:00
|
|
|
}
|
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
|
|
}
|
|
|
|
|
2017-08-25 18:40:20 -07:00
|
|
|
public function transformActionlog (Actionlog $actionlog, $settings = null)
|
2017-05-23 14:31:04 -07:00
|
|
|
{
|
2018-05-02 14:13:06 -07:00
|
|
|
$icon = $actionlog->present()->icon();
|
|
|
|
if ($actionlog->filename!='') {
|
|
|
|
$icon = e(\App\Helpers\Helper::filetype_icon($actionlog->filename));
|
|
|
|
}
|
2017-05-23 14:31:04 -07:00
|
|
|
$array = [
|
2017-08-25 18:40:20 -07:00
|
|
|
'id' => (int) $actionlog->id,
|
2018-05-02 14:13:06 -07:00
|
|
|
'icon' => $icon,
|
|
|
|
'file' => ($actionlog->filename!='') ?
|
|
|
|
[
|
|
|
|
'url' => route('show/assetfile', ['assetId' => $actionlog->item->id, 'fileId' => $actionlog->id]),
|
|
|
|
'filename' => $actionlog->filename,
|
|
|
|
'inlineable' => (bool) \App\Helpers\Helper::show_file_inline($actionlog->filename),
|
|
|
|
] : null,
|
|
|
|
|
2017-05-23 14:31:04 -07:00
|
|
|
'item' => ($actionlog->item) ? [
|
|
|
|
'id' => (int) $actionlog->item->id,
|
|
|
|
'name' => e($actionlog->item->getDisplayNameAttribute()),
|
|
|
|
'type' => e($actionlog->itemType()),
|
|
|
|
] : null,
|
2017-08-25 18:40:20 -07:00
|
|
|
'location' => ($actionlog->location) ? [
|
|
|
|
'id' => (int) $actionlog->location->id,
|
|
|
|
'name' => e($actionlog->location->name)
|
|
|
|
] : null,
|
2017-05-23 14:31:04 -07:00
|
|
|
'created_at' => Helper::getFormattedDateObject($actionlog->created_at, 'datetime'),
|
|
|
|
'updated_at' => Helper::getFormattedDateObject($actionlog->updated_at, 'datetime'),
|
2018-02-21 01:18:21 -08:00
|
|
|
'next_audit_date' => ($actionlog->itemType()=='asset') ? Helper::getFormattedDateObject($actionlog->calcNextAuditDate(null, $actionlog->item), 'date'): null,
|
2017-08-25 18:40:20 -07:00
|
|
|
'days_to_next_audit' => $actionlog->daysUntilNextAudit($settings->audit_interval, $actionlog->item),
|
2017-05-23 14:31:04 -07:00
|
|
|
'action_type' => $actionlog->present()->actionType(),
|
|
|
|
'admin' => ($actionlog->user) ? [
|
|
|
|
'id' => (int) $actionlog->user->id,
|
|
|
|
'name' => e($actionlog->user->getFullNameAttribute()),
|
|
|
|
'first_name'=> e($actionlog->user->first_name),
|
|
|
|
'last_name'=> e($actionlog->user->last_name)
|
|
|
|
] : null,
|
|
|
|
'target' => ($actionlog->target) ? [
|
|
|
|
'id' => (int) $actionlog->target->id,
|
|
|
|
'name' => ($actionlog->targetType()=='user') ? e($actionlog->target->getFullNameAttribute()) : e($actionlog->target->getDisplayNameAttribute()),
|
|
|
|
'type' => e($actionlog->targetType()),
|
|
|
|
] : null,
|
|
|
|
|
2017-09-28 15:13:05 -07:00
|
|
|
'note' => ($actionlog->note) ? e($actionlog->note): null,
|
2018-09-29 21:33:52 -07:00
|
|
|
'signature_file' => ($actionlog->signature_filename) ? route('log.signature.view', ['filename' => $actionlog->signature_filename ]) : null,
|
2017-12-12 04:59:28 -08:00
|
|
|
'log_meta' => ($actionlog->log_meta) ? json_decode($actionlog->log_meta): null,
|
2019-03-13 21:36:32 -07:00
|
|
|
'action_date' => ($actionlog->action_date) ? Helper::getFormattedDateObject($actionlog->action_date, 'date'): null,
|
2017-05-23 14:31:04 -07:00
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-02 14:13:06 -07:00
|
|
|
|
2017-05-23 14:31:04 -07:00
|
|
|
public function transformCheckedoutActionlog (Collection $accessories_users, $total)
|
|
|
|
{
|
|
|
|
|
|
|
|
$array = array();
|
|
|
|
foreach ($accessories_users as $user) {
|
|
|
|
$array[] = (new UsersTransformer)->transformUser($user);
|
|
|
|
}
|
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|