1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright 2019 Vladimir Jimenez |
5
|
|
|
* @license https://github.com/allejo/PhpPulse/blob/master/LICENSE.md MIT |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace allejo\DaPulse\Objects; |
9
|
|
|
|
10
|
|
|
use allejo\DaPulse\PulseTag; |
11
|
|
|
|
12
|
|
|
class PulseColumnTagValue extends PulseColumnValue |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Get the tags in this column. |
16
|
|
|
* |
17
|
|
|
* @return PulseTag[] |
18
|
|
|
*/ |
19
|
3 |
|
public function getValue () |
20
|
|
|
{ |
21
|
3 |
|
return parent::getValue(); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Override the existing tags in this column with the ones specified in this function call. |
26
|
|
|
* |
27
|
|
|
* If you'd like to remove just one tag or add a new one, you will have to do first call `getValue()` and manipulate |
28
|
|
|
* the array yourself; this is purposely done to prevent an excess of API calls for each minor change. |
29
|
|
|
* |
30
|
|
|
* @param PulseTag[]|string[] $tags |
31
|
|
|
* |
32
|
|
|
* @throws \InvalidArgumentException |
33
|
|
|
*/ |
34
|
1 |
|
public function updateValue (array $tags) |
35
|
|
|
{ |
36
|
1 |
|
$normalizedTags = []; |
37
|
|
|
|
38
|
1 |
|
foreach ($tags as $tag) |
39
|
|
|
{ |
40
|
1 |
|
if (is_string($tag)) |
41
|
|
|
{ |
42
|
1 |
|
$normalizedTags[] = $tag; |
43
|
|
|
} |
44
|
1 |
|
elseif ($tag instanceof PulseTag) |
45
|
|
|
{ |
46
|
1 |
|
$normalizedTags[] = $tag->getName(); |
47
|
|
|
} |
48
|
|
|
else |
49
|
|
|
{ |
50
|
1 |
|
throw new \InvalidArgumentException('Only strings or PulseTag objects can be set as tags'); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
1 |
|
$url = sprintf("%s/%d/columns/%s/tags.json", self::apiEndpoint(), $this->board_id, $this->column_id); |
55
|
|
|
$postParams = [ |
56
|
1 |
|
"pulse_id" => $this->pulse_id, |
57
|
1 |
|
"tags" => implode(',', $normalizedTags), |
58
|
|
|
]; |
59
|
|
|
|
60
|
1 |
|
$result = self::sendPut($url, $postParams); |
61
|
1 |
|
$this->setValue($result); |
62
|
1 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Cast and set the appropriate value for this column |
66
|
|
|
* |
67
|
|
|
* @param $response |
68
|
|
|
*/ |
69
|
3 |
|
protected function setValue ($response) |
70
|
|
|
{ |
71
|
3 |
|
if (!isset($response['value']['tag_ids'])) { |
72
|
|
|
$this->column_value = []; |
73
|
|
|
|
74
|
|
|
return; |
75
|
|
|
} |
76
|
|
|
|
77
|
3 |
|
$this->column_value = $response['value']['tag_ids']; |
78
|
|
|
|
79
|
3 |
|
self::lazyCastAll($this->column_value, 'PulseTag', true); |
80
|
3 |
|
} |
81
|
|
|
} |
82
|
|
|
|