diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-05-10 13:45:09 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-05-10 13:45:09 -0400 |
commit | 94a5b12e68fc5e5f6aee7bf1d6d25427421aba7a (patch) | |
tree | aa1f86e9fd134ec60534446948dcd2d54e02e5f7 /app/Model/TaskDuplication.php | |
parent | 98aab0d99465b40907bbc1f1108ea20db290e036 (diff) | |
parent | ec24efa2d9599eaf6cbc39da25cffeaff555ba3c (diff) |
Merge pull-request #847 (recurring tasks)
Diffstat (limited to 'app/Model/TaskDuplication.php')
-rwxr-xr-x[-rw-r--r--] | app/Model/TaskDuplication.php | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/app/Model/TaskDuplication.php b/app/Model/TaskDuplication.php index bd593dc1..f3ce4f7b 100644..100755 --- a/app/Model/TaskDuplication.php +++ b/app/Model/TaskDuplication.php @@ -30,6 +30,11 @@ class TaskDuplication extends Base 'category_id', 'time_estimated', 'swimlane_id', + 'recurrence_status', + 'recurrence_trigger', + 'recurrence_factor', + 'recurrence_timeframe', + 'recurrence_basedate', ); /** @@ -45,6 +50,43 @@ class TaskDuplication extends Base } /** + * Create task recurrence to the same project + * + * @access public + * @param integer $task_id Task id + * @return boolean|integer Recurrence task id + */ + public function createRecurrence($task_id) + { + $values = $this->copyFields($task_id); + + if ($values['recurrence_status'] == Task::RECURE_STATUS_PENDING) + { + $values['recurrence_parent'] = $task_id; + $values['column_id'] = $this->board->getFirstColumn($values['project_id']); + $this->recurrenceDateDue($values); + $recuretask = $this->save($task_id, $values); + + if ($recuretask) + { + $recurrenceStatusUpdate = $this->db + ->table(Task::TABLE) + ->eq('id',$task_id) + ->update(array( + 'recurrence_status' => Task::RECURE_STATUS_PROCESSED, + 'recurrence_child' => $recuretask, + )); + + if($recurrenceStatusUpdate) + { + return $recuretask; + } + } + } + return false; + } + + /** * Duplicate a task to another project * * @access public @@ -127,6 +169,51 @@ class TaskDuplication extends Base } /** + * Calculate new due date for new recurrence task + * + * @access private + * @param array $values + */ + private function recurrenceDateDue(&$values) + { + if ($values['date_due'] && $values['recurrence_factor']) + { + if ($values['recurrence_basedate']) + { + $values['date_due'] = time(); + } + + $factor = abs($values['recurrence_factor']); + + if ($values['recurrence_factor'] < 0) + { + $subtract=TRUE; + } + + switch ($values['recurrence_timeframe']) + { + case Task::RECURE_MONTHS: + $interval = 'P' . $factor . 'M'; + break; + case Task::RECURE_YEARS: + $interval = 'P' . $factor . 'Y'; + break; + default: + $interval = 'P' . $factor . 'D'; + break; + } + + $date_due = new \DateTime(); + + $date_due->setTimestamp($values['date_due']); + + $subtract ? $date_due->sub(new \DateInterval($interval)) : $date_due->add(new \DateInterval($interval)); + + $values['date_due'] = $date_due->getTimestamp(); + } + } + + /** * Duplicate fields for the new task * * @access private |