From ee5e708bbc30bbca24d77c4e3b0e75214c1296f8 Mon Sep 17 00:00:00 2001 From: anuko Date: Sat, 6 Jan 2018 16:36:04 +0000 Subject: [PATCH] More refactoring of week view related stuff. --- WEB-INF/lib/ttTimeHelper.class.php | 28 ---------------- WEB-INF/lib/ttWeekViewHelper.class.php | 44 +++++++++++++++++++++----- WEB-INF/templates/footer.tpl | 2 +- week.php | 2 +- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/WEB-INF/lib/ttTimeHelper.class.php b/WEB-INF/lib/ttTimeHelper.class.php index 5a868364..e7491904 100644 --- a/WEB-INF/lib/ttTimeHelper.class.php +++ b/WEB-INF/lib/ttTimeHelper.class.php @@ -746,34 +746,6 @@ class ttTimeHelper { 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; - } - // getDayTotals calculates total durations for each day from the existing data in $dataArray. static function getDayTotals($dataArray, $dayHeaders) { $dayTotals = array(); diff --git a/WEB-INF/lib/ttWeekViewHelper.class.php b/WEB-INF/lib/ttWeekViewHelper.class.php index 48809703..7031dab7 100644 --- a/WEB-INF/lib/ttWeekViewHelper.class.php +++ b/WEB-INF/lib/ttWeekViewHelper.class.php @@ -110,7 +110,7 @@ class ttWeekViewHelper { // 'day_6' => array('control_id' => '0_day_6', 'tt_log_id' => null, 'duration' => null) // ), // array( // Row 1. - // 'row_id' => 'cl:546,bl:1,pr:23456,ts:27464,cf_1:7623_0', // Row identifier. See ttTimeHelper::makeRecordIdentifier(). + // 'row_id' => 'cl:546,bl:1,pr:23456,ts:27464,cf_1:7623_0', // Row identifier. See ttWeekViewHelper::makeRowIdentifier(). // 'label' => 'Anuko - Time Tracker - Coding', // Human readable label for the row describing what this time entry is for. // 'day_0' => array('control_id' => '1_day_0', 'tt_log_id' => 12345, 'duration' => '00:00'), // control_id is row_id plus day header for column. // 'day_1' => array('control_id' => '1_day_1', 'tt_log_id' => 12346, 'duration' => '01:00'), @@ -151,20 +151,20 @@ class ttWeekViewHelper { // Iterate through records and build $dataArray cell by cell. foreach ($records as $record) { // Create record id without suffix. - $record_id_no_suffix = ttTimeHelper::makeRecordIdentifier($record); + $row_id_no_suffix = ttWeekViewHelper::makeRowIdentifier($record); // Handle potential multiple records with the same attributes by using a numerical suffix. $suffix = 0; - $record_id = $record_id_no_suffix.'_'.$suffix; + $row_id = $row_id_no_suffix.'_'.$suffix; $day_header = substr($record['date'], 8); // Day number in month. - while (ttTimeHelper::cellExists($record_id, $day_header, $dataArray)) { + while (ttTimeHelper::cellExists($row_id, $day_header, $dataArray)) { $suffix++; - $record_id = $record_id_no_suffix.'_'.$suffix; + $row_id = $row_id_no_suffix.'_'.$suffix; } // Find row. - $pos = ttTimeHelper::findRow($record_id, $dataArray); + $pos = ttTimeHelper::findRow($row_id, $dataArray); if ($pos < 0) { - $dataArray[] = array('row_id' => $record_id,'label' => ttWeekViewHelper::makeRowLabel($record)); // Insert row. - $pos = ttTimeHelper::findRow($record_id, $dataArray); + $dataArray[] = array('row_id' => $row_id,'label' => ttWeekViewHelper::makeRowLabel($record)); // Insert row. + $pos = ttTimeHelper::findRow($row_id, $dataArray); // Insert empty cells with proper control ids. for ($i = 0; $i < 7; $i++) { $control_id = $pos.'_'. $dayHeaders[$i]; @@ -213,6 +213,34 @@ class ttWeekViewHelper { return $lockedDays; } + // makeRowIdentifier - builds a string identifying a row for a week view from a single record properties. + // Note that the return value is without a suffix. + // 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" + static function makeRowIdentifier($record) { + global $user; + // Start with client. + if ($user->isPluginEnabled('cl')) + $row_identifier = $record['client_id'] ? 'cl:'.$record['client_id'] : ''; + // Add billable flag. + if (!empty($row_identifier)) $row_identifier .= ','; + $row_identifier .= 'bl:'.$record['billable']; + // Add project. + $row_identifier .= $record['project_id'] ? ',pr:'.$record['project_id'] : ''; + // Add task. + $row_identifier .= $record['task_id'] ? ',ts:'.$record['task_id'] : ''; + // Add custom field 1. + if ($user->isPluginEnabled('cf')) { + if ($record['cf_1_id']) + $row_identifier .= ',cf_1:'.$record['cf_1_id']; + else if ($record['cf_1_value']) + $row_identifier .= ',cf_1:'.$record['cf_1_value']; + } + + return $row_identifier; + } + // makeRowLabel - builds a human readable label for a row in week view, // which is a combination ot record properties. // Client - Project - Task - Custom field 1. diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index e7472249..cb4b19b3 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.13.7.3724 | Copyright © Anuko | +  Anuko Time Tracker 1.13.7.3725 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/week.php b/week.php index c10dfca0..f4bde294 100644 --- a/week.php +++ b/week.php @@ -353,7 +353,7 @@ if ($request->isPost()) { $record['project_id'] = $cl_project; $record['task_id'] = $cl_task; $record['cf_1_value'] = $cl_cf_1; - $fields['row_id'] = ttTimeHelper::makeRecordIdentifier($record).'_0'; // TODO: Handle a possible conflict with already existing row... + $fields['row_id'] = ttWeekViewHelper::makeRowIdentifier($record).'_0'; // TODO: Handle a possible conflict with already existing row... // We may have to increment the suffix here. $fields['note'] = $cl_note; } -- 2.20.1