diff --git a/app/controllers/admin/UsersController.php b/app/controllers/admin/UsersController.php index 2772f5abf115..da4aaf871e23 100755 --- a/app/controllers/admin/UsersController.php +++ b/app/controllers/admin/UsersController.php @@ -20,7 +20,7 @@ use Sentry; use Validator; use View; -use Chumper\Datatable\Facades\Datatable; +use Datatable; use League\Csv\Reader; use Mail; @@ -47,41 +47,9 @@ class UsersController extends AdminController */ public function getIndex() { - // Grab all the users - depending on the scope to include - $users = Sentry::getUserProvider()->createModel(); - - // Do we want to include the deleted users? - // the with and onlyTrashed calls currently do not work - returns an - // inconsistent array which cannot be displayed by the blade output - - if (Input::get('withTrashed')) { - - $users = $users->withTrashed(); - //$users = Sentry::getUserProvider()->createModel()->paginate(); - - } elseif (Input::get('onlyTrashed')) { - - // this is a tempoary 'fix' to display NO deleted users. - //$users = Sentry::getUserProvider()->createModel()->whereNotNull('deleted_at')->paginate(); - //$users = Sentry::findAllUsers(); - //$users = users::deletedUsers()->paginate(); - $users = Sentry::getUserProvider()->createModel()->onlyTrashed(); - //$users = users::whereNotNull('deleted_at')->paginate(); - //$users = $users->onlyTrashed(); - //$users = Users::onlyTrashed()->get(); - //$users = Sentry::getUserProvider()->createModel(); - } - - - // Paginate the users - $users = $users->paginate(100000) - ->appends(array( - 'withTrashed' => Input::get('withTrashed'), - 'onlyTrashed' => Input::get('onlyTrashed'), - )); - + // Show the page - return View::make('backend/users/index', compact('users')); + return View::make('backend/users/index'); } /** @@ -490,34 +458,7 @@ public function getView($userId = null) } - public function getDatatable() - { - return Datatable::collection(User::all()) - ->addColumn('name',function ($model) { - $name = HTML::image($model->gravatar(), $model->first_name, array('class'=>'img-circle avatar hidden-phone', 'style'=>'max-width: 45px')); - $name .= HTML::link(URL::action('Controllers\Admin\UsersController@getView', $model->id), $model->first_name . ' ' . $model->last_name, array('class' => 'name')); - return $name; - } - ) - ->showColumns('email') - ->addColumn('assets', function ($model) { - $assets = $model->assets->count(); - return $assets; - } - ) - ->addColumn('licenses', function ($model) { - $licenses = $model->licenses->count(); - return $licenses; - } - ) - ->addColumn('activated', function ($model) { - $activated = $model->isActivated() ? '' : ''; - return $activated; - } - ) - ->make(); - } - + /** * Unsuspend the given user. * @@ -733,6 +674,87 @@ public function postImport() } + + public function getDatatable($status = null) + { + + $users = User::with('assets'); + + switch ($status) { + case 'deleted': + $users->GetDeleted(); + break; + case '': + $users->GetNotDeleted(); + break; + } + + $users = $users->orderBy('created_at', 'DESC')->get(); + + $actions = new \Chumper\Datatable\Columns\FunctionColumn('actions', function ($users) + { + $action_buttons = ''; + + + if ( ! is_null($users->deleted_at)) { + $action_buttons .= ' '; + } else { + if ($users->accountStatus()=='suspended') { + $action_buttons .= ' '; + } + + $action_buttons .= ' '; + + if ((Sentry::getId() !== $users->id) && (!Config::get('app.lock_passwords'))) { + $action_buttons .= ' '; + } else { + $action_buttons .= ' '; + } + } + return $action_buttons; + + }); + + + return Datatable::collection($users) + ->addColumn('name',function($users) + { + return ''.$users->fullName().''; + }) + + ->addColumn('email',function($users) + { + return ''.$users->email.''; + }) + + ->addColumn('manager',function($users) + { + if ($users->manager) { + return ''.$users->manager->fullName().''; + } + }) + + ->addColumn('assets',function($users) + { + return $users->assets->count(); + }) + + ->addColumn('licenses',function($users) + { + return $users->licenses->count(); + }) + ->addColumn('activated',function($users) + { + return $users->isActivated() ? '' : ''; + }) + + ->addColumn($actions) + ->searchColumns('name','email','manager','activated', 'licenses','assets') + ->orderColumns('name','email','manager','activated', 'licenses','assets') + ->make(); + + } + diff --git a/app/models/User.php b/app/models/User.php index d5875f3d3e9c..bc8009197770 100755 --- a/app/models/User.php +++ b/app/models/User.php @@ -23,6 +23,7 @@ public function fullName() { return "{$this->first_name} {$this->last_name}"; } + /** * Returns the user Gravatar image url. @@ -89,4 +90,16 @@ public function accountStatus() return ''; } } + + public function scopeGetDeleted($query) + { + return $query->whereNotNull('deleted_at'); + } + + public function scopeGetNotDeleted($query) + { + return $query->whereNull('deleted_at'); + } + + } diff --git a/app/routes.php b/app/routes.php index b2d5c6c200bb..ca21e1f784f5 100755 --- a/app/routes.php +++ b/app/routes.php @@ -212,7 +212,7 @@ # User Management Route::group(array('prefix' => 'users'), function () { - Route::get('/', array('as' => 'users', 'uses' => 'UsersController@getIndex')); + Route::get('create', array('as' => 'create/user', 'uses' => 'UsersController@getCreate')); Route::post('create', 'UsersController@postCreate'); Route::get('import', array('as' => 'import/user', 'uses' => 'UsersController@getImport')); @@ -225,9 +225,9 @@ Route::get('{userId}/restore', array('as' => 'restore/user', 'uses' => 'UsersController@getRestore')); Route::get('{userId}/view', array('as' => 'view/user', 'uses' => 'UsersController@getView')); Route::get('{userId}/unsuspend', array('as' => 'unsuspend/user', 'uses' => 'UsersController@getUnsuspend')); - - - Route::get('datatable', array('as' => 'api.users', 'uses' => 'UsersController@getDatatable')); + Route::get('api/users/{status?}', array('as'=>'api.users', 'uses'=>'UsersController@getDatatable')); + Route::get('/', array('as' => 'users', 'uses' => 'UsersController@getIndex')); + }); # Group Management diff --git a/app/views/backend/users/index.blade.php b/app/views/backend/users/index.blade.php index 37ae9bdd4466..243037e17202 100755 --- a/app/views/backend/users/index.blade.php +++ b/app/views/backend/users/index.blade.php @@ -13,10 +13,10 @@
Import @lang('general.create') - @if (Input::get('onlyTrashed')) + @if (Input::get('status')=='deleted') Show Current Users @else - Show Deleted Users + Deleted Users @endif

@@ -32,93 +32,49 @@
-@if ($users->getTotal() > 0) -
-
- - - - - - - - - - - - - - - @foreach ($users as $user) - - - - - - - - - - - @endforeach - -
@lang('admin/users/table.name')@lang('admin/users/table.email')@lang('admin/users/table.manager')@lang('general.assets')@lang('general.licenses')@lang('admin/users/table.activated')@lang('table.actions')
- @if ($user->avatar) - - @else - - @endif - {{{ $user->fullName() }}} - - {{{ $user->email }}} - @if ($user->manager) {{{ $user->manager->fullName() }}} - @endif - {{{ $user->assets->count() }}}{{{ $user->licenses->count() }}}{{ $user->isActivated() ? '' : ''}} - - - @if (is_null($user->deleted_at)) - @if ($user->accountStatus()=='suspended') - - @endif - @endif - +{{ Datatable::table() + ->addColumn( + Lang::get('admin/users/table.name'), + Lang::get('admin/users/table.email'), + Lang::get('admin/users/table.manager'), + Lang::get('general.assets'), + Lang::get('general.licenses'), + Lang::get('admin/users/table.activated'), + Lang::get('table.actions') + ) + ->setUrl(route('api.users', Input::get('status'))) // this is the route where data will be retrieved + ->setOptions( + array( + 'deferRender'=> true, + 'stateSave'=> true, + 'stateDuration'=> -1, + 'dom' =>'CT<"clear">lfrtip', + 'tableTools' => array( + 'sSwfPath'=> Config::get('app.url').'/assets/swf/copy_csv_xls_pdf.swf', + 'aButtons'=>array( + 'copy', + 'print', + array( + 'sExtends'=>'collection', + 'sButtonText'=>'Export', + 'aButtons'=>array( + 'csv', + 'xls', + 'pdf' + ) + ) + ) + ), + 'colVis'=> array('showAll'=>'Show All','restore'=>'Restore','activate'=>'mouseover'), + 'columnDefs'=> array(array('visible'=>false,'targets'=>array()),array('bSortable'=>false,'targets'=>array(6))), + 'order'=>array(array(1,'asc')), + ) + ) + ->render() }} - @if ( ! is_null($user->deleted_at)) - - @else - - @if ((Sentry::getId() !== $user->id) && (!Config::get('app.lock_passwords'))) - - - @else - - @endif - @endif -
- - -@else -
-
- - @lang('general.no_results') - -
-
-@endif - @stop