add multi filter support
This commit is contained in:
parent
a12ea63848
commit
2709a79986
@ -24,7 +24,7 @@ class Taskwarrior
|
|||||||
/**
|
/**
|
||||||
* @param string $taskrc
|
* @param string $taskrc
|
||||||
* @param string $taskData
|
* @param string $taskData
|
||||||
* @param array $rcOptions
|
* @param array $rcOptions
|
||||||
*/
|
*/
|
||||||
public function __construct($taskrc = '~/.taskrc', $taskData = '~/.task', $rcOptions = [])
|
public function __construct($taskrc = '~/.taskrc', $taskData = '~/.task', $rcOptions = [])
|
||||||
{
|
{
|
||||||
@ -76,11 +76,15 @@ class Taskwarrior
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $filter
|
* @param string|array $filter
|
||||||
* @return Task[]
|
* @return Task[]
|
||||||
*/
|
*/
|
||||||
public function filterAll($filter = '')
|
public function filterAll($filter = null)
|
||||||
{
|
{
|
||||||
|
if (is_string($filter)) {
|
||||||
|
$filter = explode(' ', $filter);
|
||||||
|
}
|
||||||
|
|
||||||
$result = $this->export($filter);
|
$result = $this->export($filter);
|
||||||
|
|
||||||
foreach ($result as $key => $task) {
|
foreach ($result as $key => $task) {
|
||||||
@ -98,10 +102,10 @@ class Taskwarrior
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $filter
|
* @param string|array $filter
|
||||||
* @return Task[]
|
* @return Task[]
|
||||||
*/
|
*/
|
||||||
public function filter($filter = '')
|
public function filter($filter = null)
|
||||||
{
|
{
|
||||||
$tasks = $this->filterAll($filter . ' status:pending');
|
$tasks = $this->filterAll($filter . ' status:pending');
|
||||||
|
|
||||||
@ -164,10 +168,10 @@ class Taskwarrior
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $filter
|
* @param string|array $filter
|
||||||
* @return Task[]
|
* @return Task[]
|
||||||
*/
|
*/
|
||||||
private function export($filter = '')
|
private function export($filter = null)
|
||||||
{
|
{
|
||||||
$json = $this->command('export', $filter);
|
$json = $this->command('export', $filter);
|
||||||
|
|
||||||
@ -179,18 +183,26 @@ class Taskwarrior
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $command
|
* @param string $command
|
||||||
* @param string $filter
|
* @param string|array $filter
|
||||||
* @param array $options
|
* @param array $options
|
||||||
* @return string
|
* @return string
|
||||||
* @throws TaskwarriorException
|
* @throws TaskwarriorException
|
||||||
*/
|
*/
|
||||||
private function command($command, $filter = null, $options = array())
|
private function command($command, $filter = null, array $options = array())
|
||||||
{
|
{
|
||||||
$builder = $this->createProcessBuilder();
|
$builder = $this->createProcessBuilder();
|
||||||
|
|
||||||
if ($filter) {
|
if (!is_array($filter)) {
|
||||||
$builder->add($filter);
|
$filter = [$filter];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($filter as $param) {
|
||||||
|
if (empty($param)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$builder->add($param);
|
||||||
}
|
}
|
||||||
|
|
||||||
$builder->add($command);
|
$builder->add($command);
|
||||||
@ -264,13 +276,16 @@ class Taskwarrior
|
|||||||
*/
|
*/
|
||||||
private function sort(array $tasks)
|
private function sort(array $tasks)
|
||||||
{
|
{
|
||||||
usort($tasks, function (Task $a, Task $b) {
|
usort(
|
||||||
if(0 != $diff = $b->getUrgency() - $a->getUrgency()) {
|
$tasks,
|
||||||
return $diff;
|
function (Task $a, Task $b) {
|
||||||
}
|
if (0 != $diff = $b->getUrgency() - $a->getUrgency()) {
|
||||||
|
return $diff;
|
||||||
|
}
|
||||||
|
|
||||||
return $a->getEntry() >= $b->getEntry() ? 1 : -1;
|
return $a->getEntry() >= $b->getEntry() ? 1 : -1;
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return $tasks;
|
return $tasks;
|
||||||
}
|
}
|
||||||
@ -309,9 +324,9 @@ class Taskwarrior
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Task $task
|
* @param Task $task
|
||||||
* @param string $attr
|
* @param string $attr
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
*/
|
*/
|
||||||
private function setValue(Task $task, $attr, $value)
|
private function setValue(Task $task, $attr, $value)
|
||||||
{
|
{
|
||||||
|
@ -116,6 +116,20 @@ class TaskwarriorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertCount(2, $this->taskwarrior->filter());
|
$this->assertCount(2, $this->taskwarrior->filter());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testMultiFilter()
|
||||||
|
{
|
||||||
|
$task1 = new Task();
|
||||||
|
$task1->setDescription('foo1');
|
||||||
|
|
||||||
|
$task2 = new Task();
|
||||||
|
$task2->setDescription('foo2');
|
||||||
|
|
||||||
|
$this->taskwarrior->save($task1);
|
||||||
|
$this->taskwarrior->save($task2);
|
||||||
|
|
||||||
|
$this->assertCount(2, $this->taskwarrior->filter('status:pending')); // todo better test
|
||||||
|
}
|
||||||
|
|
||||||
public function testPending()
|
public function testPending()
|
||||||
{
|
{
|
||||||
$task1 = new Task();
|
$task1 = new Task();
|
||||||
|
Loading…
Reference in New Issue
Block a user