]> wagnertech.de Git - timetracker.git/blobdiff - WEB-INF/lib/ttReportHelper.class.php
A little bit more refactoring.
[timetracker.git] / WEB-INF / lib / ttReportHelper.class.php
index d76b027adb0b71cb5fbcec89d1734435caa58b23..42463d08af6dcfce113a8c8f59015823ba37293b 100644 (file)
@@ -127,8 +127,8 @@ class ttReportHelper {
     $canViewReports = $user->can('view_reports');
     $isClient = $user->isClient();
 
-    $group_by_option = $bean->getAttribute('group_by');
-    $convertTo12Hour = ('%I:%M %p' == $user->time_format) && ($bean->getAttribute('chstart') || $bean->getAttribute('chfinish'));
+    $group_by_option = $options['group_by'];
+    $convertTo12Hour = ('%I:%M %p' == $user->time_format) && ($options['show_start'] || $options['show_end']);
 
     // Prepare a query for time items in tt_log table.
     $fields = array(); // An array of fields for database query.
@@ -138,16 +138,16 @@ class ttReportHelper {
     if($canViewReports || $isClient)
       array_push($fields, 'u.name as user');
     // Add client name if it is selected.
-    if ($bean->getAttribute('chclient') || 'client' == $group_by_option)
+    if ($options['show_client'] || 'client' == $group_by_option)
       array_push($fields, 'c.name as client');
     // Add project name if it is selected.
-    if ($bean->getAttribute('chproject') || 'project' == $group_by_option)
+    if ($options['show_project'] || 'project' == $group_by_option)
       array_push($fields, 'p.name as project');
     // Add task name if it is selected.
-    if ($bean->getAttribute('chtask') || 'task' == $group_by_option)
+    if ($options['show_task'] || 'task' == $group_by_option)
       array_push($fields, 't.name as task');
     // Add custom field.
-    $include_cf_1 = $bean->getAttribute('chcf_1') || 'cf_1' == $group_by_option;
+    $include_cf_1 = $options['show_custom_field_1'] || 'cf_1' == $group_by_option;
     if ($include_cf_1) {
       $custom_fields = new CustomFields($user->group_id);
       $cf_1_type = $custom_fields->fields[0]['type'];
@@ -158,16 +158,18 @@ class ttReportHelper {
       }
     }
     // Add start time.
-    if ($bean->getAttribute('chstart')) {
+    if ($options['show_start']) {
       array_push($fields, "l.start as unformatted_start");
       array_push($fields, "TIME_FORMAT(l.start, '%k:%i') as start");
     }
     // Add finish time.
-    if ($bean->getAttribute('chfinish'))
+    if ($options['show_end'])
       array_push($fields, "TIME_FORMAT(sec_to_time(time_to_sec(l.start) + time_to_sec(l.duration)), '%k:%i') as finish");
     // Add duration.
-    if ($bean->getAttribute('chduration'))
+    if ($options['show_duration'])
       array_push($fields, "TIME_FORMAT(l.duration, '%k:%i') as duration");
+
+// TODO: refactoring in progress down from here... The above is identical to getFavItems and is ready to merge.
     // Add work units.
     if ($bean->getAttribute('chunits')) {
       if ($user->unit_totals_only)
@@ -1804,24 +1806,34 @@ class ttReportHelper {
     $options['period'] = $bean->getAttribute('period');
     $options['period_start'] = $bean->getAttribute('start_date');
     $options['period_end'] = $bean->getAttribute('end_date');
+    $options['show_client'] = $bean->getAttribute('chclient');
 
 /*
  * TODO: remaining fields to fill in...
-  `show_client` tinyint(4) NOT NULL default 0,           # whether to show client column
   `show_invoice` tinyint(4) NOT NULL default 0,          # whether to show invoice column
   `show_paid` tinyint(4) NOT NULL default 0,             # whether to show paid column
   `show_ip` tinyint(4) NOT NULL default 0,               # whether to show ip column
-  `show_project` tinyint(4) NOT NULL default 0,          # whether to show project column
-  `show_start` tinyint(4) NOT NULL default 0,            # whether to show start field
-  `show_duration` tinyint(4) NOT NULL default 0,         # whether to show duration field
+ */
+    $options['show_project'] = $bean->getAttribute('chproject');
+    $options['show_start'] = $bean->getAttribute('chstart');
+    $options['show_duration'] = $bean->getAttribute('chduration');
+/*
   `show_cost` tinyint(4) NOT NULL default 0,             # whether to show cost field
-  `show_task` tinyint(4) NOT NULL default 0,             # whether to show task column
-  `show_end` tinyint(4) NOT NULL default 0,              # whether to show end field
+ */
+    $options['show_task'] = $bean->getAttribute('chtask');
+    $options['show_end'] = $bean->getAttribute('chfinish');
+/*
   `show_note` tinyint(4) NOT NULL default 0,             # whether to show note column
   `show_custom_field_1` tinyint(4) NOT NULL default 0,   # whether to show custom field 1
+ */
+    $options['show_custom_field_1'] = $bean->getAttribute('chcf_1');
+ /*
   `show_work_units` tinyint(4) NOT NULL default 0,       # whether to show work units
   `show_totals_only` tinyint(4) NOT NULL default 0,      # whether to show totals only
-  `group_by` varchar(20) default NULL,                   # group by field
+ **/
+    $options['group_by'] = $bean->getAttribute('group_by');
+/*
+ * TODO: remaining fields to fill in...
   `status` tinyint(4) default 1,                         # favorite report status
   PRIMARY KEY (`id`)
 );