From 97b3d42523b5b38d88c1da58a29eeb33b7c9b4dd Mon Sep 17 00:00:00 2001 From: ttpllt46 <“praneet_s@tekditechnologies.com”> Date: Tue, 22 Jun 2021 19:45:15 +0530 Subject: [PATCH] Issue #172665 feat: Support set of filters in TjReports --- tjreports/site/assets/js/tjrContentUI.js | 18 +- tjreports/site/models/reports.php | 32 +- .../views/reports/tmpl/default_filters.php | 368 +++++++++++++----- tjreports/site/views/reports/view.base.php | 22 +- 4 files changed, 328 insertions(+), 112 deletions(-) mode change 100644 => 100755 tjreports/site/views/reports/tmpl/default_filters.php diff --git a/tjreports/site/assets/js/tjrContentUI.js b/tjreports/site/assets/js/tjrContentUI.js index 6fcc4a5..ed21b26 100755 --- a/tjreports/site/assets/js/tjrContentUI.js +++ b/tjreports/site/assets/js/tjrContentUI.js @@ -12,13 +12,13 @@ tjrContentUI.root_url = (typeof root_url == 'undefined') ? '' : root_url; tjrContentUI.base_url = (typeof root_url == 'undefined') ? '' : root_url; tjrContentUI.report = tjrContentUI.report ? tjrContentUI.report : {}; - +addMorefilterCnt = 1; jQuery.extend(tjrContentUI.report, { searchToggle: true, $form: null, url: 'index.php?option=com_tjreports&view=reports&format=json', querySaveUrl: 'index.php?option=com_tjreports&format=json', - submitTJRData: function(task) { + submitTJRData: function(task, addMorefilter) { // Set the view layout on the basis of task task = (typeof task == 'undefined' ) ? 'default' : task; @@ -47,6 +47,19 @@ jQuery.extend(tjrContentUI.report, { this.searchToggle = jQuery('div#topFilters').is(':visible'); tjrContentUI.utility.loadingLayer('show'); this.$form = jQuery('#adminForm'); + + if (addMorefilterCnt >= 1) + { + if (addMorefilter != undefined) + { + addMorefilterCnt++; + } + + jQuery('#tjReportaddMorefilter').remove(); + + this.$form.append(''); + } + var doProcess = this.validate(); if (!doProcess) { return false; @@ -138,6 +151,7 @@ jQuery.extend(tjrContentUI.report, { .val('') .removeAttr('checked') .removeAttr('selected'); + addMorefilterCnt = 1; tjrContentUI.report.submitTJRData(task); }, validate: function() { diff --git a/tjreports/site/models/reports.php b/tjreports/site/models/reports.php index 2cd5968..7e6350d 100755 --- a/tjreports/site/models/reports.php +++ b/tjreports/site/models/reports.php @@ -117,6 +117,9 @@ class TjreportsModelReports extends ListModel */ public $supportedFieldTypesForSummaryReport = array ('radio', 'checkbox', 'rating'); + + public $allowToCreateResultSets = false; + /** * Constructor. * @@ -676,6 +679,8 @@ protected function getListQuery() $colToshow = array_merge($colToshow, $topLevelFilters); } + $addMorefilter = $input->get('addMorefilter', 0, 'INT'); + // Select columns which are directly linked to table columns foreach ($colToshow as $columnName) { @@ -730,11 +735,34 @@ protected function getListQuery() { if ($dispFilter['type'] == 'custom') { - $query->where(sprintf($dispFilter['searchin'], $db->quote($filters[$key]))); + if ($dispFilter['search_type'] == 'select' && $dispFilter['multiple'] && is_array($filters[$key])) + { + $filters[$key] = array_map(array($db, 'quote'), $filters[$key]); + + // Create safe string of array. + $filters[$key] = implode(',', $filters[$key]); + $query->where(sprintf($dispFilter['searchin'], $filters[$key])); + } + else + { + $query->where(sprintf($dispFilter['searchin'], $db->quote($filters[$key]))); + } } else { - $query->where($db->quoteName($columnName) . '=' . $db->quote($filters[$key])); + if ($dispFilter['search_type'] == 'select' && $dispFilter['multiple'] && is_array($filters[$key])) + { + $filters[$key] = array_map(array($db, 'quote'), $filters[$key]); + + // Create safe string of array. + $filters[$key] = implode(',', $filters[$key]); + + $query->where($db->quoteName($columnName) . ' IN (' . $filters[$key] . ')'); + } + else + { + $query->where($db->quoteName($columnName) . '=' . $db->quote($filters[$key])); + } } } else diff --git a/tjreports/site/views/reports/tmpl/default_filters.php b/tjreports/site/views/reports/tmpl/default_filters.php old mode 100644 new mode 100755 index bb41736..7fbdba3 --- a/tjreports/site/views/reports/tmpl/default_filters.php +++ b/tjreports/site/views/reports/tmpl/default_filters.php @@ -19,123 +19,227 @@ $classForShowHide = 'col-filter-header'; } -foreach($displayFilters as $searchKey => $filter) +if ($this->addMorefilter && $this->allowToCreateResultSets) { - $searchType = $filter['search_type']; - $searchValue = isset($filters[$searchKey]) ? $filters[$searchKey] : ''; - $filterHtml = ''; - $filterHide = $searchValue === '' ? 'filter-hide' : 'filter-show'; - - if ($searchType == 'text') + for ($i = 0; $i < $this->addMorefilter; $i++) { - $filterHtml = '
- - - - -
'; - - if(isset($this->colKey)) + ?> +
+ + $filter) { - $filterHtml .= JHtml::_('grid.sort', '', $this->colKey, $this->listDirn, $this->listOrder); - } - } - elseif($searchType == 'select' && isset($filter['select_options'])) - { - $svalue = isset($filter['select_value']) ? $filter['select_value'] : "value"; - $stext = isset($filter['select_text']) ? $filter['select_text'] : "text"; + $searchType = $filter['search_type']; + $searchValue = isset($filters['options-' . $i][$searchKey]) ? $filters['options-' . $i][$searchKey] : ''; + $filterHtml = ''; + $filterHide = $searchValue === '' ? 'filter-hide' : 'filter-show'; - $filterHtml = '
'; + if ($searchType == 'text') + { + $filterHtml = '
+ + + + +
'; - $filterHtml .= JHtml::_('select.genericlist', $filter['select_options'], 'filters[' . $searchKey . ']', - 'class="filter-input ' . $filterHide . '" size="1" onchange="tjrContentUI.report.submitTJRData();"', - $svalue, $stext, $searchValue); + if(isset($this->colKey)) + { + $filterHtml .= JHtml::_('grid.sort', '', $this->colKey, $this->listDirn, $this->listOrder); + } + } + elseif($searchType == 'select' && isset($filter['select_options'])) + { + $svalue = isset($filter['select_value']) ? $filter['select_value'] : "value"; + $stext = isset($filter['select_text']) ? $filter['select_text'] : "text"; + $multiple = isset($filter['multiple']) && $filter['multiple'] ? "multiple='true'" : ""; + $arrayFilter = isset($filter['multiple']) && $filter['multiple'] ? "[]" : ""; + $class = isset($filter['class']) ? $filter['class'] : ""; - if ($this->filterLevel == 1) - { - $filterHtml .= '
'; - } - else - { - $filterHtml .= ' - -
'; - } + $filterHtml = '
'; - if(isset($this->colKey)) - { - $filterHtml .= JHtml::_('grid.sort', '', $this->colKey, $this->listDirn, $this->listOrder); - } - } - elseif($searchType == 'date.range' || $searchType == 'calendar') - { - $j = ($searchType == 'date.range') ? 2 : 1; + $filterHtml .= JHtml::_('select.genericlist', $filter['select_options'], 'filters[options-' . $i . '][' . $searchKey . ']' . $arrayFilter, + 'class="filter-input ' . $filterHide . ' ' . $class . ' " size="1" onchange="tjrContentUI.report.submitTJRData();"' . $multiple, + $svalue, $stext, $searchValue); - for ($i=1; $i<=$j; $i++) - { - $altfieldKey = ''; + if ($this->filterLevel == 1) + { + $filterHtml .= '
'; + } + else + { + $filterHtml .= ' + + '; + } - if ($searchType == 'date.range') - { - $fieldKey = ($i == 1) ? ($searchKey . '_from') : ($searchKey . '_to'); - $altfieldKey = ($i == 1) ? ($searchKey . '_to') : ($searchKey . '_from'); + if(isset($this->colKey)) + { + $filterHtml .= JHtml::_('grid.sort', '', $this->colKey, $this->listDirn, $this->listOrder); + } } - else + elseif($searchType == 'date.range' || $searchType == 'calendar') { - $fieldKey = $searchKey; - } + $j = ($searchType == 'date.range') ? 2 : 1; - $searchValue = isset($filters[$fieldKey]) ? $filters[$fieldKey] : ''; - $dateFormat = isset($filters['dateFormat']) ? $filters['dateFormat'] : '%Y-%m-%d'; + for ($i=1; $i<=$j; $i++) + { + $altfieldKey = ''; - if ($j == 2) - { - $altSearchValue = isset($filters[$altfieldKey]) ? $filters[$altfieldKey] : ''; - $filterHide = ($searchValue === '' && $altSearchValue === '') ? 'filter-hide' : 'filter-show'; - } - else - { - $filterHide = $searchValue === '' ? 'filter-hide' : 'filter-show'; - } + if ($searchType == 'date.range') + { + $fieldKey = ($i == 1) ? ($searchKey . '_from') : ($searchKey . '_to'); + $altfieldKey = ($i == 1) ? ($searchKey . '_to') : ($searchKey . '_from'); + } + else + { + $fieldKey = $searchKey; + } + + $searchValue = isset($filters['options-' . $i][$fieldKey]) ? $filters['options-' . $i][$fieldKey] : ''; + $dateFormat = isset($filters['dateFormat']) ? $filters['dateFormat'] : '%Y-%m-%d'; - $attrib = array('class' => 'tjrsmall-input dash-calendar validate-ymd-date ' . $filterHide); + if ($j == 2) + { + $altSearchValue = isset($filters[$altfieldKey]) ? $filters[$altfieldKey] : ''; + $filterHide = ($searchValue === '' && $altSearchValue === '') ? 'filter-hide' : 'filter-show'; + } + else + { + $filterHide = $searchValue === '' ? 'filter-hide' : 'filter-show'; + } - if (isset($filter[$fieldKey]['attrib'])) + $attrib = array('class' => 'tjrsmall-input dash-calendar validate-ymd-date ' . $filterHide); + + if (isset($filter[$fieldKey]['attrib'])) + { + $fieldAttr = array_merge($filter[$fieldKey]['attrib'], $attrib); + } + elseif (isset($filter['attrib'])) + { + $fieldAttr = array_merge($filter['attrib'], $attrib); + } + else + { + $fieldAttr = $attrib; + } + + $filterHtml .= ''; + } + elseif ($this->filterLevel != 1 && $i != 1 || $searchType == 'calendar' ) + { + $filterHtml .= ' + + '; + } + + if(isset($this->colKey)) + { + $filterHtml .= JHtml::_('grid.sort', '', $this->colKey, $this->listDirn, $this->listOrder); + } + } + } + elseif($searchType == 'html') { - $fieldAttr = array_merge($filter[$fieldKey]['attrib'], $attrib); + $filterHtml = $filter['html']; } - elseif (isset($filter['attrib'])) + ?> + + +
+ + + + +
+ + $filter) + { + $searchType = $filter['search_type']; + $searchValue = isset($filters[$searchKey]) ? $filters[$searchKey] : ''; + $filterHtml = ''; + $filterHide = $searchValue === '' ? 'filter-hide' : 'filter-show'; + + if ($searchType == 'text') + { + $filterHtml = '
+ + + + +
'; + + if(isset($this->colKey)) { - $fieldAttr = $attrib; + $filterHtml .= JHtml::_('grid.sort', '', $this->colKey, $this->listDirn, $this->listOrder); } + } + elseif($searchType == 'select' && isset($filter['select_options'])) + { + $svalue = isset($filter['select_value']) ? $filter['select_value'] : "value"; + $stext = isset($filter['select_text']) ? $filter['select_text'] : "text"; + $multiple = isset($filter['multiple']) && $filter['multiple'] ? "multiple='true'" : ""; + $arrayFilter = isset($filter['multiple']) && $filter['multiple'] ? "[]" : ""; + $class = isset($filter['class']) ? $filter['class'] : ""; + + $filterHtml = '
'; - $filterHtml .= ''; } - elseif ($this->filterLevel != 1 && $i != 1 || $searchType == 'calendar' ) + else { - $filterHtml .= ' - -
'; + $filterHtml .= ' + + '; } if(isset($this->colKey)) @@ -143,14 +247,82 @@ class="input input-mini filter-input ' . $filterHide . '" ' . $filterHtml .= JHtml::_('grid.sort', '', $this->colKey, $this->listDirn, $this->listOrder); } } + elseif($searchType == 'date.range' || $searchType == 'calendar') + { + $j = ($searchType == 'date.range') ? 2 : 1; + + for ($i=1; $i<=$j; $i++) + { + $altfieldKey = ''; + + if ($searchType == 'date.range') + { + $fieldKey = ($i == 1) ? ($searchKey . '_from') : ($searchKey . '_to'); + $altfieldKey = ($i == 1) ? ($searchKey . '_to') : ($searchKey . '_from'); + } + else + { + $fieldKey = $searchKey; + } + + $searchValue = isset($filters[$fieldKey]) ? $filters[$fieldKey] : ''; + $dateFormat = isset($filters['dateFormat']) ? $filters['dateFormat'] : '%Y-%m-%d'; + + if ($j == 2) + { + $altSearchValue = isset($filters[$altfieldKey]) ? $filters[$altfieldKey] : ''; + $filterHide = ($searchValue === '' && $altSearchValue === '') ? 'filter-hide' : 'filter-show'; + } + else + { + $filterHide = $searchValue === '' ? 'filter-hide' : 'filter-show'; + } + + $attrib = array('class' => 'tjrsmall-input dash-calendar validate-ymd-date ' . $filterHide); + + if (isset($filter[$fieldKey]['attrib'])) + { + $fieldAttr = array_merge($filter[$fieldKey]['attrib'], $attrib); + } + elseif (isset($filter['attrib'])) + { + $fieldAttr = array_merge($filter['attrib'], $attrib); + } + else + { + $fieldAttr = $attrib; + } + + $filterHtml .= ''; + } + elseif ($this->filterLevel != 1 && $i != 1 || $searchType == 'calendar' ) + { + $filterHtml .= ' + + '; + } + + if(isset($this->colKey)) + { + $filterHtml .= JHtml::_('grid.sort', '', $this->colKey, $this->listDirn, $this->listOrder); + } + } + } + elseif($searchType == 'html') + { + $filterHtml = $filter['html']; + } + ?> + + - - showHideColumns = array_intersect($this->model->showhideCols, array_merge($this->defaultColToshow, $this->defaultColToHide)); } - $this->sortable = $this->model->sortableColumns; - $this->emailColumn = $this->model->getState('emailColumn'); - $this->srButton = $this->model->showSearchResetButton; - $this->colToshow = $this->model->getState('colToshow'); - $this->filterValues = $this->model->getState('filters'); - $this->userFilters = $this->model->displayFilters(); - $this->messages = $this->model->getTJRMessages(); - $this->showSummaryReport = $this->model->getState('showSummaryReport'); - $this->enableReportPlugins = $this->model->getenableReportPlugins($this->client); - $this->isExport = $user->authorise('core.export', 'com_tjreports.tjreport.' . $this->reportId); + $this->sortable = $this->model->sortableColumns; + $this->emailColumn = $this->model->getState('emailColumn'); + $this->srButton = $this->model->showSearchResetButton; + $this->colToshow = $this->model->getState('colToshow'); + $this->filterValues = $this->model->getState('filters'); + $this->userFilters = $this->model->displayFilters(); + $this->messages = $this->model->getTJRMessages(); + $this->showSummaryReport = $this->model->getState('showSummaryReport'); + $this->enableReportPlugins = $this->model->getenableReportPlugins($this->client); + $this->isExport = $user->authorise('core.export', 'com_tjreports.tjreport.' . $this->reportId); + $this->allowToCreateResultSets = $this->model->allowToCreateResultSets; + $this->addMorefilter = $input->get('addMorefilter', 1, 'INT'); return true; }