dev/core#2684 Fix filters tpl in civi reports to permit more than one table in a...
authorEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 9 Jul 2021 01:46:51 +0000 (13:46 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 15 Jul 2021 21:09:25 +0000 (09:09 +1200)
CRM/Report/Form.php
templates/CRM/Report/Form/Tabs/Filters.tpl

index 369628754da4684ab8a627341830269473b5cb0f..1bb30fb303fb6f73d309ede47c2b5e655baea2a4 100644 (file)
@@ -684,7 +684,7 @@ class CRM_Report_Form extends CRM_Core_Form {
       $this->assign('mode', 'instance');
     }
     elseif (!$this->noController) {
-      list($optionValueID, $optionValue) = CRM_Report_Utils_Report::getValueIDFromUrl();
+      [$optionValueID, $optionValue] = CRM_Report_Utils_Report::getValueIDFromUrl();
       $instanceCount = CRM_Report_Utils_Report::getInstanceCount($optionValue);
       if (($instanceCount > 0) && $optionValueID) {
         $this->assign('instanceUrl',
@@ -1325,20 +1325,29 @@ class CRM_Report_Form extends CRM_Core_Form {
    */
   public function addFilters() {
     $filters = $filterGroups = [];
-    $count = 1;
 
     foreach ($this->_filters as $table => $attributes) {
-      if (isset($this->_columns[$table]['group_title'])) {
-        // The presence of 'group_title' is secret code for 'is_a_custom_table'
-        // which magically means to 'display in an accordian'
-        // here we make this explicit.
-        $filterGroups[$table] = [
-          'group_title' => $this->_columns[$table]['group_title'],
-          'use_accordian_for_field_selection' => TRUE,
-
-        ];
+      $groupingKey = $this->_columns[$table]['grouping'] ?? '';
+      $filterGroups[$groupingKey]['tables'][$table] = [];
+      // If a prior table hasn't set group title then set it.
+      if (empty($filterGroups[$groupingKey]['group_title'])) {
+        $filterGroups[$groupingKey]['group_title'] = $this->_columns[$table]['group_title'] ?? '';
       }
+      // The presence of 'group_title' is secret code for 'display in an accordion'
+      // here we make this explicit.
+      if (!isset($filterGroups[$groupingKey]['use_accordion_for_field_selection'])) {
+        if (isset($this->_columns[$table]['use_accordion_for_field_selection'])) {
+          $filterGroups[$groupingKey]['use_accordion_for_field_selection'] = $this->_columns[$table]['use_accordion_for_field_selection'];
+        }
+        else {
+          $filterGroups[$groupingKey]['use_accordion_for_field_selection'] = isset($this->_columns[$table]['group_title']);
+        }
+      }
+
       foreach ($attributes as $fieldName => $field) {
+        $filterGroups[$groupingKey]['tables'][$table][$fieldName] = $field;
+        // Filters is deprecated in favour of filterGroups.
+        $filters[$table][$fieldName] = $field;
         // get ready with option value pair
         // @ todo being able to specific options for a field (e.g a date field) in the field spec as an array rather than an override
         // would be useful
@@ -1346,8 +1355,6 @@ class CRM_Report_Form extends CRM_Core_Form {
           CRM_Utils_Array::value('operatorType', $field),
           $fieldName);
 
-        $filters[$table][$fieldName] = $field;
-
         switch (CRM_Utils_Array::value('operatorType', $field)) {
           case CRM_Report_Form::OP_MONTH:
             if (!array_key_exists('options', $field) ||
@@ -1446,15 +1453,16 @@ class CRM_Report_Form extends CRM_Core_Form {
         }
       }
     }
-    if (!empty($filters)) {
+    if (!empty($filterGroups)) {
       $this->tabs['Filters'] = [
         'title' => ts('Filters'),
         'tpl' => 'Filters',
         'div_label' => 'set-filters',
       ];
     }
-    $this->assign('filters', $filters);
     $this->assign('filterGroups', $filterGroups);
+    // Filters is deprecated in favour of filterGroups.
+    $this->assign('filters', $filters);
   }
 
   /**
@@ -2271,7 +2279,7 @@ class CRM_Report_Form extends CRM_Core_Form {
     }
 
     if ($relative) {
-      list($from, $to) = $this->getFromTo($relative, $from, $to, $fromTime, $toTime);
+      [$from, $to] = $this->getFromTo($relative, $from, $to, $fromTime, $toTime);
     }
 
     if ($from) {
@@ -3396,7 +3404,7 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND
             $from = $this->_params["{$fieldName}_from"] ?? NULL;
             $to = $this->_params["{$fieldName}_to"] ?? NULL;
             if (!empty($this->_params["{$fieldName}_relative"])) {
-              list($from, $to) = CRM_Utils_Date::getFromTo($this->_params["{$fieldName}_relative"], NULL, NULL);
+              [$from, $to] = CRM_Utils_Date::getFromTo($this->_params["{$fieldName}_relative"], NULL, NULL);
             }
             if (strlen($to) === 10) {
               // If we just have the date we assume the end of that day.
@@ -3891,7 +3899,7 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND
    * @param string $tableAlias
    */
   public function buildACLClause($tableAlias = 'contact_a') {
-    list($this->_aclFrom, $this->_aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause($tableAlias);
+    [$this->_aclFrom, $this->_aclWhere] = CRM_Contact_BAO_Contact_Permission::cacheClause($tableAlias);
   }
 
   /**
@@ -5844,6 +5852,10 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a
         }
       }
     }
+    if (isset($options['grouping'])) {
+      $columns[$tableName]['grouping'] = $options['grouping'];
+      $columns[$tableName]['group_title'] = $options['group_title'] ?? '';
+    }
     return $columns;
   }
 
index f32628a5a23af21db2194cfe8cea5ed0136bcbf2..5324ca33af7e4b5d1279c14ac9d754af89069430 100644 (file)
@@ -8,27 +8,21 @@
  +--------------------------------------------------------------------+
 *}
 
-  <div id="report-tab-set-filters" class="civireport-criteria">
-    <table class="report-layout">
+<div id="report-tab-set-filters" class="civireport-criteria">
+  <div class="report-layout">
       {assign var="counter" value=1}
-      {foreach from=$filters item=table key=tableName}
-        {assign  var="filterCount" value=$table|@count}
+      {foreach from=$filterGroups item=filterGroup}
         {* Wrap custom field sets in collapsed accordion pane. *}
-        {if !empty($filterGroups.$tableName.group_title) and $filterCount gte 1}
-          {* we should close table that contains other filter elements before we start building custom group accordion
-           *}
-          {if $counter eq 1}
-    </table>
-            {assign var="counter" value=0}
-          {/if}
+        {if $filterGroup.use_accordion_for_field_selection}
           <div class="crm-accordion-wrapper crm-accordion collapsed">
             <div class="crm-accordion-header">
-              {$filterGroups.$tableName.group_title}
+              {$filterGroup.group_title}
             </div><!-- /.crm-accordion-header -->
             <div class="crm-accordion-body">
-              <table class="report-layout">
         {/if}
-        {foreach from=$table item=field key=fieldName}
+        <table class="report-layout">
+        {foreach from=$filterGroup.tables item=table key=tableName}
+          {foreach from=$table item=field key=fieldName}
                 {assign var=fieldOp     value=$fieldName|cat:"_op"}
                 {assign var=filterVal   value=$fieldName|cat:"_value"}
                 {assign var=filterMin   value=$fieldName|cat:"_min"}
                     </td>
                   </tr>
                 {/if}
+          {/foreach}
         {/foreach}
-        {if !empty($filterGroups.$tableName.group_title)}
-              </table>
+        </table>
+        {if $filterGroup.use_accordion_for_field_selection}
             </div><!-- /.crm-accordion-body -->
           </div><!-- /.crm-accordion-wrapper -->
-          {assign var=closed value="1"} {*-- ie table tags are closed-- *}
-        {else}
-          {assign var=closed     value="0"} {*-- ie table tags are not closed-- *}
         {/if}
       {/foreach}
-    {if $closed eq 0 }
-      </table>
-    {/if}
   </div>
+</div>