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\InvalidObjectException; |
11
|
|
|
use allejo\DaPulse\Objects\ApiObject; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class PulseNote |
15
|
|
|
* |
16
|
|
|
* @api |
17
|
|
|
* @package allejo\DaPulse |
18
|
|
|
* @since 0.1.0 |
19
|
|
|
*/ |
20
|
|
|
class PulseNote extends ApiObject |
21
|
|
|
{ |
22
|
|
|
const API_PREFIX = "pulses"; |
23
|
|
|
|
24
|
|
|
// ================================================================================================================ |
25
|
|
|
// Instance Variables |
26
|
|
|
// ================================================================================================================ |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The collaboration box type (rich_text, file_list, faq_list). |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $type; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The note's title. |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $title; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* The note's project_id. |
44
|
|
|
* |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
protected $project_id; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Describes who can edit this note. Can be either 'everyone' or 'owners'. |
51
|
|
|
* |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
protected $permissions; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* The note's body |
58
|
|
|
* |
59
|
|
|
* @var string |
60
|
|
|
*/ |
61
|
|
|
protected $content; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Creation time. |
65
|
|
|
* |
66
|
|
|
* @var \DateTime |
67
|
|
|
*/ |
68
|
|
|
protected $created_at; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Last update time. |
72
|
|
|
* |
73
|
|
|
* @var \DateTime |
74
|
|
|
*/ |
75
|
|
|
protected $updated_at; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* PulseNote constructor. |
79
|
|
|
* |
80
|
|
|
* @internal |
81
|
|
|
* |
82
|
|
|
* @param array $array |
83
|
|
|
*/ |
84
|
1 |
|
public function __construct ($array) |
85
|
|
|
{ |
86
|
1 |
|
$this->arrayConstructionOnly = true; |
87
|
|
|
|
88
|
1 |
|
parent::__construct($array); |
89
|
1 |
|
} |
90
|
|
|
|
91
|
|
|
// ================================================================================================================ |
92
|
|
|
// Getter functions |
93
|
|
|
// ================================================================================================================ |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* The collaboration box type (rich_text, file_list, faq_list). |
97
|
|
|
* |
98
|
|
|
* @api |
99
|
|
|
* |
100
|
|
|
* @since 0.1.0 |
101
|
|
|
* |
102
|
|
|
* @return string |
103
|
|
|
*/ |
104
|
1 |
|
public function getType () |
105
|
|
|
{ |
106
|
1 |
|
return $this->type; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* The note's id. |
111
|
|
|
* |
112
|
|
|
* @api |
113
|
|
|
* |
114
|
|
|
* @since 0.1.0 |
115
|
|
|
* |
116
|
|
|
* @return string |
|
|
|
|
117
|
|
|
*/ |
118
|
2 |
|
public function getId () |
119
|
|
|
{ |
120
|
2 |
|
return $this->id; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* The note's title. |
125
|
|
|
* |
126
|
|
|
* @api |
127
|
|
|
* |
128
|
|
|
* @since 0.1.0 |
129
|
|
|
* |
130
|
|
|
* @return string |
131
|
|
|
*/ |
132
|
2 |
|
public function getTitle () |
133
|
|
|
{ |
134
|
2 |
|
return $this->title; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* The note's project_id. |
139
|
|
|
* |
140
|
|
|
* @api |
141
|
|
|
* |
142
|
|
|
* @since 0.1.0 |
143
|
|
|
* |
144
|
|
|
* @return string |
145
|
|
|
*/ |
146
|
2 |
|
public function getPulseId () |
147
|
|
|
{ |
148
|
2 |
|
return $this->project_id; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Describes who can edit this note. Can be either 'everyone' or 'owners'. |
153
|
|
|
* |
154
|
|
|
* @api |
155
|
|
|
* |
156
|
|
|
* @since 0.1.0 |
157
|
|
|
* |
158
|
|
|
* @return string |
159
|
|
|
*/ |
160
|
1 |
|
public function getPermissions () |
161
|
|
|
{ |
162
|
1 |
|
return $this->permissions; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* The note's body. |
167
|
|
|
* |
168
|
|
|
* @api |
169
|
|
|
* |
170
|
|
|
* @since 0.1.0 |
171
|
|
|
* |
172
|
|
|
* @return string |
173
|
|
|
*/ |
174
|
2 |
|
public function getContent () |
175
|
|
|
{ |
176
|
2 |
|
return $this->content; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Creation time. |
181
|
|
|
* |
182
|
|
|
* @api |
183
|
|
|
* |
184
|
|
|
* @since 0.1.0 |
185
|
|
|
* |
186
|
|
|
* @return \DateTime |
187
|
|
|
*/ |
188
|
1 |
|
public function getCreatedAt () |
189
|
|
|
{ |
190
|
1 |
|
self::lazyCast($this->created_at, '\DateTime'); |
191
|
|
|
|
192
|
1 |
|
return $this->created_at; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Last update time. |
197
|
|
|
* |
198
|
|
|
* @api |
199
|
|
|
* |
200
|
|
|
* @since 0.1.0 |
201
|
|
|
* |
202
|
|
|
* @return \DateTime |
203
|
|
|
*/ |
204
|
1 |
|
public function getUpdatedAt () |
205
|
|
|
{ |
206
|
1 |
|
self::lazyCast($this->updated_at, '\DateTime'); |
207
|
|
|
|
208
|
1 |
|
return $this->updated_at; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
// ================================================================================================================ |
212
|
|
|
// Modification functions |
213
|
|
|
// ================================================================================================================ |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Edit a note's content or information. Set values to NULL in order to not update them |
217
|
|
|
* |
218
|
|
|
* @api |
219
|
|
|
* |
220
|
|
|
* @param null|string $title The new title of the note |
221
|
|
|
* @param null|string $content The new content of the note |
222
|
|
|
* @param null|int|PulseUser $user The new author of the note |
223
|
|
|
* @param null|bool $createUpdate Whether to create an update or not |
224
|
|
|
* |
225
|
|
|
* @since 0.1.0 |
226
|
|
|
* |
227
|
|
|
* @throws InvalidObjectException The object has already been deleted from DaPulse |
228
|
|
|
* @throws \InvalidArgumentException An update was to be created but no author for the update was specified |
229
|
|
|
* |
230
|
|
|
* @return $this |
231
|
|
|
*/ |
232
|
1 |
|
public function editNote ($title = null, $content = null, $user = null, $createUpdate = null) |
233
|
|
|
{ |
234
|
1 |
|
$this->checkInvalid(); |
235
|
|
|
|
236
|
1 |
|
if (!is_null($user)) |
237
|
|
|
{ |
238
|
|
|
$user = PulseUser::_castToInt($user); |
239
|
|
|
} |
240
|
|
|
|
241
|
1 |
|
$url = $this->getNotesUrl(); |
242
|
|
|
$postParams = [ |
243
|
1 |
|
"id" => $this->getPulseId(), |
244
|
1 |
|
"note_id" => $this->getId() |
245
|
|
|
]; |
246
|
|
|
|
247
|
1 |
|
self::setIfNotNullOrEmpty($postParams, "title", $title); |
248
|
1 |
|
self::setIfNotNullOrEmpty($postParams, "content", $content); |
249
|
1 |
|
self::setIfNotNullOrEmpty($postParams, "user_id", $user); |
250
|
1 |
|
self::setIfNotNullOrEmpty($postParams, "create_update", $createUpdate); |
251
|
|
|
|
252
|
1 |
|
if ($createUpdate && is_null($user)) |
253
|
|
|
{ |
254
|
|
|
throw new \InvalidArgumentException('The $user value must be set if an update is to be created'); |
255
|
|
|
} |
256
|
|
|
|
257
|
1 |
|
$this->jsonResponse = self::sendPut($url, $postParams); |
|
|
|
|
258
|
1 |
|
$this->assignResults(); |
259
|
|
|
|
260
|
1 |
|
return $this; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* Edit the title of the note only. |
265
|
|
|
* |
266
|
|
|
* **Note** This is a convenience function that just calls PulseNote->editNote(). In order to change multiple |
267
|
|
|
* values, use PulseNote->editNote() instead of chaining the individual edit functions because each convenience |
268
|
|
|
* function will make their own separate API call making the process significantly slower. |
269
|
|
|
* |
270
|
|
|
* @api |
271
|
|
|
* |
272
|
|
|
* @param string $title The new title of the note |
273
|
|
|
* |
274
|
|
|
* @since 0.1.0 |
275
|
|
|
* |
276
|
|
|
* @return $this |
277
|
|
|
*/ |
278
|
1 |
|
public function editTitle ($title) |
279
|
|
|
{ |
280
|
1 |
|
return $this->editNote($title); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* Edit the content of the note only. |
285
|
|
|
* |
286
|
|
|
* **Note** This is a convenience function that just calls PulseNote->editNote(). In order to change multiple |
287
|
|
|
* values, use PulseNote->editNote() instead of chaining the individual edit functions because each convenience |
288
|
|
|
* function will make their own separate API call making the process significantly slower. |
289
|
|
|
* |
290
|
|
|
* @api |
291
|
|
|
* |
292
|
|
|
* @param string $content The new content of the note |
293
|
|
|
* |
294
|
|
|
* @since 0.1.0 |
295
|
|
|
* |
296
|
|
|
* @return $this |
297
|
|
|
*/ |
298
|
1 |
|
public function editContent ($content) |
299
|
|
|
{ |
300
|
1 |
|
return $this->editNote(null, $content); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* Edit the author of the note only. |
305
|
|
|
* |
306
|
|
|
* **Note** This is a convenience function that just calls PulseNote->editNote(). In order to change multiple |
307
|
|
|
* values, use PulseNote->editNote() instead of chaining the individual edit functions because each convenience |
308
|
|
|
* function will make their own separate API call making the process significantly slower. |
309
|
|
|
* |
310
|
|
|
* @api |
311
|
|
|
* |
312
|
|
|
* @param string $userId The new author of the note |
313
|
|
|
* |
314
|
|
|
* @since 0.1.0 |
315
|
|
|
* |
316
|
|
|
* @return $this |
317
|
|
|
*/ |
318
|
|
|
public function editAuthor ($userId) |
319
|
|
|
{ |
320
|
|
|
return $this->editNote(null, null, $userId); |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* Delete this note |
325
|
|
|
* |
326
|
|
|
* @api |
327
|
|
|
* |
328
|
|
|
* @since 0.1.0 |
329
|
|
|
* |
330
|
|
|
* @throws InvalidObjectException The object has already been deleted from DaPulse |
331
|
|
|
*/ |
332
|
1 |
|
public function deleteNote () |
333
|
|
|
{ |
334
|
1 |
|
$this->checkInvalid(); |
335
|
|
|
|
336
|
1 |
|
self::sendDelete($this->getNotesUrl()); |
337
|
|
|
|
338
|
1 |
|
$this->deletedObject = true; |
339
|
1 |
|
} |
340
|
|
|
|
341
|
2 |
|
private function getNotesUrl () |
342
|
|
|
{ |
343
|
2 |
|
return sprintf("%s/%s/notes/%s.json", self::apiEndpoint(), $this->getPulseId(), $this->getId()); |
344
|
|
|
} |
345
|
|
|
} |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.