A bit of refactoring.
[timetracker.git] / WEB-INF / lib / ttReportHelper.class.php
index 4d510bb..1f16547 100644 (file)
@@ -657,7 +657,7 @@ class ttReportHelper {
   }
 
   // prepareReportBody - prepares an email body for report.
-  static function prepareReportBody($bean, $comment)
+  static function prepareReportBody($bean, $options, $comment)
   {
     global $user;
     global $i18n;
@@ -665,10 +665,9 @@ class ttReportHelper {
     // Determine these once as they are used in multiple places in this function.
     $canViewReports = $user->can('view_reports') || $user->can('view_all_reports');
     $isClient = $user->isClient();
-    $options = ttReportHelper::getReportOptions($bean);
 
     $items = ttReportHelper::getItems($options);
-    $group_by = $bean->getAttribute('group_by');
+    $group_by = $options['group_by'];
     if ($group_by && 'no_grouping' != $group_by)
       $subtotals = ttReportHelper::getSubtotals($options);
     $totals = ttReportHelper::getTotals($options);
@@ -700,7 +699,7 @@ class ttReportHelper {
     // Output comment.
     if ($comment) $body .= '<p>'.htmlspecialchars($comment).'</p>';
 
-    if ($bean->getAttribute('chtotalsonly')) {
+    if ($options['show_totals_only']) {
       // Totals only report. Output subtotals.
 
       // Determine group_by header.
@@ -714,27 +713,27 @@ class ttReportHelper {
       $body .= '<table border="0" cellpadding="4" cellspacing="0" width="100%">';
       $body .= '<tr>';
       $body .= '<td style="'.$tableHeader.'">'.$group_by_header.'</td>';
-      if ($bean->getAttribute('chduration'))
+      if ($options['show_duration'])
         $body .= '<td style="'.$tableHeaderCentered.'" width="5%">'.$i18n->get('label.duration').'</td>';
-      if ($bean->getAttribute('chunits'))
+      if ($options['show_work_units'])
         $body .= '<td style="'.$tableHeaderCentered.'" width="5%">'.$i18n->get('label.work_units_short').'</td>';
-      if ($bean->getAttribute('chcost'))
+      if ($options['show_cost'])
         $body .= '<td style="'.$tableHeaderCentered.'" width="5%">'.$i18n->get('label.cost').'</td>';
       $body .= '</tr>';
       foreach($subtotals as $subtotal) {
         $body .= '<tr style="'.$rowSubtotal.'">';
         $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.($subtotal['name'] ? htmlspecialchars($subtotal['name']) : '&nbsp;').'</td>';
-        if ($bean->getAttribute('chduration')) {
+        if ($options['show_duration']) {
           $body .= '<td style="'.$cellRightAlignedSubtotal.'">';
           if ($subtotal['time'] <> '0:00') $body .= $subtotal['time'];
           $body .= '</td>';
         }
-        if ($bean->getAttribute('chunits')) {
+        if ($options['show_work_units']) {
           $body .= '<td style="'.$cellRightAlignedSubtotal.'">';
           $body .= $subtotal['units'];
           $body .= '</td>';
         }
-        if ($bean->getAttribute('chcost')) {
+        if ($options['show_cost']) {
           $body .= '<td style="'.$cellRightAlignedSubtotal.'">';
           $body .= ($canViewReports || $isClient) ? $subtotal['cost'] : $subtotal['expenses'];
           $body .= '</td>';
@@ -742,6 +741,11 @@ class ttReportHelper {
         $body .= '</tr>';
       }
 
+// TODO: refactoring ongoing down from here...
+
+
+
+
       // Print totals.
       $body .= '<tr><td>&nbsp;</td></tr>';
       $body .= '<tr style="'.$rowSubtotal.'">';
@@ -973,7 +977,7 @@ class ttReportHelper {
   }
 
   // prepareFavReportBody - prepares an email body for a favorite report.
-  static function prepareFavReportBody($options)
+  static function prepareFavReportBody($options, $comment = null)
   {
     global $user;
     global $i18n;
@@ -1013,7 +1017,7 @@ class ttReportHelper {
     $body .= '<p style="'.$style_title.'">'.$i18n->get('form.mail.report_subject').': '.$totals['start_date'].' - '.$totals['end_date'].'</p>';
 
     // Output comment.
-    // if ($comment) $body .= '<p>'.htmlspecialchars($comment).'</p>'; // No comment for fav. reports.
+    if ($comment) $body .= '<p>'.htmlspecialchars($comment).'</p>';
 
     if ($options['show_totals_only']) {
       // Totals only report. Output subtotals.