|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Helix\Asana\Project; |
|
4
|
|
|
|
|
5
|
|
|
use Helix\Asana\Base\AbstractEntity; |
|
6
|
|
|
use Helix\Asana\Base\AbstractEntity\CrudTrait; |
|
7
|
|
|
use Helix\Asana\Project; |
|
8
|
|
|
use Helix\Asana\Task; |
|
9
|
|
|
use IteratorAggregate; |
|
10
|
|
|
use Traversable; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* A project section. |
|
14
|
|
|
* |
|
15
|
|
|
* @see https://developers.asana.com/docs/asana-sections |
|
16
|
|
|
* @see https://developers.asana.com/docs/section |
|
17
|
|
|
* |
|
18
|
|
|
* @method string getCreatedAt () RFC3339x |
|
19
|
|
|
* @method string getName () |
|
20
|
|
|
* @method Project getProject () |
|
21
|
|
|
* |
|
22
|
|
|
* @method $this setName (string $name) |
|
23
|
|
|
*/ |
|
24
|
|
|
class Section extends AbstractEntity implements IteratorAggregate { |
|
25
|
|
|
|
|
26
|
|
|
use CrudTrait; |
|
27
|
|
|
|
|
28
|
|
|
const DIR = 'sections'; |
|
29
|
|
|
const TYPE = 'section'; |
|
30
|
|
|
|
|
31
|
|
|
protected const MAP = [ |
|
32
|
|
|
'project' => Project::class |
|
33
|
|
|
]; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var Project |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $parent; |
|
39
|
|
|
|
|
40
|
|
|
public function __construct ($caller, array $data = []) { |
|
41
|
|
|
parent::__construct($caller, $data); |
|
42
|
|
|
$this->parent = $this->getProject(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
protected function _setData (array $data): void { |
|
46
|
|
|
// deprecated for the singular project field. |
|
47
|
|
|
unset($data['projects']); |
|
48
|
|
|
|
|
49
|
|
|
parent::_setData($data); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param array $filter |
|
54
|
|
|
* @return Traversable|Task[] |
|
55
|
|
|
*/ |
|
56
|
|
|
public function getIterator (array $filter = Task::GET_INCOMPLETE) { |
|
57
|
|
|
$filter['section'] = $this->getGid(); |
|
58
|
|
|
return $this->api->loadEach($this, Task::class, 'tasks', $filter); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param array $filter |
|
63
|
|
|
* @return Task[] |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getTasks (array $filter = Task::GET_INCOMPLETE) { |
|
66
|
|
|
return iterator_to_array($this->getIterator($filter)); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Factory. |
|
71
|
|
|
* |
|
72
|
|
|
* @return Task |
|
73
|
|
|
*/ |
|
74
|
|
|
public function newTask () { |
|
75
|
|
|
/** @var Task $task */ |
|
76
|
|
|
$task = $this->api->factory($this, Task::class); |
|
77
|
|
|
return $task->addToProject($this); |
|
78
|
|
|
} |
|
79
|
|
|
} |