CRM-15941 further fix including renaming folder for tab files to tabs
authorEileen McNaughton <eileen@fuzion.co.nz>
Mon, 2 Mar 2015 18:21:50 +0000 (05:21 +1100)
committerEileen McNaughton <eileen@fuzion.co.nz>
Mon, 2 Mar 2015 19:29:00 +0000 (06:29 +1100)
CRM/Report/Form.php
CRM/Report/Form/Register.php
templates/CRM/Report/Form/Criteria.tpl
templates/CRM/Report/Form/Fields.tpl
templates/CRM/Report/Form/Tabs/FieldSelection.tpl [moved from templates/CRM/Report/Form/Criteria/FieldSelection.tpl with 100% similarity]
templates/CRM/Report/Form/Tabs/Filters.tpl [moved from templates/CRM/Report/Form/Criteria/Filters.tpl with 100% similarity]
templates/CRM/Report/Form/Tabs/GroupBy.tpl [moved from templates/CRM/Report/Form/Criteria/GroupBy.tpl with 100% similarity]
templates/CRM/Report/Form/Tabs/OrderBy.tpl [moved from templates/CRM/Report/Form/Criteria/OrderBy.tpl with 100% similarity]
templates/CRM/Report/Form/Tabs/ReportOptions.tpl [moved from templates/CRM/Report/Form/Criteria/ReportOptions.tpl with 100% similarity]

