CRM-17837 store rollup result grand total on the class rather than discarding it
authoreileen <emcnaughton@wikimedia.org>
Tue, 19 Jan 2016 19:47:59 +0000 (08:47 +1300)
committereileen <emcnaughton@wikimedia.org>
Tue, 19 Jan 2016 19:48:24 +0000 (08:48 +1300)
This makes it available for re-use in the statistics

CRM/Report/Form.php

index c3a2cb6f84eb7e1721169f3097a1df46661d924d..93b813de400cab54b66d50ba25c1ead983f3159c 100644 (file)
@@ -398,6 +398,13 @@ class CRM_Report_Form extends CRM_Core_Form {
    */
   protected $_createNew;
 
+  /**
+   *  When a grand total row has calculated the status we pop it off to here.
+   *
+   * This allows us to access it from the stats function and avoid recalculating.
+   */
+  protected $rollupRow = array();
+
   /**
    * SQL being run in this report.
    *
@@ -2122,26 +2129,27 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND
    * @return bool
    */
   public function grandTotal(&$rows) {
-    if (!$this->_rollup || ($this->_rollup == '') ||
+    if (!$this->_rollup || ($this->_rollup == '' || count($rows) == 1) ||
       ($this->_limit && count($rows) >= self::ROW_COUNT_LIMIT)
     ) {
       return FALSE;
     }
-    $lastRow = array_pop($rows);
+
+    $this->rollupRow = array_pop($rows);
 
     foreach ($this->_columnHeaders as $fld => $val) {
       if (!in_array($fld, $this->_statFields)) {
         if (!$this->_grandFlag) {
-          $lastRow[$fld] = "Grand Total";
+          $this->rollupRow[$fld] = "Grand Total";
           $this->_grandFlag = TRUE;
         }
         else {
-          $lastRow[$fld] = "";
+          $this->rollupRow[$fld] = "";
         }
       }
     }
 
-    $this->assign('grandStat', $lastRow);
+    $this->assign('grandStat', $this->rollupRow);
     return TRUE;
   }
 
@@ -2871,7 +2879,7 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND
     $statistics = array();
 
     $count = count($rows);
-
+    // Why do we increment the count for rollup seems to artificially inflate the count.
     if ($this->_rollup && ($this->_rollup != '') && $this->_grandFlag) {
       $count++;
     }