diff options
-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()) |