/** * Display entries * * @return void */ public function displayTask() { // Incoming $filters = array('search' => urldecode(Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', '')), 'sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'title'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'ASC')); $entries = Viewlevel::all(); if ($filters['search']) { $entries->whereLike('title', strtolower((string) $filters['search'])); } $rows = $entries->order($filters['sort'], $filters['sort_Dir'])->paginated('limitstart', 'limit')->rows(); // Output the HTML $this->view->set('rows', $rows)->set('filters', $filters)->display(); }
/** * Method to return a list of view levels for which the user is authorised. * * @param integer $userId Id of the user for which to get the list of authorised view levels. * @return array List of view levels for which the user is authorised. */ public static function getAuthorisedViewLevels($userId) { // Get all groups that the user is mapped to recursively. $groups = self::getGroupsByUser($userId); // Only load the view levels once. if (empty(self::$viewLevels)) { // Build the view levels array. $levels = Viewlevel::all()->rows(); foreach ($levels as $level) { self::$viewLevels[$level->get('id')] = (array) json_decode($level->get('rules')); } } // Initialise the authorised array. $authorised = array(1); // Find the authorised levels. foreach (self::$viewLevels as $level => $rule) { foreach ($rule as $id) { if ($id < 0 && $id * -1 == $userId) { $authorised[] = $level; break; } elseif ($id >= 0 && in_array($id, $groups)) { $authorised[] = $level; break; } } } return $authorised; }
/** * Delete this object and its dependencies * * @return boolean */ public function destroy() { if ($this->get('id') == 0) { $this->addError('JGLOBAL_CATEGORY_NOT_FOUND'); return false; } if ($this->get('parent_id') == 0) { $this->addError('JLIB_DATABASE_ERROR_DELETE_ROOT'); return false; } if ($this->get('lft') == 0 or $this->get('rgt') == 0) { $this->addError('JLIB_DATABASE_ERROR_DELETE_ROOT'); return false; } // Select it's children $children = self::all()->where('lft', '>=', (int) $this->get('lft'))->where('rgt', '<=', (int) $this->get('rgt'))->rows(); if (!$children->count()) { $this->addError('JLIB_DATABASE_ERROR_DELETE_CATEGORY'); return false; } // Delete the dependencies $ids = array(); foreach ($children as $child) { $ids[] = $child->get('id'); } $query = $this->getQuery()->delete($this->getTableName())->whereIn('id', $ids); if (!$query->execute()) { $this->addError($query->getError()); return false; } // Delete the usergroup in view levels $find = array(); $replace = array(); foreach ($ids as $id) { $find[] = "[{$id},"; $find[] = ",{$id},"; $find[] = ",{$id}]"; $find[] = "[{$id}]"; $replace[] = "["; $replace[] = ","; $replace[] = "]"; $replace[] = "[]"; } $rules = Viewlevel::all()->rows(); foreach ($rules as $rule) { foreach ($ids as $id) { if (strstr($rule->get('rules'), '[' . $id) || strstr($rule->get('rules'), ',' . $id) || strstr($rule->get('rules'), $id . ']')) { $rule->set('rules', str_replace($find, $replace, $rule->get('rules'))); if (!$rule->save()) { $this->addError($rule->getError()); return false; } } } } // Delete the user to usergroup mappings for the group(s) from the database. try { Map::destroyByGroup($ids); } catch (\Exception $e) { $this->addError($e->getMessage()); return false; } return true; }