1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* User: chipwasson |
4
|
|
|
* Date: 1/25/17 |
5
|
|
|
* Time: 6:47 PM |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace GorkaLaucirica\HipchatAPIv2Client\Model; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class Card |
12
|
|
|
* |
13
|
|
|
* Allows you to send a Card format message rather than a plain text/only-html message. |
14
|
|
|
* |
15
|
|
|
* Some Hipchat clients may not support Cards, you must still include a `message` property in your Message. |
16
|
|
|
* |
17
|
|
|
* More Info: https://developer.atlassian.com/hipchat/guide/sending-messages#SendingMessages-UsingCards |
18
|
|
|
* Even More Info: https://www.hipchat.com/docs/apiv2/method/send_room_notification |
19
|
|
|
* |
20
|
|
|
* @package GorkaLaucirica\HipchatAPIv2Client\Model |
21
|
|
|
*/ |
22
|
|
|
class Card |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var CardStyle $style @required |
26
|
|
|
* Type of the card |
27
|
|
|
* Valid length range: 1 - 16. |
28
|
|
|
* Valid values: file, image, application, link, media. |
29
|
|
|
*/ |
30
|
|
|
protected $style; |
31
|
|
|
/** |
32
|
|
|
* @var string $description @required |
33
|
|
|
* |
34
|
|
|
*/ |
35
|
|
|
protected $description; |
36
|
|
|
/** |
37
|
|
|
* @var CardFormat $format |
38
|
|
|
* Application cards can be compact (1 to 2 lines) or medium (1 to 5 lines) |
39
|
|
|
* Valid length range: 1 - 25. |
40
|
|
|
* Valid values: compact, medium. |
41
|
|
|
*/ |
42
|
|
|
protected $format; |
43
|
|
|
/** |
44
|
|
|
* @var string $url |
45
|
|
|
*/ |
46
|
|
|
protected $url; |
47
|
|
|
/** |
48
|
|
|
* @var string $title @required |
49
|
|
|
*/ |
50
|
|
|
protected $title; |
51
|
|
|
/** |
52
|
|
|
* @var CardThumbnail $thumbnail |
53
|
|
|
*/ |
54
|
|
|
protected $thumbnail; |
55
|
|
|
/** |
56
|
|
|
* @var CardActivity $activity |
57
|
|
|
*/ |
58
|
|
|
protected $activity; |
59
|
|
|
/** |
60
|
|
|
* @var CardAttribute[] $attributes |
61
|
|
|
*/ |
62
|
|
|
protected $attributes; |
63
|
|
|
/** |
64
|
|
|
* @var string $id @required |
65
|
|
|
*/ |
66
|
|
|
protected $id; |
67
|
|
|
/** |
68
|
|
|
* @var CardIcon $icon |
69
|
|
|
*/ |
70
|
|
|
protected $icon; |
71
|
|
|
/** |
72
|
|
|
* @var CardImage $images |
73
|
|
|
*/ |
74
|
|
|
protected $images; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Card constructor. |
78
|
|
|
* |
79
|
|
|
* @param CardStyle $style Style of the Card to use |
80
|
|
|
* @param string $description |
81
|
|
|
* @param string $title |
82
|
|
|
*/ |
83
|
|
|
public function __construct($title, $style, $description) |
84
|
|
|
{ |
85
|
|
|
$this->title = $title; |
86
|
|
|
$this->style = $style; |
87
|
|
|
$this->description = $description; |
88
|
|
|
$this->id = md5($title.$description); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return CardStyle |
93
|
|
|
*/ |
94
|
|
|
public function getStyle() |
95
|
|
|
{ |
96
|
|
|
return $this->style; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param CardStyle $style |
101
|
|
|
*/ |
102
|
|
|
public function setStyle($style) |
103
|
|
|
{ |
104
|
|
|
$this->style = $style; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return string |
109
|
|
|
*/ |
110
|
|
|
public function getDescription() |
111
|
|
|
{ |
112
|
|
|
return $this->description; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param string $description |
117
|
|
|
*/ |
118
|
|
|
public function setDescription($description) |
119
|
|
|
{ |
120
|
|
|
$this->description = $description; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return CardFormat |
125
|
|
|
*/ |
126
|
|
|
public function getFormat() |
127
|
|
|
{ |
128
|
|
|
return $this->format; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param CardFormat $format |
133
|
|
|
*/ |
134
|
|
|
public function setFormat($format) |
135
|
|
|
{ |
136
|
|
|
$this->format = $format; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @return string |
141
|
|
|
*/ |
142
|
|
|
public function getUrl() |
143
|
|
|
{ |
144
|
|
|
return $this->url; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param string $url |
149
|
|
|
*/ |
150
|
|
|
public function setUrl($url) |
151
|
|
|
{ |
152
|
|
|
$this->url = $url; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @return string |
157
|
|
|
*/ |
158
|
|
|
public function getTitle() |
159
|
|
|
{ |
160
|
|
|
return $this->title; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @param string $title |
165
|
|
|
*/ |
166
|
|
|
public function setTitle($title) |
167
|
|
|
{ |
168
|
|
|
$this->title = $title; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @return CardThumbnail |
173
|
|
|
*/ |
174
|
|
|
public function getThumbnail() |
175
|
|
|
{ |
176
|
|
|
return $this->thumbnail; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @param CardThumbnail $thumbnail |
181
|
|
|
*/ |
182
|
|
|
public function setThumbnail($thumbnail) |
183
|
|
|
{ |
184
|
|
|
$this->thumbnail = $thumbnail; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @return CardActivity |
189
|
|
|
*/ |
190
|
|
|
public function getActivity() |
191
|
|
|
{ |
192
|
|
|
return $this->activity; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @param CardActivity $activity |
197
|
|
|
*/ |
198
|
|
|
public function setActivity($activity) |
199
|
|
|
{ |
200
|
|
|
$this->activity = $activity; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @return CardAttribute[] |
205
|
|
|
*/ |
206
|
|
|
public function getAttributes() |
207
|
|
|
{ |
208
|
|
|
return $this->attributes; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @param CardAttribute $attribute |
213
|
|
|
*/ |
214
|
|
|
public function addAttribute($attribute) |
215
|
|
|
{ |
216
|
|
|
if (!isset($this->attributes)){ |
217
|
|
|
$this->attributes = array(); |
218
|
|
|
} |
219
|
|
|
$this->attributes[] = $attribute; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @return string |
224
|
|
|
*/ |
225
|
|
|
public function getId() |
226
|
|
|
{ |
227
|
|
|
return $this->id; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @param string $id |
232
|
|
|
*/ |
233
|
|
|
public function setId($id) |
234
|
|
|
{ |
235
|
|
|
$this->id = $id; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @return CardIcon |
240
|
|
|
*/ |
241
|
|
|
public function getIcon() |
242
|
|
|
{ |
243
|
|
|
return $this->icon; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @param CardIcon $icon |
248
|
|
|
*/ |
249
|
|
|
public function setIcon($icon) |
250
|
|
|
{ |
251
|
|
|
$this->icon = $icon; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* @return CardImage |
256
|
|
|
*/ |
257
|
|
|
public function getImages() |
258
|
|
|
{ |
259
|
|
|
return $this->images; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* @param CardImage $images |
264
|
|
|
*/ |
265
|
|
|
public function setImages($images) |
266
|
|
|
{ |
267
|
|
|
$this->images = $images; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
public function toArray(){ |
271
|
|
|
$result = array(); |
272
|
|
|
if ($this->style) $result['style'] = $this->style; |
273
|
|
|
if ($this->description) $result['description'] = $this->description; |
274
|
|
|
if ($this->format) $result['format'] = $this->format; |
275
|
|
|
if ($this->url) $result['url'] = $this->url; |
276
|
|
|
if ($this->title) $result['title'] = $this->title; |
277
|
|
|
if ($this->thumbnail) $result['thumbnail'] = $this->thumbnail->toArray(); |
278
|
|
|
if ($this->activity) $result['activity'] = $this->activity->toArray(); |
279
|
|
|
if ($this->attributes) { |
|
|
|
|
280
|
|
|
$result['attributes'] = array(); |
281
|
|
|
foreach ($this->attributes as $attribute) { |
282
|
|
|
$result['attributes'][] = $attribute->toArray(); |
283
|
|
|
} |
284
|
|
|
} |
285
|
|
|
if ($this->images) $result['images'] = $this->images->toArray(); |
286
|
|
|
if ($this->id) $result['id'] = $this->id; |
287
|
|
|
if ($this->icon) $result['icon'] = $this->icon->toArray(); |
288
|
|
|
return $result; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
} |
292
|
|
|
|
293
|
|
View Code Duplication |
class CardImage { |
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* @var string $url Image URL |
296
|
|
|
* @var string $url2x Image URL for the icon on retina |
297
|
|
|
*/ |
298
|
|
|
public $url; |
299
|
|
|
public $urlat2; |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* CardImage constructor. |
303
|
|
|
* |
304
|
|
|
* @param string $url Image URL |
305
|
|
|
*/ |
306
|
|
|
public function __construct($url) |
307
|
|
|
{ |
308
|
|
|
$this->url = $url; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
public function toArray(){ |
312
|
|
|
$result = array(); |
313
|
|
|
if ($this->url) $result['url'] = $this->url; |
314
|
|
|
if ($this->urlat2) $result['url@2x'] = $this->urlat2; |
315
|
|
|
return $result; |
316
|
|
|
} |
317
|
|
|
} |
318
|
|
|
|
319
|
|
View Code Duplication |
class CardAttribute { |
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* @var CardAttributeValue $value @required |
322
|
|
|
* @var string $label Valid length range: 1 - 50. |
323
|
|
|
*/ |
324
|
|
|
public $value; |
325
|
|
|
public $label; |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* CardAttribute constructor. |
329
|
|
|
* |
330
|
|
|
* @param string $value Value for the attribute |
331
|
|
|
*/ |
332
|
|
|
public function __construct($value) |
333
|
|
|
{ |
334
|
|
|
$this->value = new CardAttributeValue($value); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
public function toArray(){ |
338
|
|
|
$result = array(); |
339
|
|
|
if ($this->value) $result['value'] = $this->value->toArray(); |
340
|
|
|
if ($this->label) $result['label'] = $this->label; |
341
|
|
|
return $result; |
342
|
|
|
} |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
class CardAttributeValue { |
346
|
|
|
/** |
347
|
|
|
* @var string $url Url to be opened when a user clicks on the label. Valid length range: 1 - unlimited. |
348
|
|
|
* @var AttributeValueStyle $style AUI Integrations for now supporting only lozenges |
349
|
|
|
* @var string $label The text representation of the value @required |
350
|
|
|
* @var CardIcon $icon |
351
|
|
|
*/ |
352
|
|
|
public $url; |
353
|
|
|
public $style; |
354
|
|
|
public $label; |
355
|
|
|
public $icon; |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* CardAttributeValue constructor. |
359
|
|
|
* |
360
|
|
|
* @param string $label The text representation of the value |
361
|
|
|
*/ |
362
|
|
|
public function __construct($label) |
363
|
|
|
{ |
364
|
|
|
$this->label = $label; |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
public function toArray(){ |
368
|
|
|
$result = array(); |
369
|
|
|
if ($this->url) $result['url'] = $this->url; |
370
|
|
|
if ($this->style) $result['style'] = $this->style; |
371
|
|
|
if ($this->label) $result['label'] = $this->label; |
372
|
|
|
if ($this->icon) $result['icon'] = $this->icon; |
373
|
|
|
return $result; |
374
|
|
|
} |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* The activity will generate a collapsible card of one line showing |
379
|
|
|
* the html and the ability to maximize to see all the content. |
380
|
|
|
* |
381
|
|
|
* @package GorkaLaucirica\HipchatAPIv2Client\Model |
382
|
|
|
*/ |
383
|
|
View Code Duplication |
class CardActivity { |
|
|
|
|
384
|
|
|
/** |
385
|
|
|
* @var string $html Html for the activity to show in one line a summary of the action that happened |
386
|
|
|
* Valid length range: 1 - unlimited. @required |
387
|
|
|
* @var CardIcon $icon |
388
|
|
|
*/ |
389
|
|
|
public $html; |
390
|
|
|
public $icon; |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* CardActivity constructor. |
394
|
|
|
* |
395
|
|
|
* @param string $html Html for the activity to show in one line a summary of the action that happened |
396
|
|
|
*/ |
397
|
|
|
public function __construct($html) |
398
|
|
|
{ |
399
|
|
|
$this->html = $html; |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
public function toArray(){ |
403
|
|
|
$result = array(); |
404
|
|
|
if ($this->html) $result['html'] = $this->html; |
405
|
|
|
if ($this->icon) $result['icon'] = $this->icon->toArray(); |
406
|
|
|
return $result; |
407
|
|
|
} |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* An object with the following properties. |
412
|
|
|
* @package GorkaLaucirica\HipchatAPIv2Client\Model |
413
|
|
|
*/ |
414
|
|
View Code Duplication |
class CardIcon { |
|
|
|
|
415
|
|
|
/** |
416
|
|
|
* @var string $url The url where the icon is Valid length range: 1 - unlimited. @required |
417
|
|
|
* @var string $urlat2 The url for the icon in retina. Valid length range: 1 - unlimited. |
418
|
|
|
*/ |
419
|
|
|
public $url; |
420
|
|
|
public $urlat2; |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* CardIcon constructor. |
424
|
|
|
* |
425
|
|
|
* @param string $url The URL for the icon |
426
|
|
|
*/ |
427
|
|
|
public function __construct($url) |
428
|
|
|
{ |
429
|
|
|
$this->url = $url; |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
public function toArray(){ |
433
|
|
|
$result = array(); |
434
|
|
|
if ($this->url) $result['url'] = $this->url; |
435
|
|
|
if ($this->urlat2) $result['url@2x'] = $this->urlat2; |
436
|
|
|
return $result; |
437
|
|
|
} |
438
|
|
|
} |
439
|
|
|
|
440
|
|
|
/** |
441
|
|
|
* An object with the following properties. |
442
|
|
|
* @package GorkaLaucirica\HipchatAPIv2Client\Model |
443
|
|
|
*/ |
444
|
|
|
class CardThumbnail { |
445
|
|
|
/** |
446
|
|
|
* @var string $url The thumbnail url. Valid length range: 1 - 250. @required |
447
|
|
|
* @var integer $width The original width of the image |
448
|
|
|
* @var string $urlat2 The thumbnail url in retina. Valid length range: 1 - 250. |
449
|
|
|
* @var integer $height The original height of the image |
450
|
|
|
*/ |
451
|
|
|
public $url; |
452
|
|
|
public $width; |
453
|
|
|
public $urlat2; |
454
|
|
|
public $height; |
455
|
|
|
|
456
|
|
|
/** |
457
|
|
|
* CardThumbnail constructor. |
458
|
|
|
* |
459
|
|
|
* @param string $url The URL for the thumbnail |
460
|
|
|
*/ |
461
|
|
|
public function __construct($url) |
462
|
|
|
{ |
463
|
|
|
$this->url = $url; |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
public function toArray(){ |
467
|
|
|
$result = array(); |
468
|
|
|
if ($this->url) $result['url'] = $this->url; |
469
|
|
|
if ($this->width) $result['width'] = $this->width; |
470
|
|
|
if ($this->urlat2) $result['url@2x'] = $this->urlat2; |
471
|
|
|
if ($this->height) $result['height'] = $this->height; |
472
|
|
|
return $result; |
473
|
|
|
} |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
abstract class CardStyle { |
477
|
|
|
const file = "file"; |
478
|
|
|
const image = "image"; |
479
|
|
|
const application = "application"; |
480
|
|
|
const link = "link"; |
481
|
|
|
const media = "media"; |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
abstract class CardFormat { |
485
|
|
|
const compact = "compact"; |
486
|
|
|
const medium = "medium"; |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
abstract class AttributeValueStyle { |
490
|
|
|
const lozenge_success = "lozenge-success"; |
491
|
|
|
const lozenge_error = "lozenge-error"; |
492
|
|
|
const lozenge_current = "lozenge-current"; |
493
|
|
|
const lozenge_complete = "lozenge-complete"; |
494
|
|
|
const lozenge_moved = "lozenge-moved"; |
495
|
|
|
const lozenge = "lozenge"; |
496
|
|
|
} |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.