summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-07-23 18:10:05 -0400
committerFrederic Guillot <fred@kanboard.net>2016-07-23 18:10:05 -0400
commit2a42e0e1aae35a9bb7abf054155b516ffab701d4 (patch)
tree2df2b8d4cc738e2ccf767185dca28dc45abfd938
parente0d330dda8dea91936d5b76e212603d106e45386 (diff)
Added a new automatic action to set due date
-rw-r--r--ChangeLog5
-rw-r--r--app/Action/TaskAssignDueDateOnCreation.php96
-rw-r--r--app/ServiceProvider/ActionProvider.php2
-rw-r--r--tests/units/Action/TaskAssignDueDateOnCreationTest.php37
-rw-r--r--tests/units/Action/TaskUpdateStartDateTest.php3
5 files changed, 140 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index ee57c86c..01ad5fbd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,7 +3,9 @@ Version 1.0.32 (unreleased)
New features:
-* New automated action to close tasks without activity in a specific column
+* New automated actions:
+ - Close tasks without activity in a specific column
+ - Set due date automatically
* Added internal task links to activity stream
* Added new event for removed comments
* Added search filter for task priority
@@ -11,6 +13,7 @@ New features:
Improvements:
+* Internal events management refactoring
* Handle header X-Real-IP to get IP address
* Display project name for task auto-complete fields
* Make search attributes not case sensitive
diff --git a/app/Action/TaskAssignDueDateOnCreation.php b/app/Action/TaskAssignDueDateOnCreation.php
new file mode 100644
index 00000000..79ff765c
--- /dev/null
+++ b/app/Action/TaskAssignDueDateOnCreation.php
@@ -0,0 +1,96 @@
+<?php
+
+namespace Kanboard\Action;
+
+use Kanboard\Model\TaskModel;
+
+/**
+ * Set the due date of task
+ *
+ * @package action
+ * @author Frederic Guillot
+ */
+class TaskAssignDueDateOnCreation extends Base
+{
+ /**
+ * Get automatic action description
+ *
+ * @access public
+ * @return string
+ */
+ public function getDescription()
+ {
+ return t('Automatically set the due date on task creation');
+ }
+
+ /**
+ * Get the list of compatible events
+ *
+ * @access public
+ * @return array
+ */
+ public function getCompatibleEvents()
+ {
+ return array(
+ TaskModel::EVENT_CREATE,
+ );
+ }
+
+ /**
+ * Get the required parameter for the action (defined by the user)
+ *
+ * @access public
+ * @return array
+ */
+ public function getActionRequiredParameters()
+ {
+ return array(
+ 'duration' => t('Duration in days')
+ );
+ }
+
+ /**
+ * Get the required parameter for the event
+ *
+ * @access public
+ * @return string[]
+ */
+ public function getEventRequiredParameters()
+ {
+ return array(
+ 'task_id',
+ 'task' => array(
+ 'project_id',
+ ),
+ );
+ }
+
+ /**
+ * Execute the action (set the task color)
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool True if the action was executed or false when not executed
+ */
+ public function doAction(array $data)
+ {
+ $values = array(
+ 'id' => $data['task_id'],
+ 'date_due' => strtotime('+'.$this->getParam('duration').'days'),
+ );
+
+ return $this->taskModificationModel->update($values, false);
+ }
+
+ /**
+ * Check if the event data meet the action condition
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool
+ */
+ public function hasRequiredCondition(array $data)
+ {
+ return true;
+ }
+}
diff --git a/app/ServiceProvider/ActionProvider.php b/app/ServiceProvider/ActionProvider.php
index 9383be12..c76555fa 100644
--- a/app/ServiceProvider/ActionProvider.php
+++ b/app/ServiceProvider/ActionProvider.php
@@ -3,6 +3,7 @@
namespace Kanboard\ServiceProvider;
use Kanboard\Action\TaskAssignColorPriority;
+use Kanboard\Action\TaskAssignDueDateOnCreation;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Kanboard\Core\Action\ActionManager;
@@ -80,6 +81,7 @@ class ActionProvider implements ServiceProviderInterface
$container['actionManager']->register(new TaskMoveColumnUnAssigned($container));
$container['actionManager']->register(new TaskOpen($container));
$container['actionManager']->register(new TaskUpdateStartDate($container));
+ $container['actionManager']->register(new TaskAssignDueDateOnCreation($container));
return $container;
}
diff --git a/tests/units/Action/TaskAssignDueDateOnCreationTest.php b/tests/units/Action/TaskAssignDueDateOnCreationTest.php
new file mode 100644
index 00000000..26c0584e
--- /dev/null
+++ b/tests/units/Action/TaskAssignDueDateOnCreationTest.php
@@ -0,0 +1,37 @@
+<?php
+
+use Kanboard\Action\TaskAssignDueDateOnCreation;
+use Kanboard\EventBuilder\TaskEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskAssignDueDateOnCreationTest extends Base
+{
+ public function testAction()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->buildEvent();
+
+ $action = new TaskAssignDueDateOnCreation($this->container);
+ $action->setProjectId(1);
+ $action->setParam('duration', 4);
+
+ $this->assertTrue($action->execute($event, TaskModel::EVENT_CREATE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(date('Y-m-d', strtotime('+4days')), date('Y-m-d', $task['date_due']));
+ }
+}
diff --git a/tests/units/Action/TaskUpdateStartDateTest.php b/tests/units/Action/TaskUpdateStartDateTest.php
index 8d609b3e..05fac100 100644
--- a/tests/units/Action/TaskUpdateStartDateTest.php
+++ b/tests/units/Action/TaskUpdateStartDateTest.php
@@ -2,7 +2,6 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
@@ -12,7 +11,7 @@ use Kanboard\Action\TaskUpdateStartDate;
class TaskUpdateStartDateTest extends Base
{
- public function testClose()
+ public function testAction()
{
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);