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