1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: aappen |
5
|
|
|
* Date: 04.10.18 |
6
|
|
|
* Time: 11:07 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace seretos\testrail\api; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class Milestones extends AbstractApi |
13
|
|
|
{ |
14
|
|
|
private $cache = []; |
15
|
|
|
public function all(int $projectId) |
16
|
|
|
{ |
17
|
|
|
if (!isset($this->cache[$projectId])) { |
18
|
|
|
$this->cache[$projectId] = $this->connector->send_get('get_milestones/'.$this->encodePath($projectId)); |
19
|
|
|
} |
20
|
|
|
return $this->cache[$projectId]; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function get(int $milestoneId) |
24
|
|
|
{ |
25
|
|
|
return $this->connector->send_get('get_milestone/'.$this->encodePath($milestoneId)); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function findByName(int $projectId, string $name) |
29
|
|
|
{ |
30
|
|
|
$allMilestones = $this->all($projectId); |
31
|
|
|
foreach ($allMilestones as $milestone) { |
32
|
|
|
if ($milestone['name'] === $name) { |
33
|
|
|
return $milestone; |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
return []; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function create(int $projectId, string $name, string $description = null, \DateTime $dueOn = null) |
40
|
|
|
{ |
41
|
|
|
if ($dueOn === null) { |
42
|
|
|
$dueOn = new \DateTime(); |
43
|
|
|
} |
44
|
|
|
$milestone = $this->connector->send_post('add_milestone/'.$this->encodePath($projectId), |
45
|
|
|
['name' => $name, |
46
|
|
|
'description' => $description, |
47
|
|
|
'due_on' => $dueOn->getTimestamp()]); |
48
|
|
|
unset($this->cache[$projectId]); |
49
|
|
|
return $milestone; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param int $milestoneId |
54
|
|
|
* @param array $parameters { |
55
|
|
|
* @var bool $is_completed |
56
|
|
|
* @var bool $is_started |
57
|
|
|
* @var int $parent_id |
58
|
|
|
* @var int $start_on |
59
|
|
|
* } |
60
|
|
|
*/ |
61
|
|
|
public function update(int $milestoneId, array $parameters = []) { |
62
|
|
|
$milestone = $this->connector->send_post('update_milestone/'.$this->encodePath($milestoneId), $parameters); |
63
|
|
|
$this->cache = []; |
64
|
|
|
return $milestone; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function delete(int $milestoneId) { |
68
|
|
|
$this->connector->send_post('delete_milestone/'.$this->encodePath($milestoneId), []); |
69
|
|
|
$this->cache = []; |
70
|
|
|
} |
71
|
|
|
} |