1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file contains the Pulse class |
5
|
|
|
* |
6
|
|
|
* @copyright 2015 Vladimir Jimenez |
7
|
|
|
* @license https://github.com/allejo/PhpPulse/blob/master/LICENSE.md MIT |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace allejo\DaPulse; |
11
|
|
|
|
12
|
|
|
use allejo\DaPulse\Exceptions\ColumnNotFoundException; |
13
|
|
|
use allejo\DaPulse\Exceptions\HttpException; |
14
|
|
|
use allejo\DaPulse\Exceptions\InvalidColumnException; |
15
|
|
|
use allejo\DaPulse\Exceptions\InvalidObjectException; |
16
|
|
|
use allejo\DaPulse\Objects\PulseColumnDateValue; |
17
|
|
|
use allejo\DaPulse\Objects\PulseColumnNumericValue; |
18
|
|
|
use allejo\DaPulse\Objects\PulseColumnPersonValue; |
19
|
|
|
use allejo\DaPulse\Objects\PulseColumnStatusValue; |
20
|
|
|
use allejo\DaPulse\Objects\PulseColumnTextValue; |
21
|
|
|
use allejo\DaPulse\Objects\PulseColumnTimelineValue; |
22
|
|
|
use allejo\DaPulse\Objects\PulseColumnValue; |
23
|
|
|
use allejo\DaPulse\Objects\SubscribableObject; |
24
|
|
|
use allejo\DaPulse\Utilities\ArrayUtilities; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* A class representing a single pulse in a board |
28
|
|
|
* |
29
|
|
|
* @api |
30
|
|
|
* @package allejo\DaPulse |
31
|
|
|
* @since 0.1.0 |
32
|
|
|
*/ |
33
|
|
|
class Pulse extends SubscribableObject |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @ignore |
37
|
|
|
*/ |
38
|
|
|
const API_PREFIX = "pulses"; |
39
|
|
|
|
40
|
|
|
// ================================================================================================================ |
41
|
|
|
// Instance Variables |
42
|
|
|
// ================================================================================================================ |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* The resource's URL. |
46
|
|
|
* |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
protected $url; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* The pulse's name. |
53
|
|
|
* |
54
|
|
|
* @var string |
55
|
|
|
*/ |
56
|
|
|
protected $name; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* The amount of updates a pulse has. |
60
|
|
|
* |
61
|
|
|
* @var int |
62
|
|
|
*/ |
63
|
|
|
protected $updates_count; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* The ID of the parent board. |
67
|
|
|
* |
68
|
|
|
* @var int |
69
|
|
|
*/ |
70
|
|
|
protected $board_id; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Creation time. |
74
|
|
|
* |
75
|
|
|
* @var \DateTime |
76
|
|
|
*/ |
77
|
|
|
protected $created_at; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Last update time. |
81
|
|
|
* |
82
|
|
|
* @var \DateTime |
83
|
|
|
*/ |
84
|
|
|
protected $updated_at; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* The ID of the group this pulse belongs to |
88
|
|
|
* |
89
|
|
|
* @var string |
90
|
|
|
*/ |
91
|
|
|
protected $group_id; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @var PulseColumn[] |
95
|
|
|
*/ |
96
|
|
|
protected $column_structure; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* An array containing all of the values a pulse has for each column |
100
|
|
|
* |
101
|
|
|
* @var mixed |
102
|
|
|
*/ |
103
|
|
|
protected $raw_column_values; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* An array containing objects extended from PulseColumnValue storing all of the values for each column |
107
|
|
|
* |
108
|
|
|
* @var array |
109
|
|
|
*/ |
110
|
|
|
protected $column_values; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* The common URL path for retrieving objects relating a pulse such as subscribers, notes, or updates |
114
|
|
|
* |
115
|
|
|
* @var string |
116
|
|
|
*/ |
117
|
|
|
private $urlSyntax = "%s/%s/%s.json"; |
118
|
|
|
|
119
|
|
|
// ================================================================================================================ |
120
|
|
|
// Overloaded functions |
121
|
|
|
// ================================================================================================================ |
122
|
|
|
|
123
|
70 |
|
protected function initializeValues () |
124
|
|
|
{ |
125
|
70 |
|
$this->column_values = array(); |
126
|
70 |
|
$this->column_structure = array(); |
127
|
70 |
|
$this->raw_column_values = array(); |
128
|
70 |
|
} |
129
|
|
|
|
130
|
|
|
// ================================================================================================================ |
131
|
|
|
// Getter functions |
132
|
|
|
// ================================================================================================================ |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* The resource's URL. |
136
|
|
|
* |
137
|
|
|
* @return string |
138
|
|
|
*/ |
139
|
1 |
|
public function getUrl () |
140
|
|
|
{ |
141
|
1 |
|
return $this->url; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* The pulse's name. |
146
|
|
|
* |
147
|
|
|
* @return string |
148
|
|
|
*/ |
149
|
2 |
|
public function getName () |
150
|
|
|
{ |
151
|
2 |
|
return $this->name; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* The amount of updates a pulse has. |
156
|
|
|
* |
157
|
|
|
* @return int |
158
|
|
|
*/ |
159
|
1 |
|
public function getUpdatesCount () |
160
|
|
|
{ |
161
|
1 |
|
return $this->updates_count; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* The ID of the parent board. |
166
|
|
|
* |
167
|
|
|
* @return int |
168
|
|
|
*/ |
169
|
40 |
|
public function getBoardId () |
170
|
|
|
{ |
171
|
40 |
|
return $this->board_id; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Creation time. |
176
|
|
|
* |
177
|
|
|
* @return \DateTime |
178
|
|
|
*/ |
179
|
1 |
|
public function getCreatedAt () |
180
|
|
|
{ |
181
|
1 |
|
self::lazyCast($this->created_at, '\DateTime'); |
182
|
|
|
|
183
|
1 |
|
return $this->created_at; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Last update time. |
188
|
|
|
* |
189
|
|
|
* @return \DateTime |
190
|
|
|
*/ |
191
|
1 |
|
public function getUpdatedAt () |
192
|
|
|
{ |
193
|
1 |
|
self::lazyCast($this->updated_at, '\DateTime'); |
194
|
|
|
|
195
|
1 |
|
return $this->updated_at; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Get the ID of the group this Pulse is a part of. If this value is not available, an API call will be made to |
200
|
|
|
* find the group ID via brute force. |
201
|
|
|
* |
202
|
|
|
* **Note** The group ID is cached if it is not available. To update the cached value, use $forceFetch to force an |
203
|
|
|
* API call to get a new value. |
204
|
|
|
* |
205
|
|
|
* **Warning** An API call is always slower than using the cached value. |
206
|
|
|
* |
207
|
|
|
* @param bool $forceFetch Force an API call to get an updated group ID if it has been changed |
208
|
|
|
* |
209
|
|
|
* @since 0.1.0 |
210
|
|
|
* @return string |
211
|
|
|
*/ |
212
|
1 |
|
public function getGroupId ($forceFetch = false) |
213
|
|
|
{ |
214
|
1 |
|
if (empty($this->group_id) || $forceFetch) |
215
|
|
|
{ |
216
|
1 |
|
$parentBoard = new PulseBoard($this->board_id); |
217
|
1 |
|
$pulses = $parentBoard->getPulses(); |
218
|
|
|
|
219
|
1 |
|
foreach ($pulses as $pulse) |
220
|
|
|
{ |
221
|
1 |
|
if ($this->getId() === $pulse->getId()) |
222
|
|
|
{ |
223
|
1 |
|
$this->group_id = $pulse->getGroupId(); |
224
|
1 |
|
break; |
225
|
|
|
} |
226
|
|
|
} |
227
|
|
|
} |
228
|
|
|
|
229
|
1 |
|
return $this->group_id; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
// ================================================================================================================ |
233
|
|
|
// Pulse functions |
234
|
|
|
// ================================================================================================================ |
235
|
|
|
|
236
|
|
|
private static function editPulseNameCall ($pulseID, $newName) |
237
|
|
|
{ |
238
|
|
|
$editUrl = sprintf("%s/%d.json", self::apiEndpoint(), $pulseID); |
239
|
|
|
$postParams = array( |
240
|
|
|
'name' => $newName |
241
|
|
|
); |
242
|
|
|
|
243
|
|
|
return self::sendPut($editUrl, $postParams); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* Edit the name of a Pulse |
248
|
|
|
* |
249
|
|
|
* **Tip:** If you do not already have a Pulse object created or given to you, calling this function makes one less |
250
|
|
|
* API call than creating a Pulse object and then calling `editName()` on that instance. |
251
|
|
|
* |
252
|
|
|
* @param int $pulseID |
253
|
|
|
* @param string $newName |
254
|
|
|
* |
255
|
|
|
* @since 0.3.0 |
256
|
|
|
* |
257
|
|
|
* @return Pulse |
258
|
|
|
*/ |
259
|
|
|
public static function editPulseNameByID ($pulseID, $newName) |
260
|
|
|
{ |
261
|
|
|
$result = self::editPulseNameCall($pulseID, $newName); |
262
|
|
|
|
263
|
|
|
return (new Pulse($result)); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* Edit the name of the pulse |
268
|
|
|
* |
269
|
|
|
* **Tip:** Calling `Pulse::editPulseNameByID()` makes one less API call than creating a Pulse object. You should |
270
|
|
|
* only call this function if you already have a Pulse instance created for other purposes or it has been given to |
271
|
|
|
* you. |
272
|
|
|
* |
273
|
|
|
* @api |
274
|
|
|
* @param string $title |
275
|
|
|
* @since 0.1.0 |
276
|
|
|
*/ |
277
|
|
|
public function editName($title) |
278
|
|
|
{ |
279
|
|
|
$this->jsonResponse = self::editPulseNameCall($this->getId(), $title); |
|
|
|
|
280
|
|
|
$this->assignResults(); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
private static function archivePulseCall ($pulseID) |
284
|
|
|
{ |
285
|
|
|
$archiveURL = sprintf("%s/%d.json", self::apiEndpoint(), $pulseID); |
286
|
|
|
$getParams = array( |
287
|
|
|
'archive' => true |
288
|
|
|
); |
289
|
|
|
|
290
|
|
|
return self::sendDelete($archiveURL, $getParams); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* Archive a pulse by its ID |
295
|
|
|
* |
296
|
|
|
* @api |
297
|
|
|
* @param int $pulseID |
298
|
|
|
* @since 0.3.0 |
299
|
|
|
* @return Pulse The pulse that was deleted |
300
|
|
|
*/ |
301
|
|
|
public static function archivePulseByID ($pulseID) |
302
|
|
|
{ |
303
|
|
|
$result = self::archivePulseCall($pulseID); |
304
|
|
|
|
305
|
|
|
return (new Pulse($result)); |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* Archive the current pulse |
310
|
|
|
* |
311
|
|
|
* This is the equivalent of a soft delete and can be restored from the DaPulse website. |
312
|
|
|
* |
313
|
|
|
* @api |
314
|
|
|
* @since 0.3.0 |
315
|
|
|
*/ |
316
|
|
|
public function archivePulse () |
317
|
|
|
{ |
318
|
|
|
$this->jsonResponse = self::archivePulseCall($this->getId()); |
|
|
|
|
319
|
|
|
$this->assignResults(); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
private static function deletePulseCall ($pulseID) |
323
|
|
|
{ |
324
|
|
|
$deleteURL = sprintf("%s/%d.json", self::apiEndpoint(), $pulseID); |
325
|
|
|
|
326
|
|
|
return self::sendDelete($deleteURL); |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* Delete a Pulse by its ID |
331
|
|
|
* |
332
|
|
|
* @api |
333
|
|
|
* @param int $pulseID |
334
|
|
|
* @since 0.3.0 |
335
|
|
|
* @return Pulse |
336
|
|
|
*/ |
337
|
|
|
public static function deletePulseByID ($pulseID) |
338
|
|
|
{ |
339
|
|
|
$result = self::deletePulseCall($pulseID); |
340
|
6 |
|
$pulse = new Pulse($result); |
341
|
|
|
$pulse->_markInvalid(); |
342
|
6 |
|
|
343
|
|
|
return $pulse; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* Delete the current Pulse |
348
|
|
|
* |
349
|
|
|
* @api |
350
|
|
|
* @throws \allejo\DaPulse\Exceptions\InvalidObjectException |
351
|
|
|
*/ |
352
|
|
|
public function deletePulse () |
353
|
|
|
{ |
354
|
|
|
$this->checkInvalid(); |
355
|
|
|
|
356
|
|
|
$this->jsonResponse = self::deletePulseCall($this->getId()); |
|
|
|
|
357
|
|
|
$this->assignResults(); |
358
|
|
|
|
359
|
|
|
$this->deletedObject = true; |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
public function duplicatePulse ($groupId = NULL, $ownerId = NULL) |
363
|
9 |
|
{ |
364
|
|
|
$url = sprintf("%s/%s/pulses/%s/duplicate.json", self::apiEndpoint("boards"), $this->getBoardId(), $this->getId()); |
365
|
9 |
|
$postParams = array(); |
366
|
|
|
|
367
|
|
|
if ($ownerId instanceof PulseUser) |
368
|
|
|
{ |
369
|
|
|
$ownerId = $ownerId->getId(); |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
self::setIfNotNullOrEmpty($postParams, "group_id", $groupId); |
373
|
|
|
self::setIfNotNullOrEmpty($postParams, "owner_id", $ownerId); |
374
|
|
|
|
375
|
|
|
$result = self::sendPost($url, $postParams); |
376
|
|
|
$this->pulseInjection($result); |
377
|
|
|
|
378
|
|
|
return (new Pulse($result['pulse'])); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
View Code Duplication |
private function pulseInjection (&$result) |
|
|
|
|
382
|
|
|
{ |
383
|
|
|
$parentBoard = new PulseBoard($this->getBoardId()); |
384
|
|
|
|
385
|
|
|
// Inject some information so a Pulse object can survive on its own |
386
|
7 |
|
$result["pulse"]["group_id"] = $result["board_meta"]["group_id"]; |
387
|
|
|
$result["pulse"]["column_structure"] = $parentBoard->getColumns(); |
388
|
7 |
|
$result["pulse"]["raw_column_values"] = $result["column_values"]; |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
// ================================================================================================================ |
392
|
|
|
// Column data functions |
393
|
|
|
// ================================================================================================================ |
394
|
|
|
|
395
|
|
|
/** |
396
|
|
|
* Access a color type column value belonging to this pulse in order to read it or modify. |
397
|
|
|
* |
398
|
|
|
* This function should only be used to access color type values; an exception will be thrown otherwise. |
399
|
|
|
* |
400
|
|
|
* @api |
401
|
|
|
* |
402
|
|
|
* @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
403
|
|
|
* |
404
|
|
|
* @since 0.1.0 |
405
|
|
|
* |
406
|
|
|
* @throws ColumnNotFoundException The specified column ID does not exist for this Pulse |
407
|
|
|
* @throws InvalidColumnException The specified column is not a "color" type column |
408
|
|
|
* @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
409
|
9 |
|
* by this library or the DaPulse API. |
410
|
|
|
* |
411
|
9 |
|
* @return PulseColumnStatusValue A column object with access to its contents |
412
|
|
|
*/ |
413
|
|
|
public function getStatusColumn ($columnId) |
414
|
|
|
{ |
415
|
|
|
return $this->getColumn($columnId, PulseColumn::Status); |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
/** |
419
|
|
|
* Access a date type column value belonging to this pulse in order to read it or modify. |
420
|
|
|
* |
421
|
|
|
* This function should only be used to access data type values; an exception will be thrown otherwise. |
422
|
|
|
* |
423
|
|
|
* @api |
424
|
|
|
* |
425
|
|
|
* @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
426
|
|
|
* |
427
|
|
|
* @since 0.1.0 |
428
|
|
|
* |
429
|
|
|
* @throws ColumnNotFoundException The specified column ID does not exist for this Pulse |
430
|
|
|
* @throws InvalidColumnException The specified column is not a "date" type column |
431
|
|
|
* @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
432
|
4 |
|
* by this library or the DaPulse API. |
433
|
|
|
* |
434
|
4 |
|
* @return PulseColumnDateValue A column object with access to its contents |
435
|
|
|
*/ |
436
|
|
|
public function getDateColumn ($columnId) |
437
|
|
|
{ |
438
|
|
|
return $this->getColumn($columnId, PulseColumn::Date); |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
/** |
442
|
|
|
* Access a numeric type column value belonging to this pulse in order to read it or modify. |
443
|
|
|
* |
444
|
|
|
* This function should only be used to access data type values; an exception will be thrown otherwise. |
445
|
|
|
* |
446
|
|
|
* @api |
447
|
|
|
* |
448
|
|
|
* @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
449
|
|
|
* |
450
|
|
|
* @since 0.2.0 |
451
|
|
|
* |
452
|
|
|
* @throws ColumnNotFoundException The specified column ID does not exist for this Pulse |
453
|
|
|
* @throws InvalidColumnException The specified column is not a "numeric" type column |
454
|
|
|
* @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
455
|
5 |
|
* by this library or the DaPulse API. |
456
|
|
|
* |
457
|
5 |
|
* @return PulseColumnNumericValue A column object with access to its contents |
458
|
|
|
*/ |
459
|
|
|
public function getNumericColumn ($columnId) |
460
|
|
|
{ |
461
|
|
|
return $this->getColumn($columnId, PulseColumn::Numeric); |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
/** |
465
|
|
|
* Access a person type column value belonging to this pulse in order to read it or modify. |
466
|
|
|
* |
467
|
|
|
* This function should only be used to access person type values; an exception will be thrown otherwise. |
468
|
|
|
* |
469
|
|
|
* @api |
470
|
|
|
* |
471
|
|
|
* @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
472
|
|
|
* |
473
|
|
|
* @since 0.1.0 |
474
|
|
|
* |
475
|
|
|
* @throws ColumnNotFoundException The specified column ID does not exist for this Pulse |
476
|
40 |
|
* @throws InvalidColumnException The specified column is not a "person" type column |
477
|
|
|
* @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
478
|
40 |
|
* by this library or the DaPulse API. |
479
|
|
|
* |
480
|
40 |
|
* @return PulseColumnPersonValue A column object with access to its contents |
481
|
40 |
|
*/ |
482
|
|
|
public function getPersonColumn ($columnId) |
483
|
|
|
{ |
484
|
|
|
return $this->getColumn($columnId, PulseColumn::Person); |
485
|
|
|
} |
486
|
40 |
|
|
487
|
|
|
/** |
488
|
29 |
|
* Access a text type column value belonging to this pulse in order to read it or modify. |
489
|
|
|
* |
490
|
29 |
|
* This function should only be used to access text type values; an exception will be thrown otherwise. |
491
|
|
|
* |
492
|
|
|
* @api |
493
|
|
|
* |
494
|
|
|
* @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
495
|
29 |
|
* |
496
|
|
|
* @since 0.1.0 |
497
|
1 |
|
|
498
|
|
|
* @throws ColumnNotFoundException The specified column ID does not exist for this Pulse |
499
|
1 |
|
* @throws InvalidColumnException The specified column is not a "text" type column |
500
|
|
|
* @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
501
|
|
|
* by this library or the DaPulse API. |
502
|
|
|
* |
503
|
|
|
* @return PulseColumnTextValue A column object with access to its contents |
504
|
28 |
|
*/ |
505
|
|
|
public function getTextColumn ($columnId) |
506
|
|
|
{ |
507
|
|
|
return $this->getColumn($columnId, PulseColumn::Text); |
508
|
11 |
|
} |
509
|
11 |
|
|
510
|
|
|
/** |
511
|
11 |
|
* Access a timeline type column value belonging to this pulse in order to read it or modify. |
512
|
|
|
* |
513
|
1 |
|
* This function should only be used to access data type values; an exception will be thrown otherwise. |
514
|
|
|
* |
515
|
|
|
* @api |
516
|
|
|
* |
517
|
38 |
|
* @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
518
|
38 |
|
* |
519
|
38 |
|
* @since 0.2.1 |
520
|
|
|
* |
521
|
38 |
|
* @throws ColumnNotFoundException The specified column ID does not exist for this Pulse |
522
|
|
|
* @throws InvalidColumnException The specified column is not a "numeric" type column |
523
|
|
|
* @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
524
|
38 |
|
* by this library or the DaPulse API. |
525
|
|
|
* |
526
|
|
|
* @return PulseColumnTimelineValue A column object with access to its contents |
527
|
|
|
*/ |
528
|
|
|
public function getTimelineColumn ($columnId) |
529
|
|
|
{ |
530
|
|
|
return $this->getColumn($columnId, PulseColumn::Timeline); |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
/** |
534
|
|
|
* Build a pulse's column object if it doesn't exist or return the existing column. |
535
|
|
|
* |
536
|
|
|
* @param string $columnId The ID of the column to access. This is typically a slugified version of the column |
537
|
|
|
* title |
538
|
|
|
* @param string $columnType The type of column being accessed: 'text', 'color', 'person', 'numeric', or 'date' |
539
|
|
|
* |
540
|
|
|
* @since 0.1.0 |
541
|
|
|
* |
542
|
|
|
* @throws ColumnNotFoundException The specified column ID does not exist for this Pulse |
543
|
|
|
* @throws InvalidColumnException The specified column is not the same type as specified in `$columnType` |
544
|
|
|
* @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
545
|
|
|
* by this library or the DaPulse API. |
546
|
|
|
* |
547
|
|
|
* @return PulseColumnValue The returned object will be a child of this abstract class. |
548
|
|
|
*/ |
549
|
|
|
private function getColumn ($columnId, $columnType) |
550
|
|
|
{ |
551
|
|
|
if (!isset($this->column_values) || !array_key_exists($columnId, $this->column_values)) |
552
|
|
|
{ |
553
|
|
|
$key = ArrayUtilities::array_search_column($this->raw_column_values, 'cid', $columnId); |
554
|
|
|
$data = array(); |
555
|
|
|
|
556
|
|
|
// We can't find the key, this means that we got our information from accessing a Pulse directly instead of |
557
|
|
|
// getting it through a PulseBoard. This isn't as robust as accessing a PulseBoard but it's more efficient. |
558
|
|
|
// We make a separate API call to get the value of a column. |
559
|
|
|
if ($key === false) |
560
|
|
|
{ |
561
|
|
|
$url = sprintf("%s/%d/columns/%s/value.json", self::apiEndpoint("boards"), $this->getBoardId(), $columnId); |
562
|
|
|
$params = array( |
563
|
|
|
"pulse_id" => $this->getId() |
564
|
|
|
); |
565
|
|
|
|
566
|
|
|
try |
567
|
|
|
{ |
568
|
|
|
$results = self::sendGet($url, $params); |
569
|
|
|
} |
570
|
|
|
catch (HttpException $e) |
571
|
|
|
{ |
572
|
|
|
throw new ColumnNotFoundException("The '$columnId' column could not be found"); |
573
|
|
|
} |
574
|
|
|
|
575
|
|
|
// Store our value inside of jsonResponse so all of the respective objects can treat the data the same |
576
|
|
|
// as when accessed through a PulseBoard |
577
|
|
|
$data['jsonResponse']['value'] = $results['value']; |
578
|
|
|
} |
579
|
|
|
else |
580
|
|
|
{ |
581
|
|
|
$data = $this->raw_column_values[$key]; |
582
|
|
|
$type = $this->column_structure[$key]->getType(); |
583
|
|
|
|
584
|
|
|
if ($type !== $columnType) |
585
|
|
|
{ |
586
|
|
|
throw new InvalidColumnException("The '$columnId' column was expected to be '$columnType' but was '$type' instead."); |
587
|
|
|
} |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
$data['column_id'] = $columnId; |
591
|
|
|
$data['board_id'] = $this->getBoardId(); |
592
|
|
|
$data['pulse_id'] = $this->getId(); |
593
|
|
|
|
594
|
|
|
$this->column_values[$columnId] = PulseColumnValue::_createColumnType($columnType, $data); |
595
|
|
|
} |
596
|
20 |
|
|
597
|
|
|
return $this->column_values[$columnId]; |
598
|
20 |
|
} |
599
|
|
|
|
600
|
20 |
|
// ================================================================================================================ |
601
|
|
|
// Notes functions |
602
|
|
|
// ================================================================================================================ |
603
|
|
|
|
604
|
|
|
/** |
605
|
|
|
* Create a new note in this project |
606
|
|
|
* |
607
|
|
|
* @api |
608
|
|
|
* |
609
|
|
|
* @param string $title The title of the note |
610
|
|
|
* @param string $content The body of the note |
611
|
|
|
* @param bool $ownersOnly Set to true if only pulse owners can edit this note. |
612
|
|
|
* @param int|null $userId The id of the user to be marked as the note's last updater |
613
|
|
|
* @param bool $createUpdate Indicates whether to create an update on the pulse notifying subscribers on the |
614
|
|
|
* changes (required user_id to be set). |
615
|
|
|
* |
616
|
|
|
* @since 0.1.0 |
617
|
|
|
* @return PulseNote |
618
|
|
|
*/ |
619
|
|
|
public function addNote ($title, $content, $ownersOnly = false, $userId = NULL, $createUpdate = false) |
620
|
|
|
{ |
621
|
|
|
$url = sprintf($this->urlSyntax, self::apiEndpoint(), $this->id, "notes"); |
622
|
|
|
$postParams = array( |
623
|
|
|
"id" => $this->id, |
624
|
|
|
"title" => $title, |
625
|
|
|
"content" => $content, |
626
|
|
|
"owners_only" => $ownersOnly, |
627
|
|
|
"create_update" => $createUpdate |
628
|
|
|
); |
629
|
|
|
|
630
|
|
|
self::setIfNotNullOrEmpty($postParams, "user_id", $userId); |
631
|
|
|
|
632
|
|
|
if ($createUpdate && is_null($userId)) |
633
|
|
|
{ |
634
|
|
|
throw new \InvalidArgumentException("The user_id value must be set if an update is to be created"); |
635
|
|
|
} |
636
|
|
|
|
637
|
|
|
$noteResult = self::sendPost($url, $postParams); |
638
|
|
|
|
639
|
|
|
return (new PulseNote($noteResult)); |
640
|
|
|
} |
641
|
|
|
|
642
|
|
|
/** |
643
|
|
|
* Return all of the notes belonging to this project |
644
|
|
|
* |
645
|
|
|
* @api |
646
|
|
|
* @since 0.1.0 |
647
|
|
|
* @return PulseNote[] |
648
|
|
|
*/ |
649
|
|
|
public function getNotes () |
650
|
|
|
{ |
651
|
|
|
$url = sprintf($this->urlSyntax, self::apiEndpoint(), $this->id, "notes"); |
652
|
|
|
|
653
|
|
|
return self::fetchAndCastToObjectArray($url, "PulseNote"); |
654
|
|
|
} |
655
|
|
|
|
656
|
|
|
// ================================================================================================================ |
657
|
|
|
// Updates functions |
658
|
|
|
// ================================================================================================================ |
659
|
|
|
|
660
|
|
|
/** |
661
|
|
|
* Get all of the updates that belong to this Pulse in reverse chronological order |
662
|
|
|
* |
663
|
|
|
* @api |
664
|
|
|
* |
665
|
|
|
* @since 0.1.0 |
666
|
|
|
* |
667
|
|
|
* @return PulseUpdate[] |
668
|
|
|
*/ |
669
|
|
|
public function getUpdates () |
670
|
|
|
{ |
671
|
|
|
$url = sprintf($this->urlSyntax, self::apiEndpoint(), $this->id, "updates"); |
672
|
|
|
|
673
|
|
|
return self::fetchAndCastToObjectArray($url, "PulseUpdate"); |
674
|
|
|
} |
675
|
|
|
|
676
|
|
|
/** |
677
|
|
|
* Create an update for the current Pulse |
678
|
|
|
* |
679
|
|
|
* @api |
680
|
|
|
* |
681
|
|
|
* @param int|PulseUser $user |
682
|
|
|
* @param string $text |
683
|
|
|
* @param null|bool $announceToAll |
684
|
|
|
* |
685
|
|
|
* @since 0.2.2 A PulseUpdate object is returned containing the information of the newly created Update |
686
|
|
|
* @since 0.1.0 |
687
|
|
|
* |
688
|
|
|
* @return PulseUpdate |
689
|
|
|
*/ |
690
|
|
|
public function createUpdate ($user, $text, $announceToAll = NULL) |
691
|
|
|
{ |
692
|
|
|
return PulseUpdate::createUpdate($user, $this->getId(), $text, $announceToAll); |
693
|
|
|
} |
694
|
|
|
|
695
|
|
|
// ================================================================================================================ |
696
|
|
|
// Static functions |
697
|
|
|
// ================================================================================================================ |
698
|
|
|
|
699
|
|
|
/** |
700
|
|
|
* Get all of the pulses that belong to the organization across all boards. |
701
|
|
|
* |
702
|
|
|
* To modify the amount of data returned with pagination, use the following values in the array to configure your |
703
|
|
|
* pagination or offsets. |
704
|
|
|
* |
705
|
|
|
* ```php |
706
|
|
|
* $params = array( |
707
|
|
|
* "page" => 1, // (int) Page offset to fetch |
708
|
|
|
* "per_page" => 10, // (int) Number of results per page |
709
|
|
|
* "offset" => 5, // (int) Instead of starting at result 0, start counting from result 5 |
710
|
|
|
* "order_by_latest" => true // (bool) Order the pulses with the most recent first |
711
|
|
|
* ); |
712
|
|
|
* ``` |
713
|
|
|
* |
714
|
|
|
* @api |
715
|
|
|
* |
716
|
|
|
* @param array $params GET parameters passed to with the query to modify the data returned. |
717
|
|
|
* |
718
|
|
|
* @since 0.1.0 |
719
|
|
|
* @return Pulse[] |
720
|
|
|
*/ |
721
|
|
|
public static function getPulses ($params = array()) |
722
|
|
|
{ |
723
|
|
|
$url = sprintf("%s.json", self::apiEndpoint()); |
724
|
|
|
|
725
|
|
|
return self::fetchAndCastToObjectArray($url, "Pulse", $params); |
726
|
|
|
} |
727
|
|
|
} |
728
|
|
|
|
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..