// '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);
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;
}
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;
}
// 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();
}
}
// 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);
$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);