1 | <?php |
||
17 | class Location extends DataObject implements PermissionProvider |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * @var array |
||
22 | */ |
||
23 | private static $db = array( |
||
24 | 'Title' => 'Varchar(255)', |
||
25 | 'Featured' => 'Boolean', |
||
26 | 'Website' => 'Varchar(255)', |
||
27 | 'Phone' => 'Varchar(40)', |
||
28 | 'Email' => 'Varchar(255)', |
||
29 | 'EmailAddress' => 'Varchar(255)', |
||
30 | 'ShowInLocator' => 'Boolean', |
||
31 | 'Import_ID' => 'Int', |
||
32 | ); |
||
33 | |||
34 | /** |
||
35 | * @var array |
||
36 | */ |
||
37 | private static $has_one = array( |
||
38 | 'Category' => 'LocationCategory', |
||
39 | ); |
||
40 | |||
41 | /** |
||
42 | * @var array |
||
43 | */ |
||
44 | private static $casting = array( |
||
45 | 'distance' => 'Decimal(9,3)', |
||
46 | ); |
||
47 | |||
48 | /** |
||
49 | * @var string |
||
50 | */ |
||
51 | private static $default_sort = 'Title'; |
||
|
|||
52 | |||
53 | /** |
||
54 | * @var array |
||
55 | */ |
||
56 | private static $defaults = array( |
||
57 | 'ShowInLocator' => true, |
||
58 | ); |
||
59 | |||
60 | /** |
||
61 | * @var string |
||
62 | */ |
||
63 | private static $singular_name = 'Location'; |
||
64 | /** |
||
65 | * @var string |
||
66 | */ |
||
67 | private static $plural_name = 'Locations'; |
||
68 | |||
69 | /** |
||
70 | * api access via Restful Server module |
||
71 | * |
||
72 | * @var bool |
||
73 | */ |
||
74 | private static $api_access = true; |
||
75 | |||
76 | /** |
||
77 | * search fields for Model Admin |
||
78 | * |
||
79 | * @var array |
||
80 | */ |
||
81 | private static $searchable_fields = array( |
||
82 | 'Title', |
||
83 | 'Address', |
||
84 | 'Suburb', |
||
85 | 'State', |
||
86 | 'Postcode', |
||
87 | 'Country', |
||
88 | 'Website', |
||
89 | 'Phone', |
||
90 | 'Email', |
||
91 | 'Category.ID', |
||
92 | 'Featured', |
||
93 | ); |
||
94 | |||
95 | /** |
||
96 | * columns for grid field |
||
97 | * |
||
98 | * @var array |
||
99 | */ |
||
100 | private static $summary_fields = array( |
||
101 | 'Title', |
||
102 | 'Address', |
||
103 | 'Suburb', |
||
104 | 'State', |
||
105 | 'Postcode', |
||
106 | 'Country', |
||
107 | 'Category.Name', |
||
108 | 'Featured.NiceAsBoolean', |
||
109 | 'Coords', |
||
110 | ); |
||
111 | |||
112 | /** |
||
113 | * @var array |
||
114 | */ |
||
115 | private static $extensions = [ |
||
116 | 'VersionedDataObject', |
||
117 | ]; |
||
118 | |||
119 | /** |
||
120 | * Coords status for $summary_fields |
||
121 | * |
||
122 | * @return string |
||
123 | */ |
||
124 | public function getCoords() |
||
125 | { |
||
126 | return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false'; |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * custom labels for fields |
||
131 | * |
||
132 | * @param bool $includerelations |
||
133 | * @return array|string |
||
134 | */ |
||
135 | public function fieldLabels($includerelations = true) |
||
136 | { |
||
137 | $labels = parent::fieldLabels($includerelations); |
||
138 | |||
139 | $labels['Title'] = 'Name'; |
||
140 | $labels['Suburb'] = 'City'; |
||
141 | $labels['Postcode'] = 'Postal Code'; |
||
142 | $labels['ShowInLocator'] = 'Show'; |
||
143 | $labels['ShowInLocator.NiceAsBoolean'] = 'Show'; |
||
144 | $labels['Category.Name'] = 'Category'; |
||
145 | $labels['Category.ID'] = 'Category'; |
||
146 | $labels['Email'] = 'Email'; |
||
147 | $labels['Featured.NiceAsBoolean'] = 'Featured'; |
||
148 | $labels['Coords'] = 'Coords'; |
||
149 | $labels['Import_ID'] = 'Import_ID'; |
||
150 | |||
151 | return $labels; |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * @return FieldList |
||
156 | */ |
||
157 | public function getCMSFields() |
||
158 | { |
||
159 | $fields = FieldList::create( |
||
160 | new TabSet( |
||
161 | $name = 'Root', |
||
162 | new Tab( |
||
163 | $title = 'Main', |
||
164 | HeaderField::create('ContactHD', 'Contact Information'), |
||
165 | TextField::create('Title', 'Name'), |
||
166 | TextField::create('Phone'), |
||
167 | EmailField::create('Email', 'Email'), |
||
168 | TextField::create('Website') |
||
169 | ->setAttribute('placeholder', 'http://'), |
||
170 | DropdownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title')) |
||
171 | ->setEmptyString('-- select --'), |
||
172 | CheckboxField::create('Featured') |
||
173 | ->setDescription('Location will show at/near the top of the results list') |
||
174 | ) |
||
175 | ) |
||
176 | ); |
||
177 | |||
178 | // allow to be extended via DataExtension |
||
179 | $this->extend('updateCMSFields', $fields); |
||
180 | |||
181 | $fields->removeByName([ |
||
182 | 'ShowInLocator', |
||
183 | 'Import_ID', |
||
184 | ]); |
||
185 | |||
186 | // override Suburb field name |
||
187 | $fields->dataFieldByName('Suburb')->setTitle('City'); |
||
188 | |||
189 | return $fields; |
||
190 | } |
||
191 | |||
192 | /** |
||
193 | * @return ValidationResult |
||
194 | */ |
||
195 | public function validate() |
||
196 | { |
||
197 | $result = parent::validate(); |
||
198 | |||
199 | return $result; |
||
200 | } |
||
201 | |||
202 | /** |
||
203 | * @return bool|string |
||
204 | */ |
||
205 | public function EmailAddress() |
||
216 | |||
217 | /** |
||
218 | * @param null|Member $member |
||
219 | * |
||
220 | * @return bool |
||
221 | */ |
||
222 | public function canView($member = null) |
||
226 | |||
227 | /** |
||
228 | * @param null|Member $member |
||
229 | * @return bool|int |
||
230 | */ |
||
231 | public function canEdit($member = null) |
||
235 | |||
236 | /** |
||
237 | * @param null|Member $member |
||
238 | * @return bool|int |
||
239 | */ |
||
240 | public function canDelete($member = null) |
||
244 | |||
245 | /** |
||
246 | * @param null|Member $member |
||
247 | * @return bool|int |
||
248 | */ |
||
249 | public function canCreate($member = null) |
||
253 | |||
254 | /** |
||
255 | * @return array |
||
256 | */ |
||
257 | public function providePermissions() |
||
265 | |||
266 | } |
||
267 |
This check marks private properties in classes that are never used. Those properties can be removed.