From b8908bf246792eb57289593be54801d0a831be97 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 19 Nov 2013 03:58:26 -0500 Subject: [PATCH] Add checkin/checkout log to user profile view --- app/controllers/admin/AssetsController.php | 15 +++++---- app/controllers/admin/UsersController.php | 2 +- app/models/Actionlog.php | 20 +++++------- app/models/Asset.php | 8 +++++ app/models/User.php | 8 ++++- app/views/backend/users/view.blade.php | 38 ++++++++++++++++++++-- 6 files changed, 69 insertions(+), 22 deletions(-) diff --git a/app/controllers/admin/AssetsController.php b/app/controllers/admin/AssetsController.php index f9e5e793ec..38b76ba0ad 100644 --- a/app/controllers/admin/AssetsController.php +++ b/app/controllers/admin/AssetsController.php @@ -302,24 +302,25 @@ class AssetsController extends AdminController { return Redirect::to('admin')->with('error', Lang::get('admin/assets/message.not_found')); } - // Update the asset data - $asset->assigned_to = ''; - - if (!is_null($asset->assigned_to)) { $user = User::find($asset->assigned_to); } + $logaction = new Actionlog(); + $logaction->checkedout_to = $asset->assigned_to; + + // Update the asset data to null, since it's being checked in + $asset->assigned_to = ''; // Was the asset updated? if($asset->save()) { - $logaction = new Actionlog(); + $logaction->asset_id = $asset->id; - //$logaction->user_id = $loggedin->user_id ; + $logaction->location_id = NULL; $logaction->user_id = Sentry::getUser()->id; - $log = $logaction->logaction('checkin'); + $log = $logaction->logaction('checkin from'); // Redirect to the new asset page return Redirect::to("admin")->with('success', Lang::get('admin/assets/message.checkin.success')); diff --git a/app/controllers/admin/UsersController.php b/app/controllers/admin/UsersController.php index fc813617ca..19f3046260 100755 --- a/app/controllers/admin/UsersController.php +++ b/app/controllers/admin/UsersController.php @@ -11,6 +11,7 @@ use Input; use User; use Asset; use Lang; +use Actionlog; use Location; use Redirect; use Sentry; @@ -414,7 +415,6 @@ class UsersController extends AdminController { public function getView($userId = null) { $user = User::find($userId); - // Show the page return View::make('backend/users/view', compact('user')); } diff --git a/app/models/Actionlog.php b/app/models/Actionlog.php index 299679679b..c560a53d20 100644 --- a/app/models/Actionlog.php +++ b/app/models/Actionlog.php @@ -5,22 +5,20 @@ class ActionLog extends Eloquent { protected $table = 'asset_logs'; public $timestamps = false; - /** - * Get the parent category name - */ - public function assetlog() - { + public function assetlog() { + return $this->belongsTo('Asset','asset_id'); } - /** - * Get the parent category name - */ - public function userlog() - { - + public function adminlog() { + return $this->belongsTo('User','user_id'); } + public function userlog() { + return $this->belongsTo('User','assigned_to'); + } + + /** * Get the parent category name */ diff --git a/app/models/Asset.php b/app/models/Asset.php index eb95826b9c..c7dcb2dae7 100644 --- a/app/models/Asset.php +++ b/app/models/Asset.php @@ -55,4 +55,12 @@ class Asset extends Elegant { } + /** + * Get action logs for this asset + */ + public function asssetlog() + { + return $this->hasMany('Actionlog','asset_id'); + } + } diff --git a/app/models/User.php b/app/models/User.php index 7177e152f6..3bd7634212 100755 --- a/app/models/User.php +++ b/app/models/User.php @@ -39,9 +39,15 @@ class User extends SentryUserModel { public function assets() { return $this->hasMany('Asset', 'assigned_to'); - } + /** + * Get action logs for this user + */ + public function userlog() + { + return $this->hasMany('Actionlog','checkedout_to'); + } } diff --git a/app/views/backend/users/view.blade.php b/app/views/backend/users/view.blade.php index 403d6aaac2..3b8a491016 100644 --- a/app/views/backend/users/view.blade.php +++ b/app/views/backend/users/view.blade.php @@ -65,13 +65,47 @@ View User {{ $user->fullName() }} ::
- @lang('admin/users/table.noresults') -
@endif + + +
History for {{ $user->first_name }}
+
+ + @if (count($user->userlog) > 0) + + + + + + + + + + + @foreach ($user->userlog as $log) + + + + + + + @endforeach + +
DateActionAssetBy
{{ $log->added_on }}{{ $log->action_type }}{{ $log->assetlog->name }}{{ $log->adminlog->fullName() }}
+ @else + +
+
+ + @lang('admin/users/table.noresults') +
+
+ @endif +