From 5499735f3ad58e65d224f3dcc6de8e9f2a97ea28 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 23 May 2017 14:31:04 -0700 Subject: [PATCH] Actionlogs API transformer --- .../Transformers/ActionlogsTransformer.php | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 app/Http/Transformers/ActionlogsTransformer.php diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php new file mode 100644 index 0000000000..72369defa2 --- /dev/null +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -0,0 +1,68 @@ +transformDatatables($array, $total); + } + + public function transformActionlog (Actionlog $actionlog) + { + $array = [ + 'icon' => $actionlog->present()->icon(), + 'item' => ($actionlog->item) ? [ + 'id' => (int) $actionlog->item->id, + 'name' => e($actionlog->item->getDisplayNameAttribute()), + 'type' => e($actionlog->itemType()), + ] : null, + 'created_at' => Helper::getFormattedDateObject($actionlog->created_at, 'datetime'), + 'updated_at' => Helper::getFormattedDateObject($actionlog->updated_at, 'datetime'), + '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, + + 'note' => e($actionlog->note), + + + ]; + + + + return $array; + } + + + 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); + } + + + +}