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
|
|
|
* Sets the Date field to the current date. |
56
|
|
|
*/ |
57
|
1 |
|
public function populateDefaults() |
58
|
|
|
{ |
59
|
1 |
|
$this->End = date('Y-m-d', strtotime("+30 days")); |
60
|
1 |
|
parent::populateDefaults(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
1 |
|
public function getType() |
67
|
|
|
{ |
68
|
1 |
|
return _t(__CLASS__ . '.BlockType', 'Count Down'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return $this |
73
|
|
|
*/ |
74
|
2 |
|
public function setClientConfig() |
75
|
|
|
{ |
76
|
|
|
$clientArray = [ |
77
|
2 |
|
'End' => $this->End, |
78
|
2 |
|
'Elapse' => $this->Elapse, |
79
|
|
|
]; |
80
|
|
|
|
81
|
2 |
|
$this->client_config = ArrayData::create($this->encodeArrayValues($clientArray)); |
82
|
|
|
|
83
|
2 |
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return ArrayData |
88
|
|
|
*/ |
89
|
2 |
|
public function getClientConfig() |
90
|
|
|
{ |
91
|
2 |
|
if (!$this->client_config) { |
92
|
2 |
|
$this->setClientConfig(); |
93
|
|
|
} |
94
|
|
|
|
95
|
2 |
|
return $this->client_config; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param $array |
100
|
|
|
* @return mixed |
101
|
|
|
*/ |
102
|
2 |
|
protected function encodeArrayValues($array) |
103
|
|
|
{ |
104
|
2 |
|
foreach ($array as $key => $val) { |
105
|
2 |
|
$array[$key] = json_encode($val); |
106
|
|
|
} |
107
|
|
|
|
108
|
2 |
|
return $array; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|