+// Get the data we need to display week view.
+// Get column headers, which are day numbers in month.
+$dayHeaders = ttTimeHelper::getDayHeadersForWeek($startDate->toString(DB_DATEFORMAT));
+$lockedDays = ttTimeHelper::getLockedDaysForWeek($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), $dayHeaders);
+// Build day totals (total durations for each day in week).
+$dayTotals = ttTimeHelper::getDayTotals($dataArray, $dayHeaders);
+
+// TODO: refactoring ongoing down from here.
+
+// 1) Handle editable - not editable records properly meaning that UI should reflect this.
+// 2) Start coding modification of existing records.
+// 3) Then adding new records for existing rows.
+// 4) 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.
+
+// 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 escapes HTML for output.
+ return $this->toString();
+ }
+}
+
+// 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)['control_id']; // Our text field names (and ids) are like x_y (row_column).
+ $field = new TextField($field_name);
+ // Disable control if the date is locked.
+ global $lockedDays;
+ if ($lockedDays[$column-1])
+ $field->setEnabled(false);
+ $field->setFormName($table->getFormName());
+ $field->setSize(2);
+ $field->setValue($table->getValueAt($row,$column)['duration']);
+ $this->setValue($field->getHtml());
+ return $this->toString();
+ }
+}
+
+// Elements of weekTimeForm.
+$form = new Form('weekTimeForm');