Added proper IDs to week view controls.
authoranuko <support@anuko.com>
Wed, 27 Dec 2017 17:06:35 +0000 (17:06 +0000)
committeranuko <support@anuko.com>
Wed, 27 Dec 2017 17:06:35 +0000 (17:06 +0000)
WEB-INF/lib/ttTimeHelper.class.php
WEB-INF/templates/footer.tpl
week.php

index 67590c1..60ebe44 100644 (file)
@@ -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;
   }
index 3febef8..494880d 100644 (file)
@@ -12,7 +12,7 @@
       <br>
       <table cellspacing="0" cellpadding="4" width="100%" border="0">
         <tr>
-          <td align="center">&nbsp;Anuko Time Tracker 1.13.0.3698 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.13.0.3699 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
             <a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
             <a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
             <a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>
index f7f42f7..fa79150 100644 (file)
--- 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);