1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class SlideImage extends DataObject implements PermissionProvider |
4
|
|
|
{ |
5
|
|
|
/** |
6
|
|
|
* @var string |
7
|
|
|
*/ |
8
|
|
|
private static $singular_name = 'Slide'; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @var string |
12
|
|
|
*/ |
13
|
|
|
private static $plural_name = 'Slides'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var array |
17
|
|
|
*/ |
18
|
|
|
private static $db = array( |
19
|
|
|
'Name' => 'Varchar(255)', |
20
|
|
|
'Headline' => 'Varchar(255)', |
21
|
|
|
'Description' => 'Text', |
22
|
|
|
'SortOrder' => 'Int', |
23
|
|
|
'ShowSlide' => 'Boolean', |
24
|
|
|
); |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
private static $has_one = array( |
30
|
|
|
'Image' => 'Image', |
31
|
|
|
'Page' => 'Page', |
32
|
|
|
'PageLink' => 'SiteTree', |
33
|
|
|
); |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private static $default_sort = 'SortOrder'; |
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
private static $defaults = array( |
44
|
|
|
'ShowSlide' => true, |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var array |
49
|
|
|
*/ |
50
|
|
|
private static $summary_fields = array( |
51
|
|
|
'Image.CMSThumbnail' => 'Image', |
52
|
|
|
'Name' => 'Name', |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var array |
57
|
|
|
*/ |
58
|
|
|
private static $searchable_fields = array( |
59
|
|
|
'Name', |
60
|
|
|
'Headline', |
61
|
|
|
'Description', |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var int |
66
|
|
|
*/ |
67
|
|
|
private static $image_size_limit = 512000; |
|
|
|
|
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return FieldList |
71
|
|
|
*/ |
72
|
1 |
|
public function getCMSFields() |
73
|
|
|
{ |
74
|
1 |
|
$fields = parent::getCMSFields(); |
75
|
|
|
|
76
|
1 |
|
$fields->removeByName([ |
77
|
1 |
|
'SortOrder', |
78
|
1 |
|
'PageID', |
79
|
1 |
|
]); |
80
|
|
|
|
81
|
1 |
|
if($name = $fields->dataFieldByName('Name')){ |
82
|
1 |
|
$name->setDescription('for internal reference only'); |
83
|
1 |
|
} |
84
|
|
|
|
85
|
1 |
|
if($headline = $fields->dataFieldByName('Headline')){ |
86
|
1 |
|
$headline->setDescription('optional, used in template'); |
87
|
1 |
|
} |
88
|
|
|
|
89
|
1 |
|
if($description = $fields->dataFieldByName('Description')){ |
90
|
1 |
|
$description->setDescription('optional, used in template'); |
91
|
1 |
|
} |
92
|
|
|
|
93
|
1 |
|
if($link = $fields->dataFieldByName('PageLinkID')){ |
94
|
1 |
|
if(!$link instanceof TreeDropdownField){ |
95
|
1 |
|
$fields->replaceField( |
96
|
|
|
'PageLinkID', |
97
|
1 |
|
$link = TreeDropdownField::create('PageLinkID', null, SiteTree::class) |
98
|
1 |
|
); |
99
|
1 |
|
} |
100
|
1 |
|
$link->setTitle("Choose a page to link to:"); |
101
|
1 |
|
} |
102
|
1 |
|
|
103
|
|
|
if($image = $fields->dataFieldByName('Image')){ |
104
|
1 |
|
$image->setFolderName('Uploads/SlideImages') |
105
|
1 |
|
->setAllowedMaxFileNumber(1) |
106
|
|
|
->setAllowedFileCategories('image'); |
107
|
1 |
|
$fields->insertBefore($image, 'ShowSlide'); |
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$fields->dataFieldByName('ShowSlide') |
111
|
|
|
->setDescription('Include this slide in the slider. Uncheck to hide'); |
112
|
|
|
|
113
|
6 |
|
return $fields; |
114
|
|
|
} |
115
|
6 |
|
|
116
|
|
|
/** |
117
|
6 |
|
* @return ValidationResult |
118
|
1 |
|
*/ |
119
|
1 |
|
public function validate() |
120
|
|
|
{ |
121
|
6 |
|
$result = parent::validate(); |
122
|
2 |
|
|
123
|
2 |
|
if (!$this->Name) { |
|
|
|
|
124
|
|
|
$result->error('A Name is required before you can save'); |
125
|
6 |
|
} |
126
|
|
|
|
127
|
|
|
if (!$this->ImageID) { |
|
|
|
|
128
|
|
|
$result->error('An Image is required before you can save'); |
129
|
|
|
} |
130
|
|
|
|
131
|
1 |
|
return $result; |
132
|
|
|
} |
133
|
|
|
|
134
|
1 |
|
/** |
135
|
1 |
|
* @return array |
136
|
1 |
|
*/ |
137
|
1 |
|
public function providePermissions() |
138
|
|
|
{ |
139
|
|
|
return array( |
140
|
|
|
'Slide_EDIT' => 'Slide Edit', |
141
|
|
|
'Slide_DELETE' => 'Slide Delete', |
142
|
|
|
'Slide_CREATE' => 'Slide Create', |
143
|
|
|
); |
144
|
1 |
|
} |
145
|
|
|
|
146
|
1 |
|
/** |
147
|
|
|
* @param null $member |
148
|
|
|
* @return bool|int |
149
|
|
|
*/ |
150
|
|
|
public function canCreate($member = null) |
151
|
|
|
{ |
152
|
|
|
return Permission::check('Slide_CREATE'); |
153
|
1 |
|
} |
154
|
|
|
|
155
|
1 |
|
/** |
156
|
|
|
* @param null $member |
157
|
|
|
* @return bool|int |
158
|
|
|
*/ |
159
|
|
|
public function canEdit($member = null) |
160
|
|
|
{ |
161
|
|
|
return Permission::check('Slide_EDIT'); |
162
|
1 |
|
} |
163
|
|
|
|
164
|
1 |
|
/** |
165
|
|
|
* @param null $member |
166
|
|
|
* @return bool|int |
167
|
|
|
*/ |
168
|
|
|
public function canDelete($member = null) |
169
|
|
|
{ |
170
|
|
|
return Permission::check('Slide_DELETE'); |
171
|
1 |
|
} |
172
|
|
|
|
173
|
1 |
|
/** |
174
|
|
|
* @param null $member |
175
|
|
|
* @return bool |
176
|
1 |
|
*/ |
177
|
|
|
public function canView($member = null) |
178
|
|
|
{ |
179
|
|
|
return true; |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.