1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Helix\Asana\User; |
4
|
|
|
|
5
|
|
|
use Helix\Asana\Base\AbstractEntity; |
6
|
|
|
use Helix\Asana\Task; |
7
|
|
|
use Helix\Asana\User; |
8
|
|
|
use Helix\Asana\Workspace; |
9
|
|
|
use IteratorAggregate; |
10
|
|
|
use Traversable; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* A user's task list in a given workspace. |
14
|
|
|
* |
15
|
|
|
* @see https://developers.asana.com/docs/asana-user-task-lists |
16
|
|
|
* @see https://developers.asana.com/docs/user-task-list |
17
|
|
|
* |
18
|
|
|
* @immutable User task lists are read-only through the API. |
19
|
|
|
* |
20
|
|
|
* @method string getName () |
21
|
|
|
* @method User getOwner () |
22
|
|
|
* @method Workspace getWorkspace () |
23
|
|
|
*/ |
24
|
|
|
class TaskList extends AbstractEntity implements IteratorAggregate { |
25
|
|
|
|
26
|
|
|
const TYPE = 'user_task_list'; |
27
|
|
|
|
28
|
|
|
protected static $map = [ |
29
|
|
|
'owner' => User::class, |
30
|
|
|
'workspace' => Workspace::class |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
final public function __toString (): string { |
34
|
|
|
return "user_task_lists/{$this->getGid()}"; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getCacheKeys () { |
38
|
|
|
$keys = parent::getCacheKeys(); |
39
|
|
|
|
40
|
|
|
/** @see User::getTaskList() */ |
41
|
|
|
$keys[] = "{$this->getOwner()}/user_task_list?workspace={$this->getWorkspace()->getGid()}"; |
42
|
|
|
|
43
|
|
|
return $keys; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return Task[] |
48
|
|
|
*/ |
49
|
|
|
public function getIncompleteTasks () { |
50
|
|
|
return $this->getTasks(['completed_since' => 'now']); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param array $filter |
55
|
|
|
* @return Traversable|Task[] |
56
|
|
|
*/ |
57
|
|
|
public function getIterator (array $filter = []) { |
58
|
|
|
return $this->_loadEach(Task::class, "{$this}/tasks"); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* All of the user's tasks. |
63
|
|
|
* |
64
|
|
|
* @see https://developers.asana.com/docs/get-tasks-from-a-user-task-list |
65
|
|
|
* |
66
|
|
|
* @param array $filter |
67
|
|
|
* @return Task[] |
68
|
|
|
*/ |
69
|
|
|
public function getTasks (array $filter = []) { |
70
|
|
|
return iterator_to_array($this->getIterator($filter)); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param callable $filter `fn( Task $task ): bool` |
75
|
|
|
* @param array $apiFilter Given to the API to reduce network load. |
76
|
|
|
* @return Task[] |
77
|
|
|
*/ |
78
|
|
|
public function selectTasks (callable $filter, array $apiFilter) { |
79
|
|
|
return $this->_select($this->getIterator($apiFilter), $filter); |
80
|
|
|
} |
81
|
|
|
} |