Refactored ttReportHelper::getItems for multiple group by condition.
authorNik Okuntseff <support@anuko.com>
Mon, 29 Oct 2018 14:19:52 +0000 (14:19 +0000)
committerNik Okuntseff <support@anuko.com>
Mon, 29 Oct 2018 14:19:52 +0000 (14:19 +0000)
WEB-INF/lib/ttReportHelper.class.php
WEB-INF/templates/footer.tpl

index 0b8dc83..e80e7d0 100644 (file)
@@ -348,18 +348,11 @@ class ttReportHelper {
         if ('.' != $user->decimal_mark)
           $val['expense'] = str_replace('.', $user->decimal_mark, $val['expense']);
       }
-// CODING STOPPED RIGHT HERE replace with a combined key...
-      if ('no_grouping' != $group_by_option) {
-        $val['grouped_by'] = $val[$group_by_option];
-        if ('date' == $group_by_option) {
-          $val['grouped_by'] = ttDateToUserFormat($val['grouped_by']);
-        }
-      }
 
+      if (!$no_grouping) $val['grouped_by'] = ttReportHelper::makeGroupByKey($options, $val);
       $val['date'] = ttDateToUserFormat($val['date']);
 
-      $row = $val;
-      $report_items[] = $row;
+      $report_items[] = $val;
     }
 
     return $report_items;
@@ -1096,4 +1089,32 @@ class ttReportHelper {
     // TODO: add additional checks here. Perhaps do it before saving the bean for consistency.
     return true;
   }
+
+  // makeGroupByKey - builds a combined group by key from group_by1, group_by2 and group_by3 values
+  // (passed in $options) and a row of data ($row obtained from a db query).
+  static function makeGroupByKey($options, $row) {
+    if ($options['group_by1'] != null && $options['group_by1'] != 'no_grouping') {
+      // We have group_by1.
+      $group_by1 = $options['group_by1'];
+      $group_by1_value = $row[$group_by1];
+      if ($group_by1 == 'date') $group_by1_value = ttDateToUserFormat($group_by1_value);
+      $group_by_key .= ' - '.$group_by1_value;
+    }
+    if ($options['group_by2'] != null && $options['group_by2'] != 'no_grouping') {
+      // We have group_by2.
+      $group_by2 = $options['group_by2'];
+      $group_by2_value = $row[$group_by2];
+      if ($group_by2 == 'date') $group_by2_value = ttDateToUserFormat($group_by2_value);
+      $group_by_key .= ' - '.$group_by2_value;
+    }
+    if ($options['group_by3'] != null && $options['group_by3'] != 'no_grouping') {
+      // We have group_by3.
+      $group_by3 = $options['group_by3'];
+      $group_by3_value = $row[$group_by3];
+      if ($group_by3 == 'date') $group_by3_value = ttDateToUserFormat($group_by3_value);
+      $group_by_key .= ' - '.$group_by3_value;
+    }
+    $group_by_key = trim($group_by_key, ' -');
+    return $group_by_key;
+  }
 }
index 5fe8827..81f2623 100644 (file)
@@ -12,7 +12,7 @@
       <br>
       <table cellspacing="0" cellpadding="4" width="100%" border="0">
         <tr>
-          <td align="center">&nbsp;Anuko Time Tracker 1.18.01.4330 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.18.01.4331 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
             <a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
             <a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
             <a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>