1
|
|
|
<?php |
2
|
|
|
namespace Kerox\Messenger\Model\Message\Attachment\Template\Element; |
3
|
|
|
|
4
|
|
|
class GenericElement extends AbstractElement |
5
|
|
|
{ |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @var null|string |
9
|
|
|
*/ |
10
|
|
|
protected $itemUrl; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var null|\Kerox\Messenger\Model\Common\Buttons\AbstractButtons[] |
14
|
|
|
*/ |
15
|
|
|
protected $buttons = []; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Element constructor. |
19
|
|
|
* |
20
|
|
|
* @param string $title |
21
|
|
|
*/ |
22
|
|
|
public function __construct(string $title) |
23
|
|
|
{ |
24
|
|
|
parent::__construct($title); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param string $subtitle |
29
|
|
|
* @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\GenericElement |
30
|
|
|
*/ |
31
|
|
|
public function setSubtitle(string $subtitle): GenericElement |
32
|
|
|
{ |
33
|
|
|
parent::setSubtitle($subtitle); |
34
|
|
|
|
35
|
|
|
return $this; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param string $imageUrl |
40
|
|
|
* @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\GenericElement |
41
|
|
|
*/ |
42
|
|
|
public function setImageUrl(string $imageUrl): GenericElement |
43
|
|
|
{ |
44
|
|
|
parent::setImageUrl($imageUrl); |
45
|
|
|
|
46
|
|
|
return $this; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param mixed $itemUrl |
51
|
|
|
* @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\GenericElement |
52
|
|
|
*/ |
53
|
|
|
public function setItemUrl(string $itemUrl): GenericElement |
54
|
|
|
{ |
55
|
|
|
$this->isValidUrl($itemUrl); |
56
|
|
|
$this->itemUrl = $itemUrl; |
57
|
|
|
|
58
|
|
|
return $this; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param \Kerox\Messenger\Model\Common\Buttons\AbstractButtons[] $buttons |
63
|
|
|
* @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\GenericElement |
64
|
|
|
*/ |
65
|
|
|
public function setButtons(array $buttons): GenericElement |
66
|
|
|
{ |
67
|
|
|
$this->isValidArray($buttons, 3); |
68
|
|
|
$this->buttons = $buttons; |
69
|
|
|
|
70
|
|
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return array |
75
|
|
|
*/ |
76
|
|
|
public function jsonSerialize(): array |
77
|
|
|
{ |
78
|
|
|
$json = parent::jsonSerialize(); |
79
|
|
|
$json += [ |
80
|
|
|
'item_url' => $this->itemUrl, |
81
|
|
|
'image_url' => $this->imageUrl, |
82
|
|
|
'subtitle' => $this->subtitle, |
83
|
|
|
'buttons' => $this->buttons, |
84
|
|
|
]; |
85
|
|
|
|
86
|
|
|
return array_filter($json); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|