1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright 2017 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\PulseUser; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class PulseColumnTextValue |
14
|
|
|
* |
15
|
|
|
* @package allejo\DaPulse\Objects |
16
|
|
|
* @since 0.1.0 |
17
|
|
|
*/ |
18
|
|
|
class PulseColumnPersonValue extends PulseColumnValue |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Get the person assigned listed in the person column |
22
|
|
|
* |
23
|
|
|
* @api |
24
|
|
|
* |
25
|
|
|
* @since 0.1.0 |
26
|
|
|
* |
27
|
|
|
* @return PulseUser|null Null is returned when no person is listed in this person column |
28
|
|
|
*/ |
29
|
4 |
|
public function getValue () |
30
|
|
|
{ |
31
|
4 |
|
return parent::getValue(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Update the person in a person column |
36
|
|
|
* |
37
|
|
|
* @api |
38
|
|
|
* |
39
|
|
|
* @param int|PulseUser $user The new user that will be assigned to the person column |
40
|
|
|
* |
41
|
|
|
* @since 0.3.0 \InvalidArgumentException is now thrown |
42
|
|
|
* @since 0.1.0 |
43
|
|
|
* |
44
|
|
|
* @throws \InvalidArgumentException if $user is not an integer, is not positive, or is not a PulseUser object |
45
|
|
|
*/ |
46
|
7 |
|
public function updateValue ($user) |
47
|
|
|
{ |
48
|
7 |
|
$user = PulseUser::_castToInt($user); |
49
|
2 |
|
$url = sprintf("%s/%d/columns/%s/person.json", self::apiEndpoint(), $this->board_id, $this->column_id); |
50
|
|
|
$postParams = [ |
51
|
2 |
|
"pulse_id" => $this->pulse_id, |
52
|
2 |
|
"user_id" => $user |
53
|
|
|
]; |
54
|
|
|
|
55
|
2 |
|
$result = self::sendPut($url, $postParams); |
56
|
2 |
|
$this->setValue($result); |
57
|
2 |
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
4 |
|
protected function isNullValue () |
63
|
|
|
{ |
64
|
|
|
// Thank you very much, DaPulse. Changing the return type of an API endpoint clearly does not break any existing |
65
|
|
|
// code. Check to see if an invalid user is returned to be able to return null |
66
|
|
|
|
67
|
4 |
|
return parent::isNullValue() || |
68
|
3 |
|
(is_array($this->jsonResponse) && |
69
|
3 |
|
isset($this->jsonResponse['value']) && is_array($this->jsonResponse['value']) && |
70
|
4 |
|
isset($this->jsonResponse['value']['id']) && $this->jsonResponse['value']['id'] === 0); |
71
|
|
|
} |
72
|
|
|
|
73
|
3 |
|
protected function setValue ($response) |
74
|
|
|
{ |
75
|
3 |
|
$this->column_value = new PulseUser($response["value"]["id"]); |
76
|
|
|
} |
77
|
|
|
} |