Skip to content

Commit

Permalink
Issue #172665 feat: Support set of filters in TjReports
Browse files Browse the repository at this point in the history
  • Loading branch information
ttpllt46 committed Jun 22, 2021
1 parent 76099dc commit 97b3d42
Show file tree
Hide file tree
Showing 4 changed files with 328 additions and 112 deletions.
18 changes: 16 additions & 2 deletions tjreports/site/assets/js/tjrContentUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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('<input type="hidden" id="tjReportaddMorefilter" name="addMorefilter" value=' + addMorefilterCnt + '>');
}

var doProcess = this.validate();
if (!doProcess) {
return false;
Expand Down Expand Up @@ -138,6 +151,7 @@ jQuery.extend(tjrContentUI.report, {
.val('')
.removeAttr('checked')
.removeAttr('selected');
addMorefilterCnt = 1;
tjrContentUI.report.submitTJRData(task);
},
validate: function() {
Expand Down
32 changes: 30 additions & 2 deletions tjreports/site/models/reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ class TjreportsModelReports extends ListModel
*/
public $supportedFieldTypesForSummaryReport = array ('radio', 'checkbox', 'rating');


public $allowToCreateResultSets = false;

/**
* Constructor.
*
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 97b3d42

Please sign in to comment.