From a53ead7e74924579db243bc43125ac52aeb86b91 Mon Sep 17 00:00:00 2001 From: Yannick Armand Date: Sat, 14 Oct 2017 20:31:41 +0200 Subject: Add filter by score/complexity --- app/Filter/BaseComparisonFilter.php | 49 ++++++++++++++++++++++++++++++++++ app/Filter/TaskScoreFilter.php | 38 ++++++++++++++++++++++++++ app/ServiceProvider/FilterProvider.php | 2 ++ 3 files changed, 89 insertions(+) create mode 100644 app/Filter/BaseComparisonFilter.php create mode 100644 app/Filter/TaskScoreFilter.php 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 @@ + '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 @@ +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()) -- cgit v1.2.3