1
|
|
|
<?php |
2
|
|
|
namespace Maknz\Slack\BlockElement; |
3
|
|
|
|
4
|
|
|
use DateTime; |
5
|
|
|
use Maknz\Slack\BlockElement; |
6
|
|
|
use Maknz\Slack\BlockElement\Text; |
7
|
|
|
|
8
|
|
|
class DatePicker extends Confirmable |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Block type. |
12
|
|
|
* |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $type = 'datepicker'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Action triggered when the date is selected. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $action_id; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Placeholder shown on the date picker. |
26
|
|
|
* |
27
|
|
|
* @var \Maknz\Slack\BlockElement\Text |
28
|
|
|
*/ |
29
|
|
|
protected $placeholder; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Initial date to be selected. |
33
|
|
|
* |
34
|
|
|
* @var \DateTime |
35
|
|
|
*/ |
36
|
|
|
protected $initial_date; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Internal attribute to property map. |
40
|
|
|
* |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
protected static $availableAttributes = [ |
44
|
|
|
'action_id' => 'action_id', |
45
|
|
|
'placeholder' => 'placeholder', |
46
|
|
|
'initial_date' => 'initial_date', |
47
|
|
|
'confirm' => 'confirm', |
48
|
|
|
]; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get the action. |
52
|
|
|
* |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
1 |
|
public function getActionId() |
56
|
|
|
{ |
57
|
1 |
|
return $this->action_id; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Set the action. |
62
|
|
|
* |
63
|
|
|
* @param string $actionId |
64
|
|
|
* |
65
|
|
|
* @return DatePicker |
66
|
|
|
*/ |
67
|
2 |
|
public function setActionId($actionId) |
68
|
|
|
{ |
69
|
2 |
|
$this->action_id = $actionId; |
70
|
|
|
|
71
|
2 |
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Get the placeholder. |
76
|
|
|
* |
77
|
|
|
* @return \Maknz\Slack\BlockElement\Text |
78
|
|
|
*/ |
79
|
2 |
|
public function getPlaceholder() |
80
|
|
|
{ |
81
|
2 |
|
return $this->placeholder; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Set the placeholder. |
86
|
|
|
* |
87
|
|
|
* @param mixed $placeholder |
88
|
|
|
* |
89
|
|
|
* @return DatePicker |
90
|
|
|
* |
91
|
|
|
* @throws \InvalidArgumentException |
92
|
|
|
*/ |
93
|
2 |
|
public function setPlaceholder($placeholder) |
94
|
|
|
{ |
95
|
2 |
|
$this->placeholder = Text::create($placeholder, Text::TYPE_PLAIN); |
96
|
|
|
|
97
|
2 |
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Get the initial date. |
102
|
|
|
* |
103
|
|
|
* @return \DateTime |
104
|
|
|
*/ |
105
|
2 |
|
public function getInitialDate() |
106
|
|
|
{ |
107
|
2 |
|
return $this->initial_date; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Set the initial date. |
112
|
|
|
* |
113
|
|
|
* @param \DateTime $initialDate |
114
|
|
|
* |
115
|
|
|
* @return DatePicker |
116
|
|
|
*/ |
117
|
2 |
|
public function setInitialDate(DateTime $initialDate) |
118
|
|
|
{ |
119
|
2 |
|
$this->initial_date = $initialDate; |
120
|
|
|
|
121
|
2 |
|
return $this; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Convert the block to its array representation. |
126
|
|
|
* |
127
|
|
|
* @return array |
128
|
|
|
*/ |
129
|
1 |
|
public function toArray() |
130
|
|
|
{ |
131
|
|
|
$data = [ |
132
|
1 |
|
'type' => $this->getType(), |
133
|
1 |
|
'action_id' => $this->getActionId(), |
134
|
|
|
]; |
135
|
|
|
|
136
|
1 |
|
if ($this->getPlaceholder()) { |
137
|
1 |
|
$data['placeholder'] = $this->getPlaceholder()->toArray(); |
138
|
|
|
} |
139
|
|
|
|
140
|
1 |
|
if ($this->getInitialDate()) { |
141
|
1 |
|
$data['initial_date'] = $this->getInitialDate()->format('Y-m-d'); |
142
|
|
|
} |
143
|
|
|
|
144
|
1 |
|
if ($this->getConfirm()) { |
145
|
1 |
|
$data['confirm'] = $this->getConfirm()->toArray(); |
146
|
|
|
} |
147
|
|
|
|
148
|
1 |
|
return $data; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|