diff --git a/application/controllers/system/Filters.php b/application/controllers/system/Filters.php index 648868d61..c0c1f7a4c 100644 --- a/application/controllers/system/Filters.php +++ b/application/controllers/system/Filters.php @@ -3,553 +3,508 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); /** - * + * This controller operates between (interface) the JS (GUI) and the FiltersLib (back-end) + * Provides data to the ajax get calls about the filter + * Accepts ajax post calls to change the filter data + * This controller works with JSON calls on the HTTP GET or POST and the output is always JSON */ -class Filters extends VileSci_Controller +class Filters extends FHC_Controller { - const SESSION_NAME = 'FHC_FILTER_WIDGET'; - - const SELECTED_FIELDS = 'selectedFields'; - const SELECTED_FILTERS = 'selectedFilters'; - const ACTIVE_FILTERS = 'activeFilters'; - const ACTIVE_FILTERS_OPTION = 'activeFiltersOption'; - const ACTIVE_FILTERS_OPERATION = 'activeFiltersOperation'; - const FILTER_NAME = 'filterName'; + const FILTER_PAGE_PARAM = 'filter_page'; /** - * + * Calls the parent's constructor and loads the FiltersLib */ public function __construct() { parent::__construct(); - // Load session library - $this->load->library('session'); - - $this->load->model('system/Filters_model', 'FiltersModel'); - $this->load->model('person/Benutzer_model', 'BenutzerModel'); + $this->_loadFiltersLib(); // Loads the FiltersLib with parameters } - /** - * - */ - public function tableDataset() - { - $json = new stdClass(); - - $session = $this->_readSession($this->_getFilterUniqueId()); - - $json->selectedFields = $this->_getFromSession('selectedFields'); - $json->columnsAliases = $this->_getFromSession('columnsAliases'); - $json->additionalColumns = $this->_getFromSession('additionalColumns'); - $json->checkboxes = $this->_getFromSession('checkboxes'); - $json->dataset = $this->_getFromSession('dataset'); - - $this->output->set_content_type('application/json')->set_output(json_encode($json)); - } + //------------------------------------------------------------------------------------------------------------------ + // Public methods /** * */ - public function selectFields() + public function getFilter() { - $json = new stdClass(); - - $session = $this->_readSession($this->_getFilterUniqueId()); - - $json->allSelectedFields = $this->_getFromSession('allSelectedFields'); - $json->allColumnsAliases = $this->_getFromSession('allColumnsAliases'); - - $json->selectedFields = $this->_getFromSession('selectedFields'); - $json->columnsAliases = $this->_getFromSession('columnsAliases'); - - $this->output->set_content_type('application/json')->set_output(json_encode($json)); + $this->outputJsonSuccess($this->filterslib->getSession()); } /** - * - */ - public function sortSelectedFields() - { - $selectedFieldsLst = $this->input->post('selectedFieldsLst'); - - $filterUniqueId = $this->_getFilterUniqueId(); - - $json = new stdClass(); - - $session = $this->_readSession($filterUniqueId); - - $allSelectedFields = $this->_getFromSession('allSelectedFields'); - $allColumnsAliases = $this->_getFromSession('allColumnsAliases'); - - $json->selectedFields = $this->_getFromSession('selectedFields'); - $json->columnsAliases = $this->_getFromSession('columnsAliases'); - - if (isset($selectedFieldsLst) && is_array($selectedFieldsLst)) - { - $json->selectedFields = $selectedFieldsLst; - $json->columnsAliases = array(); - - for ($i = 0; $i < count($json->selectedFields); $i++) - { - $pos = array_search($json->selectedFields[$i], $allSelectedFields); - - $json->columnsAliases[$i] = $json->selectedFields[$i]; - - if ($pos !== false) - { - if ($allColumnsAliases != null && is_array($allColumnsAliases)) - { - $json->columnsAliases[$i] = $allColumnsAliases[$pos]; - } - } - } - } - - $_SESSION[self::SESSION_NAME][$filterUniqueId]['selectedFields'] = $json->selectedFields; - $_SESSION[self::SESSION_NAME][$filterUniqueId]['columnsAliases'] = $json->columnsAliases; - - $this->output->set_content_type('application/json')->set_output(json_encode($json)); - } - - /** - * - */ - public function selectFilters() - { - $json = new stdClass(); - - $session = $this->_readSession($this->_getFilterUniqueId()); - - $json->allSelectedFields = $this->_getFromSession('allSelectedFields'); - $json->allColumnsAliases = $this->_getFromSession('allColumnsAliases'); - - $json->selectedFilters = $this->_getFromSession('selectedFilters'); - $json->selectedFiltersAliases = array(); - $json->selectedFiltersMetaData = array(); - - $json->selectedFiltersActiveFilters = array(); - $json->selectedFiltersActiveFiltersOperation = array(); - $json->selectedFiltersActiveFiltersOption = array(); - - $metaData = $this->_getFromSession('metaData'); - $activeFilters = $this->_getFromSession('activeFilters'); - $activeFiltersOperation = $this->_getFromSession('activeFiltersOperation'); - $activeFiltersOption = $this->_getFromSession('activeFiltersOption'); - - for ($i = 0; $i < count($json->selectedFilters); $i++) - { - $pos = array_search($json->selectedFilters[$i], $json->allSelectedFields); - - if ($pos !== false) - { - $json->selectedFiltersAliases[$i] = $json->selectedFilters[$i]; - if ($json->allColumnsAliases != null && is_array($json->allColumnsAliases)) - { - $json->selectedFiltersAliases[$i] = $json->allColumnsAliases[$pos]; - } - - $json->selectedFiltersMetaData[] = $metaData[$pos]; - - if (isset($activeFilters[$json->selectedFilters[$i]])) - { - $json->selectedFiltersActiveFilters[] = $activeFilters[$json->selectedFilters[$i]]; - } - - if (isset($activeFiltersOperation[$json->selectedFilters[$i]])) - { - $json->selectedFiltersActiveFiltersOperation[] = $activeFiltersOperation[$json->selectedFilters[$i]]; - } - - if (isset($activeFiltersOption[$json->selectedFilters[$i]])) - { - $json->selectedFiltersActiveFiltersOption[] = $activeFiltersOption[$json->selectedFilters[$i]]; - } - } - } - - $this->output->set_content_type('application/json')->set_output(json_encode($json)); - } - - /** - * - */ - public function saveFilter() - { - $this->_saveFilter($this->input->post("customFilterDescription"), $this->_getFilterUniqueId()); - - $this->output->set_content_type('application/json')->set_output(json_encode('Filter saved')); - } - - /** - * - */ - private function _saveFilter($customFilterDescription, $filterUniqueId) - { - $objToBeSaved = new stdClass(); - - $filterSessionArray = $this->_readSession($filterUniqueId); - - $objToBeSaved->name = $customFilterDescription; - - if (isset($filterSessionArray[self::SELECTED_FIELDS])) - { - $selectedFields = $filterSessionArray[self::SELECTED_FIELDS]; - $objToBeSaved->columns = array(); - - for ($selectedFieldsCounter = 0; $selectedFieldsCounter < count($selectedFields); $selectedFieldsCounter++) - { - $objToBeSaved->columns[$selectedFieldsCounter] = new stdClass(); - $objToBeSaved->columns[$selectedFieldsCounter]->name = $selectedFields[$selectedFieldsCounter]; - } - } - - if (isset($filterSessionArray[self::SELECTED_FILTERS])) - { - $selectedFilters = $filterSessionArray[self::SELECTED_FILTERS]; - $objToBeSaved->filters = array(); - - for ($selectedFiltersCounter = 0; $selectedFiltersCounter < count($selectedFilters); $selectedFiltersCounter++) - { - $objToBeSaved->filters[$selectedFiltersCounter] = new stdClass(); - $objToBeSaved->filters[$selectedFiltersCounter]->name = $selectedFilters[$selectedFiltersCounter]; - - if (isset($filterSessionArray[self::ACTIVE_FILTERS]) - && isset($filterSessionArray[self::ACTIVE_FILTERS][$selectedFilters[$selectedFiltersCounter]])) - { - $objToBeSaved->filters[$selectedFiltersCounter]->condition = $filterSessionArray[self::ACTIVE_FILTERS][$selectedFilters[$selectedFiltersCounter]]; - } - - if (isset($filterSessionArray[self::ACTIVE_FILTERS_OPERATION]) - && isset($filterSessionArray[self::ACTIVE_FILTERS_OPERATION][$selectedFilters[$selectedFiltersCounter]])) - { - $objToBeSaved->filters[$selectedFiltersCounter]->operation = $filterSessionArray[self::ACTIVE_FILTERS_OPERATION][$selectedFilters[$selectedFiltersCounter]]; - } - - if (isset($filterSessionArray[self::ACTIVE_FILTERS_OPTION]) - && isset($filterSessionArray[self::ACTIVE_FILTERS_OPTION][$selectedFilters[$selectedFiltersCounter]])) - { - $objToBeSaved->filters[$selectedFiltersCounter]->option = $filterSessionArray[self::ACTIVE_FILTERS_OPTION][$selectedFilters[$selectedFiltersCounter]]; - } - } - } - - $desc = $customFilterDescription; - $descPGArray = '{"'.$desc.'", "'.$desc.'", "'.$desc.'", "'.$desc.'"}'; - - $resultBenutzer = $this->BenutzerModel->load(getAuthUID()); - $personId = $resultBenutzer->retval[0]->person_id; - - $result = $this->FiltersModel->loadWhere(array( - 'app' => $_SESSION[self::SESSION_NAME][$filterUniqueId]['app'], - 'dataset_name' => $_SESSION[self::SESSION_NAME][$filterUniqueId]['datasetName'], - 'description' => $descPGArray, - 'person_id' => $personId - )); - - if (hasData($result)) - { - $this->FiltersModel->update( - array( - 'app' => $_SESSION[self::SESSION_NAME][$filterUniqueId]['app'], - 'dataset_name' => $_SESSION[self::SESSION_NAME][$filterUniqueId]['datasetName'], - 'description' => $descPGArray, - 'person_id' => $personId - ), - array( - 'filter' => json_encode($objToBeSaved) - ) - ); - } - else - { - $this->FiltersModel->insert(array( - 'app' => $_SESSION[self::SESSION_NAME][$filterUniqueId]['app'], - 'dataset_name' => $_SESSION[self::SESSION_NAME][$filterUniqueId]['datasetName'], - 'filter_kurzbz' => uniqid($personId, true), - 'person_id' => $personId, - 'description' => $descPGArray, - 'sort' => null, - 'default_filter' => false, - 'filter' => json_encode($objToBeSaved), - 'oe_kurzbz' => null - )); - } - } - - /** - * - */ - public function deleteCustomFilter() - { - $filter_id = $this->input->post('filter_id'); - - if (is_numeric($filter_id)) - { - $this->FiltersModel->deleteCustomFilter($filter_id); - - $this->output->set_content_type('application/json')->set_output(json_encode('Removed')); - } - } - - /** - * - */ - public function removeSelectedFields() - { - $fieldName = $this->input->post('fieldName'); - $filterUniqueId = $this->_getFilterUniqueId(); - - $session = $this->_readSession($filterUniqueId); - - $allSelectedFields = $this->_getFromSession('allSelectedFields'); - $allColumnsAliases = $this->_getFromSession('allColumnsAliases'); - - $selectedFields = $this->_getFromSession('selectedFields'); - $columnsAliases = $this->_getFromSession('columnsAliases'); - - if (($pos = array_search($fieldName, $selectedFields)) !== false) - { - array_splice($selectedFields, $pos, 1); - - if ($columnsAliases != null && is_array($columnsAliases)) - { - array_splice($columnsAliases, $pos, 1); - } - } - - $_SESSION[self::SESSION_NAME][$filterUniqueId]['selectedFields'] = $selectedFields; - $_SESSION[self::SESSION_NAME][$filterUniqueId]['columnsAliases'] = $columnsAliases; - - $json = new stdClass(); - - $json->allSelectedFields = $allSelectedFields; - $json->allColumnsAliases = $allColumnsAliases; - $json->selectedFields = $selectedFields; - $json->columnsAliases = $columnsAliases; - - $this->output->set_content_type('application/json')->set_output(json_encode($json)); - } - - /** - * - */ - public function removeSelectedFilters() - { - $fieldName = $this->input->post('fieldName'); - $filterUniqueId = $this->_getFilterUniqueId(); - - $session = $this->_readSession($filterUniqueId); - - $selectedFilters = $this->_getFromSession('selectedFilters'); - $selectedFiltersActiveFilters = $this->_getFromSession('activeFilters'); - $selectedFiltersActiveFiltersOperation = $this->_getFromSession('activeFiltersOperation'); - $selectedFiltersActiveFiltersOption = $this->_getFromSession('activeFiltersOption'); - - if (($pos = array_search($fieldName, $selectedFilters)) !== false) - { - array_splice($selectedFilters, $pos, 1); - array_splice($selectedFiltersActiveFilters, $pos, 1); - array_splice($selectedFiltersActiveFiltersOperation, $pos, 1); - array_splice($selectedFiltersActiveFiltersOption, $pos, 1); - } - - $_SESSION[self::SESSION_NAME][$filterUniqueId]['selectedFilters'] = $selectedFilters; - $_SESSION[self::SESSION_NAME][$filterUniqueId]['activeFilters'] = $selectedFiltersActiveFilters; - $_SESSION[self::SESSION_NAME][$filterUniqueId]['activeFiltersOperation'] = $selectedFiltersActiveFiltersOperation; - $_SESSION[self::SESSION_NAME][$filterUniqueId]['activeFiltersOption'] = $selectedFiltersActiveFiltersOption; - - $json = new stdClass(); - - $json->selectedFilters = $selectedFilters; - $json->selectedFiltersActiveFilters = $selectedFiltersActiveFilters; - $json->selectedFiltersActiveFiltersOperation = $selectedFiltersActiveFiltersOperation; - $json->selectedFiltersActiveFiltersOption = $selectedFiltersActiveFiltersOption; - - $this->output->set_content_type('application/json')->set_output(json_encode($json)); - } - - /** - * - */ - public function addSelectedFields() - { - $fieldName = $this->input->post('fieldName'); - $filterUniqueId = $this->_getFilterUniqueId(); - - $session = $this->_readSession($filterUniqueId); - - $allSelectedFields = $this->_getFromSession('allSelectedFields'); - $allColumnsAliases = $this->_getFromSession('allColumnsAliases'); - - $selectedFields = $this->_getFromSession('selectedFields'); - $columnsAliases = $this->_getFromSession('columnsAliases'); - - if (($pos = array_search($fieldName, $allSelectedFields)) !== false - && array_search($fieldName, $selectedFields) === false) - { - array_push($selectedFields, $fieldName); - - if ($columnsAliases != null && is_array($columnsAliases)) - { - array_push($columnsAliases, $allColumnsAliases[$pos]); - } - } - - $_SESSION[self::SESSION_NAME][$filterUniqueId]['selectedFields'] = $selectedFields; - $_SESSION[self::SESSION_NAME][$filterUniqueId]['columnsAliases'] = $columnsAliases; - - $json = new stdClass(); - - $json->allSelectedFields = $allSelectedFields; - $json->allColumnsAliases = $allColumnsAliases; - $json->selectedFields = $selectedFields; - $json->columnsAliases = $columnsAliases; - - $this->output->set_content_type('application/json')->set_output(json_encode($json)); - } - - /** - * - */ - public function addSelectedFilters() - { - $fieldName = $this->input->post('fieldName'); - $filterUniqueId = $this->_getFilterUniqueId(); - - $session = $this->_readSession($filterUniqueId); - - $selectedFilters = $this->_getFromSession('selectedFilters'); - $selectedFiltersActiveFilters = $this->_getFromSession('activeFilters'); - $selectedFiltersActiveFiltersOperation = $this->_getFromSession('activeFiltersOperation'); - $selectedFiltersActiveFiltersOption = $this->_getFromSession('activeFiltersOption'); - - if (!in_array($fieldName, $selectedFilters)) - { - array_push($selectedFilters, $fieldName); - $selectedFiltersActiveFilters[$fieldName] = ""; - $selectedFiltersActiveFiltersOperation[$fieldName] = ""; - $selectedFiltersActiveFiltersOption[$fieldName] = ""; - } - - $_SESSION[self::SESSION_NAME][$filterUniqueId]['selectedFilters'] = $selectedFilters; - $_SESSION[self::SESSION_NAME][$filterUniqueId]['activeFilters'] = $selectedFiltersActiveFilters; - $_SESSION[self::SESSION_NAME][$filterUniqueId]['activeFiltersOperation'] = $selectedFiltersActiveFiltersOperation; - $_SESSION[self::SESSION_NAME][$filterUniqueId]['activeFiltersOption'] = $selectedFiltersActiveFiltersOption; - - $json = new stdClass(); - - $json->selectedFilters = $selectedFilters; - $json->selectedFiltersActiveFilters = $selectedFiltersActiveFilters; - $json->selectedFiltersActiveFiltersOperation = $selectedFiltersActiveFiltersOperation; - $json->selectedFiltersActiveFiltersOption = $selectedFiltersActiveFiltersOption; - - $this->output->set_content_type('application/json')->set_output(json_encode($json)); - } - - /** - * - */ - public function applyFilter() - { - $fieldNames = $this->input->post('filterNames'); - $filterOperations = $this->input->post('filterOperations'); - $filterOperationValues = $this->input->post('filterOperationValues'); - $filterOptions = $this->input->post('filterOptions'); - $filterUniqueId = $this->_getFilterUniqueId(); - - $session = $this->_readSession($filterUniqueId); - - $activeFilters = array_combine($fieldNames, $filterOperationValues); - $activeFiltersOperation = array_combine($fieldNames, $filterOperations); - $activeFiltersOption = array_combine($fieldNames, $filterOptions); - - $_SESSION[self::SESSION_NAME][$filterUniqueId]['activeFilters'] = $activeFilters; - $_SESSION[self::SESSION_NAME][$filterUniqueId]['activeFiltersOperation'] = $activeFiltersOperation; - $_SESSION[self::SESSION_NAME][$filterUniqueId]['activeFiltersOption'] = $activeFiltersOption; - - $json = new stdClass(); - - $json->fieldNames = $fieldNames; - $json->activeFilters = $activeFilters; - $json->activeFiltersOperation = $activeFiltersOperation; - $json->activeFiltersOption = $activeFiltersOption; - - $this->output->set_content_type('application/json')->set_output(json_encode($json)); - } - - /** - * + * Retrives the number of records present in the dataset */ public function rowNumber() { - $json = new stdClass(); + $rowNumber = 0; + $dataset = $this->filterslib->getElementSession(FiltersLib::SESSION_DATASET); - $session = $this->_readSession($this->_getFilterUniqueId()); - - $dataset = $this->_getFromSession('dataset'); - - if (is_array($dataset)) + if (isset($dataset) && is_array($dataset)) { - $json->rowNumber = count($dataset); + $rowNumber = count($dataset); } - $this->output->set_content_type('application/json')->set_output(json_encode($json)); + $this->outputJsonSuccess($rowNumber); } - /** - * - */ - private function _readSession($filterUniqueId) - { - if (isset($_SESSION[self::SESSION_NAME]) && isset($_SESSION[self::SESSION_NAME][$filterUniqueId])) - return $_SESSION[self::SESSION_NAME][$filterUniqueId]; - - return array(); - } + //------------------------------------------------------------------------------------------------------------------ + // Private methods /** - * + * Loads the FiltersLib with the FILTER_PAGE_PARAM parameter + * If the parameter FILTER_PAGE_PARAM is not given then the execution of the controller is terminated and + * an error message is printed */ - private function _writeSession($data, $filterUniqueId) + private function _loadFiltersLib() { - if (!isset($_SESSION[self::SESSION_NAME]) - || (isset($_SESSION[self::SESSION_NAME]) && !is_array($_SESSION[self::SESSION_NAME]))) + // If the parameter FILTER_PAGE_PARAM is present in the HTTP GET or POST + if (isset($_GET[self::FILTER_PAGE_PARAM]) || isset($_POST[self::FILTER_PAGE_PARAM])) { - $_SESSION[self::SESSION_NAME] = array(); + // If it is present in the HTTP GET + if (isset($_GET[self::FILTER_PAGE_PARAM])) + { + $filterPage = $this->input->get(self::FILTER_PAGE_PARAM); // is retrived from the HTTP GET + } + elseif (isset($_POST[self::FILTER_PAGE_PARAM])) // Else if it is present in the HTTP POST + { + $filterPage = $this->input->post(self::FILTER_PAGE_PARAM); // is retrived from the HTTP POST + } + + // Loads the FiltersLib that contains all the used logic + $this->load->library('FiltersLib', array(self::FILTER_PAGE_PARAM => $filterPage)); } - - $_SESSION[self::SESSION_NAME][$filterUniqueId] = $data; - } - - /** - * - */ - private function _getFilterUniqueId() - { - $_getFilterUniqueId = ''; - - if ($_SERVER['REQUEST_METHOD'] === 'POST') + else // Otherwise an error will be written in the output { - $_getFilterUniqueId = $this->input->post('filter_page').'/'.$this->input->post('fhc_controller_id'); + $this->outputJsonError('Parameter '.self::FILTER_PAGE_PARAM.' not provided!'); + exit; } - elseif ($_SERVER['REQUEST_METHOD'] === 'GET') - { - $_getFilterUniqueId = $this->input->get('filter_page').'/'.$this->input->get('fhc_controller_id'); - } - - return $_getFilterUniqueId; } - /** - * - */ - private function _getFromSession($el) - { - $_getFromSession = null; - - if (isset($_SESSION[$el])) return $_SESSION[$el]; - - return $_getFromSession; - } + // /** + // * + // */ + // public function getFields() + // { + // $json = new stdClass(); + // + // $json->fields = $this->filterslib->getElementSession(FiltersLib::SESSION_FIELDS); + // $json->selectedFields = $this->filterslib->getElementSession(FiltersLib::SESSION_SELECTED_FIELDS); + // $json->columnsAliases = $this->filterslib->getElementSession(FiltersLib::SESSION_COLUMNS_ALIASES); + // + // $this->outputJsonSuccess($json); + // } + // + // /** + // * + // */ + // public function getFilters() + // { + // $json = new stdClass(); + // + // $session = $this->_readSession($this->_getFilterUniqueId()); + // + // $json->allSelectedFields = $this->_getFromSession('allSelectedFields'); + // $json->allColumnsAliases = $this->_getFromSession('allColumnsAliases'); + // + // $json->selectedFilters = $this->_getFromSession('selectedFilters'); + // $json->selectedFiltersAliases = array(); + // $json->selectedFiltersMetaData = array(); + // + // $json->selectedFiltersActiveFilters = array(); + // $json->selectedFiltersActiveFiltersOperation = array(); + // $json->selectedFiltersActiveFiltersOption = array(); + // + // $metaData = $this->_getFromSession('metaData'); + // $activeFilters = $this->_getFromSession('activeFilters'); + // $activeFiltersOperation = $this->_getFromSession('activeFiltersOperation'); + // $activeFiltersOption = $this->_getFromSession('activeFiltersOption'); + // + // for ($i = 0; $i < count($json->selectedFilters); $i++) + // { + // $pos = array_search($json->selectedFilters[$i], $json->allSelectedFields); + // + // if ($pos !== false) + // { + // $json->selectedFiltersAliases[$i] = $json->selectedFilters[$i]; + // if ($json->allColumnsAliases != null && is_array($json->allColumnsAliases)) + // { + // $json->selectedFiltersAliases[$i] = $json->allColumnsAliases[$pos]; + // } + // + // $json->selectedFiltersMetaData[] = $metaData[$pos]; + // + // if (isset($activeFilters[$json->selectedFilters[$i]])) + // { + // $json->selectedFiltersActiveFilters[] = $activeFilters[$json->selectedFilters[$i]]; + // } + // + // if (isset($activeFiltersOperation[$json->selectedFilters[$i]])) + // { + // $json->selectedFiltersActiveFiltersOperation[] = $activeFiltersOperation[$json->selectedFilters[$i]]; + // } + // + // if (isset($activeFiltersOption[$json->selectedFilters[$i]])) + // { + // $json->selectedFiltersActiveFiltersOption[] = $activeFiltersOption[$json->selectedFilters[$i]]; + // } + // } + // } + // + // $this->output->set_content_type('application/json')->set_output(json_encode($json)); + // } + // + // /** + // * + // */ + // public function sortSelectedFields() + // { + // $selectedFieldsLst = $this->input->post('selectedFieldsLst'); + // + // $filterUniqueId = $this->_getFilterUniqueId(); + // + // $json = new stdClass(); + // + // $session = $this->_readSession($filterUniqueId); + // + // $allSelectedFields = $this->_getFromSession('allSelectedFields'); + // $allColumnsAliases = $this->_getFromSession('allColumnsAliases'); + // + // $json->selectedFields = $this->_getFromSession('selectedFields'); + // $json->columnsAliases = $this->_getFromSession('columnsAliases'); + // + // if (isset($selectedFieldsLst) && is_array($selectedFieldsLst)) + // { + // $json->selectedFields = $selectedFieldsLst; + // $json->columnsAliases = array(); + // + // for ($i = 0; $i < count($json->selectedFields); $i++) + // { + // $pos = array_search($json->selectedFields[$i], $allSelectedFields); + // + // $json->columnsAliases[$i] = $json->selectedFields[$i]; + // + // if ($pos !== false) + // { + // if ($allColumnsAliases != null && is_array($allColumnsAliases)) + // { + // $json->columnsAliases[$i] = $allColumnsAliases[$pos]; + // } + // } + // } + // } + // + // $_SESSION[self::SESSION_NAME][$filterUniqueId]['selectedFields'] = $json->selectedFields; + // $_SESSION[self::SESSION_NAME][$filterUniqueId]['columnsAliases'] = $json->columnsAliases; + // + // $this->output->set_content_type('application/json')->set_output(json_encode($json)); + // } + // + // /** + // * + // */ + // public function saveFilter() + // { + // $this->_saveFilter($this->input->post("customFilterDescription"), $this->_getFilterUniqueId()); + // + // $this->output->set_content_type('application/json')->set_output(json_encode('Filter saved')); + // } + // + // /** + // * + // */ + // private function _saveFilter($customFilterDescription, $filterUniqueId) + // { + // $objToBeSaved = new stdClass(); + // + // $filterSessionArray = $this->_readSession($filterUniqueId); + // + // $objToBeSaved->name = $customFilterDescription; + // + // if (isset($filterSessionArray[self::SELECTED_FIELDS])) + // { + // $selectedFields = $filterSessionArray[self::SELECTED_FIELDS]; + // $objToBeSaved->columns = array(); + // + // for ($selectedFieldsCounter = 0; $selectedFieldsCounter < count($selectedFields); $selectedFieldsCounter++) + // { + // $objToBeSaved->columns[$selectedFieldsCounter] = new stdClass(); + // $objToBeSaved->columns[$selectedFieldsCounter]->name = $selectedFields[$selectedFieldsCounter]; + // } + // } + // + // if (isset($filterSessionArray[self::SELECTED_FILTERS])) + // { + // $selectedFilters = $filterSessionArray[self::SELECTED_FILTERS]; + // $objToBeSaved->filters = array(); + // + // for ($selectedFiltersCounter = 0; $selectedFiltersCounter < count($selectedFilters); $selectedFiltersCounter++) + // { + // $objToBeSaved->filters[$selectedFiltersCounter] = new stdClass(); + // $objToBeSaved->filters[$selectedFiltersCounter]->name = $selectedFilters[$selectedFiltersCounter]; + // + // if (isset($filterSessionArray[self::ACTIVE_FILTERS]) + // && isset($filterSessionArray[self::ACTIVE_FILTERS][$selectedFilters[$selectedFiltersCounter]])) + // { + // $objToBeSaved->filters[$selectedFiltersCounter]->condition = $filterSessionArray[self::ACTIVE_FILTERS][$selectedFilters[$selectedFiltersCounter]]; + // } + // + // if (isset($filterSessionArray[self::ACTIVE_FILTERS_OPERATION]) + // && isset($filterSessionArray[self::ACTIVE_FILTERS_OPERATION][$selectedFilters[$selectedFiltersCounter]])) + // { + // $objToBeSaved->filters[$selectedFiltersCounter]->operation = $filterSessionArray[self::ACTIVE_FILTERS_OPERATION][$selectedFilters[$selectedFiltersCounter]]; + // } + // + // if (isset($filterSessionArray[self::ACTIVE_FILTERS_OPTION]) + // && isset($filterSessionArray[self::ACTIVE_FILTERS_OPTION][$selectedFilters[$selectedFiltersCounter]])) + // { + // $objToBeSaved->filters[$selectedFiltersCounter]->option = $filterSessionArray[self::ACTIVE_FILTERS_OPTION][$selectedFilters[$selectedFiltersCounter]]; + // } + // } + // } + // + // $desc = $customFilterDescription; + // $descPGArray = '{"'.$desc.'", "'.$desc.'", "'.$desc.'", "'.$desc.'"}'; + // + // $resultBenutzer = $this->BenutzerModel->load(getAuthUID()); + // $personId = $resultBenutzer->retval[0]->person_id; + // + // $result = $this->FiltersModel->loadWhere(array( + // 'app' => $_SESSION[self::SESSION_NAME][$filterUniqueId]['app'], + // 'dataset_name' => $_SESSION[self::SESSION_NAME][$filterUniqueId]['datasetName'], + // 'description' => $descPGArray, + // 'person_id' => $personId + // )); + // + // if (hasData($result)) + // { + // $this->FiltersModel->update( + // array( + // 'app' => $_SESSION[self::SESSION_NAME][$filterUniqueId]['app'], + // 'dataset_name' => $_SESSION[self::SESSION_NAME][$filterUniqueId]['datasetName'], + // 'description' => $descPGArray, + // 'person_id' => $personId + // ), + // array( + // 'filter' => json_encode($objToBeSaved) + // ) + // ); + // } + // else + // { + // $this->FiltersModel->insert(array( + // 'app' => $_SESSION[self::SESSION_NAME][$filterUniqueId]['app'], + // 'dataset_name' => $_SESSION[self::SESSION_NAME][$filterUniqueId]['datasetName'], + // 'filter_kurzbz' => uniqid($personId, true), + // 'person_id' => $personId, + // 'description' => $descPGArray, + // 'sort' => null, + // 'default_filter' => false, + // 'filter' => json_encode($objToBeSaved), + // 'oe_kurzbz' => null + // )); + // } + // } + // + // /** + // * + // */ + // public function deleteCustomFilter() + // { + // $filter_id = $this->input->post('filter_id'); + // + // if (is_numeric($filter_id)) + // { + // $this->FiltersModel->deleteCustomFilter($filter_id); + // + // $this->output->set_content_type('application/json')->set_output(json_encode('Removed')); + // } + // } + // + // /** + // * + // */ + // public function removeSelectedFields() + // { + // $fieldName = $this->input->post('fieldName'); + // $filterUniqueId = $this->_getFilterUniqueId(); + // + // $session = $this->_readSession($filterUniqueId); + // + // $allSelectedFields = $this->_getFromSession('allSelectedFields'); + // $allColumnsAliases = $this->_getFromSession('allColumnsAliases'); + // + // $selectedFields = $this->_getFromSession('selectedFields'); + // $columnsAliases = $this->_getFromSession('columnsAliases'); + // + // if (($pos = array_search($fieldName, $selectedFields)) !== false) + // { + // array_splice($selectedFields, $pos, 1); + // + // if ($columnsAliases != null && is_array($columnsAliases)) + // { + // array_splice($columnsAliases, $pos, 1); + // } + // } + // + // $_SESSION[self::SESSION_NAME][$filterUniqueId]['selectedFields'] = $selectedFields; + // $_SESSION[self::SESSION_NAME][$filterUniqueId]['columnsAliases'] = $columnsAliases; + // + // $json = new stdClass(); + // + // $json->allSelectedFields = $allSelectedFields; + // $json->allColumnsAliases = $allColumnsAliases; + // $json->selectedFields = $selectedFields; + // $json->columnsAliases = $columnsAliases; + // + // $this->output->set_content_type('application/json')->set_output(json_encode($json)); + // } + // + // /** + // * + // */ + // public function removeSelectedFilters() + // { + // $fieldName = $this->input->post('fieldName'); + // $filterUniqueId = $this->_getFilterUniqueId(); + // + // $session = $this->_readSession($filterUniqueId); + // + // $selectedFilters = $this->_getFromSession('selectedFilters'); + // $selectedFiltersActiveFilters = $this->_getFromSession('activeFilters'); + // $selectedFiltersActiveFiltersOperation = $this->_getFromSession('activeFiltersOperation'); + // $selectedFiltersActiveFiltersOption = $this->_getFromSession('activeFiltersOption'); + // + // if (($pos = array_search($fieldName, $selectedFilters)) !== false) + // { + // array_splice($selectedFilters, $pos, 1); + // array_splice($selectedFiltersActiveFilters, $pos, 1); + // array_splice($selectedFiltersActiveFiltersOperation, $pos, 1); + // array_splice($selectedFiltersActiveFiltersOption, $pos, 1); + // } + // + // $_SESSION[self::SESSION_NAME][$filterUniqueId]['selectedFilters'] = $selectedFilters; + // $_SESSION[self::SESSION_NAME][$filterUniqueId]['activeFilters'] = $selectedFiltersActiveFilters; + // $_SESSION[self::SESSION_NAME][$filterUniqueId]['activeFiltersOperation'] = $selectedFiltersActiveFiltersOperation; + // $_SESSION[self::SESSION_NAME][$filterUniqueId]['activeFiltersOption'] = $selectedFiltersActiveFiltersOption; + // + // $json = new stdClass(); + // + // $json->selectedFilters = $selectedFilters; + // $json->selectedFiltersActiveFilters = $selectedFiltersActiveFilters; + // $json->selectedFiltersActiveFiltersOperation = $selectedFiltersActiveFiltersOperation; + // $json->selectedFiltersActiveFiltersOption = $selectedFiltersActiveFiltersOption; + // + // $this->output->set_content_type('application/json')->set_output(json_encode($json)); + // } + // + // /** + // * + // */ + // public function addSelectedFields() + // { + // $fieldName = $this->input->post('fieldName'); + // $filterUniqueId = $this->_getFilterUniqueId(); + // + // $session = $this->_readSession($filterUniqueId); + // + // $allSelectedFields = $this->_getFromSession('allSelectedFields'); + // $allColumnsAliases = $this->_getFromSession('allColumnsAliases'); + // + // $selectedFields = $this->_getFromSession('selectedFields'); + // $columnsAliases = $this->_getFromSession('columnsAliases'); + // + // if (($pos = array_search($fieldName, $allSelectedFields)) !== false + // && array_search($fieldName, $selectedFields) === false) + // { + // array_push($selectedFields, $fieldName); + // + // if ($columnsAliases != null && is_array($columnsAliases)) + // { + // array_push($columnsAliases, $allColumnsAliases[$pos]); + // } + // } + // + // $_SESSION[self::SESSION_NAME][$filterUniqueId]['selectedFields'] = $selectedFields; + // $_SESSION[self::SESSION_NAME][$filterUniqueId]['columnsAliases'] = $columnsAliases; + // + // $json = new stdClass(); + // + // $json->allSelectedFields = $allSelectedFields; + // $json->allColumnsAliases = $allColumnsAliases; + // $json->selectedFields = $selectedFields; + // $json->columnsAliases = $columnsAliases; + // + // $this->output->set_content_type('application/json')->set_output(json_encode($json)); + // } + // + // /** + // * + // */ + // public function addSelectedFilters() + // { + // $fieldName = $this->input->post('fieldName'); + // $filterUniqueId = $this->_getFilterUniqueId(); + // + // $session = $this->_readSession($filterUniqueId); + // + // $selectedFilters = $this->_getFromSession('selectedFilters'); + // $selectedFiltersActiveFilters = $this->_getFromSession('activeFilters'); + // $selectedFiltersActiveFiltersOperation = $this->_getFromSession('activeFiltersOperation'); + // $selectedFiltersActiveFiltersOption = $this->_getFromSession('activeFiltersOption'); + // + // if (!in_array($fieldName, $selectedFilters)) + // { + // array_push($selectedFilters, $fieldName); + // $selectedFiltersActiveFilters[$fieldName] = ""; + // $selectedFiltersActiveFiltersOperation[$fieldName] = ""; + // $selectedFiltersActiveFiltersOption[$fieldName] = ""; + // } + // + // $_SESSION[self::SESSION_NAME][$filterUniqueId]['selectedFilters'] = $selectedFilters; + // $_SESSION[self::SESSION_NAME][$filterUniqueId]['activeFilters'] = $selectedFiltersActiveFilters; + // $_SESSION[self::SESSION_NAME][$filterUniqueId]['activeFiltersOperation'] = $selectedFiltersActiveFiltersOperation; + // $_SESSION[self::SESSION_NAME][$filterUniqueId]['activeFiltersOption'] = $selectedFiltersActiveFiltersOption; + // + // $json = new stdClass(); + // + // $json->selectedFilters = $selectedFilters; + // $json->selectedFiltersActiveFilters = $selectedFiltersActiveFilters; + // $json->selectedFiltersActiveFiltersOperation = $selectedFiltersActiveFiltersOperation; + // $json->selectedFiltersActiveFiltersOption = $selectedFiltersActiveFiltersOption; + // + // $this->output->set_content_type('application/json')->set_output(json_encode($json)); + // } + // + // /** + // * + // */ + // public function applyFilter() + // { + // $fieldNames = $this->input->post('filterNames'); + // $filterOperations = $this->input->post('filterOperations'); + // $filterOperationValues = $this->input->post('filterOperationValues'); + // $filterOptions = $this->input->post('filterOptions'); + // $filterUniqueId = $this->_getFilterUniqueId(); + // + // $session = $this->_readSession($filterUniqueId); + // + // $activeFilters = array_combine($fieldNames, $filterOperationValues); + // $activeFiltersOperation = array_combine($fieldNames, $filterOperations); + // $activeFiltersOption = array_combine($fieldNames, $filterOptions); + // + // $_SESSION[self::SESSION_NAME][$filterUniqueId]['activeFilters'] = $activeFilters; + // $_SESSION[self::SESSION_NAME][$filterUniqueId]['activeFiltersOperation'] = $activeFiltersOperation; + // $_SESSION[self::SESSION_NAME][$filterUniqueId]['activeFiltersOption'] = $activeFiltersOption; + // + // $json = new stdClass(); + // + // $json->fieldNames = $fieldNames; + // $json->activeFilters = $activeFilters; + // $json->activeFiltersOperation = $activeFiltersOperation; + // $json->activeFiltersOption = $activeFiltersOption; + // + // $this->output->set_content_type('application/json')->set_output(json_encode($json)); + // } } diff --git a/application/core/FHC_Controller.php b/application/core/FHC_Controller.php index fc200d935..b63978f22 100644 --- a/application/core/FHC_Controller.php +++ b/application/core/FHC_Controller.php @@ -20,6 +20,9 @@ class FHC_Controller extends CI_Controller $this->load->helper('fhcauth'); } + //------------------------------------------------------------------------------------------------------------------ + // Public methods + /** * Wrapper to load phrases using the PhrasesLib * NOTE: The library is loaded with the alias 'p', so must me used with this alias in the rest of the code. @@ -30,6 +33,9 @@ class FHC_Controller extends CI_Controller $this->load->library('PhrasesLib', array($categories, $language), 'p'); } + //------------------------------------------------------------------------------------------------------------------ + // Protected methods + /** * Sets the unique id for the called controller * NOTE: it is only working with HTTP GET request, not neeaded with POST @@ -67,4 +73,33 @@ class FHC_Controller extends CI_Controller { return $this->_controllerId; } + + /** + * Utility method to output a success using JSON as content type + * Wraps the private method _outputJson + */ + protected function outputJsonSuccess($mixed) + { + $this->_outputJson(success($mixed)); + } + + /** + * Utility method to output an error using JSON as content type + * Wraps the private method _outputJson + */ + protected function outputJsonError($mixed) + { + $this->_outputJson(error($mixed)); + } + + //------------------------------------------------------------------------------------------------------------------ + // Private methods + + /** + * Utility method to output using JSON as content type + */ + private function _outputJson($mixed) + { + $this->output->set_content_type('application/json')->set_output(json_encode($mixed)); + } } diff --git a/application/libraries/FiltersLib.php b/application/libraries/FiltersLib.php new file mode 100644 index 000000000..c4b846809 --- /dev/null +++ b/application/libraries/FiltersLib.php @@ -0,0 +1,444 @@ +_ci =& get_instance(); + + // Loads helper message to manage returning messages + $this->_ci->load->helper('message'); + + $this->_filterUniqueId = $this->_getFilterUniqueId($params); // sets the id for the related filter widget + } + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + /** + * 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 + */ + private function _getFilterUniqueId($params) + { + // + if ($params != null + && is_array($params) + && isset($params[self::FILTER_PAGE_PARAM]) + && !empty(trim($params[self::FILTER_PAGE_PARAM]))) + { + $filterUniqueId = $params[self::FILTER_PAGE_PARAM]; + } + else + { + // Gets the current page URI + $filterUniqueId = $this->_ci->router->directory.$this->_ci->router->class.'/'.$this->_ci->router->method; + } + + // If the FHC_CONTROLLER_ID parameter is present in the HTTP GET + if (isset($_GET[self::FHC_CONTROLLER_ID])) + { + $filterUniqueId .= '/'.$this->_ci->input->get(self::FHC_CONTROLLER_ID); // then use it + } + elseif (isset($_POST[self::FHC_CONTROLLER_ID])) // else if the FHC_CONTROLLER_ID parameter is present in the HTTP POST + { + $filterUniqueId .= '/'.$this->_ci->input->post(self::FHC_CONTROLLER_ID); // then use it + } + + return $filterUniqueId; + } + + /** + * Returns the whole session for this filter widget if found, otherwise null + */ + public function getSession() + { + $session = null; + + // If it is present a session for this filter + if (isset($_SESSION[self::SESSION_NAME]) && isset($_SESSION[self::SESSION_NAME][$this->_filterUniqueId])) + { + $session = $_SESSION[self::SESSION_NAME][$this->_filterUniqueId]; + } + + return $session; + } + + /** + * Returns one element from the session of this filter widget, otherwise null + */ + public function getElementSession($name) + { + $session = $this->getSession(); // get the whole session for this filter + + if (isset($session[$name])) + { + return $session[$name]; + } + + return null; + } + + /** + * Sets the whole session for this filter widget + */ + public function setSession($data) + { + // If is NOT already present into the session + if (!isset($_SESSION[self::SESSION_NAME]) + || (isset($_SESSION[self::SESSION_NAME]) && !is_array($_SESSION[self::SESSION_NAME]))) + { + $_SESSION[self::SESSION_NAME] = array(); // then create it + } + + $_SESSION[self::SESSION_NAME][$this->_filterUniqueId] = $data; // stores data + } + + /** + * Sets one element of the session of this filter widget + */ + public function setElementSession($name, $value) + { + // If is NOT already present into the session + if (!isset($_SESSION[self::SESSION_NAME]) + || (isset($_SESSION[self::SESSION_NAME]) && !is_array($_SESSION[self::SESSION_NAME]))) + { + $_SESSION[self::SESSION_NAME] = array(); // then create it + } + + // If the session for this filter is NOT already present into the session + if (!isset($_SESSION[self::SESSION_NAME][$this->_filterUniqueId]) + || (isset($_SESSION[self::SESSION_NAME][$this->_filterUniqueId]) + && !is_array($_SESSION[self::SESSION_NAME][$this->_filterUniqueId]))) + { + $_SESSION[self::SESSION_NAME][$this->_filterUniqueId] = array(); // then create it + } + + $_SESSION[self::SESSION_NAME][$this->_filterUniqueId][$name] = $value; // stores the single value + } + + /** + * Loads the definition data from DB for a filter widget + */ + public function loadDefinition($filterId, $app, $datasetName, $filterKurzbz) + { + // Loads the needed models + $this->_ci->load->model('system/Filters_model', 'FiltersModel'); + $this->_ci->load->model('person/Benutzer_model', 'BenutzerModel'); // to get the default custom filter + + $this->_ci->FiltersModel->resetQuery(); // reset any previous built query + + $this->_ci->FiltersModel->addJoin('public.tbl_benutzer', 'person_id', 'LEFT'); // left join with benutzer table + $this->_ci->FiltersModel->addSelect('system.tbl_filters.*'); // select only from table filters + $this->_ci->FiltersModel->addOrder('sort', 'ASC'); // sort on column sort + $this->_ci->FiltersModel->addLimit(1); // if more than one filter is set as default only one will be retrived + + $definition = null; + $whereParameters = null; // where clause parameters + + // If we have a good filterId then use it! + if ($filterId != null && is_numeric($filterId) && $filterId > 0) + { + $whereParameters = array( + 'filter_id' => $filterId + ); + } + else + { + // If we can univocally retrive a filter + if ($app != null && $datasetName != null && $filterKurzbz != null) + { + $whereParameters = array( + 'app' => $app, + 'dataset_name' => $datasetName, + 'filter_kurzbz' => $filterKurzbz + ); + } + // Else if we have only app and datasetName + elseif ($app != null && $datasetName != null && $filterKurzbz == null) + { + // Try to load the custom filter (person_id = logged user person_id) with the given "app" and "dataset_name" + // that is set as default filter (default_filter = true) + $whereParameters = array( + 'app' => $app, + 'dataset_name' => $datasetName, + 'uid' => getAuthUID(), + 'default_filter' => true + ); + + $definition = $this->_ci->FiltersModel->loadWhere($whereParameters); + if (!hasData($definition)) // If a custom filter is NOT found + { + // Try to load the global filter (person_id = null) with the given "app" and "dataset_name" that is set as + // default filter (default_filter = true) + $whereParameters = array( + 'app' => $app, + 'dataset_name' => $datasetName, + 'default_filter' => true + ); + + $definition = $this->_ci->FiltersModel->loadWhere($whereParameters); + } + } + } + + // If no definition where loaded and where parameters were set + if ($definition == null && $whereParameters != null) + { + $definition = $this->_ci->FiltersModel->loadWhere($whereParameters); + } + + return $definition; + } + + /** + * Checks if the json definition of this filter is valid + */ + public function parseFilterJson($definition) + { + $jsonEncodedFilter = null; + + // If the definition contains data and they are valid + if (hasData($definition) && isset($definition->retval[0]->filter) && trim($definition->retval[0]->filter) != '') + { + // Get the json definition of the filter + $tmpJsonEncodedFilter = json_decode($definition->retval[0]->filter); + + // Checks required filter's properies + if (isset($tmpJsonEncodedFilter->name) + && isset($tmpJsonEncodedFilter->columns) + && is_array($tmpJsonEncodedFilter->columns) + && isset($tmpJsonEncodedFilter->filters) + && is_array($tmpJsonEncodedFilter->filters)) + { + $jsonEncodedFilter = $tmpJsonEncodedFilter; + } + } + + return $jsonEncodedFilter; + } + + /** + * Generate the query to retrive the dataset for a filter + * NOTE: filterJson should be already checked using the method parseFilterJson + */ + public function generateDatasetQuery($query, $filterJson) + { + $datasetQuery = null; + + // If the given query is valid and the json of the filter is valid + if (!empty(trim($query)) && $filterJson != null) + { + $definedFilters = $filterJson->filters; + $where = ''; + + for ($filtersCounter = 0; $filtersCounter < count($definedFilters); $filtersCounter++) + { + $filterDefinition = $definedFilters[$filtersCounter]; + + if ($filtersCounter > 0) $where .= ' AND '; + + if (!empty(trim($filterDefinition->name))) + { + $where .= '"'.$filterDefinition->name.'"'.$this->_getDatasetQueryCondition($filterDefinition); + } + } + + if ($where != '') + { + $datasetQuery = 'SELECT * FROM ('.$query.') '.self::DATASET_TABLE_ALIAS.' WHERE '.$where; + } + } + + return $datasetQuery; + } + + /** + * Retrives the dataset from the DB + */ + public function getDataset($datasetQuery) + { + $dataset = null; + + if ($datasetQuery != null) + { + $dataset = @$this->_ci->FiltersModel->execReadOnlyQuery($datasetQuery); + } + + return $dataset; + } + + /** + * Get the filter name, the default is the "name" property of the JSON definition + * If the property namePhrase is present into the JSON definition, then try to load that from the phrases system + * NOTE: filterJson should be already checked using the method parseFilterJson + */ + public function getFilterName($filterJson) + { + $filterName = $filterJson->name; // always present, used as default + + // Filter name from phrases system + if (isset($filterJson->namePhrase) && !empty(trim($filterJson->namePhrase))) + { + // Loads the library to use the phrases system + $this->_ci->load->library('PhrasesLib', array(self::FILTER_PHRASES_CATEGORY)); + + $tmpFilterNamePhrase = $this->_ci->phraseslib->t(self::FILTER_PHRASES_CATEGORY, $filterJson->namePhrase); + if (isset($tmpFilterNamePhrase) && !empty(trim($tmpFilterNamePhrase))) // if is not null or an empty string + { + $filterName = $tmpFilterNamePhrase; + } + } + + return $filterName; + } + + //------------------------------------------------------------------------------------------------------------------ + // Private methods + + /** + * + */ + private function _getDatasetQueryCondition($filterDefinition) + { + $condition = ''; + + if (!empty(trim($filterDefinition->operation))) + { + switch ($filterDefinition->operation) + { + case self::OP_EQUAL: + if (is_numeric($filterDefinition->condition)) $condition = '= '.$filterDefinition->condition; + break; + case self::OP_NOT_EQUAL: + if (is_numeric($filterDefinition->condition)) $condition = '!= '.$filterDefinition->condition; + break; + case self::OP_GREATER_THAN: + if (is_numeric($filterDefinition->condition) + && isset($filterDefinition->option) + && ($filterDefinition->option == self::OPT_DAYS + || $filterDefinition->option == self::OPT_MONTHS)) + { + $condition = '< (NOW() - \''.$filterDefinition->condition.' '.$filterDefinition->option.'\'::interval)'; + } + else + { + $condition = '> '.$filterDefinition->condition; + } + break; + case self::OP_LESS_THAN: + if (is_numeric($filterDefinition->condition) + && isset($filterDefinition->option) + && ($filterDefinition->option == self::OPT_DAYS + || $filterDefinition->option == self::OPT_MONTHS)) + { + $condition = '> (NOW() - \''.$filterDefinition->condition.' '.$filterDefinition->option.'\'::interval)'; + } + else + { + $condition = '< '.$filterDefinition->condition; + } + break; + case self::OP_CONTAINS: + $condition = 'ILIKE \'%'.$this->_ci->FiltersModel->escapeLike($filterDefinition->condition).'%\''; + break; + case self::OP_NOT_CONTAINS: + $condition = 'NOT ILIKE \'%'.$this->_ci->FiltersModel->escapeLike($filterDefinition->condition).'%\''; + break; + case self::OP_IS_TRUE: + $condition = 'IS TRUE'; + break; + case self::OP_IS_FALSE: + $condition = 'IS FALSE'; + break; + case self::OP_SET: + $condition = 'IS NOT NULL'; + break; + case self::OP_NOT_SET: + $condition = 'IS NULL'; + break; + default: + $condition = 'IS NOT NULL'; + break; + } + } + + if (!empty(trim($condition))) $condition = ' '.$condition; + + return $condition; + } +} diff --git a/application/views/system/infocenter/infocenterData.php b/application/views/system/infocenter/infocenterData.php index 5ba35ed2d..807e8c45b 100755 --- a/application/views/system/infocenter/infocenterData.php +++ b/application/views/system/infocenter/infocenterData.php @@ -151,7 +151,7 @@ ),\', \' ) AS "StgAktiv", pl.zeitpunkt AS "LockDate", - pl.lockuser as "LockUser", + pl.lockuser AS "LockUser", pd.parkdate AS "ParkDate" FROM public.tbl_person p LEFT JOIN (SELECT person_id, zeitpunkt, uid as lockuser FROM system.tbl_person_lock WHERE app = \''.$APP.'\') pl USING(person_id) @@ -299,18 +299,9 @@ } ); - $filterId = isset($_GET[InfoCenter::FILTER_ID]) ? $_GET[InfoCenter::FILTER_ID] : null; - - if (isset($filterId) && is_numeric($filterId)) - { - $filterWidgetArray[InfoCenter::FILTER_ID] = $filterId; - } - else - { - $filterWidgetArray['app'] = $APP; - $filterWidgetArray['datasetName'] = 'PersonActions'; - $filterWidgetArray['filterKurzbz'] = 'InfoCenterNotSentApplicationAll'; - } + $filterWidgetArray[InfoCenter::FILTER_ID] = $this->input->get(InfoCenter::FILTER_ID); + $filterWidgetArray['app'] = $APP; + $filterWidgetArray['datasetName'] = 'PersonActions'; echo $this->widgetlib->widget('FilterWidget', $filterWidgetArray); ?> diff --git a/application/views/widgets/filter/filter.php b/application/views/widgets/filter/filter.php index ef5da3c6c..8f1c5b4f3 100644 --- a/application/views/widgets/filter/filter.php +++ b/application/views/widgets/filter/filter.php @@ -1,9 +1,7 @@