Initial work done to support negative durations, some issues remain.
[timetracker.git] / WEB-INF / lib / ttChartHelper.class.php
index 75a38d0..efb30c6 100644 (file)
@@ -27,6 +27,7 @@
 // +----------------------------------------------------------------------+
 
 import('Period');
+import('ttTimeHelper');
 
 // Definitions for chart types.
 define('CHART_PROJECTS', 1);
@@ -77,7 +78,7 @@ class ttChartHelper {
         where l.status = 1 and l.duration > 0 and l.user_id = $user_id $q_period group by l.task_id";
     } elseif (CHART_CLIENTS == $chart_type) {
       // Data for clients.
-      $sql = "select coalesce(c.name, 'NULL') as name, sum(time_to_sec(l.duration)) as time from tt_log l
+      $sql = "select c.name as name, sum(time_to_sec(l.duration)) as time from tt_log l
         left join tt_clients c on (c.id = l.client_id)
         where l.status = 1 and l.duration > 0 and l.user_id = $user_id $q_period group by l.client_id";
     }
@@ -97,7 +98,7 @@ class ttChartHelper {
     // Add a string representation of time + percentage to names. Example: "Time Tracker (1:15 - 6%)".
     foreach ($result as &$one_val) {
       $percent = round(100*$one_val['time']/$total).'%';
-      $one_val['name'] .= ' ('.sec_to_time_fmt_hm($one_val['time']).' - '.$percent.')';
+      $one_val['name'] .= ' ('.ttTimeHelper::minutesToDuration($one_val['time'] / 60).' - '.$percent.')';
     }
 
     // Note: the remaining code here is needed to display labels on the side of the diagram.
@@ -132,4 +133,39 @@ class ttChartHelper {
 
     return $result;
   }
+
+  // adjustType - adjust chart type to something that is available for a group.
+  static function adjustType($requested_type) {
+    global $user;
+    $tracking_mode = $user->getTrackingMode();
+    $client_option = $user->isPluginEnabled('cl');
+
+    // We have 3 possible options for chart tyep: projects, tasks, or clients.
+    // Deal with each one individually.
+
+    if ($requested_type == CHART_PROJECTS) {
+      if ($tracking_mode == MODE_PROJECTS || $tracking_mode == MODE_PROJECTS_AND_TASKS)
+        return CHART_PROJECTS;
+      else if ($client_option)
+        return CHART_CLIENTS;
+    }
+
+    if ($requested_type == CHART_TASKS) {
+      if ($tracking_mode == MODE_PROJECTS_AND_TASKS)
+        return CHART_TASKS;
+      if ($tracking_mode == MODE_PROJECTS)
+        return CHART_PROJECTS;
+      else if ($client_option)
+        return CHART_CLIENTS;
+    }
+
+    if ($requested_type == CHART_CLIENTS) {
+      if ($client_option)
+        return CHART_CLIENTS;
+      else if ($tracking_mode == MODE_PROJECTS || ($tracking_mode == MODE_PROJECTS_AND_TASKS))
+        return CHART_PROJECTS;
+    }
+
+    return  CHART_PROJECTS;
+  }
 }