From 7e9b290b40c6f9f2efe6a7e28fae630bdffeca1e Mon Sep 17 00:00:00 2001 From: anuko Date: Wed, 27 Dec 2017 17:06:35 +0000 Subject: [PATCH] Added proper IDs to week view controls. --- WEB-INF/lib/ttTimeHelper.class.php | 29 +++++++++++++++++------------ WEB-INF/templates/footer.tpl | 2 +- week.php | 23 ++++++++++------------- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/WEB-INF/lib/ttTimeHelper.class.php b/WEB-INF/lib/ttTimeHelper.class.php index 67590c15..60ebe446 100644 --- a/WEB-INF/lib/ttTimeHelper.class.php +++ b/WEB-INF/lib/ttTimeHelper.class.php @@ -767,7 +767,7 @@ class ttTimeHelper { // 'day_6' => array('control_id' => '1_day_6', 'duration' => null) // ) // ); - static function getDataForWeekView($user_id, $start_date, $end_date) { + static function getDataForWeekView($user_id, $start_date, $end_date, $dayHeaders) { // Start by obtaining all records in interval. $records = ttTimeHelper::getRecordsForInterval($user_id, $start_date, $end_date); @@ -790,9 +790,14 @@ class ttTimeHelper { if ($pos < 0) { $dataArray[] = array('row_id' => $record_id,'label' => ttTimeHelper::makeRecordLabel($record)); // Insert row. $pos = ttTimeHelper::findRow($record_id, $dataArray); + // Insert empty cells with proper control ids. + for ($i = 0; $i < 7; $i++) { + $control_id = $pos.'_'. $dayHeaders[$i]; + $dataArray[$pos][$dayHeaders[$i]] = array('control_id' => $control_id, 'tt_log_id' => null,'duration' => null); + } } - // Insert cell data from $record. - $dataArray[$pos][$day_header] = array('id' => $record['id'],'duration' => $record['duration']); + // Insert actual cell data from $record (one cell only). + $dataArray[$pos][$day_header] = array('control_id' => $pos.'_'. $day_header, 'tt_log_id' => $record['id'],'duration' => $record['duration']); } return $dataArray; } @@ -878,21 +883,21 @@ class ttTimeHelper { 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. - if (strlen($dayHeaders['day_header_0']) == 1) // Which is an implementation detail of DateAndTime class. - $dayHeaders['day_header_0'] = '0'.$dayHeaders['day_header_0']; // Add a 0 for single digit day. + $dayHeaders[] = (string) $objDate->getDate(); // It returns an int on first call. + if (strlen($dayHeaders[0]) == 1) // Which is an implementation detail of DateAndTime class. + $dayHeaders[0] = '0'.$dayHeaders[0]; // Add a 0 for single digit day. $objDate->incDay(); - $dayHeaders['day_header_1'] = $objDate->getDate(); // After incDay it returns a string with leading 0, when necessary. + $dayHeaders[] = $objDate->getDate(); // After incDay it returns a string with leading 0, when necessary. $objDate->incDay(); - $dayHeaders['day_header_2'] = $objDate->getDate(); + $dayHeaders[] = $objDate->getDate(); $objDate->incDay(); - $dayHeaders['day_header_3'] = $objDate->getDate(); + $dayHeaders[] = $objDate->getDate(); $objDate->incDay(); - $dayHeaders['day_header_4'] = $objDate->getDate(); + $dayHeaders[] = $objDate->getDate(); $objDate->incDay(); - $dayHeaders['day_header_5'] = $objDate->getDate(); + $dayHeaders[] = $objDate->getDate(); $objDate->incDay(); - $dayHeaders['day_header_6'] = $objDate->getDate(); + $dayHeaders[] = $objDate->getDate(); unset($objDate); return $dayHeaders; } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 3febef8e..494880d0 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.13.0.3698 | Copyright © Anuko | +  Anuko Time Tracker 1.13.0.3699 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/week.php b/week.php index f7f42f7c..fa791504 100644 --- a/week.php +++ b/week.php @@ -110,23 +110,24 @@ $_SESSION['task'] = $cl_task; // Get column headers, which are day numbers in month. $dayHeaders = ttTimeHelper::getDayHeadersForWeek($startDate->toString(DB_DATEFORMAT)); // Build data array for the table. Format is described in the function.. -$dataArray = ttTimeHelper::getDataForWeekView($user->getActiveUser(), $startDate->toString(DB_DATEFORMAT), $endDate->toString(DB_DATEFORMAT)); +$dataArray = ttTimeHelper::getDataForWeekView($user->getActiveUser(), $startDate->toString(DB_DATEFORMAT), $endDate->toString(DB_DATEFORMAT), $dayHeaders); // Build day totals (total durations for each day in week). $dayTotals = ttTimeHelper::getDayTotals($dataArray, $dayHeaders); // TODO: refactoring ongoing down from here. +// 1) Start coding modification of existing records. +// 2) Then adding new records for existing rows. +// 3) Then add code and UI for adding a new row. + // Actually this is work in progress at this point, even documenting the array, as we still miss control IDs, and // editing entries is not yet implemented. When this is done, we will have to re-document the above. -// TODO: -// 1) make sure we have IDs for cells, which are now missing. - // Define rendering class for a label field to the left of durations. class LabelCellRenderer extends DefaultCellRenderer { function render(&$table, $value, $row, $column, $selected = false) { $this->setOptions(array('width'=>200,'valign'=>'middle')); - $this->setValue(htmlspecialchars($value)); + $this->setValue(htmlspecialchars($value)); // This escapes HTML for output. return $this->toString(); } } @@ -134,7 +135,7 @@ class LabelCellRenderer extends DefaultCellRenderer { // Define rendering class for a single cell for time entry in week view table. class TimeCellRenderer extends DefaultCellRenderer { function render(&$table, $value, $row, $column, $selected = false) { - $field_name = $table->getValueAt($row,$column)['id']; // Our text field names (and ids) are like x_y (row_column). + $field_name = $table->getValueAt($row,$column)['control_id']; // Our text field names (and ids) are like x_y (row_column). $field = new TextField($field_name); $field->setFormName($table->getFormName()); $field->setSize(2); @@ -169,13 +170,9 @@ $table->setRowOptions(array('class'=>'tableHeaderCentered')); $table->setData($dataArray); // Add columns to table. $table->addColumn(new TableColumn('label', '', new LabelCellRenderer(), $dayTotals['label'])); -$table->addColumn(new TableColumn($dayHeaders['day_header_0'], $dayHeaders['day_header_0'], new TimeCellRenderer(), $dayTotals[$dayHeaders['day_header_0']])); -$table->addColumn(new TableColumn($dayHeaders['day_header_1'], $dayHeaders['day_header_1'], new TimeCellRenderer(), $dayTotals[$dayHeaders['day_header_1']])); -$table->addColumn(new TableColumn($dayHeaders['day_header_2'], $dayHeaders['day_header_2'], new TimeCellRenderer(), $dayTotals[$dayHeaders['day_header_2']])); -$table->addColumn(new TableColumn($dayHeaders['day_header_3'], $dayHeaders['day_header_3'], new TimeCellRenderer(), $dayTotals[$dayHeaders['day_header_3']])); -$table->addColumn(new TableColumn($dayHeaders['day_header_4'], $dayHeaders['day_header_4'], new TimeCellRenderer(), $dayTotals[$dayHeaders['day_header_4']])); -$table->addColumn(new TableColumn($dayHeaders['day_header_5'], $dayHeaders['day_header_5'], new TimeCellRenderer(), $dayTotals[$dayHeaders['day_header_5']])); -$table->addColumn(new TableColumn($dayHeaders['day_header_6'], $dayHeaders['day_header_6'], new TimeCellRenderer(), $dayTotals[$dayHeaders['day_header_6']])); +for ($i = 0; $i < 7; $i++) { + $table->addColumn(new TableColumn($dayHeaders[$i], $dayHeaders[$i], new TimeCellRenderer(), $dayTotals[$dayHeaders[$i]])); +} $table->setInteractive(false); $form->addInputElement($table); -- 2.20.1