summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-07-27 18:20:14 -0400
committerFrederic Guillot <fred@kanboard.net>2016-07-27 18:20:14 -0400
commit8e1c216130d1afc52fe5be3416486fc942bef424 (patch)
tree7b640472f6fe6d2b86d553779d1131b4d911252f
parent18d59f8ccf66d14f31a3a4fbc619ebccd06561b8 (diff)
parent2363da274c412cdd0dc2fc68b8f45222f4467a0a (diff)
Merge pull-request #2525
-rw-r--r--app/Filter/TaskMovedDateFilter.php38
-rw-r--r--app/ServiceProvider/FilterProvider.php4
-rw-r--r--tests/units/Filter/TaskMovedDateFilterTest.php43
3 files changed, 85 insertions, 0 deletions
diff --git a/app/Filter/TaskMovedDateFilter.php b/app/Filter/TaskMovedDateFilter.php
new file mode 100644
index 00000000..d57b7d23
--- /dev/null
+++ b/app/Filter/TaskMovedDateFilter.php
@@ -0,0 +1,38 @@
+<?php
+
+namespace Kanboard\Filter;
+
+use Kanboard\Core\Filter\FilterInterface;
+use Kanboard\Model\TaskModel;
+
+/**
+ * Filter tasks by modification date
+ *
+ * @package filter
+ * @author Frederic Guillot
+ */
+class TaskMovedDateFilter extends BaseDateFilter implements FilterInterface
+{
+ /**
+ * Get search attribute
+ *
+ * @access public
+ * @return string[]
+ */
+ public function getAttributes()
+ {
+ return array('moved');
+ }
+
+ /**
+ * Apply filter
+ *
+ * @access public
+ * @return FilterInterface
+ */
+ public function apply()
+ {
+ $this->applyDateFilter(TaskModel::TABLE.'.date_moved');
+ return $this;
+ }
+}
diff --git a/app/ServiceProvider/FilterProvider.php b/app/ServiceProvider/FilterProvider.php
index 436288dc..443d3588 100644
--- a/app/ServiceProvider/FilterProvider.php
+++ b/app/ServiceProvider/FilterProvider.php
@@ -21,6 +21,7 @@ use Kanboard\Filter\TaskDueDateFilter;
use Kanboard\Filter\TaskIdFilter;
use Kanboard\Filter\TaskLinkFilter;
use Kanboard\Filter\TaskModificationDateFilter;
+use Kanboard\Filter\TaskMovedDateFilter;
use Kanboard\Filter\TaskPriorityFilter;
use Kanboard\Filter\TaskProjectFilter;
use Kanboard\Filter\TaskReferenceFilter;
@@ -158,6 +159,9 @@ class FilterProvider implements ServiceProviderInterface
->withFilter(TaskModificationDateFilter::getInstance()
->setDateParser($c['dateParser'])
)
+ ->withFilter(TaskMovedDateFilter::getInstance()
+ ->setDateParser($c['dateParser'])
+ )
->withFilter(new TaskProjectFilter())
->withFilter(new TaskReferenceFilter())
->withFilter(new TaskStatusFilter())
diff --git a/tests/units/Filter/TaskMovedDateFilterTest.php b/tests/units/Filter/TaskMovedDateFilterTest.php
new file mode 100644
index 00000000..9b721913
--- /dev/null
+++ b/tests/units/Filter/TaskMovedDateFilterTest.php
@@ -0,0 +1,43 @@
+<?php
+
+use Kanboard\Filter\TaskMovedDateFilter;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskModificationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\UserModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskMovedDateFilterTest extends Base
+{
+ public function test()
+ {
+ $taskFinder = new TaskFinderModel($this->container);
+ $taskCreation = new TaskCreationModel($this->container);
+ $taskModification = new TaskModificationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test1', 'project_id' => 1)));
+ $this->assertTrue($taskModification->update(array('id' => 1, 'date_moved' => time())));
+ $this->assertEquals(2, $taskCreation->create(array('title' => 'Test2', 'project_id' => 1)));
+ $this->assertTrue($taskModification->update(array('id' => 2, 'date_moved' => strtotime('-1days'))));
+ $this->assertEquals(3, $taskCreation->create(array('title' => 'Test3', 'project_id' => 1)));
+ $this->assertTrue($taskModification->update(array('id' => 3, 'date_moved' => strtotime('-3days'))));
+
+ $query = $taskFinder->getExtendedQuery();
+ $filter = new TaskMovedDateFilter('>='.date('Y-m-d', strtotime('-1days')));
+ $filter->setDateParser($this->container['dateParser']);
+ $filter->withQuery($query)->apply();
+
+ $this->assertCount(2, $query->findAll());
+
+ $query = $taskFinder->getExtendedQuery();
+ $filter = new TaskMovedDateFilter('<yesterday');
+ $filter->setDateParser($this->container['dateParser']);
+ $filter->withQuery($query)->apply();
+
+ $this->assertCount(1, $query->findAll());
+ }
+}