+
+ // Handle durations and comments in separate blocks of code.
+ if (!$user->isPluginEnabled('wvns') || (0 == $rowNumber % 2)) {
+ // Handle durations row here.
+
+ // Obtain existing and posted durations.
+ $postedDuration = $request->getParameter($control_id);
+ $existingDuration = $dataArray[$rowNumber][$dayHeader]['duration'];
+ // If posted value is not null, check and normalize it.
+ if ($postedDuration) {
+ if (false === ttTimeHelper::postedDurationToMinutes($postedDuration)) {
+ $err->add($i18n->get('error.field'), $i18n->get('label.duration'));
+ $result = false; break; // Break out. Stop any further processing.
+ } else {
+ $minutes = ttTimeHelper::postedDurationToMinutes($postedDuration);
+ $postedDuration = ttTimeHelper::minutesToDuration($minutes);
+ }
+ }
+ // Do not process if value has not changed.
+ if ($postedDuration == $existingDuration)
+ continue;
+ // Posted value is different.
+ if ($existingDuration == null) {
+ // Skip inserting 0 duration values.
+ if (0 == ttTimeHelper::toMinutes($postedDuration))
+ continue;
+ // Insert a new record.
+ $fields = array();
+ $fields['row_id'] = $dataArray[$rowNumber]['row_id'];
+ if (!$fields['row_id']) {
+ // Special handling for row 0, a new entry. Need to construct new row_id.
+ $record = array();
+ $record['client_id'] = $cl_client;
+ $record['billable'] = $cl_billable ? '1' : '0';
+ $record['project_id'] = $cl_project;
+ $record['task_id'] = $cl_task;
+ $record['cf_1_value'] = $cl_cf_1;
+ $fields['row_id'] = ttWeekViewHelper::makeRowIdentifier($record).'_0';
+ // Note: no need to check for a possible conflict with an already existing row
+ // because we are doing an insert that does not affect already existing data.
+
+ if ($user->isPluginEnabled('wvn')) {
+ $fields['note'] = $request->getParameter('note');
+ }
+ }
+ $fields['day_header'] = $dayHeader;
+ $fields['start_date'] = $startDate->toString(DB_DATEFORMAT); // To be able to determine date for the entry using $dayHeader.
+ $fields['duration'] = $postedDuration;
+ $fields['browser_today'] = $request->getParameter('browser_today', null);
+ if ($user->isPluginEnabled('wvns')) {
+ // Take note value from the control below duration.
+ $noteRowNumber = $rowNumber + 1;
+ $note_control_id = $noteRowNumber.'_'.$dayHeader;
+ $fields['note'] = $request->getParameter($note_control_id);
+ }
+ $result = ttWeekViewHelper::insertDurationFromWeekView($fields, $custom_fields, $err);
+ } elseif ($postedDuration == null || 0 == ttTimeHelper::toMinutes($postedDuration)) {
+ // Delete an already existing record here.
+ $result = ttTimeHelper::delete($dataArray[$rowNumber][$dayHeader]['tt_log_id'], $user->getUser());