@@ -27,247 +27,247 @@ |
||
27 | 27 | */ |
28 | 28 | class Locator extends \Page |
29 | 29 | { |
30 | - /** |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - private static $singular_name = 'Locator'; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - private static $plural_name = 'Locators'; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var string |
|
42 | - */ |
|
43 | - private static $description = 'Display locations on a map'; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var array |
|
47 | - */ |
|
48 | - private static $db = [ |
|
49 | - 'Unit' => 'Enum("m,km","m")', |
|
50 | - ]; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - private static $many_many = [ |
|
56 | - 'Categories' => LocationCategory::class, |
|
57 | - ]; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var string |
|
61 | - */ |
|
62 | - private static $table_name = 'Locator'; |
|
63 | - |
|
64 | - /** |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - private static $location_class = LocationPage::class; |
|
68 | - |
|
69 | - /** |
|
70 | - * @return FieldList |
|
71 | - */ |
|
72 | - public function getCMSFields() |
|
73 | - { |
|
74 | - $this->beforeUpdateCMSFields(function ($fields) { |
|
75 | - // Settings |
|
76 | - $fields->addFieldsToTab('Root.Settings', [ |
|
77 | - HeaderField::create('DisplayOptions', 'Display Options', 3), |
|
78 | - OptionsetField::create('Unit', 'Unit of measure', ['m' => 'Miles', 'km' => 'Kilometers']), |
|
79 | - ]); |
|
80 | - |
|
81 | - // Filter categories |
|
82 | - $config = GridFieldConfig_RelationEditor::create(); |
|
83 | - $config->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
|
84 | - $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
85 | - $categories = $this->Categories(); |
|
86 | - $categoriesField = GridField::create('Categories', 'Categories', $categories, $config) |
|
87 | - ->setDescription('only show locations from the selected category'); |
|
88 | - |
|
89 | - // Filter |
|
90 | - $fields->addFieldsToTab('Root.Filter', [ |
|
91 | - HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
92 | - $categoriesField, |
|
93 | - ]); |
|
94 | - }); |
|
95 | - |
|
96 | - return parent::getCMSFields(); |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @param array $filter |
|
101 | - * @param array $filterAny |
|
102 | - * @param array $exclude |
|
103 | - * @param null|callable $callback |
|
104 | - * |
|
105 | - * @return DataList|ArrayList |
|
106 | - */ |
|
107 | - public static function get_locations($filter = [], $filterAny = [], $exclude = [], $callback = null) |
|
108 | - { |
|
109 | - $locationClass = Config::inst()->get(static::class, 'location_class'); |
|
110 | - $locations = $locationClass::get()->filter($filter)->exclude($exclude); |
|
111 | - |
|
112 | - if (!empty($filterAny)) { |
|
113 | - $locations = $locations->filterAny($filterAny); |
|
114 | - } |
|
115 | - if (!empty($exclude)) { |
|
116 | - $locations = $locations->exclude($exclude); |
|
117 | - } |
|
118 | - |
|
119 | - if ($callback !== null && is_callable($callback)) { |
|
120 | - $locations->filterByCallback($callback); |
|
121 | - } |
|
122 | - |
|
123 | - return $locations; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @return DataList |
|
128 | - */ |
|
129 | - public static function get_all_categories() |
|
130 | - { |
|
131 | - return LocationCategory::get(); |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * @return bool |
|
136 | - */ |
|
137 | - public function getPageCategories() |
|
138 | - { |
|
139 | - return self::locator_categories_by_locator($this->ID); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * @param int $id |
|
144 | - * |
|
145 | - * @return bool| |
|
146 | - */ |
|
147 | - public static function locator_categories_by_locator($id = 0) |
|
148 | - { |
|
149 | - if ($id == 0) { |
|
150 | - return false; |
|
151 | - } |
|
152 | - |
|
153 | - /** @var Locator $locator */ |
|
154 | - if ($locator = static::get()->byID($id)) { |
|
155 | - return $locator->getUsedCategories(); |
|
156 | - } |
|
157 | - |
|
158 | - return false; |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Gets the list of radii |
|
163 | - * |
|
164 | - * @return ArrayList |
|
165 | - */ |
|
166 | - public function getRadii() |
|
167 | - { |
|
168 | - $radii = [ |
|
169 | - '0' => '25', |
|
170 | - '1' => '50', |
|
171 | - '2' => '75', |
|
172 | - '3' => '100', |
|
173 | - ]; |
|
174 | - $config_radii = $this->config()->get('radii'); |
|
175 | - if ($config_radii) { |
|
176 | - $radii = $config_radii; |
|
177 | - } |
|
178 | - |
|
179 | - return $radii; |
|
180 | - } |
|
181 | - |
|
182 | - public function getRadiiArrayList() |
|
183 | - { |
|
184 | - $list = []; |
|
185 | - |
|
186 | - foreach ($this->getRadii() as $radius) { |
|
187 | - $list[] = new ArrayData([ |
|
188 | - 'Radius' => $radius, |
|
189 | - ]); |
|
190 | - } |
|
191 | - |
|
192 | - return new ArrayList($list); |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Gets the limit of locations |
|
197 | - * @return mixed |
|
198 | - */ |
|
199 | - public function getLimit() |
|
200 | - { |
|
201 | - return $this->config()->get('limit'); |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Gets if the radius drop down should be shown |
|
206 | - * @return mixed |
|
207 | - */ |
|
208 | - public function getShowRadius() |
|
209 | - { |
|
210 | - return $this->config()->get('show_radius'); |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * @return mixed |
|
215 | - */ |
|
216 | - public function getUsedCategories() |
|
217 | - { |
|
218 | - return $this->Categories()->filter([ |
|
219 | - 'LocationSet.ID:GreaterThan' => 0, |
|
220 | - ]); |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Gets the path of the info window template |
|
225 | - * |
|
226 | - * @return string |
|
227 | - */ |
|
228 | - public function getInfoWindowTemplate() |
|
229 | - { |
|
230 | - return ModuleResourceLoader::singleton()->resolveURL( |
|
231 | - Config::inst()->get( |
|
232 | - static::class, |
|
233 | - 'infoWindowTemplate' |
|
234 | - ) |
|
235 | - ); |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Gets the path of the list template |
|
240 | - * |
|
241 | - * @return string |
|
242 | - */ |
|
243 | - public function getListTemplate() |
|
244 | - { |
|
245 | - return ModuleResourceLoader::singleton()->resolveURL( |
|
246 | - Config::inst()->get( |
|
247 | - static::class, |
|
248 | - 'listTemplate' |
|
249 | - ) |
|
250 | - ); |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * @return null|string |
|
255 | - */ |
|
256 | - public function getMapStyle() |
|
257 | - { |
|
258 | - return AddressDataExtension::getMapStyleJSON(); |
|
259 | - } |
|
260 | - |
|
261 | - public function getMapStyleJSONPath() |
|
262 | - { |
|
263 | - return AddressDataExtension::getMapStyleJSONPath(); |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * @return null|string |
|
268 | - */ |
|
269 | - public function getMarkerIcon() |
|
270 | - { |
|
271 | - return AddressDataExtension::getIconImage(); |
|
272 | - } |
|
30 | + /** |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + private static $singular_name = 'Locator'; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + private static $plural_name = 'Locators'; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var string |
|
42 | + */ |
|
43 | + private static $description = 'Display locations on a map'; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var array |
|
47 | + */ |
|
48 | + private static $db = [ |
|
49 | + 'Unit' => 'Enum("m,km","m")', |
|
50 | + ]; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + private static $many_many = [ |
|
56 | + 'Categories' => LocationCategory::class, |
|
57 | + ]; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var string |
|
61 | + */ |
|
62 | + private static $table_name = 'Locator'; |
|
63 | + |
|
64 | + /** |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + private static $location_class = LocationPage::class; |
|
68 | + |
|
69 | + /** |
|
70 | + * @return FieldList |
|
71 | + */ |
|
72 | + public function getCMSFields() |
|
73 | + { |
|
74 | + $this->beforeUpdateCMSFields(function ($fields) { |
|
75 | + // Settings |
|
76 | + $fields->addFieldsToTab('Root.Settings', [ |
|
77 | + HeaderField::create('DisplayOptions', 'Display Options', 3), |
|
78 | + OptionsetField::create('Unit', 'Unit of measure', ['m' => 'Miles', 'km' => 'Kilometers']), |
|
79 | + ]); |
|
80 | + |
|
81 | + // Filter categories |
|
82 | + $config = GridFieldConfig_RelationEditor::create(); |
|
83 | + $config->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
|
84 | + $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
85 | + $categories = $this->Categories(); |
|
86 | + $categoriesField = GridField::create('Categories', 'Categories', $categories, $config) |
|
87 | + ->setDescription('only show locations from the selected category'); |
|
88 | + |
|
89 | + // Filter |
|
90 | + $fields->addFieldsToTab('Root.Filter', [ |
|
91 | + HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
92 | + $categoriesField, |
|
93 | + ]); |
|
94 | + }); |
|
95 | + |
|
96 | + return parent::getCMSFields(); |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @param array $filter |
|
101 | + * @param array $filterAny |
|
102 | + * @param array $exclude |
|
103 | + * @param null|callable $callback |
|
104 | + * |
|
105 | + * @return DataList|ArrayList |
|
106 | + */ |
|
107 | + public static function get_locations($filter = [], $filterAny = [], $exclude = [], $callback = null) |
|
108 | + { |
|
109 | + $locationClass = Config::inst()->get(static::class, 'location_class'); |
|
110 | + $locations = $locationClass::get()->filter($filter)->exclude($exclude); |
|
111 | + |
|
112 | + if (!empty($filterAny)) { |
|
113 | + $locations = $locations->filterAny($filterAny); |
|
114 | + } |
|
115 | + if (!empty($exclude)) { |
|
116 | + $locations = $locations->exclude($exclude); |
|
117 | + } |
|
118 | + |
|
119 | + if ($callback !== null && is_callable($callback)) { |
|
120 | + $locations->filterByCallback($callback); |
|
121 | + } |
|
122 | + |
|
123 | + return $locations; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @return DataList |
|
128 | + */ |
|
129 | + public static function get_all_categories() |
|
130 | + { |
|
131 | + return LocationCategory::get(); |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * @return bool |
|
136 | + */ |
|
137 | + public function getPageCategories() |
|
138 | + { |
|
139 | + return self::locator_categories_by_locator($this->ID); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * @param int $id |
|
144 | + * |
|
145 | + * @return bool| |
|
146 | + */ |
|
147 | + public static function locator_categories_by_locator($id = 0) |
|
148 | + { |
|
149 | + if ($id == 0) { |
|
150 | + return false; |
|
151 | + } |
|
152 | + |
|
153 | + /** @var Locator $locator */ |
|
154 | + if ($locator = static::get()->byID($id)) { |
|
155 | + return $locator->getUsedCategories(); |
|
156 | + } |
|
157 | + |
|
158 | + return false; |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * Gets the list of radii |
|
163 | + * |
|
164 | + * @return ArrayList |
|
165 | + */ |
|
166 | + public function getRadii() |
|
167 | + { |
|
168 | + $radii = [ |
|
169 | + '0' => '25', |
|
170 | + '1' => '50', |
|
171 | + '2' => '75', |
|
172 | + '3' => '100', |
|
173 | + ]; |
|
174 | + $config_radii = $this->config()->get('radii'); |
|
175 | + if ($config_radii) { |
|
176 | + $radii = $config_radii; |
|
177 | + } |
|
178 | + |
|
179 | + return $radii; |
|
180 | + } |
|
181 | + |
|
182 | + public function getRadiiArrayList() |
|
183 | + { |
|
184 | + $list = []; |
|
185 | + |
|
186 | + foreach ($this->getRadii() as $radius) { |
|
187 | + $list[] = new ArrayData([ |
|
188 | + 'Radius' => $radius, |
|
189 | + ]); |
|
190 | + } |
|
191 | + |
|
192 | + return new ArrayList($list); |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Gets the limit of locations |
|
197 | + * @return mixed |
|
198 | + */ |
|
199 | + public function getLimit() |
|
200 | + { |
|
201 | + return $this->config()->get('limit'); |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Gets if the radius drop down should be shown |
|
206 | + * @return mixed |
|
207 | + */ |
|
208 | + public function getShowRadius() |
|
209 | + { |
|
210 | + return $this->config()->get('show_radius'); |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * @return mixed |
|
215 | + */ |
|
216 | + public function getUsedCategories() |
|
217 | + { |
|
218 | + return $this->Categories()->filter([ |
|
219 | + 'LocationSet.ID:GreaterThan' => 0, |
|
220 | + ]); |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Gets the path of the info window template |
|
225 | + * |
|
226 | + * @return string |
|
227 | + */ |
|
228 | + public function getInfoWindowTemplate() |
|
229 | + { |
|
230 | + return ModuleResourceLoader::singleton()->resolveURL( |
|
231 | + Config::inst()->get( |
|
232 | + static::class, |
|
233 | + 'infoWindowTemplate' |
|
234 | + ) |
|
235 | + ); |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Gets the path of the list template |
|
240 | + * |
|
241 | + * @return string |
|
242 | + */ |
|
243 | + public function getListTemplate() |
|
244 | + { |
|
245 | + return ModuleResourceLoader::singleton()->resolveURL( |
|
246 | + Config::inst()->get( |
|
247 | + static::class, |
|
248 | + 'listTemplate' |
|
249 | + ) |
|
250 | + ); |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * @return null|string |
|
255 | + */ |
|
256 | + public function getMapStyle() |
|
257 | + { |
|
258 | + return AddressDataExtension::getMapStyleJSON(); |
|
259 | + } |
|
260 | + |
|
261 | + public function getMapStyleJSONPath() |
|
262 | + { |
|
263 | + return AddressDataExtension::getMapStyleJSONPath(); |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * @return null|string |
|
268 | + */ |
|
269 | + public function getMarkerIcon() |
|
270 | + { |
|
271 | + return AddressDataExtension::getIconImage(); |
|
272 | + } |
|
273 | 273 | } |
@@ -13,35 +13,35 @@ |
||
13 | 13 | */ |
14 | 14 | class EmailAddressTask extends BuildTask |
15 | 15 | { |
16 | - /** |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - protected $title = 'Email Address Task'; // title of the script |
|
16 | + /** |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + protected $title = 'Email Address Task'; // title of the script |
|
20 | 20 | |
21 | - /** |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $description = "Convert depreciated 'Email Address' field to new 'Email' field."; |
|
21 | + /** |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $description = "Convert depreciated 'Email Address' field to new 'Email' field."; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @param HTTPRequest $request |
|
28 | - */ |
|
29 | - public function run($request) |
|
30 | - { |
|
31 | - Config::inst()->update('DataObject', 'validation_enabled', false); |
|
26 | + /** |
|
27 | + * @param HTTPRequest $request |
|
28 | + */ |
|
29 | + public function run($request) |
|
30 | + { |
|
31 | + Config::inst()->update('DataObject', 'validation_enabled', false); |
|
32 | 32 | |
33 | - $ct = 0; |
|
34 | - $updateEmail = function ($location) use (&$ct) { |
|
35 | - if (!$location->Email && $location->EmailAddress) { |
|
36 | - $location->Email = $location->EmailAddress; |
|
37 | - $location->write(); |
|
38 | - ++$ct; |
|
39 | - } |
|
40 | - }; |
|
33 | + $ct = 0; |
|
34 | + $updateEmail = function ($location) use (&$ct) { |
|
35 | + if (!$location->Email && $location->EmailAddress) { |
|
36 | + $location->Email = $location->EmailAddress; |
|
37 | + $location->write(); |
|
38 | + ++$ct; |
|
39 | + } |
|
40 | + }; |
|
41 | 41 | |
42 | - Location::get()->each($updateEmail); |
|
43 | - Config::modify()->set('DataObject', 'validation_enabled', true); |
|
42 | + Location::get()->each($updateEmail); |
|
43 | + Config::modify()->set('DataObject', 'validation_enabled', true); |
|
44 | 44 | |
45 | - echo '<p>' . $ct . ' Locations updated</p>'; |
|
46 | - } |
|
45 | + echo '<p>' . $ct . ' Locations updated</p>'; |
|
46 | + } |
|
47 | 47 | } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | Config::inst()->update('DataObject', 'validation_enabled', false); |
32 | 32 | |
33 | 33 | $ct = 0; |
34 | - $updateEmail = function ($location) use (&$ct) { |
|
34 | + $updateEmail = function($location) use (&$ct) { |
|
35 | 35 | if (!$location->Email && $location->EmailAddress) { |
36 | 36 | $location->Email = $location->EmailAddress; |
37 | 37 | $location->write(); |
@@ -42,6 +42,6 @@ discard block |
||
42 | 42 | Location::get()->each($updateEmail); |
43 | 43 | Config::modify()->set('DataObject', 'validation_enabled', true); |
44 | 44 | |
45 | - echo '<p>' . $ct . ' Locations updated</p>'; |
|
45 | + echo '<p>'.$ct.' Locations updated</p>'; |
|
46 | 46 | } |
47 | 47 | } |