diff options
Diffstat (limited to 'app')
-rwxr-xr-x | app/Model/TaskDuplication.php | 31 | ||||
-rw-r--r-- | app/Model/TaskPosition.php | 15 | ||||
-rw-r--r-- | app/Model/TaskStatus.php | 11 | ||||
-rw-r--r-- | app/ServiceProvider/EventDispatcherProvider.php | 2 | ||||
-rw-r--r-- | app/Subscriber/Base.php | 1 | ||||
-rw-r--r-- | app/Subscriber/RecurringTaskSubscriber.php | 38 |
6 files changed, 60 insertions, 38 deletions
diff --git a/app/Model/TaskDuplication.php b/app/Model/TaskDuplication.php index ada3b6d6..7f9308d2 100755 --- a/app/Model/TaskDuplication.php +++ b/app/Model/TaskDuplication.php @@ -52,39 +52,40 @@ class TaskDuplication extends Base } /** - * Create task recurrence to the same project + * Duplicate recurring task * * @access public * @param integer $task_id Task id * @return boolean|integer Recurrence task id */ - public function createRecurrence($task_id) + public function duplicateRecurringTask($task_id) { $values = $this->copyFields($task_id); - if ($values['recurrence_status'] == Task::RECURE_STATUS_PENDING) - { + 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); + $this->calculateRecurringTaskDueDate($values); + + $recurring_task_id = $this->save($task_id, $values); - if ($recuretask) - { - $recurrenceStatusUpdate = $this->db + if ($recurring_task_id > 0) { + + $parent_update = $this->db ->table(Task::TABLE) - ->eq('id',$task_id) + ->eq('id', $task_id) ->update(array( 'recurrence_status' => Task::RECURE_STATUS_PROCESSED, - 'recurrence_child' => $recuretask, + 'recurrence_child' => $recurring_task_id, )); - if($recurrenceStatusUpdate) - { - return $recuretask; + if ($parent_update) { + return $recurring_task_id; } } } + return false; } @@ -176,7 +177,7 @@ class TaskDuplication extends Base * @access private * @param array $values */ - private function recurrenceDateDue(array &$values) + private function calculateRecurringTaskDueDate(array &$values) { if (! empty($values['date_due']) && $values['recurrence_factor'] != 0) { diff --git a/app/Model/TaskPosition.php b/app/Model/TaskPosition.php index 37c1ace0..0c4beb2d 100644 --- a/app/Model/TaskPosition.php +++ b/app/Model/TaskPosition.php @@ -39,19 +39,6 @@ class TaskPosition extends Base if ($fire_events) { $this->fireEvents($original_task, $column_id, $position, $swimlane_id); } - - if ($original_task['recurrence_status'] == Task::RECURE_STATUS_PENDING - && $original_task['column_id'] != $column_id - && ( - ($original_task['column_id'] == $this->board->getFirstColumn($project_id) - && $original_task['recurrence_trigger'] == Task::RECURE_TRIGGER_FIRST) - || ($column_id == $this->board->getLastColumn($project_id) - && $original_task['recurrence_trigger'] == Task::RECURE_TRIGGER_LAST) - ) - ) - { - $this->taskDuplication->createRecurrence($task_id); - } } return $result; @@ -159,6 +146,8 @@ class TaskPosition extends Base 'src_column_id' => $task['column_id'], 'dst_column_id' => $new_column_id, 'date_moved' => $task['date_moved'], + 'recurrence_status' => $task['recurrence_status'], + 'recurrence_trigger' => $task['recurrence_trigger'], ); if ($task['swimlane_id'] != $new_swimlane_id) { diff --git a/app/Model/TaskStatus.php b/app/Model/TaskStatus.php index 1ae8bfeb..30a65e1e 100644 --- a/app/Model/TaskStatus.php +++ b/app/Model/TaskStatus.php @@ -89,9 +89,7 @@ class TaskStatus extends Base */ private function changeStatus($task_id, $status, $date_completed, $event) { - $task = $this->taskFinder->getById($task_id); - - if (!$task['id']) { + if (! $this->taskFinder->exists($task_id)) { return false; } @@ -109,13 +107,6 @@ class TaskStatus extends Base $event, new TaskEvent(array('task_id' => $task_id) + $this->taskFinder->getById($task_id)) ); - - if ($status == Task::STATUS_CLOSED - && $task['recurrence_status'] == Task::RECURE_STATUS_PENDING - && $task['recurrence_trigger'] == Task::RECURE_TRIGGER_CLOSE) - { - $this->taskDuplication->createRecurrence($task_id); - } } return $result; diff --git a/app/ServiceProvider/EventDispatcherProvider.php b/app/ServiceProvider/EventDispatcherProvider.php index f002db74..f566ede8 100644 --- a/app/ServiceProvider/EventDispatcherProvider.php +++ b/app/ServiceProvider/EventDispatcherProvider.php @@ -15,6 +15,7 @@ use Subscriber\WebhookSubscriber; use Subscriber\SubtaskTimesheetSubscriber; use Subscriber\TaskMovedDateSubscriber; use Subscriber\TransitionSubscriber; +use Subscriber\RecurringTaskSubscriber; class EventDispatcherProvider implements ServiceProviderInterface { @@ -31,6 +32,7 @@ class EventDispatcherProvider implements ServiceProviderInterface $container['dispatcher']->addSubscriber(new SubtaskTimesheetSubscriber($container)); $container['dispatcher']->addSubscriber(new TaskMovedDateSubscriber($container)); $container['dispatcher']->addSubscriber(new TransitionSubscriber($container)); + $container['dispatcher']->addSubscriber(new RecurringTaskSubscriber($container)); // Automatic actions $container['action']->attachEvents(); diff --git a/app/Subscriber/Base.php b/app/Subscriber/Base.php index 95f311e7..10040626 100644 --- a/app/Subscriber/Base.php +++ b/app/Subscriber/Base.php @@ -24,6 +24,7 @@ use Pimple\Container; * @property \Model\ProjectDailySummary $projectDailySummary * @property \Model\Subtask $subtask * @property \Model\Task $task + * @property \Model\TaskDuplication $taskDuplication * @property \Model\TaskExport $taskExport * @property \Model\TaskFinder $taskFinder * @property \Model\SubtaskTimeTracking $subtaskTimeTracking diff --git a/app/Subscriber/RecurringTaskSubscriber.php b/app/Subscriber/RecurringTaskSubscriber.php new file mode 100644 index 00000000..57812fba --- /dev/null +++ b/app/Subscriber/RecurringTaskSubscriber.php @@ -0,0 +1,38 @@ +<?php + +namespace Subscriber; + +use Event\TaskEvent; +use Model\Task; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +class RecurringTaskSubscriber extends Base implements EventSubscriberInterface +{ + public static function getSubscribedEvents() + { + return array( + Task::EVENT_MOVE_COLUMN => array('onMove', 0), + Task::EVENT_CLOSE => array('onClose', 0), + ); + } + + public function onMove(TaskEvent $event) + { + if ($event['recurrence_status'] == Task::RECURE_STATUS_PENDING) { + + if ($event['recurrence_trigger'] == Task::RECURE_TRIGGER_FIRST && $this->board->getFirstColumn($event['project_id']) == $event['src_column_id']) { + $this->taskDuplication->duplicateRecurringTask($event['task_id']); + } + else if ($event['recurrence_trigger'] == Task::RECURE_TRIGGER_LAST && $this->board->getLastColumn($event['project_id']) == $event['dst_column_id']) { + $this->taskDuplication->duplicateRecurringTask($event['task_id']); + } + } + } + + public function onClose(TaskEvent $event) + { + if ($event['recurrence_status'] == Task::RECURE_STATUS_PENDING && $event['recurrence_trigger'] == Task::RECURE_TRIGGER_CLOSE) { + $this->taskDuplication->duplicateRecurringTask($event['task_id']); + } + } +} |