X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2FttTimeHelper.class.php;h=f378d0c0a255dd5a732369b6378ba4382a3be29c;hb=11441db31dcbed7b2070e800bcb1b0e6547b86bd;hp=e1b2470fbb83cc7125f413247afb13efc187ac7e;hpb=2ae2b6401a0758b21e016148851eadea7dd3f619;p=timetracker.git diff --git a/WEB-INF/lib/ttTimeHelper.class.php b/WEB-INF/lib/ttTimeHelper.class.php index e1b2470f..f378d0c0 100644 --- a/WEB-INF/lib/ttTimeHelper.class.php +++ b/WEB-INF/lib/ttTimeHelper.class.php @@ -146,13 +146,10 @@ class ttTimeHelper { return (int)@$time_a[1] + ((int)@$time_a[0]) * 60; } - // toDuration - calculates duration between start and finish times in 00:00 format. - static function toDuration($start, $finish) { - $duration_minutes = ttTimeHelper::toMinutes($finish) - ttTimeHelper::toMinutes($start); - if ($duration_minutes <= 0) return false; - - $hours = (string)((int)($duration_minutes / 60)); - $mins = (string)($duration_minutes % 60); + // fromMinutes - converts a number of minutes to format 00:00 + static function fromMinutes($minutes){ + $hours = (string)((int)($minutes / 60)); + $mins = (string)(abs($minutes % 60)); if (strlen($hours) == 1) $hours = '0'.$hours; if (strlen($mins) == 1) @@ -160,6 +157,14 @@ class ttTimeHelper { return $hours.':'.$mins; } + // toDuration - calculates duration between start and finish times in 00:00 format. + static function toDuration($start, $finish) { + $duration_minutes = ttTimeHelper::toMinutes($finish) - ttTimeHelper::toMinutes($start); + if ($duration_minutes <= 0) return false; + + return ttTimeHelper::fromMinutes($duration_minutes); + } + // The to12HourFormat function converts a 24-hour time value (such as 15:23) to 12 hour format (03:23 PM). static function to12HourFormat($value) { if ('24:00' == $value) return '12:00 AM'; @@ -167,9 +172,9 @@ class ttTimeHelper { $time_a = explode(':', $value); if ($time_a[0] > 12) $res = (string)((int)$time_a[0] - 12).':'.$time_a[1].' PM'; - else if ($time_a[0] == 12) + elseif ($time_a[0] == 12) $res = $value.' PM'; - else if ($time_a[0] == 0) + elseif ($time_a[0] == 0) $res = '12:'.$time_a[1].' AM'; else $res = $value.' AM'; @@ -488,6 +493,21 @@ class ttTimeHelper { return 0; } + // getTimeForMonth - gets total time for a user for a given month. + static function getTimeForMonth($user_id, $date){ + import('Period'); + $mdb2 = getConnection(); + + $period = new Period(INTERVAL_THIS_MONTH, $date); + $sql = "select sum(time_to_sec(duration)) as sm from tt_log where user_id = $user_id and date >= '".$period->getBeginDate(DB_DATEFORMAT)."' and date <= '".$period->getEndDate(DB_DATEFORMAT)."' and status = 1"; + $res = $mdb2->query($sql); + if (!is_a($res, 'PEAR_Error')) { + $val = $res->fetchRow(); + return sec_to_time_fmt_hm($val['sm']); + } + return 0; + } + // getUncompleted - retrieves an uncompleted record for user, if one exists. static function getUncompleted($user_id) { $mdb2 = getConnection(); @@ -615,12 +635,12 @@ class ttTimeHelper { $mdb2 = getConnection(); $client_field = null; - if (in_array('cl', explode(',', $user->plugins))) + if ($user->isPluginEnabled('cl')) $client_field = ", c.name as client"; $left_joins = " left join tt_projects p on (l.project_id = p.id)". " left join tt_tasks t on (l.task_id = t.id)"; - if (in_array('cl', explode(',', $user->plugins))) + if ($user->isPluginEnabled('cl')) $left_joins .= " left join tt_clients c on (l.client_id = c.id)"; $sql = "select l.id as id, TIME_FORMAT(l.start, $sql_time_format) as start,