From b51d41f331b0948add637d5f0f7093b96c268dd0 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 10 May 2015 13:56:03 -0400 Subject: Recurring tasks (#847): Fix php error (substract is not always defined) --- app/Model/TaskDuplication.php | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'app/Model') diff --git a/app/Model/TaskDuplication.php b/app/Model/TaskDuplication.php index f3ce4f7b..ada3b6d6 100755 --- a/app/Model/TaskDuplication.php +++ b/app/Model/TaskDuplication.php @@ -2,6 +2,8 @@ namespace Model; +use DateTime; +use DateInterval; use Event\TaskEvent; /** @@ -174,24 +176,18 @@ class TaskDuplication extends Base * @access private * @param array $values */ - private function recurrenceDateDue(&$values) + private function recurrenceDateDue(array &$values) { - if ($values['date_due'] && $values['recurrence_factor']) - { - if ($values['recurrence_basedate']) - { + if (! empty($values['date_due']) && $values['recurrence_factor'] != 0) { + + if ($values['recurrence_basedate'] == Task::RECURE_BASEDATE_TRIGGERDATE) { $values['date_due'] = time(); } $factor = abs($values['recurrence_factor']); + $subtract = $values['recurrence_factor'] < 0; - if ($values['recurrence_factor'] < 0) - { - $subtract=TRUE; - } - - switch ($values['recurrence_timeframe']) - { + switch ($values['recurrence_timeframe']) { case Task::RECURE_MONTHS: $interval = 'P' . $factor . 'M'; break; @@ -200,14 +196,12 @@ class TaskDuplication extends Base break; default: $interval = 'P' . $factor . 'D'; - break; } - $date_due = new \DateTime(); - + $date_due = new DateTime(); $date_due->setTimestamp($values['date_due']); - $subtract ? $date_due->sub(new \DateInterval($interval)) : $date_due->add(new \DateInterval($interval)); + $subtract ? $date_due->sub(new DateInterval($interval)) : $date_due->add(new DateInterval($interval)); $values['date_due'] = $date_due->getTimestamp(); } -- cgit v1.2.3