Completed
Push — master ( 229587...563851 )
by Jason
02:55
created

ElementCountDown::encodeArrayValues()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
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';
0 ignored issues
show
introduced by
The private property $icon is not used, and could be removed.
Loading history...
23
24
    /**
25
     * @var string
26
     */
27
    private static $singular_name = 'Count Down Element';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
28
29
    /**
30
     * @var string
31
     */
32
    private static $plural_name = 'Count Down Elements';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
33
34
    /**
35
     * @var array
36
     */
37
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
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';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
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