diff --git a/app/controllers/admin/UsersController.php b/app/controllers/admin/UsersController.php index cc40728bbb..7b2226b794 100755 --- a/app/controllers/admin/UsersController.php +++ b/app/controllers/admin/UsersController.php @@ -824,94 +824,88 @@ class UsersController extends AdminController { return Redirect::route('users')->with('duplicates', $duplicates)->with('success', 'Success'); } - public function getDatatable($status = null) { + public function getDatatable($status = null) + { + + if (Input::has('offset')) { + $offset = e(Input::get('offset')); + } else { + $offset = 0; + } + + if (Input::has('limit')) { + $limit = e(Input::get('limit')); + } else { + $limit = 50; + } $users = User::with('assets', 'accessories', 'consumables', 'licenses', 'manager', 'sentryThrottle', 'groups', 'userloc'); - switch ($status) { - case 'deleted': - $users->GetDeleted(); - break; - case '': - $users->GetNotDeleted(); - break; - } - $users = $users->orderBy('created_at', 'DESC')->get(); + if (Input::has('search')) { + $users = $users->TextSearch(Input::get('search')); + } - $actions = new \Chumper\Datatable\Columns\FunctionColumn('actions', function ($users) { - $action_buttons = ''; + $allowed_columns = ['last_name','first_name','email','username','manager','location','assets','accessories', 'consumables','licenses','groups']; + $order = Input::get('order') === 'asc' ? 'asc' : 'desc'; + $sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'last_name'; - if (!is_null($users->deleted_at)) { - $action_buttons .= ' '; + $userCount = $users->count(); + $users = $users->skip($offset)->take($limit)->get(); + + + $rows = array(); + + foreach ($users as $user) + { + + $group_names = ''; + $inout = ''; + $actions = ''; + + foreach ($user->groups as $group) { + $group_names .= '' . $group->name . ' '; + } + + + if (!is_null($user->deleted_at)) { + + $actions .= ' '; } else { - if ($users->accountStatus() == 'suspended') { - $action_buttons .= ' '; + + if ($user->accountStatus() == 'suspended') { + $actions .= ' '; } - $action_buttons .= ' '; + $actions .= ' '; - if ((Sentry::getId() !== $users->id) && (!Config::get('app.lock_passwords'))) { - $action_buttons .= ' '; + if ((Sentry::getId() !== $user->id) && (!Config::get('app.lock_passwords'))) { + $actions .= ' '; } else { - $action_buttons .= ' '; + $actions .= ' '; } } - return $action_buttons; - }); + $rows[] = array( + 'checkbox' =>'
', + 'name' => ''.$user->fullName().'', + 'email' => ($user->email!='') ? '' : '', + 'username' => $user->username, + 'location' => ($user->location_id!='') ? $user->userloc->name : '', + 'manager' => ($user->manager_id!='') ? '' . $user->manager->fullName() . '' : '', + 'assets' => $user->assets->count(), + 'licenses' => $user->licenses->count(), + 'accessories' => $user->accessories->count(), + 'consumables' => $user->consumables->count(), + 'groups' => $group_names, + 'notes' => $user->notes, + 'actions' => ($actions) ? $actions : '' + ); + } - return Datatable::collection($users) - ->addColumn('', function($users) { - return '
'; - }) - ->addColumn('name', function($users) { - return '' . $users->fullName() . ''; - }) - ->addColumn('email', function($users) { - if ($users->email) { - return '
'; - } else { - return ''; - } - }) - ->addColumn('username', function($users) { - return $users->username; - }) - ->addColumn('manager', function($users) { - if ($users->manager) { - return '' . $users->manager->fullName() . ''; - } - }) - ->addColumn('location', function($users) { - if ($users->userloc) { - return $users->userloc->name; - } - }) - ->addColumn('assets', function($users) { - return $users->assets->count(); - }) - ->addColumn('licenses', function($users) { - return $users->licenses->count(); - }) - ->addColumn('accessories', function($users) { - return $users->accessories->count(); - }) - ->addColumn('consumables', function($users) { - return $users->consumables->count(); - }) - ->addColumn('groups', function($users) { - $group_names = ''; - foreach ($users->groups as $group) { - $group_names .= '' . $group->name . ' '; - } - return $group_names; - }) - ->addColumn($actions) - ->searchColumns('name', 'email', 'username', 'manager', 'activated', 'groups', 'location') - ->orderColumns('name', 'email', 'username', 'manager', 'activated', 'licenses', 'assets', 'accessories', 'consumables', 'groups', 'location') - ->make(); + $data = array('total'=>$userCount, 'rows'=>$rows); + return $data; } /**