X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=WEB-INF%2Flib%2FttChartHelper.class.php;h=31d35e3fd60f7be24320c4ebcd6f2b4d8202d294;hb=9c1005341a3db52333fcb732960acbdf03fbe4e7;hp=7a4d25843258ccf0c2cf2371a8e1ce35b7647340;hpb=9af5722a81d1999243ac3a3d51d3cf3c3256d86a;p=timetracker.git diff --git a/WEB-INF/lib/ttChartHelper.class.php b/WEB-INF/lib/ttChartHelper.class.php index 7a4d2584..31d35e3f 100644 --- a/WEB-INF/lib/ttChartHelper.class.php +++ b/WEB-INF/lib/ttChartHelper.class.php @@ -27,6 +27,7 @@ // +----------------------------------------------------------------------+ import('Period'); +import('ttTimeHelper'); // Definitions for chart types. define('CHART_PROJECTS', 1); @@ -69,23 +70,24 @@ class ttChartHelper { // Data for projects. $sql = "select p.name as name, sum(time_to_sec(l.duration)) as time from tt_log l left join tt_projects p on (p.id = l.project_id) - where l.status = 1 and l.duration > 0 and l.user_id = $user_id $q_period group by l.project_id"; + where l.status = 1 and l.user_id = $user_id $q_period group by l.project_id"; } elseif (CHART_TASKS == $chart_type) { // Data for tasks. $sql = "select t.name as name, sum(time_to_sec(l.duration)) as time from tt_log l left join tt_tasks t on (t.id = l.task_id) - where l.status = 1 and l.duration > 0 and l.user_id = $user_id $q_period group by l.task_id"; + where l.status = 1 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"; + where l.status = 1 and l.user_id = $user_id $q_period group by l.client_id"; } $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { while ($val = $res->fetchRow()) { - $result[] = array('name'=>$val['name'],'time'=>$val['time']); // name - project name, time - total for project in seconds. + if ($val['time'] >= 0) // Only positive totals make sense in pie charts. Skip negatives entirely. + $result[] = array('name'=>$val['name'],'time'=>$val['time']); // name - project name, time - total for project in seconds. } } @@ -97,7 +99,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. @@ -139,7 +141,7 @@ class ttChartHelper { $tracking_mode = $user->getTrackingMode(); $client_option = $user->isPluginEnabled('cl'); - // We have 3 possible options for chart tyep: projects, tasks, or clients. + // We have 3 possible options for chart type: projects, tasks, or clients. // Deal with each one individually. if ($requested_type == CHART_PROJECTS) {