From 75f676a0c24fc8593c94ba3fedd366a99fe45a93 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Mon, 29 Oct 2018 14:19:52 +0000 Subject: [PATCH] Refactored ttReportHelper::getItems for multiple group by condition. --- WEB-INF/lib/ttReportHelper.class.php | 39 +++++++++++++++++++++------- WEB-INF/templates/footer.tpl | 2 +- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/WEB-INF/lib/ttReportHelper.class.php b/WEB-INF/lib/ttReportHelper.class.php index 0b8dc83c..e80e7d03 100644 --- a/WEB-INF/lib/ttReportHelper.class.php +++ b/WEB-INF/lib/ttReportHelper.class.php @@ -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; + } } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 5fe88277..81f2623e 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.01.4330 | Copyright © Anuko | +  Anuko Time Tracker 1.18.01.4331 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} -- 2.20.1