From f6c2f33e3183019686f07aa93ff880f3a009d6eb Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Sat, 6 Apr 2019 17:48:07 +0000 Subject: [PATCH] Started to use different icons on time.php page for records with attached files. --- WEB-INF/lib/ttTimeHelper.class.php | 47 ++++++++++++++++++++++++++++++ WEB-INF/templates/footer.tpl | 2 +- WEB-INF/templates/time.tpl | 6 +++- time.php | 6 ++-- 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/WEB-INF/lib/ttTimeHelper.class.php b/WEB-INF/lib/ttTimeHelper.class.php index b2bb2c07..a5152071 100644 --- a/WEB-INF/lib/ttTimeHelper.class.php +++ b/WEB-INF/lib/ttTimeHelper.class.php @@ -753,6 +753,53 @@ class ttTimeHelper { return $result; } + // getRecordsWithFiles - returns time records for a user for a given date + // with information whether they have attached files (has_files property). + // A separate fiunction from getRecords because sql here is more complex. + static function getRecordsWithFiles($user_id, $date) { + global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + $sql_time_format = "'%k:%i'"; // 24 hour format. + if ('%I:%M %p' == $user->getTimeFormat()) + $sql_time_format = "'%h:%i %p'"; // 12 hour format for MySQL TIME_FORMAT function. + + $client_field = null; + 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 ($user->isPluginEnabled('cl')) + $left_joins .= " left join tt_clients c on (l.client_id = c.id)"; + + $left_joins .= " left join (select distinct entity_id from tt_files". + " where entity_type = 'time' and group_id = $group_id and org_id = $org_id and status = 1) Sub1". + " on (l.id = Sub1.entity_id)"; + + $result = array(); + $sql = "select l.id as id, TIME_FORMAT(l.start, $sql_time_format) as start,". + " TIME_FORMAT(sec_to_time(time_to_sec(l.start) + time_to_sec(l.duration)), $sql_time_format) as finish,". + " TIME_FORMAT(l.duration, '%k:%i') as duration, p.name as project, t.name as task, l.comment,". + " if(Sub1.entity_id is null, 0, 1) as has_files,". + " l.billable, l.approved, l.timesheet_id, l.invoice_id $client_field from tt_log l $left_joins". + " where l.date = '$date' and l.user_id = $user_id and l.group_id = $group_id and l.org_id = $org_id and l.status = 1". + " order by l.start, l.id"; + $res = $mdb2->query($sql); + if (!is_a($res, 'PEAR_Error')) { + while ($val = $res->fetchRow()) { + if($val['duration']=='0:00') + $val['finish'] = ''; + $result[] = $val; + } + } else return false; + + return $result; + } + // canAdd determines if we can add a record in case there is a limit. static function canAdd() { $mdb2 = getConnection(); diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index da88e071..3f7bfb70 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
- {if $show_files} - + {if $record.has_files} + + {else} + + {/if} {/if}
 Anuko Time Tracker 1.18.64.4915 | Copyright © Anuko | +  Anuko Time Tracker 1.18.64.4916 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/WEB-INF/templates/time.tpl b/WEB-INF/templates/time.tpl index 1f1c7adc..e531d2b6 100644 --- a/WEB-INF/templates/time.tpl +++ b/WEB-INF/templates/time.tpl @@ -140,7 +140,11 @@ {if ($record.duration == '0:00' && $record.start <> '')}{$i18n.form.time.uncompleted}{else}{$record.duration}{/if} {if $record.comment}{$record.comment|escape}{else} {/if}{$i18n.label.files}{$i18n.label.files}{$i18n.label.files} {if $record.approved || $record.timesheet_id || $record.invoice_id} diff --git a/time.php b/time.php index e31c98ac..63f5b8cf 100644 --- a/time.php +++ b/time.php @@ -396,12 +396,14 @@ if ($request->isPost()) { } // isPost $week_total = ttTimeHelper::getTimeForWeek($selected_date); +$showFiles = $user->isPluginEnabled('at'); +$timeRecords = $showFiles? ttTimeHelper::getRecordsWithFiles($user_id, $cl_date) : ttTimeHelper::getRecords($user_id, $cl_date); $smarty->assign('selected_date', $selected_date); $smarty->assign('week_total', $week_total); $smarty->assign('day_total', ttTimeHelper::getTimeForDay($cl_date)); -$smarty->assign('time_records', ttTimeHelper::getRecords($user_id, $cl_date)); -$smarty->assign('show_files', $user->isPluginEnabled('at')); +$smarty->assign('time_records', $timeRecords); +$smarty->assign('show_files', $showFiles); $smarty->assign('client_list', $client_list); $smarty->assign('project_list', $project_list); $smarty->assign('task_list', $task_list); -- 2.20.1