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 /app/Filter | |
parent | 90e291a0e65cb52888d0d02b42f337b1e7b998d0 (diff) |
Add filter by score/complexity
Diffstat (limited to 'app/Filter')
-rw-r--r-- | app/Filter/BaseComparisonFilter.php | 49 | ||||
-rw-r--r-- | app/Filter/TaskScoreFilter.php | 38 |
2 files changed, 87 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; + } +} |