From a9e7850820183fc39ef4541d3485cbcb077aca34 Mon Sep 17 00:00:00 2001 From: anuko Date: Thu, 28 Dec 2017 23:05:57 +0000 Subject: [PATCH] Inserting new cells from already existing week view rows should now work with custom field. --- WEB-INF/lib/ttTimeHelper.class.php | 26 +++++++++++++++----------- WEB-INF/templates/footer.tpl | 2 +- week.php | 7 ++++--- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/WEB-INF/lib/ttTimeHelper.class.php b/WEB-INF/lib/ttTimeHelper.class.php index c88ed6a9..81a5ccf7 100644 --- a/WEB-INF/lib/ttTimeHelper.class.php +++ b/WEB-INF/lib/ttTimeHelper.class.php @@ -977,7 +977,7 @@ class ttTimeHelper { } // insertDurationFromWeekView - inserts a new record in log tables from a week view post. - static function insertDurationFromWeekView($fields, $err) { + static function insertDurationFromWeekView($fields, $custom_fields, $err) { global $i18n; global $user; @@ -994,13 +994,6 @@ class ttTimeHelper { } } - // Temporary check for custom field and exit if one is found, as this is not yet implemented. - $temp = ttTimeHelper::parseFromWeekViewRow($fields['row_id'], 'cf_1'); - if ($temp) { - $err->add("Week view is work in progress. Inserting records with custom fields is not yet implemented. Try again later."); - return false; - } - // Prepare an array of fields for regular insert function. $fields4insert = array(); $fields4insert['user_id'] = $user->getActiveUser(); @@ -1015,15 +1008,26 @@ class ttTimeHelper { $id = ttTimeHelper::insert($fields4insert); if (!$id) return false; // Something failed. - // TODO: Deal with custom fieeld log here. Currently not implemented. + // Insert custom field if we have it. + $result = true; + $cf_1 = ttTimeHelper::parseFromWeekViewRow($fields['row_id'], 'cf_1'); + if ($custom_fields && $cf_1) { + if ($custom_fields->fields[0]['type'] == CustomFields::TYPE_TEXT) + $result = $custom_fields->insert($id, $custom_fields->fields[0]['id'], null, $cf_1); + elseif ($custom_fields->fields[0]['type'] == CustomFields::TYPE_DROPDOWN) + $result = $custom_fields->insert($id, $custom_fields->fields[0]['id'], $cf_1, null); + } - return true; // Not implemented. + return $result; } // modifyFromWeekView - modifies a duration of an existing record from a week view post. static function modifyDurationFromWeekView($fields, $err) { - $err->add("Week view is work in progress. Editing records is not yet implemented. Try again later."); + + // Possible error conditions. Overlap? What else? + + $err->add("Week view is work in progress. Editing records is not yet implemented. Try deleting and then inserting a record instead."); return false; // static function modifyDurationFromWeekView($tt_log_id, $new_duration, $user_id) { diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 5b00397a..825f144b 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.13.0.3704| Copyright © Anuko | +  Anuko Time Tracker 1.13.0.3705| Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/week.php b/week.php index 34efd56e..7cf1c945 100644 --- a/week.php +++ b/week.php @@ -394,14 +394,15 @@ if ($request->isPost()) { $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); - $result = ttTimeHelper::insertDurationFromWeekView($fields, $err); + $result = ttTimeHelper::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->getActiveUser()); } else { $fields = array(); + $fields['tt_log_id'] = $dataArray[$rowNumber][$dayHeader]['tt_log_id']; + $fields['duration'] = $postedDuration; $result = ttTimeHelper::modifyDurationFromWeekView($fields, $err); - //$result = ttTimeHelper::modifyDurationFromWeekView($dataArray[$rowNumber][$dayHeader]['tt_log_id'], $postedDuration, $user->getActiveUser()); } if (!$result) break; // Break out of the loop in case of first error. } @@ -412,7 +413,7 @@ if ($request->isPost()) { header('Location: week.php'); // Normal exit. exit(); } - $err->add($i18n->getKey('error.db')); + // $err->add($i18n->getKey('error.db')); /* // // -- 2.20.1