From 1a9924b363fec9c044f8198ccad589ab8f5f112c Mon Sep 17 00:00:00 2001 From: anuko Date: Wed, 27 Dec 2017 00:18:01 +0000 Subject: [PATCH] A bit of cleanup in week view. --- WEB-INF/lib/ttTimeHelper.class.php | 69 +++++++--------------- WEB-INF/templates/footer.tpl | 2 +- week.php | 94 +++++------------------------- 3 files changed, 37 insertions(+), 128 deletions(-) diff --git a/WEB-INF/lib/ttTimeHelper.class.php b/WEB-INF/lib/ttTimeHelper.class.php index da768827..5e2cdf53 100644 --- a/WEB-INF/lib/ttTimeHelper.class.php +++ b/WEB-INF/lib/ttTimeHelper.class.php @@ -731,8 +731,8 @@ class ttTimeHelper { 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. // @@ -741,32 +741,26 @@ class ttTimeHelper { // // "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); @@ -874,25 +868,6 @@ class ttTimeHelper { 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(); diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 1002303b..7ec43abc 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.13.0.3696 | Copyright © Anuko | +  Anuko Time Tracker 1.13.0.3697 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/week.php b/week.php index c6841f80..c6c194f3 100644 --- a/week.php +++ b/week.php @@ -106,7 +106,15 @@ $_SESSION['project'] = $cl_project; $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. @@ -114,45 +122,12 @@ $_SESSION['task'] = $cl_task; +// 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 { @@ -176,18 +151,6 @@ class TimeCellRenderer 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'); @@ -210,7 +173,7 @@ $table = new Table('week_durations'); // $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']])); @@ -223,7 +186,6 @@ $table->addColumn(new TableColumn($dayHeaders['day_header_6'], $dayHeaders['day_ $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); @@ -464,14 +426,8 @@ if ($request->isPost()) { $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); @@ -480,28 +436,6 @@ $smarty->assign('forms', array($form->getName()=>$form->toArray())); $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'); -- 2.20.1