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