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