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