_ci =& get_instance(); // get code igniter instance } //------------------------------------------------------------------------------------------------------------------ // Public methods /** * Checks if at least one of the permissions given as parameter (requiredPermissions) belongs * to the authenticated user, if confirmed then is allowed to use this FilterWidget. * If the parameter requiredPermissions is NOT given or is not present in the session, * then NO one is allow to use this FilterWidget * Wrapper method to permissionlib->hasAtLeastOne */ public function isAllowed($requiredPermissions = null) { $this->_ci->load->library('PermissionLib'); // Load permission library // Gets the required permissions from the session if they are not provided as parameter $rq = $requiredPermissions; if ($rq == null) $rq = $this->getSessionElement(self::REQUIRED_PERMISSIONS_PARAMETER); return $this->_ci->permissionlib->hasAtLeastOne($rq, self::PERMISSION_TABLE_METHOD, self::PERMISSION_TYPE); } /** * Wrapper method to the session helper funtions to retrieve the whole session for this filter */ public function getSession() { return getSessionElement(self::SESSION_NAME, $this->_tableUniqueId); } /** * Wrapper method to the session helper funtions to retrieve one element from the session of this filter */ public function getSessionElement($name) { $session = getSessionElement(self::SESSION_NAME, $this->_tableUniqueId); if (isset($session[$name])) { return $session[$name]; } return null; } /** * Wrapper method to the session helper funtions to set the whole session for this filter */ public function setSession($data) { setSessionElement(self::SESSION_NAME, $this->_tableUniqueId, $data); } /** * Wrapper method to the session helper funtions to set one element in the session for this filter */ public function setSessionElement($name, $value) { $session = getSessionElement(self::SESSION_NAME, $this->_tableUniqueId); $session[$name] = $value; setSessionElement(self::SESSION_NAME, $this->_tableUniqueId, $session); // stores the single value } /** * Generate the query to retrieve the dataset for a filter */ public function generateDatasetQuery($query) { return 'SELECT * FROM ('.$query.') '.self::DATASET_TABLE_ALIAS; } /** * Retrieves the dataset from the DB */ public function getDataset($datasetQuery) { $dataset = null; if ($datasetQuery != null) { $this->_ci->load->model('system/Filters_model', 'FiltersModel'); // Execute the given SQL statement suppressing error messages $dataset = @$this->_ci->FiltersModel->execReadOnlyQuery($datasetQuery); } return $dataset; } /** * Retrieves metadata from the last executed query */ public function getExecutedQueryMetaData() { return $this->_ci->FiltersModel->getExecutedQueryMetaData(); } /** * Retrieves the list of fields from the last executed query */ public function getExecutedQueryListFields() { return $this->_ci->FiltersModel->getExecutedQueryListFields(); } /** * Return an unique string that identify this filter widget * NOTE: The default value is the URI where the FilterWidget is called * If the fhc_controller_id is present then is also used */ public function setTableUniqueIdByParams($params) { if ($params != null && is_array($params) && isset($params[self::TABLE_UNIQUE_ID]) && !isEmptyString($params[self::TABLE_UNIQUE_ID])) { $tableUniqueId = $this->_ci->router->directory.$this->_ci->router->class.'/'. $this->_ci->router->method.'/'. $params[self::TABLE_UNIQUE_ID]; $this->setTableUniqueId($tableUniqueId); } } /** * Set the _tableUniqueId property */ public function setTableUniqueId($tableUniqueId) { $this->_tableUniqueId = $tableUniqueId; } }