1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace allejo\DaPulse; |
4
|
|
|
|
5
|
|
|
use allejo\DaPulse\Exceptions\InvalidObjectException; |
6
|
|
|
use allejo\DaPulse\Objects\ApiObject; |
7
|
|
|
|
8
|
|
|
class PulseUpdate extends ApiObject |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* User who wrote the update. |
12
|
|
|
* |
13
|
|
|
* @var array|PulseUser |
14
|
|
|
*/ |
15
|
|
|
protected $user; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The resource's URL. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $url; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The update's id. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $id; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The update's body. |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $body; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The update's body in plain text |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $body_text; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The replies made to this update. |
47
|
|
|
* |
48
|
|
|
* @var array |
49
|
|
|
*/ |
50
|
|
|
protected $replies; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* The update's kind. |
54
|
|
|
* |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
protected $kind; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* The update's has_assets. |
61
|
|
|
* |
62
|
|
|
* @var string |
63
|
|
|
*/ |
64
|
|
|
protected $has_assets; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* The update's assets. |
68
|
|
|
* |
69
|
|
|
* @var string |
70
|
|
|
*/ |
71
|
|
|
protected $assets; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* The users who watch this update. |
75
|
|
|
* |
76
|
|
|
* @var array |
77
|
|
|
*/ |
78
|
|
|
protected $watched; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Creation time. |
82
|
|
|
* |
83
|
|
|
* @var \DateTime |
84
|
|
|
*/ |
85
|
|
|
protected $created_at; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Last update time. |
89
|
|
|
* |
90
|
|
|
* @var \DateTime |
91
|
|
|
*/ |
92
|
|
|
protected $updated_at; |
93
|
|
|
|
94
|
|
|
// ================================================================================================================= |
95
|
|
|
// Getter functions |
96
|
|
|
// ================================================================================================================= |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* User who wrote the update. |
100
|
|
|
* |
101
|
|
|
* @return PulseUser |
102
|
|
|
*/ |
103
|
|
|
public function getUser() |
104
|
|
|
{ |
105
|
|
|
self::lazyLoad($this->user, "PulseUser"); |
106
|
|
|
|
107
|
|
|
return $this->user; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* The resource's URL. |
112
|
|
|
* |
113
|
|
|
* @return string |
114
|
|
|
*/ |
115
|
|
|
public function getUrl() |
116
|
|
|
{ |
117
|
|
|
return $this->url; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* The update's id. |
122
|
|
|
* |
123
|
|
|
* @return string |
124
|
|
|
*/ |
125
|
|
|
public function getId() |
126
|
|
|
{ |
127
|
|
|
return $this->id; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* The update's body. |
132
|
|
|
* |
133
|
|
|
* @return string |
134
|
|
|
*/ |
135
|
|
|
public function getBody() |
136
|
|
|
{ |
137
|
|
|
return $this->body; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* The update's body in plain text |
142
|
|
|
* |
143
|
|
|
* @return string |
144
|
|
|
*/ |
145
|
|
|
public function getBodyText() |
146
|
|
|
{ |
147
|
|
|
return $this->body_text; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* The replies made to this update. |
152
|
|
|
* |
153
|
|
|
* @return static[] |
154
|
|
|
*/ |
155
|
|
|
public function getReplies() |
156
|
|
|
{ |
157
|
|
|
self::lazyArray($this->replies, "PulseUpdate"); |
158
|
|
|
|
159
|
|
|
return $this->replies; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* The update's kind. |
164
|
|
|
* |
165
|
|
|
* @return string |
166
|
|
|
*/ |
167
|
|
|
public function getKind() |
168
|
|
|
{ |
169
|
|
|
return $this->kind; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* The update's has_assets. |
174
|
|
|
* |
175
|
|
|
* @return string |
176
|
|
|
*/ |
177
|
|
|
public function getHasAssets() |
178
|
|
|
{ |
179
|
|
|
return $this->has_assets; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* The update's assets. |
184
|
|
|
* |
185
|
|
|
* @return string |
186
|
|
|
*/ |
187
|
|
|
public function getAssets() |
188
|
|
|
{ |
189
|
|
|
return $this->assets; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* Creation time. |
194
|
|
|
* |
195
|
|
|
* @return \DateTime |
196
|
|
|
*/ |
197
|
|
|
public function getCreatedAt() |
198
|
|
|
{ |
199
|
|
|
self::lazyLoad($this->created_at, '\DateTime'); |
200
|
|
|
|
201
|
|
|
return $this->created_at; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Last update time. |
206
|
|
|
* |
207
|
|
|
* @return \DateTime |
208
|
|
|
*/ |
209
|
|
|
public function getUpdatedAt() |
210
|
|
|
{ |
211
|
|
|
self::lazyLoad($this->updated_at, '\DateTime'); |
212
|
|
|
|
213
|
|
|
return $this->updated_at; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Get the users watching this update |
218
|
|
|
* |
219
|
|
|
* @return PulseUser[] |
220
|
|
|
*/ |
221
|
|
|
public function getWatchers () |
222
|
|
|
{ |
223
|
|
|
self::lazyArray($this->watched, "PulseUser"); |
224
|
|
|
|
225
|
|
|
return $this->watched; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
// ================================================================================================================= |
229
|
|
|
// Modification functions |
230
|
|
|
// ================================================================================================================= |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Delete this update |
234
|
|
|
* |
235
|
|
|
* @api |
236
|
|
|
* |
237
|
|
|
* @since 0.1.0 |
238
|
|
|
* |
239
|
|
|
* @throws InvalidObjectException This PulseUpdate as already been deleted |
240
|
|
|
*/ |
241
|
|
View Code Duplication |
public function deleteUpdate() |
|
|
|
|
242
|
|
|
{ |
243
|
|
|
$this->checkInvalid(); |
244
|
|
|
|
245
|
|
|
$url = sprintf("%s/%d.json", self::apiEndpoint(), $this->getId()); |
246
|
|
|
self::sendDelete($url); |
247
|
|
|
|
248
|
|
|
$this->deletedObject = true; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
// ================================================================================================================= |
252
|
|
|
// Liking functions |
253
|
|
|
// ================================================================================================================= |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* Have a user like an update |
257
|
|
|
* |
258
|
|
|
* @api |
259
|
|
|
* |
260
|
|
|
* @param int|PulseUser $user The user that will be liking/un-liking the update |
261
|
|
|
* |
262
|
|
|
* @since 0.1.0 |
263
|
|
|
*/ |
264
|
|
|
public function likeUpdate ($user) |
265
|
|
|
{ |
266
|
|
|
$this->likeUnlikeUpdate($user, true); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* Have a user unlike an update |
271
|
|
|
* |
272
|
|
|
* @api |
273
|
|
|
* |
274
|
|
|
* @param int|PulseUser $user The user that will be liking/un-liking the update |
275
|
|
|
* |
276
|
|
|
* @since 0.1.0 |
277
|
|
|
*/ |
278
|
|
|
public function unlikeUpdate ($user) |
279
|
|
|
{ |
280
|
|
|
$this->likeUnlikeUpdate($user, false); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* Like and un-liking functionality |
285
|
|
|
* |
286
|
|
|
* @param int|PulseUser $user The user that will be liking/un-liking the update |
287
|
|
|
* @param bool $like True to like the update, false to unlike |
288
|
|
|
*/ |
289
|
|
View Code Duplication |
private function likeUnlikeUpdate ($user, $like) |
|
|
|
|
290
|
|
|
{ |
291
|
|
|
if ($user instanceof PulseUser) |
292
|
|
|
{ |
293
|
|
|
$user = $user->getId(); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
$url = sprintf("%s/%d/%s.json", self::apiEndpoint(), $this->getId(), (($like) ? "like" : "unlike")); |
297
|
|
|
$params = array( |
298
|
|
|
"user" => $user |
299
|
|
|
); |
300
|
|
|
|
301
|
|
|
self::sendPost($url, $params); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
// ================================================================================================================= |
305
|
|
|
// PulseUpdate functions |
306
|
|
|
// ================================================================================================================= |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* Get all of the account's updates (ordered from new to old) |
310
|
|
|
* |
311
|
|
|
* @api |
312
|
|
|
* |
313
|
|
|
* @param array $params GET parameters passed to the URL |
314
|
|
|
* |
315
|
|
|
* @since 0.1.0 |
316
|
|
|
* |
317
|
|
|
* @return PulseUpdate[] |
318
|
|
|
*/ |
319
|
|
|
public static function getUpdates ($params = array()) |
320
|
|
|
{ |
321
|
|
|
$url = sprintf("%s.json", self::apiEndpoint()); |
322
|
|
|
|
323
|
|
|
return self::sendGet($url, $params); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* Create a new update |
328
|
|
|
* |
329
|
|
|
* @api |
330
|
|
|
* |
331
|
|
|
* @param int|PulseUser $user The author of this post |
332
|
|
|
* @param int|Pulse $pulse The Pulse to whom this update will belong to |
333
|
|
|
* @param string $text The content of the update |
334
|
|
|
* @param null|bool $announceToAll Whether or not to announce this update to everyone's wall |
335
|
|
|
* |
336
|
|
|
* @since 0.1.0 |
337
|
|
|
* |
338
|
|
|
* @return PulseUpdate |
339
|
|
|
*/ |
340
|
|
|
public static function createUpdate ($user, $pulse, $text, $announceToAll = NULL) |
341
|
|
|
{ |
342
|
|
|
if ($user instanceof PulseUser) |
343
|
|
|
{ |
344
|
|
|
$user = $user->getId(); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
if ($pulse instanceof Pulse) |
348
|
|
|
{ |
349
|
|
|
$pulse = $pulse->getId(); |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
$url = sprintf("%s.json", self::apiEndpoint()); |
353
|
|
|
$params = array( |
354
|
|
|
"user" => $user, |
355
|
|
|
"pulse" => $pulse, |
356
|
|
|
"update_text" => $text |
357
|
|
|
); |
358
|
|
|
|
359
|
|
|
self::setIfNotNullOrEmpty($params, "announcement", $announceToAll); |
|
|
|
|
360
|
|
|
|
361
|
|
|
$result = self::sendPost($url, $params); |
362
|
|
|
|
363
|
|
|
return (new PulseUpdate($result)); |
364
|
|
|
} |
365
|
|
|
} |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString
.