1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Elements\CountDown\Elements; |
4
|
|
|
|
5
|
|
|
use DNADesign\Elemental\Models\BaseElement; |
6
|
|
|
use SilverStripe\View\ArrayData; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class ElementCountDown |
10
|
|
|
* @package Dynamic\Elements\Elements |
11
|
|
|
* |
12
|
|
|
* @property string $End |
13
|
|
|
* @property boolean $ShowMonths |
14
|
|
|
* @property boolean $ShowSeconds |
15
|
|
|
* @property boolean $Elapse |
16
|
|
|
*/ |
17
|
|
|
class ElementCountDown extends BaseElement |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
private static $icon = 'sectionnav-icon'; |
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
private static $singular_name = 'Count Down Element'; |
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private static $plural_name = 'Count Down Elements'; |
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
private static $db = [ |
|
|
|
|
38
|
|
|
'End' => 'DBDatetime', |
39
|
|
|
'ShowMonths' => 'Boolean', |
40
|
|
|
'ShowSeconds' => 'Boolean', |
41
|
|
|
'Elapse' => 'Boolean', |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
private static $table_name = 'ElementCountDown'; |
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var ArrayData |
51
|
|
|
*/ |
52
|
|
|
private $client_config; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
1 |
|
public function getType() |
58
|
|
|
{ |
59
|
1 |
|
return _t(__CLASS__ . '.BlockType', 'Count Down'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return \SilverStripe\ORM\ValidationResult |
64
|
|
|
*/ |
65
|
1 |
|
public function validate() |
66
|
|
|
{ |
67
|
1 |
|
$result = parent::validate(); |
68
|
|
|
|
69
|
1 |
|
if (!$this->End) { |
70
|
1 |
|
$result->addError('An end date is required'); |
71
|
|
|
} |
72
|
|
|
|
73
|
1 |
|
return $result; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return $this |
78
|
|
|
*/ |
79
|
2 |
|
public function setClientConfig() |
80
|
|
|
{ |
81
|
|
|
$clientArray = [ |
82
|
2 |
|
'End' => $this->End, |
83
|
2 |
|
'Elapse' => $this->Elapse, |
84
|
|
|
]; |
85
|
|
|
|
86
|
2 |
|
$this->client_config = ArrayData::create($this->encodeArrayValues($clientArray)); |
87
|
|
|
|
88
|
2 |
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return ArrayData |
93
|
|
|
*/ |
94
|
2 |
|
public function getClientConfig() |
95
|
|
|
{ |
96
|
2 |
|
if (!$this->client_config) { |
97
|
2 |
|
$this->setClientConfig(); |
98
|
|
|
} |
99
|
|
|
|
100
|
2 |
|
return $this->client_config; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param $array |
105
|
|
|
* @return mixed |
106
|
|
|
*/ |
107
|
2 |
|
protected function encodeArrayValues($array) |
108
|
|
|
{ |
109
|
2 |
|
foreach ($array as $key => $val) { |
110
|
2 |
|
$array[$key] = json_encode($val); |
111
|
|
|
} |
112
|
|
|
|
113
|
2 |
|
return $array; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|