-
- // findRow returns an existing row position in $dataArray, -1 otherwise.
- static function findRow($record_id, $dataArray) {
- $pos = 0; // Row position in array.
- foreach($dataArray as $row) {
- if ($row['id'] == $record_id)
- return $pos;
- $pos++; // Increment for search.
- }
- return -1; // Row not found.
- }
-
- // makeRecordIdentifier - builds a string identifying a record for a grouped display (such as a week view).
- // For example:
- // "cl:546,bl:0,pr:23456,ts:27464,cf_1:example text"
- // "cl:546,bl:1,pr:23456,ts:27464,cf_1:7623"
- // See comment for getGroupedRecordsForInterval.
- static function makeRecordIdentifier($record) {
- global $user;
- // Start with client.
- if ($user->isPluginEnabled('cl'))
- $record_identifier = $record['client_id'] ? 'cl'.$record['client_id'] : '';
- // Add billable flag.
- if (!empty($record_identifier)) $record_identifier .= ',';
- $record_identifier .= 'bl:'.$record['billable'];
- // Add project.
- $record_identifier .= $record['project_id'] ? ',pr:'.$record['project_id'] : '';
- // Add task.
- $record_identifier .= $record['task_id'] ? ',ts:'.$record['task_id'] : '';
- // Add custom field 1. This requires modifying the query to get the data we need.
- if ($user->isPluginEnabled('cf')) {
- if ($record['cf_1_id'])
- $record_identifier .= ',cf_1:'.$record['cf_1_id'];
- else if ($record['cf_1_value'])
- $record_identifier .= ',cf_1:'.$record['cf_1_value'];
- }
-
- return $record_identifier;
- }
-
- // makeRecordLabel - builds a human readable label for a row in week view,
- // which is a combination ot record properties.
- // Client - Project - Task - Custom field 1.
- // Note that billable property is not part of the label. Instead, we intend to
- // identify such records with a different color in week view.
- static function makeRecordLabel($record) {
- // TODO: debug this function.
- global $user;
- // Start with client.
- if ($user->isPluginEnabled('cl'))
- $label = $record['client'];
-
- // Add project.
- $project = $record['project'] ? $record['project'] : '';
- if (!empty($label)) $label .= ' - ';
- $label .= $project;
-
- // Add task.
- $task = $record['task'] ? $record['task'] : '';
- if (!empty($label)) $label .= ' - ';
- $label .= $task;
-
- // Add custom field 1.
- if ($user->isPluginEnabled('cf')) {
- if ($record['cf_1_value']) {
- if (!empty($label)) $label .= ' - ';
- $label .= $record['cf_1_value'];
- }
- }
-
- return $label;
- }
-
- // getGroupedRecordsTotals - returns day totals for grouped records.
- static function getGroupedRecordsTotals($groupedRecords) {
- $groupedRecordsTotals = array();
- foreach ($groupedRecords as $groupedRecord) {
- foreach($groupedRecord as $key => $dayEntry) {
- if ($dayEntry['duration']) {
- $minutes = ttTimeHelper::toMinutes($dayEntry['duration']);
- $groupedRecordsTotals[$key] += $minutes;
- }
- }
- }
- // Convert minutes to hh:mm for display.
- foreach ($groupedRecordsTotals as $key => $single_total) {
- $groupedRecordsTotals[$key] = ttTimeHelper::toAbsDuration($single_total);
- }
-
- return $groupedRecordsTotals;
- }
-
- // getDayHeadersForWeek - obtains day column headers for week view, which are simply day numbers in month.
- static function getDayHeadersForWeek($start_date) {
- $dayHeaders = array();
- $objDate = new DateAndTime(DB_DATEFORMAT, $start_date);
- $dayHeaders['day_header_0'] = (string)$objDate->getDate(); // It returns an int on first call. Why?
- $objDate->incDay();
- $dayHeaders['day_header_1'] = $objDate->getDate();
- $objDate->incDay();
- $dayHeaders['day_header_2'] = $objDate->getDate();
- $objDate->incDay();
- $dayHeaders['day_header_3'] = $objDate->getDate();
- $objDate->incDay();
- $dayHeaders['day_header_4'] = $objDate->getDate();
- $objDate->incDay();
- $dayHeaders['day_header_5'] = $objDate->getDate();
- $objDate->incDay();
- $dayHeaders['day_header_6'] = $objDate->getDate();
- unset($objDate);
- return $dayHeaders;
- }
-
- // getDayTotals calculates total durations for each day from the existing data in $dataArray.
- static function getDayTotals($dataArray, $dayHeaders) {
- $dayTotals = array();
-
- // Insert label.
- global $i18n;
- $dayTotals['label'] = $i18n->getKey('label.total');
-
- foreach ($dataArray as $row) {
- foreach($dayHeaders as $dayHeader) {
- if (array_key_exists($dayHeader, $row)) {
- $minutes = ttTimeHelper::toMinutes($row[$dayHeader]['duration']);
- $dayTotals[$dayHeader] += $minutes;
- }
- }
- }
- // Convert minutes to hh:mm for display.
- foreach($dayHeaders as $dayHeader) {
- $dayTotals[$dayHeader] = ttTimeHelper::toAbsDuration($dayTotals[$dayHeader]);
- }
- return $dayTotals;
- }