/** * Handle the event * * @param User $user * @param $remember */ public function handle(User $user, $remember) { $userSession = Session::get('mophie.user'); $allUsersSession = Session::get('mophie.all_users'); // Save current user to session if (!$userSession) { $userRoles = $user->role()->get(); foreach ($userRoles as $role) { $roles[$role->id] = $role->name; } Session::put('mophie.user', ['id' => $user->id, 'first_name' => $user->first_name, 'last_name' => $user->last_name, 'email' => $user->email, 'active' => $user->active, 'roles' => $roles]); } // Save all users to session if (!$allUsersSession) { $allUsers = $this->userApi->usersList(); Session::put('mophie.all_users', $allUsers); } }
/** * Setup additional keys/values when searching all created * * @param $searchTerms * @param $roles * @param $adminId * @return array|mixed */ public function prepareSearchAllCreated($searchTerms, $roles, $adminId) { // If user has root privileges, get all the plans that were created. // Otherwise just get the plans created with administrator privilege. $adminList = []; $roleName = ''; if (in_array('root', $roles)) { $userId = 0; $roleName = 'root'; } // Display selected creator of the plan if (isset($adminId)) { $userId = $adminId; } // Administrators who created plans $admins = $this->userApi->getAllUsersByRole(['root', 'administrator']); // Set up dropdown list of all admins $adminsList = Tools::getUsersDropdrownOptions($admins, 'admin'); $columns = ['description', 'first_name', 'last_name', 'status', 'created_at', 'updated_at', 'edit']; $results = $this->tablesApi->searchPlans($searchTerms, $columns); $results += ['userId' => $userId, 'role' => $roleName, 'adminsList' => $adminsList]; return $results; }