Add filter by score/complexity
This commit is contained in:
parent
90e291a0e6
commit
a53ead7e74
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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())
|
||||
|
|
|
|||
Loading…
Reference in New Issue