return $result;
}
- // getGroupedRecordsForInterval - returns time records for a user for a given interval of dates grouped in an array of dates.
- // Example: for a week view we want one row representing the same attributes to have 7 values for each day of week.
+ // getDataForWeekView - builds an array to render a table of durations for week view.
+ // In a week view we want one row representing the same attributes to have 7 values for each day of week.
// We identify simlar records by a combination of client, billable, project, task, and custom field values.
// This will allow us to extend the feature when more custom fields are added.
//
//
// "cl:546,bl:0,pr:23456,ts:27464,cf_1:7623"
// The above means client 546, not billable, project 23456, task 27464, custom field option id 7623.
- static function getGroupedRecordsForInterval($user_id, $start_date, $end_date) {
- // Start by obtaining all records in interval.
- // Then, iterate through them to build an array.
- $records = ttTimeHelper::getRecordsForInterval($user_id, $start_date, $end_date);
- $groupedRecords = array();
- foreach ($records as $record) {
- $record_identifier_no_suffix = ttTimeHelper::makeRecordIdentifier($record);
- // Handle potential multiple records with the same attributes by using a numerical suffix.
- $suffix = 0;
- $record_identifier = $record_identifier_no_suffix.'_'.$suffix;
- while (!empty($groupedRecords[$record_identifier][$record['date']])) {
- $suffix++;
- $record_identifier = $record_identifier_no_suffix.'_'.$suffix;
- }
- $groupedRecords[$record_identifier][$record['date']] = array('id'=>$record['id'], 'duration'=>$record['duration']);
- $groupedRecords[$record_identifier]['client'] = $record['client'];
- $groupedRecords[$record_identifier]['cf_1_value'] = $record['cf_1_value'];
- $groupedRecords[$record_identifier]['project'] = $record['project'];
- $groupedRecords[$record_identifier]['task'] = $record['task'];
- $groupedRecords[$record_identifier]['billable'] = $record['billable'];
- }
-
- return $groupedRecords;
- }
-
- // getDataForWeekView - builds an array to render a table of durations for week view.
+ //
+ // Description of $dataArray format that the function returns.
+ // $dataArray = array(
+ // array( // Row 0.
+ // 'id' => 'cl:546,bl:1,pr:23456,ts:27464,cf_1:7623', // Record identifier. See ttTimeHelper::makeRecordIdentifier().
+ // 'label' => 'Anuko - Time Tracker - Coding', // Human readable label for the row describing what this time entry is for.
+ // 'day_0' => array('id' => '0_0', 'duration' => '00:00'),
+ // 'day_1' => array('id' => '0_1', 'duration' => '01:00'),
+ // 'day_2' => array('id' => '0_2', 'duration' => '02:00'),
+ // 'day_3' => array('id' => '0_3', 'duration' => null),
+ // 'day_4' => array('id' => '0_4', 'duration' => '04:00')
+ // ),
+ // array( // Row 1.
+ // 'id' => 'bl:0',
+ // 'label' => '', // In this case the label is empty as we don't have anything to put in, only not billable flag.
+ // 'day_0' => array('id' => '1_0', 'duration' => '00:30'),
+ // 'day_1' => array('id' => '1_1', 'duration' => '01:30'),
+ // 'day_2' => array('id' => '1_2', 'duration' => '02:30'),
+ // )
+ // );
static function getDataForWeekView($user_id, $start_date, $end_date) {
// Start by obtaining all records in interval.
$records = ttTimeHelper::getRecordsForInterval($user_id, $start_date, $end_date);
return $label;
}
- // getGroupedRecordsTotals - returns day totals for grouped records.
- static function getGroupedRecordsTotals($groupedRecords) {
- $groupedRecordsTotals = array();
- foreach ($groupedRecords as $groupedRecord) {
- foreach($groupedRecord as $key => $dayEntry) {
- if ($dayEntry['duration']) {
- $minutes = ttTimeHelper::toMinutes($dayEntry['duration']);
- $groupedRecordsTotals[$key] += $minutes;
- }
- }
- }
- // Convert minutes to hh:mm for display.
- foreach ($groupedRecordsTotals as $key => $single_total) {
- $groupedRecordsTotals[$key] = ttTimeHelper::toAbsDuration($single_total);
- }
-
- return $groupedRecordsTotals;
- }
-
// getDayHeadersForWeek - obtains day column headers for week view, which are simply day numbers in month.
static function getDayHeadersForWeek($start_date) {
$dayHeaders = array();
$cl_task = $request->getParameter('task', ($request->getMethod()=='POST'? null : @$_SESSION['task']));
$_SESSION['task'] = $cl_task;
+// 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));
+// 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));
+// Build day totals (total durations for each day in week).
+$dayTotals = ttTimeHelper::getDayTotals($dataArray, $dayHeaders);
+// TODO: refactoring ongoing down from here.
+// 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.
-
-
-// Get column headers.
-$dayHeaders = ttTimeHelper::getDayHeadersForWeek($startDate->toString(DB_DATEFORMAT));
-// Build data array for the table.
-$dataArray = ttTimeHelper::getDataForWeekView($user->getActiveUser(), $startDate->toString(DB_DATEFORMAT), $endDate->toString(DB_DATEFORMAT));
-// Build day totals.
-$dayTotals = ttTimeHelper::getDayTotals($dataArray, $dayHeaders);
-
-// TODO: replace these two sample arrays with real data.
-$durations_with_labels = array(
- array( // Row 0.
- 'id' => 'something goes here too', // Row identifier.
- 'label' => 'This is a label for row 0',
- 'day_0' => array('id' => '0_0', 'duration' => '00:00'),
- 'day_1' => array('id' => '0_1', 'duration' => '01:00'),
- 'day_2' => array('id' => '0_2', 'duration' => '02:00'),
- 'day_3' => array('id' => '0_3', 'duration' => null),
- 'day_4' => array('id' => '0_4', 'duration' => '04:00')
- ),
- array( // Row 1.
- 'label' => 'This is a label for row 1',
- 'day_0' => array('id' => '1_0', 'duration' => '00:30'),
- 'day_1' => array('id' => '1_1', 'duration' => '01:30'),
- 'day_2' => array('id' => '1_2', 'duration' => '02:30'),
- )
-);
-
-$totals = array(
- 'label' => 'Total:',
- 'day_0' => '00:30',
- 'day_1' => '02:30',
- 'day_2' => '04:30',
- 'day_3' => null,
- 'day_4' => '04:00',
- 'day_5' => null,
- 'day_6' => null
-);
+// TODO:
+// 1) escape cf_1 values in record identifiers as this may come from user for text fields.
+// 2) 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 {
}
}
-//$durations = ttTimeHelper::getDurationsForWeek($user->getActiveUser(), $startDate->toString(DB_DATEFORMAT), $endDate->toString(DB_DATEFORMAT));
-
-
-
-//$groupedRecords = ttTimeHelper::getGroupedRecordsForInterval($user->getActiveUser(), $startDate->toString(DB_DATEFORMAT), $endDate->toString(DB_DATEFORMAT));
-//$dayTotals = ttTimeHelper::getGroupedRecordsTotals($groupedRecords);
-
-
-
-
-
-
// Elements of weekTimeForm.
$form = new Form('weekTimeForm');
// $table->setIAScript('markModified'); // TODO: write a script to mark table or particular cells as modified.
$table->setTableOptions(array('width'=>'100%','cellspacing'=>'1','cellpadding'=>'3','border'=>'0'));
$table->setRowOptions(array('class'=>'tableHeaderCentered'));
-$table->setData($dataArray); // $durations_with_labels);
+$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->setInteractive(false);
$form->addInputElement($table);
-
// Dropdown for clients in MODE_TIME. Use all active clients.
if (MODE_TIME == $user->tracking_mode && $user->isPluginEnabled('cl')) {
$active_clients = ttTeamHelper::getActiveClients($user->team_id, true);
$week_total = ttTimeHelper::getTimeForWeek($user->getActiveUser(), $selected_date);
-
-
$smarty->assign('selected_date', $selected_date);
$smarty->assign('week_total', $week_total);
-$smarty->assign('day_total', ttTimeHelper::getTimeForDay($user->getActiveUser(), $cl_date));
-//$groupedRecords = ttTimeHelper::getGroupedRecordsForInterval($user->getActiveUser(), $startDate->toString(DB_DATEFORMAT), $endDate->toString(DB_DATEFORMAT));
-//$smarty->assign('grouped_records', $groupedRecords);
-//$smarty->assign('grouped_records_totals', ttTimeHelper::getGroupedRecordsTotals($groupedRecords));
$smarty->assign('client_list', $client_list);
$smarty->assign('project_list', $project_list);
$smarty->assign('onload', 'onLoad="fillDropdowns()"');
$smarty->assign('timestring', $startDate->toString($user->date_format).' - '.$endDate->toString($user->date_format));
-// Prepare and assign date headers. Note how startDate moves to the end of the week, so it no longer holds correct start week value.
-$smarty->assign('date_0', $startDate->toString(DB_DATEFORMAT));
-$smarty->assign('day_header_0', $startDate->getDate());
-$startDate->incDay();
-$smarty->assign('date_1', $startDate->toString(DB_DATEFORMAT));
-$smarty->assign('day_header_1', $startDate->getDate());
-$startDate->incDay();
-$smarty->assign('date_2', $startDate->toString(DB_DATEFORMAT));
-$smarty->assign('day_header_2', $startDate->getDate());
-$startDate->incDay();
-$smarty->assign('date_3', $startDate->toString(DB_DATEFORMAT));
-$smarty->assign('day_header_3', $startDate->getDate());
-$startDate->incDay();
-$smarty->assign('date_4', $startDate->toString(DB_DATEFORMAT));
-$smarty->assign('day_header_4', $startDate->getDate());
-$startDate->incDay();
-$smarty->assign('date_5', $startDate->toString(DB_DATEFORMAT));
-$smarty->assign('day_header_5', $startDate->getDate());
-$startDate->incDay();
-$smarty->assign('date_6', $startDate->toString(DB_DATEFORMAT));
-$smarty->assign('day_header_6', $startDate->getDate());
-
$smarty->assign('title', $i18n->getKey('title.time'));
$smarty->assign('content_page_name', 'week.tpl');
$smarty->display('index.tpl');