diff options
author | Yannick Armand <yannick.armand@protonmail.com> | 2017-10-14 20:31:41 +0200 |
---|---|---|
committer | fguillot <fred@kanboard.net> | 2017-10-16 10:53:35 -0700 |
commit | a53ead7e74924579db243bc43125ac52aeb86b91 (patch) | |
tree | 92656292f0311ed2604b6277a55663f3b1cdc4dd | |
parent | 90e291a0e65cb52888d0d02b42f337b1e7b998d0 (diff) |
Add filter by score/complexity
-rw-r--r-- | app/Filter/BaseComparisonFilter.php | 49 | ||||
-rw-r--r-- | app/Filter/TaskScoreFilter.php | 38 | ||||
-rw-r--r-- | app/ServiceProvider/FilterProvider.php | 2 |
3 files changed, 89 insertions, 0 deletions
diff --git a/app/Filter/BaseComparisonFilter.php b/app/Filter/BaseComparisonFilter.php new file mode 100644 index 00000000..f890342e --- /dev/null +++ b/app/Filter/BaseComparisonFilter.php @@ -0,0 +1,49 @@ +<?php + +namespace Kanboard\Filter; + +/** + * Base comparison filter class + * + * @package filter + */ +abstract class BaseComparisonFilter extends BaseFilter +{ + /** + * Parse operator in the input string + * + * @access protected + * @return string + */ + protected function parseOperator() + { + $operators = array( + '<=' => 'lte', + '>=' => 'gte', + '<' => 'lt', + '>' => 'gt', + ); + + foreach ($operators as $operator => $method) { + if (strpos($this->value, $operator) === 0) { + $this->value = substr($this->value, strlen($operator)); + return $method; + } + } + + return 'eq'; + } + + /** + * Apply a comparison filter + * + * @access protected + * @param string $field + */ + protected function applyComparisonFilter($field) + { + $method = $this->parseOperator(); + + $this->query->$method($field, $this->value); + } +} diff --git a/app/Filter/TaskScoreFilter.php b/app/Filter/TaskScoreFilter.php new file mode 100644 index 00000000..ca2013bc --- /dev/null +++ b/app/Filter/TaskScoreFilter.php @@ -0,0 +1,38 @@ +<?php + +namespace Kanboard\Filter; + +use Kanboard\Core\Filter\FilterInterface; +use Kanboard\Model\TaskModel; + +/** + * Class TaskScoreFilter + * + * @package Kanboard\Filter + */ +class TaskScoreFilter extends BaseComparisonFilter implements FilterInterface +{ + /** + * Get search attribute + * + * @access public + * @return string[] + */ + public function getAttributes() + { + return array('score', 'complexity'); + } + + /** + * Apply filter + * + * @access public + * @return FilterInterface + */ + public function apply() + { + $this->applyComparisonFilter(TaskModel::TABLE.'.score'); + + return $this; + } +} diff --git a/app/ServiceProvider/FilterProvider.php b/app/ServiceProvider/FilterProvider.php index 1cc4da8a..11a29e69 100644 --- a/app/ServiceProvider/FilterProvider.php +++ b/app/ServiceProvider/FilterProvider.php @@ -27,6 +27,7 @@ use Kanboard\Filter\TaskMovedDateFilter; use Kanboard\Filter\TaskPriorityFilter; use Kanboard\Filter\TaskProjectFilter; use Kanboard\Filter\TaskReferenceFilter; +use Kanboard\Filter\TaskScoreFilter; use Kanboard\Filter\TaskStatusFilter; use Kanboard\Filter\TaskSubtaskAssigneeFilter; use Kanboard\Filter\TaskSwimlaneFilter; @@ -172,6 +173,7 @@ class FilterProvider implements ServiceProviderInterface ) ->withFilter(new TaskProjectFilter()) ->withFilter(new TaskReferenceFilter()) + ->withFilter(new TaskScoreFilter()) ->withFilter(new TaskStatusFilter()) ->withFilter(TaskSubtaskAssigneeFilter::getInstance() ->setCurrentUserId($c['userSession']->getId()) |