1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace allejo\DaPulse\Objects; |
4
|
|
|
|
5
|
|
|
use allejo\DaPulse\PulseUser; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* A class representing a Pulse object which supports subscribers |
9
|
|
|
* |
10
|
|
|
* @internal |
11
|
|
|
* @package allejo\DaPulse\Objects |
12
|
|
|
* @since 0.1.0 |
13
|
|
|
*/ |
14
|
|
|
abstract class SubscribableObject extends ApiObject |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* The objects's unique identifier. |
18
|
|
|
* |
19
|
|
|
* @var int |
20
|
|
|
*/ |
21
|
|
|
protected $id; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The objects's unique identifier. |
25
|
|
|
* |
26
|
|
|
* @return int |
27
|
|
|
*/ |
28
|
|
|
public function getId () |
29
|
|
|
{ |
30
|
|
|
return $this->id; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Get the users who are subscribed to this object |
35
|
|
|
* |
36
|
|
|
* @api |
37
|
|
|
* |
38
|
|
|
* @param array $params |
39
|
|
|
* |
40
|
|
|
* @since 0.1.0 |
41
|
|
|
* |
42
|
|
|
* @return PulseUser[] |
43
|
|
|
*/ |
44
|
|
|
public function getSubscribers ($params = array()) |
45
|
|
|
{ |
46
|
|
|
$url = sprintf("%s/%d/subscribers.json", $this::apiEndpoint(), $this->getId()); |
47
|
|
|
|
48
|
|
|
return self::fetchJsonArrayToObjectArray($url, "PulseUser", $params); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Subscriber a user to a object |
53
|
|
|
* |
54
|
|
|
* @api |
55
|
|
|
* |
56
|
|
|
* @param int|PulseUser $userId The user that will be subscribed to the board |
57
|
|
|
* @param bool|null $asAdmin Set to true if the user will be an admin of the board |
58
|
|
|
* |
59
|
|
|
* @since 0.1.0 |
60
|
|
|
*/ |
61
|
|
|
public function addSubscriber ($userId, $asAdmin = NULL) |
62
|
|
|
{ |
63
|
|
|
if ($userId instanceof PulseUser) |
64
|
|
|
{ |
65
|
|
|
$userId = $userId->getId(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$url = sprintf("%s/%d/subscribers.json", self::apiEndpoint(), $this->getId()); |
69
|
|
|
$params = array( |
70
|
|
|
"user_id" => $userId |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
self::setIfNotNullOrEmpty($params, "as_admin", $asAdmin); |
|
|
|
|
74
|
|
|
self::sendPut($url, $params); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Unsubscribe a user from this object |
79
|
|
|
* |
80
|
|
|
* @api |
81
|
|
|
* |
82
|
|
|
* @param int|PulseUser $userId The user that will be unsubscribed from the board |
83
|
|
|
* |
84
|
|
|
* @since 0.1.0 |
85
|
|
|
*/ |
86
|
|
|
public function removeSubscriber ($userId) |
87
|
|
|
{ |
88
|
|
|
if ($userId instanceof PulseUser) |
89
|
|
|
{ |
90
|
|
|
$userId = $userId->getId(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$url = sprintf("%s/%d/subscribers/%d.json", self::apiEndpoint(), $this->getId(), $userId); |
94
|
|
|
|
95
|
|
|
self::sendDelete($url); |
96
|
|
|
} |
97
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: