Format a duration given in seconds according to the global setting. Either
seconds are shown or not.
public static formatDuration ( $sek ) : integer | array | ||
return | integer | array | depending on the $sek param which contains the formatted duration |
function invoice_add_to_array(&$array, $row, $short_form) { global $activityIndexMap; if ($short_form && $row['type'] == 'timeSheet') { if (isset($activityIndexMap[$row['desc']])) { $index = $activityIndexMap[$row['desc']]; $totalTime = $array[$index]['hour']; $totalAmount = $array[$index]['amount']; $start = $array[$index]['start']; $end = $array[$index]['end']; $duration = $array[$index]['duration']; $array[$index] = array('type' => 'timeSheet', 'desc' => $row['desc'], 'start' => $start < $row['start'] ? $start : $row['start'], 'end' => $end > $row['end'] ? $end : $row['end'], 'hour' => $totalTime + $row['hour'], 'fDuration' => Kimai_Format::formatDuration($duration + $row['duration']), 'duration' => $duration + $row['duration'], 'timestamp' => $start < $row['start'] ? $start : $row['start'], 'amount' => $totalAmount + $row['amount'], 'description' => $row['description'], 'rate' => ($totalAmount + $row['amount']) / ($totalTime + $row['hour']), 'comment' => $row['comment'], 'username' => $row['username'], 'useralias' => $row['useralias'], 'location' => $row['location'], 'trackingNr' => $row['trackingNr'], 'projectID' => $row['projectID'], 'projectName' => $row['projectName'], 'projectComment' => $row['projectComment'], 'date' => date("m/d/Y", $row['timestamp'])); return; } else { $activityIndexMap[$row['desc']] = count($array); } } $array[] = $row; }
$success = export_expense_set_cleared(substr($id, 7), $axValue == 1); } echo $success ? 1 : 0; break; // save selected columns // save selected columns case 'toggle_header': // $axValue: header name $success = export_toggle_header($axValue); echo $success ? 1 : 0; break; // Load data and return it // Load data and return it case 'reload': $view->assign('exportData', export_get_data($in, $out, $filterUsers, $filterCustomers, $filterProjects, $filterActivities, false, $reverse_order, $default_location, $filter_cleared, $filter_type, false, $filter_refundable)); $view->assign('total', Kimai_Format::formatDuration($database->get_duration($in, $out, $filterUsers, $filterCustomers, $filterProjects, $filterActivities, $filter_cleared))); $ann = export_get_user_annotations($in, $out, $filterUsers, $filterCustomers, $filterProjects, $filterActivities); Kimai_Format::formatAnnotations($ann); $view->assign('user_annotations', $ann); $ann = export_get_customer_annotations($in, $out, $filterUsers, $filterCustomers, $filterProjects, $filterActivities); Kimai_Format::formatAnnotations($ann); $view->assign('customer_annotations', $ann); $ann = export_get_project_annotations($in, $out, $filterUsers, $filterCustomers, $filterProjects, $filterActivities); Kimai_Format::formatAnnotations($ann); $view->assign('project_annotations', $ann); $ann = export_get_activity_annotations($in, $out, $filterUsers, $filterCustomers, $filterProjects, $filterActivities); Kimai_Format::formatAnnotations($ann); $view->assign('activity_annotations', $ann); $view->assign('timeformat', $timeformat); $view->assign('dateformat', $dateformat); if (isset($kga['user'])) {
$in = $timeframe[0]; $out = $timeframe[1]; $view = new Zend_View(); $view->setBasePath(WEBROOT . 'extensions/' . $dir_ext . '/' . $dir_templates); $view->addHelperPath(WEBROOT . '/templates/helpers', 'Zend_View_Helper'); $view->assign('kga', $kga); // prevent IE from caching the response header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); // Get the total time displayed in the table. if (isset($kga['customer'])) { $total = Kimai_Format::formatDuration($database->get_duration($in, $out, null, array($kga['customer']['customerID']), null)); } else { $total = Kimai_Format::formatDuration($database->get_duration($in, $out, array($kga['user']['userID']), null, null)); } $view->assign('total', $total); // Get the array of timesheet entries. if (isset($kga['customer'])) { $timeSheetEntries = $database->get_timeSheet($in, $out, null, array($kga['customer']['customerID']), null, 1); $view->assign('latest_running_entry', null); } else { $timeSheetEntries = $database->get_timeSheet($in, $out, array($kga['user']['userID']), null, null, 1); $view->assign('latest_running_entry', $database->get_latest_running_entry()); } if (count($timeSheetEntries) > 0) { $view->assign('timeSheetEntries', $timeSheetEntries); } else { $view->assign('timeSheetEntries', 0); }
header("Pragma: no-cache"); $timeformat = 'H:M'; $dateformat = $kga->getDateFormat(1); $view->assign('timeformat', $timeformat); $view->assign('dateformat', $dateformat); echo $view->render('panel.php'); $view->assign('timeformat', preg_replace('/([A-Za-z])/', '%$1', $timeformat)); $users = null; $customers = null; if (isset($kga['customer'])) { $customers = array($kga['customer']['customerID']); } else { $users = array($kga['user']['userID']); } // Get the total amount of time shown in the table. $total = Kimai_Format::formatDuration($database->get_duration($in, $out, $users, $customers, null)); $view->assign('total', $total); $view->assign('exportData', export_get_data($in, $out, $users, $customers)); // Get the annotations for the user sub list. $userAnnotations = export_get_user_annotations($in, $out, $users, $customers); Kimai_Format::formatAnnotations($userAnnotations); $view->assign('user_annotations', $userAnnotations); // Get the annotations for the customer sub list. $customerAnnotations = export_get_customer_annotations($in, $out, $users, $customers); Kimai_Format::formatAnnotations($customerAnnotations); $view->assign('customer_annotations', $customerAnnotations); // Get the annotations for the project sub list. $projectAnnotations = export_get_project_annotations($in, $out, $users, $customers); Kimai_Format::formatAnnotations($projectAnnotations); $view->assign('project_annotations', $projectAnnotations); // Get the annotations for the activity sub list.
/** * returns timesheet for specific user as multidimensional array * * @param integer $start start of timeframe in unix seconds * @param integer $end end of timeframe in unix seconds * @param array $users * @param array $customers * @param array $projects * @param array $activities * @param bool $limit * @param bool $reverse_order * @param integer $filterCleared where -1 (default) means no filtering, 0 means only not cleared entries, 1 means only cleared entries * @param int $startRows * @param int $limitRows * @param bool $countOnly * @return array * @author th */ public function get_timeSheet($start, $end, $users = null, $customers = null, $projects = null, $activities = null, $limit = false, $reverse_order = false, $filterCleared = null, $startRows = 0, $limitRows = 0, $countOnly = false) { // -1 for disabled, 0 for only not cleared entries if (!is_numeric($filterCleared)) { $filterCleared = -1; if ($this->kga->getSettings()->isHideClearedEntries()) { $filterCleared = 0; } } $start = MySQL::SQLValue($start, MySQL::SQLVALUE_NUMBER); $end = MySQL::SQLValue($end, MySQL::SQLVALUE_NUMBER); $filterCleared = MySQL::SQLValue($filterCleared, MySQL::SQLVALUE_NUMBER); $limit = MySQL::SQLValue($limit, MySQL::SQLVALUE_BOOLEAN); $p = $this->kga['server_prefix']; $whereClauses = $this->timeSheet_whereClausesFromFilters($users, $customers, $projects, $activities); if (isset($this->kga['customer'])) { $whereClauses[] = "project.internal = 0"; } if ($start) { $whereClauses[] = "(end > {$start} || end = 0)"; } if ($end) { $whereClauses[] = "start < {$end}"; } if ($filterCleared > -1) { $whereClauses[] = "cleared = {$filterCleared}"; } if ($limit) { if (!empty($limitRows)) { $startRows = (int) $startRows; $limit = "LIMIT {$startRows}, {$limitRows}"; } else { $limit = "LIMIT " . $this->kga->getSettings()->getRowLimit(); } } else { $limit = ""; } $select = "SELECT timeSheet.*, status.status, customer.name AS customerName, customer.customerID as customerID, activity.name AS activityName,\n project.name AS projectName, project.comment AS projectComment, user.name AS userName, user.alias AS userAlias "; if ($countOnly) { $select = "SELECT COUNT(*) AS total"; $limit = ""; } $query = "{$select}\n FROM {$p}timeSheet AS timeSheet\n JOIN {$p}projects AS project USING (projectID)\n JOIN {$p}customers AS customer USING (customerID)\n JOIN {$p}users AS user USING(userID)\n JOIN {$p}statuses AS status USING(statusID)\n JOIN {$p}activities AS activity USING(activityID) " . (count($whereClauses) > 0 ? " WHERE " : " ") . implode(" AND ", $whereClauses) . ' ORDER BY start ' . ($reverse_order ? 'ASC ' : 'DESC ') . $limit . ';'; $result = $this->conn->Query($query); if ($result === false) { $this->logLastError('get_timeSheet'); } if ($countOnly) { $this->conn->MoveFirst(); $row = $this->conn->Row(); return $row->total; } $i = 0; $arr = array(); $this->conn->MoveFirst(); while (!$this->conn->EndOfSeek()) { $row = $this->conn->Row(); $arr[$i]['timeEntryID'] = $row->timeEntryID; // Start time should not be less than the selected start time. This would confuse the user. if ($start && $row->start <= $start) { $arr[$i]['start'] = $start; } else { $arr[$i]['start'] = $row->start; } // End time should not be less than the selected start time. This would confuse the user. if ($end && $row->end >= $end) { $arr[$i]['end'] = $end; } else { $arr[$i]['end'] = $row->end; } if ($row->end != 0) { // only calculate time after recording is complete $arr[$i]['duration'] = $arr[$i]['end'] - $arr[$i]['start']; $arr[$i]['formattedDuration'] = Kimai_Format::formatDuration($arr[$i]['duration']); $arr[$i]['wage_decimal'] = $arr[$i]['duration'] / 3600 * $row->rate; $fixedRate = (double) $row->fixedRate; if ($fixedRate) { $arr[$i]['wage'] = sprintf("%01.2f", $fixedRate); } else { $arr[$i]['wage'] = sprintf("%01.2f", $arr[$i]['wage_decimal']); } } else { $arr[$i]['duration'] = null; $arr[$i]['formattedDuration'] = null; $arr[$i]['wage_decimal'] = null; $arr[$i]['wage'] = null; } $arr[$i]['budget'] = $row->budget; $arr[$i]['approved'] = $row->approved; $arr[$i]['rate'] = $row->rate; $arr[$i]['projectID'] = $row->projectID; $arr[$i]['activityID'] = $row->activityID; $arr[$i]['userID'] = $row->userID; $arr[$i]['customerName'] = $row->customerName; $arr[$i]['customerID'] = $row->customerID; $arr[$i]['activityName'] = $row->activityName; $arr[$i]['projectName'] = $row->projectName; $arr[$i]['projectComment'] = $row->projectComment; $arr[$i]['location'] = $row->location; $arr[$i]['trackingNumber'] = $row->trackingNumber; $arr[$i]['statusID'] = $row->statusID; $arr[$i]['status'] = $row->status; $arr[$i]['billable'] = $row->billable; $arr[$i]['description'] = $row->description; $arr[$i]['comment'] = $row->comment; $arr[$i]['cleared'] = $row->cleared; $arr[$i]['commentType'] = $row->commentType; $arr[$i]['userAlias'] = $row->userAlias; $arr[$i]['userName'] = $row->userName; $i++; } return $arr; }
} $invoiceArray[$time_index]['hour'] = $rounded; $invoiceArray[$time_index]['amount'] = $invoiceArray[$time_index]['hour'] * $rate; } $time_index++; } } // calculate invoice sums $ttltime = 0; $rawTotalTime = 0; $total = 0; while (list($id, $fd) = each($invoiceArray)) { $total += $invoiceArray[$id]['amount']; $ttltime += $invoiceArray[$id]['hour']; } $fttltime = Kimai_Format::formatDuration($ttltime * 3600); // sort invoice entries if (isset($_REQUEST['sort_invoice'])) { switch ($_REQUEST['sort_invoice']) { case 'date_asc': uasort($invoiceArray, 'ext_invoice_sort_by_date_asc'); break; case 'date_desc': uasort($invoiceArray, 'ext_invoice_sort_by_date_desc'); break; case 'name': uasort($invoiceArray, 'ext_invoice_sort_by_name'); break; } } $vat_rate = $customer['vat'];
$wd = $kga['lang']['weekdays_short'][date("w", time())]; $dp_start = 0; if ($kga['calender_start'] != "") { $dp_start = $kga['calender_start']; } else { if (isset($kga['user'])) { $dp_start = date("d/m/Y", $database->getjointime($kga['user']['userID'])); } } $dp_today = date("d/m/Y", time()); $view->assign('dp_start', $dp_start); $view->assign('dp_today', $dp_today); if (isset($kga['customer'])) { $view->assign('total', Kimai_Format::formatDuration($database->get_duration($in, $out, null, array($kga['customer']['customerID'])))); } else { $view->assign('total', Kimai_Format::formatDuration($database->get_duration($in, $out, $kga['user']['userID']))); } // =========================== // = DatePicker localization = // =========================== $localized_DatePicker = ""; $view->assign('weekdays_array', sprintf("['%s','%s','%s','%s','%s','%s','%s']\n", $kga['lang']['weekdays'][0], $kga['lang']['weekdays'][1], $kga['lang']['weekdays'][2], $kga['lang']['weekdays'][3], $kga['lang']['weekdays'][4], $kga['lang']['weekdays'][5], $kga['lang']['weekdays'][6])); $view->assign('weekdays_short_array', sprintf("['%s','%s','%s','%s','%s','%s','%s']\n", $kga['lang']['weekdays_short'][0], $kga['lang']['weekdays_short'][1], $kga['lang']['weekdays_short'][2], $kga['lang']['weekdays_short'][3], $kga['lang']['weekdays_short'][4], $kga['lang']['weekdays_short'][5], $kga['lang']['weekdays_short'][6])); $view->assign('months_array', sprintf("['%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s']\n", $kga['lang']['months'][0], $kga['lang']['months'][1], $kga['lang']['months'][2], $kga['lang']['months'][3], $kga['lang']['months'][4], $kga['lang']['months'][5], $kga['lang']['months'][6], $kga['lang']['months'][7], $kga['lang']['months'][8], $kga['lang']['months'][9], $kga['lang']['months'][10], $kga['lang']['months'][11])); $view->assign('months_short_array', sprintf("['%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s']", $kga['lang']['months_short'][0], $kga['lang']['months_short'][1], $kga['lang']['months_short'][2], $kga['lang']['months_short'][3], $kga['lang']['months_short'][4], $kga['lang']['months_short'][5], $kga['lang']['months_short'][6], $kga['lang']['months_short'][7], $kga['lang']['months_short'][8], $kga['lang']['months_short'][9], $kga['lang']['months_short'][10], $kga['lang']['months_short'][11])); // assign view placeholders $view->assign('current_timer_hour', $current_timer['hour']); $view->assign('current_timer_min', $current_timer['min']); $view->assign('current_timer_sec', $current_timer['sec']); $view->assign('current_timer_start', $current_timer['all'] ? $current_timer['all'] : time()); $view->assign('current_time', time());