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 () |
19
|
|
|
* @method string getName () |
20
|
|
|
* @method $this setName (string $name) |
21
|
|
|
* @method Project getProject () |
22
|
|
|
*/ |
23
|
|
|
class Section extends AbstractEntity implements IteratorAggregate { |
24
|
|
|
|
25
|
|
|
use CrudTrait; |
26
|
|
|
|
27
|
|
|
const TYPE = 'section'; |
28
|
|
|
|
29
|
|
|
protected static $map = [ |
30
|
|
|
'project' => Project::class |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
final public function __toString (): string { |
34
|
|
|
return "sections/{$this->getGid()}"; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
final protected function _getDir (): string { |
38
|
|
|
return "{$this->getProject()}/sections"; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param array $filter |
43
|
|
|
* @return Traversable|Task[] |
44
|
|
|
*/ |
45
|
|
|
public function getIterator (array $filter = []) { |
46
|
|
|
$filter['section'] = $this->getGid(); |
47
|
|
|
return $this->_loadEach(Task::class, 'tasks', $filter); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param array $filter |
52
|
|
|
* @return Task[] |
53
|
|
|
*/ |
54
|
|
|
public function getTasks (array $filter = []) { |
55
|
|
|
return iterator_to_array($this->getIterator($filter)); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Instantiates and returns a new task for the section. |
60
|
|
|
* |
61
|
|
|
* @depends after-create |
62
|
|
|
* @return Task |
63
|
|
|
*/ |
64
|
|
|
public function newTask () { |
65
|
|
|
/** @var Task $task */ |
66
|
|
|
$task = $this->_factory(Task::class); |
67
|
|
|
return $task->addToProject($this->getProject(), $this); |
68
|
|
|
} |
69
|
|
|
} |