Completed
Push — master ( b23224...622181 )
by Nic
10s
created

ElementCountDown::getClientConfig()   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 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
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
class ElementCountDown extends BaseElement
13
{
14
    /**
15
     * @var string
16
     */
17
    private static $icon = 'sectionnav-icon';
0 ignored issues
show
introduced by
The private property $icon is not used, and could be removed.
Loading history...
18
19
    /**
20
     * @var string
21
     */
22
    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...
23
24
    /**
25
     * @var string
26
     */
27
    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...
28
29
    /**
30
     * @var array
31
     */
32
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
33
        'End' => 'DBDatetime',
34
        'ShowMonths' => 'Boolean',
35
        'ShowSeconds' => 'Boolean',
36
        'Elapse' => 'Boolean',
37
    ];
38
39
    /**
40
     * @var string
41
     */
42
    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...
43
44
    /**
45
     * @var ArrayData
46
     */
47
    private $client_config;
48
49
    /**
50
     * @return string
51
     */
52 1
    public function getType()
53
    {
54 1
        return _t(__CLASS__ . '.BlockType', 'Count Down');
55
    }
56
57
    /**
58
     * @return $this
59
     */
60 2
    public function setClientConfig()
61
    {
62
        $clientArray = [
63 2
            'End' => $this->End,
0 ignored issues
show
Bug Best Practice introduced by
The property End does not exist on Dynamic\Elements\CountDo...ements\ElementCountDown. Since you implemented __get, consider adding a @property annotation.
Loading history...
64 2
            'Elapse' => $this->Elapse,
0 ignored issues
show
Bug Best Practice introduced by
The property Elapse does not exist on Dynamic\Elements\CountDo...ements\ElementCountDown. Since you implemented __get, consider adding a @property annotation.
Loading history...
65
        ];
66
67 2
        $this->client_config = ArrayData::create($this->encodeArrayValues($clientArray));
68
69 2
        return $this;
70
    }
71
72
    /**
73
     * @return ArrayData
74
     */
75 2
    public function getClientConfig()
76
    {
77 2
        if (!$this->client_config) {
78 2
            $this->setClientConfig();
79
        }
80
81 2
        return $this->client_config;
82
    }
83
84
    /**
85
     * @param $array
86
     * @return mixed
87
     */
88 2
    protected function encodeArrayValues($array)
89
    {
90 2
        foreach ($array as $key => $val) {
91 2
            $array[$key] = json_encode($val);
92
        }
93
94 2
        return $array;
95
    }
96
}
97