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