X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/timetracker.git/blobdiff_plain/b027028b5322fcbfb6de53e7a74529cbac7931de..75f676a0c24fc8593c94ba3fedd366a99fe45a93:/WEB-INF/lib/ttReportHelper.class.php diff --git a/WEB-INF/lib/ttReportHelper.class.php b/WEB-INF/lib/ttReportHelper.class.php index 280b70db..e80e7d03 100644 --- a/WEB-INF/lib/ttReportHelper.class.php +++ b/WEB-INF/lib/ttReportHelper.class.php @@ -348,26 +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) { - // This is needed to get the date in user date format. - //$o_date = new DateAndTime(DB_DATEFORMAT, $val['grouped_by']); - //$val['grouped_by'] = $o_date->toString($user->date_format); - //unset($o_date); - - $val['grouped_by'] = ttDateToUserFormat($val['grouped_by']); - } - } - // This is needed to get the date in user date format. - $o_date = new DateAndTime(DB_DATEFORMAT, $val['date']); - $val['date'] = $o_date->toString($user->date_format); - unset($o_date); + 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; @@ -538,10 +523,7 @@ class ttReportHelper { while ($val = $res->fetchRow()) { if ('date' == $group_by_option) { - // This is needed to get the date in user date format. - $o_date = new DateAndTime(DB_DATEFORMAT, $val['group_field']); - $val['group_field'] = $o_date->toString($user->date_format); - unset($o_date); + $val['group_field'] = ttDateToUserFormat($val['group_field']); } $time = $val['time'] ? sec_to_time_fmt_hm($val['time']) : null; if ($options['show_cost']) { @@ -1107,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; + } }