1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ilateral\SilverStripe\ModelAdminPlus; |
4
|
|
|
|
5
|
|
|
use SilverStripe\View\ViewableData; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Object representing a snippet of generic data that can be loaded at the top of a |
9
|
|
|
* ModelAdminPlus interface |
10
|
|
|
*/ |
11
|
|
|
abstract class ModelAdminSnippet extends ViewableData |
12
|
|
|
{ |
13
|
|
|
const PRIMARY = "primary"; |
14
|
|
|
|
15
|
|
|
const SECONDARY = "secondary"; |
16
|
|
|
|
17
|
|
|
const SUCCESS = "success"; |
18
|
|
|
|
19
|
|
|
const INFO = "info"; |
20
|
|
|
|
21
|
|
|
const WARNING = "warning"; |
22
|
|
|
|
23
|
|
|
const DANGER = "danger"; |
24
|
|
|
|
25
|
|
|
const LIGHT = "light"; |
26
|
|
|
|
27
|
|
|
const DARK = "dark"; |
28
|
|
|
|
29
|
|
|
const WHITE = "white"; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The name/title of the current snippet. |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
private static $title; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The order in which this snippet will be loaded |
40
|
|
|
* |
41
|
|
|
* @var int |
42
|
|
|
*/ |
43
|
|
|
private static $priority = 0; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Default background colour |
47
|
|
|
* |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
private static $background = self::INFO; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Default text colour |
54
|
|
|
* |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
private static $text = self::WHITE; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* The current parent controller |
61
|
|
|
* |
62
|
|
|
* @var ModelAdminPlus |
63
|
|
|
*/ |
64
|
|
|
protected $parent; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* List of extra CSS classes applied to this snippet |
68
|
|
|
* |
69
|
|
|
* @var array |
70
|
|
|
*/ |
71
|
|
|
protected $extra_classes = []; |
72
|
|
|
|
73
|
|
|
private $casting = [ |
|
|
|
|
74
|
|
|
"Order" => "Float" |
75
|
|
|
]; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Return an i18n friendly version of the title. |
79
|
|
|
* |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
public function getTitle() |
83
|
|
|
{ |
84
|
|
|
return _t(__CLASS__ . "Title", $this->config()->title); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function getOrder() |
88
|
|
|
{ |
89
|
|
|
return $this->config()->priority; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Render the current snippet |
94
|
|
|
* |
95
|
|
|
* @return string |
96
|
|
|
*/ |
97
|
|
|
public function getSnippet() |
98
|
|
|
{ |
99
|
|
|
return $this->renderWith(__CLASS__); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Return the background colour suitable for a template |
104
|
|
|
* |
105
|
|
|
* @return string |
106
|
|
|
*/ |
107
|
|
|
public function getBackgroundColour() |
108
|
|
|
{ |
109
|
|
|
return $this->config()->background; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Return the background colour suitable for a template |
114
|
|
|
* |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
|
|
public function getTextColour() |
118
|
|
|
{ |
119
|
|
|
return $this->config()->text; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* The content of this snippet that will be rendered below |
124
|
|
|
* the title. |
125
|
|
|
* |
126
|
|
|
* @return string |
127
|
|
|
*/ |
128
|
|
|
abstract public function getContent(); |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Get the current parent controller |
132
|
|
|
* |
133
|
|
|
* @return ModelAdminPlus |
134
|
|
|
*/ |
135
|
|
|
public function getParent() |
136
|
|
|
{ |
137
|
|
|
return $this->parent; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Set the current parent controller |
142
|
|
|
* |
143
|
|
|
* @param ModelAdminPlus $parent The current parent controller |
144
|
|
|
* |
145
|
|
|
* @return self |
146
|
|
|
*/ |
147
|
|
|
public function setParent(ModelAdminPlus $parent) |
148
|
|
|
{ |
149
|
|
|
$this->parent = $parent; |
150
|
|
|
return $this; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Get extra CSS classes as a string |
155
|
|
|
* |
156
|
|
|
* @return string |
157
|
|
|
*/ |
158
|
|
|
public function getExtraClasses() |
159
|
|
|
{ |
160
|
|
|
return implode(" ", $this->extra_classes); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Add additional css classes |
165
|
|
|
* |
166
|
|
|
* @param array|string $extra_classes extra CSS classes |
167
|
|
|
* |
168
|
|
|
* @return self |
169
|
|
|
*/ |
170
|
|
|
public function addExtraClasses($classes) |
171
|
|
|
{ |
172
|
|
|
if (!is_array($classes)) { |
173
|
|
|
$classes = explode(" ", $classes); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
$this->extra_classes = array_merge( |
177
|
|
|
$this->extra_classes, |
178
|
|
|
$classes |
179
|
|
|
); |
180
|
|
|
|
181
|
|
|
return $this; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Remove provided CSS classes |
186
|
|
|
* |
187
|
|
|
* @param array|string $extra_classes extra CSS classes |
188
|
|
|
* |
189
|
|
|
* @return self |
190
|
|
|
*/ |
191
|
|
|
public function removeExtraClasses($classes) |
192
|
|
|
{ |
193
|
|
|
if (!is_array($classes)) { |
194
|
|
|
$classes = explode(" ", $classes); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
foreach ($classes as $class) { |
198
|
|
|
if (isset($this->extra_classes[$class])) { |
199
|
|
|
unset($this->extra_classes[$class]); |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
return $this; |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|