index 21bc6065a916e592bb3029c2626bca5cbc766e51..4d74ac00fea16325851ccd1d5e3aaa0197e7517a 100644 (file)
@@ -144,12 +144,11 @@ class CRM_Report_Form extends CRM_Core_Form {
 
   /**
    * specify entity table for tags filter
-   *
    */
   protected $_tagFilterTable = 'civicrm_contact';
 
   /**
-   * build groups filter
+   * Build groups filter.
    *
    * @var bool
    */
@@ -165,7 +164,15 @@ class CRM_Report_Form extends CRM_Core_Form {
   public $_drilldownReport = array();
 
   /**
-   * Tabs to display on report.
+   * Array of tabs to display on report.
+   *
+   * E.g we define the tab title, the tpl and the tab-specific part of the css or  html link.
+   *
+   *  $this->tabs['OrderBy'] = array(
+   *    'title' => ts('Sorting'),
+   *    'tpl' => 'OrderBy',
+   *    'div_label' => 'order-by',
+   *  );
    *
    * @var array
    */
@@ -383,7 +390,6 @@ class CRM_Report_Form extends CRM_Core_Form {
 
     $this->addClass('crm-report-form');
 
-    // Build tag filter.
     if ($this->_tagFilter) {
       $this->buildTagFilter();
     }
@@ -427,6 +433,13 @@ class CRM_Report_Form extends CRM_Core_Form {
     $this->assign('currencyColumn', $this->_currencyColumn);
   }
 
+  /**
+   * Shared pre-process function.
+   *
+   * If overriding preProcess function this should still be called.
+   *
+   * @throws \Exception
+   */
   public function preProcessCommon() {
     $this->_force
       = CRM_Utils_Request::retrieve(
@@ -552,6 +565,9 @@ class CRM_Report_Form extends CRM_Core_Form {
     $this->_chartButtonName = $this->getButtonName('submit', 'chart');
   }
 
+  /**
+   * Add bread crumb.
+   */
   public function addBreadCrumb() {
     $breadCrumbs
       = array(
@@ -564,6 +580,11 @@ class CRM_Report_Form extends CRM_Core_Form {
     CRM_Utils_System::appendBreadCrumb($breadCrumbs);
   }
 
+  /**
+   * Pre process function.
+   *
+   * Called prior to build form.
+   */
   public function preProcess() {
     $this->preProcessCommon();
 
@@ -911,7 +932,7 @@ class CRM_Report_Form extends CRM_Core_Form {
   }
 
   /**
-   * Setter for $_id
+   * Setter for $_id.
    *
    * @param int $instanceID
    */
@@ -920,7 +941,7 @@ class CRM_Report_Form extends CRM_Core_Form {
   }
 
   /**
-   * Setter for $_force
+   * Setter for $_force,
    *
    * @param $isForce
    */
@@ -998,10 +1019,18 @@ class CRM_Report_Form extends CRM_Core_Form {
     $this->addCheckBox("fields", ts('Select Columns'), $options, NULL,
       NULL, NULL, NULL, $this->_fourColumnAttribute, TRUE
     );
-    $this->tabs[] = 'FieldSelection';
-    // Note this assignment is only really required in buildForm. It is being 'over-called'
-    // to reduce risk of being missed due to overridden functions.
-    $this->assign('tabs', $this->tabs);
+    if (!empty($colGroups)) {
+      $this->tabs['FieldSelection'] = array(
+        'title' => ts('Columns'),
+        'tpl' => 'FieldSelection',
+        'div_label' => 'col-groups',
+      );
+
+      // Note this assignment is only really required in buildForm. It is being 'over-called'
+      // to reduce risk of being missed due to overridden functions.
+      $this->assign('tabs', $this->tabs);
+    }
+
     $this->assign('colGroups', $colGroups);
   }
 
@@ -1119,14 +1148,41 @@ class CRM_Report_Form extends CRM_Core_Form {
         }
       }
     }
-    $this->tabs[] = 'Filters';
-    // Note this assignment is only really required in buildForm. It is being 'over-called'
-    // to reduce risk of being missed due to overridden functions.
-    $this->assign('tabs', $this->tabs);
+    if (!empty($filters)) {
+      $this->tabs['Filters'] = array(
+        'title' => ts('Filters'),
+        'tpl' => 'Filters',
+        'div_label' => 'set-filters',
+      );
+    }
     $this->assign('filters', $filters);
   }
 
-  /*
+  /**
+   * Function to assign the tabs to the template in the correct order.
+   *
+   * We want the tabs to wind up in this order (if not overridden).
+   *
+   *   - Field Selection
+   *   - Group Bys
+   *   - Order Bys
+   *   - Other Options
+   *   - Filters
+   */
+  protected function assignTabs() {
+    $order = array(
+      'FieldSelection',
+      'GroupBy',
+      'OrderBy',
+      'ReportOptions',
+      'Filters',
+    );
+    $order = array_intersect_key(array_fill_keys($order, 1), $this->tabs);
+    $order = array_merge($order, $this->tabs);
+    $this->assign('tabs', $order);
+  }
+
+  /**
    * Add options defined in $this->_options to the report.
    */
   public function addOptions() {
@@ -1148,10 +1204,13 @@ class CRM_Report_Form extends CRM_Core_Form {
         }
       }
     }
-    $this->tabs[] = 'OrderBy';
-    // Note this assignment is only really required in buildForm. It is being 'over-called'
-    // to reduce risk of being missed due to overridden functions.
-    $this->assign('tabs', $this->tabs);
+    if (!empty($this->_options)) {
+      $this->tabs['ReportOptions'] = array(
+        'title' => ts('Display Options'),
+        'tpl' => 'ReportOptions',
+        'div_label' => 'other-options',
+      );
+    }
     $this->assign('otherOptions', $this->_options);
   }
 
@@ -1188,10 +1247,13 @@ class CRM_Report_Form extends CRM_Core_Form {
       NULL, NULL, NULL, $this->_fourColumnAttribute
     );
     $this->assign('groupByElements', $options);
-    $this->tabs[] = 'GroupBy';
-    // Note this assignment is only really required in buildForm. It is being 'over-called'
-    // to reduce risk of being missed due to overridden functions.
-    $this->assign('tabs', $this->tabs);
+    if (!empty($options)) {
+      $this->tabs['GroupBy'] = array(
+        'title' => ts('Grouping'),
+        'tpl' => 'GroupBy',
+        'div_label' => 'group-by-elements',
+      );
+    }
 
     foreach ($freqElements as $name) {
       $this->addElement('select', "group_bys_freq[$name]",
@@ -1200,11 +1262,14 @@ class CRM_Report_Form extends CRM_Core_Form {
     }
   }
 
+  /**
+   * Add data for order by tab.
+   */
   public function addOrderBys() {
     $options = array();
     foreach ($this->_columns as $tableName => $table) {
 
-      // Report developer may define any column to order by; include these as order-by options
+      // Report developer may define any column to order by; include these as order-by options.
       if (array_key_exists('order_bys', $table)) {
         foreach ($table['order_bys'] as $fieldName => $field) {
           if (!empty($field)) {
@@ -1230,10 +1295,13 @@ class CRM_Report_Form extends CRM_Core_Form {
     asort($options);
 
     $this->assign('orderByOptions', $options);
-    $this->tabs[] = 'OrderBy.tpl';
-    // Note this assignment is only really required in buildForm. It is being 'over-called'
-    // to reduce risk of being missed due to overridden functions.
-    $this->assign('tabs', $this->tabs);
+    if (!empty($options)) {
+      $this->tabs['OrderBy'] = array(
+        'title' => ts('Sorting'),
+        'tpl' => 'OrderBy',
+        'div_label' => 'order-by',
+      );
+    }
 
     if (!empty($options)) {
       $options = array(
@@ -1251,6 +1319,9 @@ class CRM_Report_Form extends CRM_Core_Form {
     }
   }
 
+  /**
+   *
+   */
   public function buildInstanceAndButtons() {
     CRM_Report_Form_Instance::buildForm($this);
 
@@ -1302,6 +1373,9 @@ class CRM_Report_Form extends CRM_Core_Form {
     );
   }
 
+  /**
+   * Main build form function.
+   */
   public function buildQuickForm() {
     $this->addColumns();
 
@@ -1315,22 +1389,21 @@ class CRM_Report_Form extends CRM_Core_Form {
 
     $this->buildInstanceAndButtons();
 
-    //add form rule for report
+    // Add form rule for report.
     if (is_callable(array(
       $this,
       'formRule',
     ))) {
       $this->addFormRule(array(get_class($this), 'formRule'), $this);
     }
-    // Note this assignment is only really required in buildForm. It is being 'over-called'
-    // to reduce risk of being missed due to overridden functions.
-    $this->assign('tabs', $this->tabs);
+    $this->assignTabs();
   }
 
   /**
    * A form rule function to ensure that fields selected in group_by
    * (if any) should only be the ones present in display/select fields criteria;
    * note: works if and only if any custom field selected in group_by.
+   *
    * @param array $fields
    * @param array $ignoreFields
    *
@@ -1369,8 +1442,10 @@ class CRM_Report_Form extends CRM_Core_Form {
   }
 
   /**
-   * Note: $fieldName param allows inheriting class to build operationPairs
-   * specific to a field.
+   * Get operators to display on form.
+   *
+   * Note: $fieldName param allows inheriting class to build operationPairs specific to a field.
+   *
    * @param string $type
    * @param string $fieldName
    *
@@ -1465,7 +1540,7 @@ class CRM_Report_Form extends CRM_Core_Form {
   }
 
   /**
-   * Adds group filters to _columns (called from _Construct
+   * Adds group filters to _columns (called from _Construct).
    */
   public function buildGroupFilter() {
     $this->_columns['civicrm_group']['filters'] = array(
index 16b658ad8ac1b0a2722864c3359d0a10742e58ab..10165ae49fb2c8fb9e6e091602ef7bb6c1792788 100644 (file)
@@ -62,9 +62,6 @@ class CRM_Report_Form_Register extends CRM_Core_Form {
    * @return array
    *   reference to the array of default values
    */
-  /**
-   * @return array
-   */
   public function setDefaultValues() {
     $defaults = array();
     if ($this->_action & CRM_Core_Action::DELETE) {
index 7ebb5ad8f58e490e0decf7c81d3b71eb7a233555..8848967aae7c1c0ac01e4598fe272f96b6b0fd75 100644 (file)
@@ -26,8 +26,8 @@
 {* Report form criteria section *}
 
 {foreach from=$tabs item=tab}
-  $region = {"report-tab"|cat:$tab}
-  $fileName = {"Criteria/"|cat:$tab|cat:".tpl"}
+  {assign var = 'region' value = "report-tab"|cat:$tab.div_label}
+  {assign var = 'fileName' value = "CRM/Report/Form/Tabs/"|cat:$tab.tpl|cat:".tpl"}
   {crmRegion name=$region}
     {include file=$fileName}
   {/crmRegion}
index fba109a89b4035df5fda4abcc799332a34693ebc..49c7043b5c0aa84b28629ac908a90337244e0201 100644 (file)
       <div id="mainTabContainer">
         {*tab navigation bar*}
         <ul>
-          {if $colGroups}
+          {foreach from=$tabs item='tab'}
             <li class="ui-corner-all">
-              <a title="{ts}Columns{/ts}" href="#report-tab-col-groups">{ts}Columns{/ts}</a>
+              <a title="{$tab.title}" href="#report-tab-{$tab.div_label}">{$tab.title}</a>
             </li>
-          {/if}
-          {if $groupByElements}
-            <li class="ui-corner-all">
-              <a title="{ts}Grouping{/ts}" href="#report-tab-group-by-elements">{ts}Grouping{/ts}</a>
-            </li>
-          {/if}
-          {if $orderByOptions}
-            <li class="ui-corner-all">
-              <a title="{ts}Sorting{/ts}" href="#report-tab-order-by-elements">{ts}Sorting{/ts}</a>
-            </li>
-          {/if}
-          {if $otherOptions}
-            <li class="ui-corner-all">
-              <a title="{ts}Display Options{/ts}" href="#report-tab-other-options">{ts}Display{/ts}</a>
-            </li>
-          {/if}
-          {if $filters}
-            <li class="ui-corner-all">
-              <a title="{ts}Filters{/ts}" href="#report-tab-set-filters">{ts}Filters{/ts}</a>
-            </li>
-          {/if}
+          {/foreach}
           {if $instanceForm OR $instanceFormError}
             <li id="tab_settings" class="ui-corner-all">
               <a title="{ts}Title and Format{/ts}" href="#report-tab-format">{ts}Title and Format{/ts}</a>