|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @author Donatas Navidonskis <[email protected]> |
|
5
|
|
|
* @since 2017 |
|
6
|
|
|
* @class BaseSliderItem |
|
7
|
|
|
* |
|
8
|
|
|
* @property int BlockID |
|
9
|
|
|
* @property int SortOrder |
|
10
|
|
|
* @property string Title |
|
11
|
|
|
* @property string Content |
|
12
|
|
|
* @property string AlignX |
|
13
|
|
|
* @property string AlignY |
|
14
|
|
|
* @property string Style |
|
15
|
|
|
* |
|
16
|
|
|
* @method SliderBlock Block |
|
17
|
|
|
*/ |
|
18
|
|
|
class BaseSliderItem extends \DataObject { |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var array |
|
22
|
|
|
* @config |
|
23
|
|
|
*/ |
|
24
|
|
|
private static $db = [ |
|
|
|
|
|
|
25
|
|
|
'Title' => 'Varchar(320)', |
|
26
|
|
|
'Content' => 'HTMLText', |
|
27
|
|
|
'AlignX' => 'Enum(array("Left", "Center", "Right"), "Left")', |
|
28
|
|
|
'AlignY' => 'Enum(array("Top", "Middle", "Bottom"), "Middle")', |
|
29
|
|
|
'Style' => 'Enum(array("Dark", "Light"), "Light")', |
|
30
|
|
|
'SortOrder' => 'Int', |
|
31
|
|
|
]; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var array |
|
35
|
|
|
* @config |
|
36
|
|
|
*/ |
|
37
|
|
|
private static $has_one = [ |
|
|
|
|
|
|
38
|
|
|
'Block' => 'SliderBlock', |
|
39
|
|
|
]; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Get localized types |
|
43
|
|
|
* |
|
44
|
|
|
* @return array |
|
45
|
|
|
*/ |
|
46
|
|
View Code Duplication |
public function getHorizontallyTypes() { |
|
|
|
|
|
|
47
|
|
|
$types = []; |
|
48
|
|
|
|
|
49
|
|
|
foreach ($this->dbObject('AlignX')->enumValues() as $alignType) { |
|
50
|
|
|
$types[$alignType] = $this->fieldLabel($alignType); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return $types; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Get localized types |
|
58
|
|
|
* |
|
59
|
|
|
* @return array |
|
60
|
|
|
*/ |
|
61
|
|
View Code Duplication |
public function getVerticallyTypes() { |
|
|
|
|
|
|
62
|
|
|
$types = []; |
|
63
|
|
|
|
|
64
|
|
|
foreach ($this->dbObject('AlignY')->enumValues() as $alignType) { |
|
65
|
|
|
$types[$alignType] = $this->fieldLabel($alignType); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return $types; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Get localized types |
|
73
|
|
|
* |
|
74
|
|
|
* @return array |
|
75
|
|
|
*/ |
|
76
|
|
View Code Duplication |
public function getStyles() { |
|
|
|
|
|
|
77
|
|
|
$types = []; |
|
78
|
|
|
|
|
79
|
|
|
foreach ($this->dbObject('Style')->enumValues() as $style) { |
|
80
|
|
|
$types[$style] = $this->fieldLabel($style); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return $types; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @return string |
|
88
|
|
|
*/ |
|
89
|
|
|
public function getHorizontalType() { |
|
90
|
|
|
return strtolower($this->AlignX); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @return string |
|
95
|
|
|
*/ |
|
96
|
|
|
public function getLowerStyle() { |
|
97
|
|
|
return strtolower($this->Style); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @return string |
|
102
|
|
|
*/ |
|
103
|
|
|
public function getVerticalType() { |
|
104
|
|
|
return strtolower($this->AlignY); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* The default sort expression. This will be inserted in the ORDER BY |
|
109
|
|
|
* clause of a SQL query if no other sort expression is provided. |
|
110
|
|
|
* |
|
111
|
|
|
* @var string |
|
112
|
|
|
* @config |
|
113
|
|
|
*/ |
|
114
|
|
|
private static $default_sort = 'SortOrder ASC'; |
|
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @return string |
|
118
|
|
|
*/ |
|
119
|
|
|
public function singular_name() { |
|
120
|
|
|
return _t('SliderItem.SINGULARNAME', 'Slider'); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @return string |
|
125
|
|
|
*/ |
|
126
|
|
|
public function plural_name() { |
|
127
|
|
|
return _t('SliderItem.PLURALNAME', 'Sliders'); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Default summary fields within localized label title's. |
|
132
|
|
|
* |
|
133
|
|
|
* @return array |
|
134
|
|
|
*/ |
|
135
|
|
|
public function summaryFields() { |
|
136
|
|
|
return [ |
|
137
|
|
|
'Title' => $this->fieldLabel('Title'), |
|
138
|
|
|
'SliderType' => $this->fieldLabel('SliderType'), |
|
139
|
|
|
]; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @return string |
|
144
|
|
|
*/ |
|
145
|
|
|
public function getSliderType() { |
|
146
|
|
|
return $this->singular_name(); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @return \FieldList |
|
151
|
|
|
*/ |
|
152
|
|
|
public function getCMSFields() { |
|
153
|
|
|
$fields = parent::getCMSFields(); |
|
154
|
|
|
$fields->removeByName(['SortOrder', 'Title', 'Content', 'AlignX', 'AlignY', 'Style']); |
|
155
|
|
|
$fields->findOrMakeTab('Root.Media', $this->fieldLabel('Media')); |
|
156
|
|
|
|
|
157
|
|
|
$fields->addFieldsToTab('Root.Main', [ |
|
158
|
|
|
OptionsetField::create('AlignX', $this->fieldLabel('ContentHorizontallyAlignment'), $this->getHorizontallyTypes()), |
|
159
|
|
|
OptionsetField::create('AlignY', $this->fieldLabel('ContentVerticallyAlignment'), $this->getVerticallyTypes()), |
|
160
|
|
|
OptionsetField::create('Style', $this->fieldLabel('Style'), $this->getStyles()), |
|
161
|
|
|
\TextField::create('Title', $this->fieldLabel('Title')), |
|
162
|
|
|
$contentField = \HtmlEditorField::create('Content', $this->fieldLabel('Content')), |
|
163
|
|
|
]); |
|
164
|
|
|
|
|
165
|
|
|
$contentField->setRows(15); |
|
166
|
|
|
|
|
167
|
|
|
$this->extend('updateCMSFields', $fields); |
|
168
|
|
|
|
|
169
|
|
|
return $fields; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* @param bool $includeRelations |
|
174
|
|
|
* |
|
175
|
|
|
* @return array |
|
176
|
|
|
*/ |
|
177
|
|
|
public function fieldLabels($includeRelations = true) { |
|
178
|
|
|
return array_merge(parent::fieldLabels($includeRelations), [ |
|
179
|
|
|
'Title' => _t('BaseSliderItem.TITLE', 'Title'), |
|
180
|
|
|
'Content' => _t('BaseSliderItem.CONTENT', 'Content'), |
|
181
|
|
|
'Picture' => _t('BaseSliderItem.PICTURE', 'Picture'), |
|
182
|
|
|
'Media' => _t('BaseSliderItem.MEDIA', 'Media'), |
|
183
|
|
|
'Video' => _t('BaseSliderItem.VIDEO', 'Video'), |
|
184
|
|
|
'SliderType' => _t('BaseSliderItem.SLIDER_TYPE', 'Slider type'), |
|
185
|
|
|
'ContentHorizontallyAlignment' => _t('BaseSliderItem.CONTENT_HORIZONTALLY_ALIGNMENT', 'Content horizontally alignment'), |
|
186
|
|
|
'ContentVerticallyAlignment' => _t('BaseSliderItem.CONTENT_VERTICALLY_ALIGNMENT', 'Content vertically alignment'), |
|
187
|
|
|
'Left' => _t('BaseSliderItem.LEFT', 'Left'), |
|
188
|
|
|
'Center' => _t('BaseSliderItem.CENTER', 'Center'), |
|
189
|
|
|
'Right' => _t('BaseSliderItem.RIGHT', 'Right'), |
|
190
|
|
|
'Top' => _t('BaseSliderItem.TOP', 'Top'), |
|
191
|
|
|
'Middle' => _t('BaseSliderItem.MIDDLE', 'Middle'), |
|
192
|
|
|
'Bottom' => _t('BaseSliderItem.BOTTOM', 'Bottom'), |
|
193
|
|
|
'Dark' => _t('BaseSliderItem.DARK', 'Dark'), |
|
194
|
|
|
'Light' => _t('BaseSliderItem.LIGHT', 'Light'), |
|
195
|
|
|
]); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* @return \HTMLText |
|
200
|
|
|
*/ |
|
201
|
|
|
public function forTemplate() { |
|
202
|
|
|
$template = sprintf("%s_%s", $this->Block()->ClassName, $this->ClassName); |
|
|
|
|
|
|
203
|
|
|
|
|
204
|
|
|
return $this->renderWith($template); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* @return false |
|
209
|
|
|
*/ |
|
210
|
|
|
public function getSliderImage() { |
|
211
|
|
|
return false; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
public function getHeading() { |
|
215
|
|
|
$title = $this->Title; |
|
216
|
|
|
|
|
217
|
|
|
$this->extend('updateBeforeHeading', $title); |
|
218
|
|
|
|
|
219
|
|
|
return $title; |
|
220
|
|
|
} |
|
221
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.