@@ -13,89 +13,89 @@ |
||
13 | 13 | class LocationCsvBulkLoader extends CsvBulkLoader |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $columnMap = array( |
|
20 | - 'Name' => 'Title', |
|
21 | - 'EmailAddress' => 'Email', |
|
22 | - 'Categories' => '->getCategoryByName', |
|
23 | - 'Import_ID' => 'Import_ID', |
|
24 | - 'Country' => '->getCountryByName', |
|
25 | - ); |
|
16 | + /** |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $columnMap = array( |
|
20 | + 'Name' => 'Title', |
|
21 | + 'EmailAddress' => 'Email', |
|
22 | + 'Categories' => '->getCategoryByName', |
|
23 | + 'Import_ID' => 'Import_ID', |
|
24 | + 'Country' => '->getCountryByName', |
|
25 | + ); |
|
26 | 26 | |
27 | - /** |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - public $duplicateChecks = array( |
|
31 | - 'Import_ID' => 'Import_ID' |
|
32 | - ); |
|
27 | + /** |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + public $duplicateChecks = array( |
|
31 | + 'Import_ID' => 'Import_ID' |
|
32 | + ); |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param $val |
|
36 | - * @return string|string[]|null |
|
37 | - */ |
|
38 | - public function getEscape($val) |
|
39 | - { |
|
40 | - return preg_replace("/\r|\n/", "", $val); |
|
41 | - } |
|
34 | + /** |
|
35 | + * @param $val |
|
36 | + * @return string|string[]|null |
|
37 | + */ |
|
38 | + public function getEscape($val) |
|
39 | + { |
|
40 | + return preg_replace("/\r|\n/", "", $val); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param $obj |
|
45 | - * @param $val |
|
46 | - * @param $record |
|
47 | - * @throws \SilverStripe\ORM\ValidationException |
|
48 | - */ |
|
49 | - public static function getCategoryByName(&$obj, $val, $record) |
|
50 | - { |
|
51 | - $val = Convert::raw2sql($val); |
|
52 | - $parts = explode(', ', $val); |
|
43 | + /** |
|
44 | + * @param $obj |
|
45 | + * @param $val |
|
46 | + * @param $record |
|
47 | + * @throws \SilverStripe\ORM\ValidationException |
|
48 | + */ |
|
49 | + public static function getCategoryByName(&$obj, $val, $record) |
|
50 | + { |
|
51 | + $val = Convert::raw2sql($val); |
|
52 | + $parts = explode(', ', $val); |
|
53 | 53 | |
54 | - foreach ($parts as $part) { |
|
55 | - $category = LocationCategory::get()->filter(array('Name' => $part))->first(); |
|
56 | - if (!$category) { |
|
57 | - $category = LocationCategory::create(); |
|
58 | - $category->Name = $part; |
|
59 | - $category->write(); |
|
60 | - } |
|
61 | - $obj->Categories()->add($category); |
|
62 | - } |
|
63 | - } |
|
54 | + foreach ($parts as $part) { |
|
55 | + $category = LocationCategory::get()->filter(array('Name' => $part))->first(); |
|
56 | + if (!$category) { |
|
57 | + $category = LocationCategory::create(); |
|
58 | + $category->Name = $part; |
|
59 | + $category->write(); |
|
60 | + } |
|
61 | + $obj->Categories()->add($category); |
|
62 | + } |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @param $obj |
|
67 | - * @param $val |
|
68 | - * @param $record |
|
69 | - */ |
|
70 | - public function getCountryByName(&$obj, $val, $record) |
|
71 | - { |
|
72 | - $val = $this->getEscape($val); |
|
73 | - $countries = IntlLocales::singleton()->getCountries(); |
|
65 | + /** |
|
66 | + * @param $obj |
|
67 | + * @param $val |
|
68 | + * @param $record |
|
69 | + */ |
|
70 | + public function getCountryByName(&$obj, $val, $record) |
|
71 | + { |
|
72 | + $val = $this->getEscape($val); |
|
73 | + $countries = IntlLocales::singleton()->getCountries(); |
|
74 | 74 | |
75 | - if (strlen((string)$val) == 2) { |
|
76 | - $val = strtolower($val); |
|
77 | - if (array_key_exists($val, $countries)) { |
|
78 | - $obj->Country = $val; |
|
79 | - } |
|
80 | - } |
|
75 | + if (strlen((string)$val) == 2) { |
|
76 | + $val = strtolower($val); |
|
77 | + if (array_key_exists($val, $countries)) { |
|
78 | + $obj->Country = $val; |
|
79 | + } |
|
80 | + } |
|
81 | 81 | |
82 | - if (in_array($val, $countries)) { |
|
83 | - $obj->Country = array_search($val, $countries); |
|
84 | - } |
|
85 | - } |
|
82 | + if (in_array($val, $countries)) { |
|
83 | + $obj->Country = array_search($val, $countries); |
|
84 | + } |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * @param array $record |
|
89 | - * @param array $columnMap |
|
90 | - * @param \SilverStripe\Dev\BulkLoader_Result $results |
|
91 | - * @param bool $preview |
|
92 | - * @return int|void |
|
93 | - */ |
|
94 | - protected function processRecord($record, $columnMap, &$results, $preview = false) |
|
95 | - { |
|
96 | - $objID = parent::processRecord($record, $columnMap, $results, $preview = false); |
|
87 | + /** |
|
88 | + * @param array $record |
|
89 | + * @param array $columnMap |
|
90 | + * @param \SilverStripe\Dev\BulkLoader_Result $results |
|
91 | + * @param bool $preview |
|
92 | + * @return int|void |
|
93 | + */ |
|
94 | + protected function processRecord($record, $columnMap, &$results, $preview = false) |
|
95 | + { |
|
96 | + $objID = parent::processRecord($record, $columnMap, $results, $preview = false); |
|
97 | 97 | |
98 | - $location = Location::get()->byID($objID); |
|
99 | - $location->publishSingle(); |
|
100 | - } |
|
98 | + $location = Location::get()->byID($objID); |
|
99 | + $location->publishSingle(); |
|
100 | + } |
|
101 | 101 | } |
@@ -72,7 +72,7 @@ |
||
72 | 72 | $val = $this->getEscape($val); |
73 | 73 | $countries = IntlLocales::singleton()->getCountries(); |
74 | 74 | |
75 | - if (strlen((string)$val) == 2) { |
|
75 | + if (strlen((string) $val) == 2) { |
|
76 | 76 | $val = strtolower($val); |
77 | 77 | if (array_key_exists($val, $countries)) { |
78 | 78 | $obj->Country = $val; |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | |
100 | 100 | // google maps api key |
101 | 101 | $key = Config::inst()->get(GoogleGeocoder::class, 'map_api_key'); |
102 | - Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key); |
|
102 | + Requirements::javascript('https://maps.google.com/maps/api/js?key='.$key); |
|
103 | 103 | |
104 | 104 | $mapSettings = [ |
105 | 105 | 'fullMapStart' => true, |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | unset($vars['url']); |
148 | 148 | $url = ''; |
149 | 149 | if (count($vars)) { |
150 | - $url .= '?' . http_build_query($vars); |
|
150 | + $url .= '?'.http_build_query($vars); |
|
151 | 151 | } |
152 | 152 | $mapSettings['dataLocation'] = Controller::join_links($this->Link(), 'xml.xml', $url); |
153 | 153 | |
@@ -249,8 +249,8 @@ discard block |
||
249 | 249 | if ($this->getShowRadius()) { |
250 | 250 | $radiusVar = $this->data()->config()->get('radius_var'); |
251 | 251 | |
252 | - if ($radius = (int)$request->getVar($radiusVar)) { |
|
253 | - $locations = $locations->filterByCallback(function ($location) use (&$radius) { |
|
252 | + if ($radius = (int) $request->getVar($radiusVar)) { |
|
253 | + $locations = $locations->filterByCallback(function($location) use (&$radius) { |
|
254 | 254 | return $location->Distance <= $radius; |
255 | 255 | }); |
256 | 256 | } |
@@ -21,379 +21,379 @@ |
||
21 | 21 | */ |
22 | 22 | class LocatorController extends \PageController |
23 | 23 | { |
24 | - /** |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - private static $allowed_actions = [ |
|
28 | - 'xml', |
|
29 | - 'json', |
|
30 | - ]; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - private static $base_filter = []; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var array |
|
39 | - */ |
|
40 | - private static $base_exclude = [ |
|
41 | - 'Lat' => 0, |
|
42 | - 'Lng' => 0, |
|
43 | - ]; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var array |
|
47 | - */ |
|
48 | - private static $base_filter_any = []; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var bool |
|
52 | - */ |
|
53 | - private static $bootstrapify = true; |
|
54 | - |
|
55 | - /** |
|
56 | - * ID of map container |
|
57 | - * |
|
58 | - * @var string |
|
59 | - */ |
|
60 | - private static $map_container = 'map'; |
|
61 | - |
|
62 | - /** |
|
63 | - * class of location list container |
|
64 | - * |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - private static $list_container = 'loc-list'; |
|
68 | - |
|
69 | - /** |
|
70 | - * The zoom level of the map |
|
71 | - * @var int |
|
72 | - */ |
|
73 | - private static $zoom = 12; |
|
74 | - |
|
75 | - /** |
|
76 | - * The minimum zoom level the map can have |
|
77 | - * @var int |
|
78 | - */ |
|
79 | - private static $min_zoom = 6; |
|
80 | - |
|
81 | - /** |
|
82 | - * The maximum zoom level the map can have |
|
83 | - * @var int |
|
84 | - */ |
|
85 | - private static $max_zoom = 18; |
|
86 | - |
|
87 | - /** |
|
88 | - * If double clicking the map should not zoom |
|
89 | - * @var bool |
|
90 | - */ |
|
91 | - private static $disable_double_click_zoom = true; |
|
92 | - |
|
93 | - /** |
|
94 | - * If the map should disable zoom by scrollwheel |
|
95 | - * @var bool |
|
96 | - */ |
|
97 | - private static $scrollwheel = false; |
|
98 | - |
|
99 | - /** |
|
100 | - * If the map should show naviagtion controls |
|
101 | - * @var bool |
|
102 | - */ |
|
103 | - private static $navigation_control = false; |
|
104 | - |
|
105 | - /** |
|
106 | - * @var bool |
|
107 | - */ |
|
108 | - private static $draggable = false; |
|
109 | - |
|
110 | - /** |
|
111 | - * @var DataList|ArrayList |
|
112 | - */ |
|
113 | - protected $locations; |
|
114 | - |
|
115 | - /** |
|
116 | - * Set Requirements based on input from CMS |
|
117 | - */ |
|
118 | - public function init() |
|
119 | - { |
|
120 | - parent::init(); |
|
121 | - |
|
122 | - // prevent init of map if no query |
|
123 | - $request = Controller::curr()->getRequest(); |
|
124 | - if (!$this->getTrigger($request)) { |
|
125 | - return; |
|
126 | - } |
|
127 | - |
|
128 | - $locations = $this->getLocations(); |
|
129 | - |
|
130 | - // prevent init of map if there are no locations |
|
131 | - if (!$locations) { |
|
132 | - return; |
|
133 | - } |
|
134 | - |
|
135 | - // google maps api key |
|
136 | - $key = Config::inst()->get(GoogleGeocoder::class, 'map_api_key'); |
|
137 | - Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key); |
|
138 | - |
|
139 | - $mapSettings = [ |
|
140 | - 'fullMapStart' => true, |
|
141 | - 'maxDistance' => true, |
|
142 | - 'storeLimit' => -1, |
|
143 | - 'originMarker' => true, |
|
144 | - 'slideMap' => false, |
|
145 | - 'distanceAlert' => -1, |
|
146 | - 'featuredLocations' => false, |
|
147 | - 'defaultLat' => 0, |
|
148 | - 'defaultLng' => 0, |
|
149 | - 'mapSettings' => [ |
|
150 | - 'zoom' => Config::inst()->get(LocatorController::class, 'zoom'), |
|
151 | - 'minZoom' => Config::inst()->get(LocatorController::class, 'min_zoom'), |
|
152 | - 'maxZoom' => Config::inst()->get(LocatorController::class, 'max_zoom'), |
|
153 | - 'mapTypeId' => 'google.maps.MapTypeId.ROADMAP', |
|
154 | - 'disableDoubleClickZoom' => Config::inst()->get(LocatorController::class, 'disable_double_click_zoom'), |
|
155 | - 'scrollwheel' => Config::inst()->get(LocatorController::class, 'scrollwheel'), |
|
156 | - 'navigationControl' => Config::inst()->get(LocatorController::class, 'navigation_control'), |
|
157 | - 'draggable' => Config::inst()->get(LocatorController::class, 'draggable'), |
|
158 | - ], |
|
159 | - ]; |
|
160 | - |
|
161 | - $mapSettings['listTemplatePath'] = $this->getListTemplate(); |
|
162 | - $mapSettings['infowindowTemplatePath'] = $this->getInfoWindowTemplate(); |
|
163 | - $mapSettings['lengthUnit'] = $this->data()->Unit == 'km' ? 'km' : 'm'; |
|
164 | - $mapSettings['mapID'] = Config::inst()->get(LocatorController::class, 'map_container'); |
|
165 | - $mapSettings['locationList'] = Config::inst()->get(LocatorController::class, 'list_container'); |
|
166 | - |
|
167 | - if ($locations->filter('Featured', true)->count() > 0) { |
|
168 | - $mapSettings['featuredLocations'] = true; |
|
169 | - } |
|
170 | - |
|
171 | - // map config based on user input in Settings tab |
|
172 | - $limit = Config::inst()->get(LocatorController::class, 'limit'); |
|
173 | - if (0 < $limit) { |
|
174 | - $mapSettings['storeLimit'] = $limit; |
|
175 | - } |
|
176 | - |
|
177 | - if ($coords = $this->getAddressSearchCoords()) { |
|
178 | - $mapSettings['defaultLat'] = $coords->getField("Lat"); |
|
179 | - $mapSettings['defaultLat'] = $coords->getField("Lng"); |
|
180 | - } |
|
181 | - |
|
182 | - // pass GET variables to xml action |
|
183 | - $vars = $this->request->getVars(); |
|
184 | - unset($vars['url']); |
|
185 | - $url = ''; |
|
186 | - if (count($vars)) { |
|
187 | - $url .= '?' . http_build_query($vars); |
|
188 | - } |
|
189 | - $mapSettings['dataLocation'] = Controller::join_links($this->Link(), 'xml.xml', $url); |
|
190 | - |
|
191 | - if ($stylePath = $this->getMapStyleJSONPath()) { |
|
192 | - if ($style = file_get_contents($stylePath)) { |
|
193 | - $mapSettings['mapSettings']['styles'] = json_decode($style); |
|
194 | - } |
|
195 | - } |
|
196 | - |
|
197 | - if ($imagePath = $this->getMarkerIcon()) { |
|
198 | - $mapSettings['markerImg'] = $imagePath; |
|
199 | - } |
|
200 | - |
|
201 | - $this->extend('modifyMapSettings', $mapSettings); |
|
202 | - |
|
203 | - $encoded = json_encode($mapSettings, JSON_UNESCAPED_SLASHES); |
|
204 | - // mapTypeId is a javascript object |
|
205 | - $encoded = preg_replace('/("mapTypeId"\s*:\s*)"(.+?)"/i', '$1$2', $encoded); |
|
206 | - |
|
207 | - $this->extend('modifyMapSettingsEncoded', $encoded); |
|
208 | - // init map |
|
209 | - Requirements::customScript(" |
|
24 | + /** |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + private static $allowed_actions = [ |
|
28 | + 'xml', |
|
29 | + 'json', |
|
30 | + ]; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + private static $base_filter = []; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var array |
|
39 | + */ |
|
40 | + private static $base_exclude = [ |
|
41 | + 'Lat' => 0, |
|
42 | + 'Lng' => 0, |
|
43 | + ]; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var array |
|
47 | + */ |
|
48 | + private static $base_filter_any = []; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var bool |
|
52 | + */ |
|
53 | + private static $bootstrapify = true; |
|
54 | + |
|
55 | + /** |
|
56 | + * ID of map container |
|
57 | + * |
|
58 | + * @var string |
|
59 | + */ |
|
60 | + private static $map_container = 'map'; |
|
61 | + |
|
62 | + /** |
|
63 | + * class of location list container |
|
64 | + * |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + private static $list_container = 'loc-list'; |
|
68 | + |
|
69 | + /** |
|
70 | + * The zoom level of the map |
|
71 | + * @var int |
|
72 | + */ |
|
73 | + private static $zoom = 12; |
|
74 | + |
|
75 | + /** |
|
76 | + * The minimum zoom level the map can have |
|
77 | + * @var int |
|
78 | + */ |
|
79 | + private static $min_zoom = 6; |
|
80 | + |
|
81 | + /** |
|
82 | + * The maximum zoom level the map can have |
|
83 | + * @var int |
|
84 | + */ |
|
85 | + private static $max_zoom = 18; |
|
86 | + |
|
87 | + /** |
|
88 | + * If double clicking the map should not zoom |
|
89 | + * @var bool |
|
90 | + */ |
|
91 | + private static $disable_double_click_zoom = true; |
|
92 | + |
|
93 | + /** |
|
94 | + * If the map should disable zoom by scrollwheel |
|
95 | + * @var bool |
|
96 | + */ |
|
97 | + private static $scrollwheel = false; |
|
98 | + |
|
99 | + /** |
|
100 | + * If the map should show naviagtion controls |
|
101 | + * @var bool |
|
102 | + */ |
|
103 | + private static $navigation_control = false; |
|
104 | + |
|
105 | + /** |
|
106 | + * @var bool |
|
107 | + */ |
|
108 | + private static $draggable = false; |
|
109 | + |
|
110 | + /** |
|
111 | + * @var DataList|ArrayList |
|
112 | + */ |
|
113 | + protected $locations; |
|
114 | + |
|
115 | + /** |
|
116 | + * Set Requirements based on input from CMS |
|
117 | + */ |
|
118 | + public function init() |
|
119 | + { |
|
120 | + parent::init(); |
|
121 | + |
|
122 | + // prevent init of map if no query |
|
123 | + $request = Controller::curr()->getRequest(); |
|
124 | + if (!$this->getTrigger($request)) { |
|
125 | + return; |
|
126 | + } |
|
127 | + |
|
128 | + $locations = $this->getLocations(); |
|
129 | + |
|
130 | + // prevent init of map if there are no locations |
|
131 | + if (!$locations) { |
|
132 | + return; |
|
133 | + } |
|
134 | + |
|
135 | + // google maps api key |
|
136 | + $key = Config::inst()->get(GoogleGeocoder::class, 'map_api_key'); |
|
137 | + Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key); |
|
138 | + |
|
139 | + $mapSettings = [ |
|
140 | + 'fullMapStart' => true, |
|
141 | + 'maxDistance' => true, |
|
142 | + 'storeLimit' => -1, |
|
143 | + 'originMarker' => true, |
|
144 | + 'slideMap' => false, |
|
145 | + 'distanceAlert' => -1, |
|
146 | + 'featuredLocations' => false, |
|
147 | + 'defaultLat' => 0, |
|
148 | + 'defaultLng' => 0, |
|
149 | + 'mapSettings' => [ |
|
150 | + 'zoom' => Config::inst()->get(LocatorController::class, 'zoom'), |
|
151 | + 'minZoom' => Config::inst()->get(LocatorController::class, 'min_zoom'), |
|
152 | + 'maxZoom' => Config::inst()->get(LocatorController::class, 'max_zoom'), |
|
153 | + 'mapTypeId' => 'google.maps.MapTypeId.ROADMAP', |
|
154 | + 'disableDoubleClickZoom' => Config::inst()->get(LocatorController::class, 'disable_double_click_zoom'), |
|
155 | + 'scrollwheel' => Config::inst()->get(LocatorController::class, 'scrollwheel'), |
|
156 | + 'navigationControl' => Config::inst()->get(LocatorController::class, 'navigation_control'), |
|
157 | + 'draggable' => Config::inst()->get(LocatorController::class, 'draggable'), |
|
158 | + ], |
|
159 | + ]; |
|
160 | + |
|
161 | + $mapSettings['listTemplatePath'] = $this->getListTemplate(); |
|
162 | + $mapSettings['infowindowTemplatePath'] = $this->getInfoWindowTemplate(); |
|
163 | + $mapSettings['lengthUnit'] = $this->data()->Unit == 'km' ? 'km' : 'm'; |
|
164 | + $mapSettings['mapID'] = Config::inst()->get(LocatorController::class, 'map_container'); |
|
165 | + $mapSettings['locationList'] = Config::inst()->get(LocatorController::class, 'list_container'); |
|
166 | + |
|
167 | + if ($locations->filter('Featured', true)->count() > 0) { |
|
168 | + $mapSettings['featuredLocations'] = true; |
|
169 | + } |
|
170 | + |
|
171 | + // map config based on user input in Settings tab |
|
172 | + $limit = Config::inst()->get(LocatorController::class, 'limit'); |
|
173 | + if (0 < $limit) { |
|
174 | + $mapSettings['storeLimit'] = $limit; |
|
175 | + } |
|
176 | + |
|
177 | + if ($coords = $this->getAddressSearchCoords()) { |
|
178 | + $mapSettings['defaultLat'] = $coords->getField("Lat"); |
|
179 | + $mapSettings['defaultLat'] = $coords->getField("Lng"); |
|
180 | + } |
|
181 | + |
|
182 | + // pass GET variables to xml action |
|
183 | + $vars = $this->request->getVars(); |
|
184 | + unset($vars['url']); |
|
185 | + $url = ''; |
|
186 | + if (count($vars)) { |
|
187 | + $url .= '?' . http_build_query($vars); |
|
188 | + } |
|
189 | + $mapSettings['dataLocation'] = Controller::join_links($this->Link(), 'xml.xml', $url); |
|
190 | + |
|
191 | + if ($stylePath = $this->getMapStyleJSONPath()) { |
|
192 | + if ($style = file_get_contents($stylePath)) { |
|
193 | + $mapSettings['mapSettings']['styles'] = json_decode($style); |
|
194 | + } |
|
195 | + } |
|
196 | + |
|
197 | + if ($imagePath = $this->getMarkerIcon()) { |
|
198 | + $mapSettings['markerImg'] = $imagePath; |
|
199 | + } |
|
200 | + |
|
201 | + $this->extend('modifyMapSettings', $mapSettings); |
|
202 | + |
|
203 | + $encoded = json_encode($mapSettings, JSON_UNESCAPED_SLASHES); |
|
204 | + // mapTypeId is a javascript object |
|
205 | + $encoded = preg_replace('/("mapTypeId"\s*:\s*)"(.+?)"/i', '$1$2', $encoded); |
|
206 | + |
|
207 | + $this->extend('modifyMapSettingsEncoded', $encoded); |
|
208 | + // init map |
|
209 | + Requirements::customScript(" |
|
210 | 210 | $(function(){ |
211 | 211 | $('#map-container').storeLocator({$encoded}); |
212 | 212 | }); |
213 | 213 | ", 'jquery-locator'); |
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * @param HTTPRequest $request |
|
218 | - * |
|
219 | - * @return bool |
|
220 | - */ |
|
221 | - public function getTrigger(HTTPRequest $request = null) |
|
222 | - { |
|
223 | - if ($request === null) { |
|
224 | - $request = $this->getRequest(); |
|
225 | - } |
|
226 | - return !empty($this->getRequest()->getVars()) || $this->data()->ResultsOnLoad; |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * @return ArrayList|DataList |
|
231 | - */ |
|
232 | - public function getLocations() |
|
233 | - { |
|
234 | - if (!$this->locations) { |
|
235 | - $this->setLocations($this->request); |
|
236 | - } |
|
237 | - |
|
238 | - return $this->locations; |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * @param HTTPRequest|null $request |
|
243 | - * |
|
244 | - * @return $this |
|
245 | - */ |
|
246 | - public function setLocations(HTTPRequest $request = null) |
|
247 | - { |
|
248 | - |
|
249 | - if ($request === null) { |
|
250 | - $request = $this->request; |
|
251 | - } |
|
252 | - $filter = $this->config()->get('base_filter'); |
|
253 | - |
|
254 | - $categoryVar = $this->data()->config()->get('category_var'); |
|
255 | - if ($request->getVar($categoryVar)) { |
|
256 | - $filter['Categories.ID'] = $request->getVar($categoryVar); |
|
257 | - } else { |
|
258 | - if ($this->getPageCategories()->exists()) { |
|
259 | - foreach ($this->getPageCategories() as $category) { |
|
260 | - $filter['Categories.ID'][] = $category->ID; |
|
261 | - } |
|
262 | - } |
|
263 | - } |
|
264 | - |
|
265 | - $this->extend('updateLocatorFilter', $filter, $request); |
|
266 | - |
|
267 | - $filterAny = $this->config()->get('base_filter_any'); |
|
268 | - $this->extend('updateLocatorFilterAny', $filterAny, $request); |
|
269 | - |
|
270 | - $exclude = $this->config()->get('base_exclude'); |
|
271 | - $this->extend('updateLocatorExclude', $exclude, $request); |
|
272 | - |
|
273 | - $class = $this->data()->ClassName; |
|
274 | - $locations = $class::get_locations($filter, $filterAny, $exclude); |
|
275 | - $locations = DataToArrayListHelper::to_array_list($locations); |
|
276 | - |
|
277 | - //allow for adjusting list post possible distance calculation |
|
278 | - $this->extend('updateLocationList', $locations); |
|
279 | - |
|
280 | - if ($locations->canSortBy('Distance')) { |
|
281 | - $locations = $locations->sort('Distance'); |
|
282 | - } |
|
283 | - |
|
284 | - if ($this->getShowRadius()) { |
|
285 | - $radiusVar = $this->data()->config()->get('radius_var'); |
|
286 | - |
|
287 | - if ($radius = (int)$request->getVar($radiusVar)) { |
|
288 | - $locations = $locations->filterByCallback(function ($location) use (&$radius) { |
|
289 | - return $location->Distance <= $radius; |
|
290 | - }); |
|
291 | - } |
|
292 | - } |
|
293 | - |
|
294 | - //allow for returning list to be set as |
|
295 | - $this->extend('updateListType', $locations); |
|
296 | - |
|
297 | - $limit = $this->getLimit(); |
|
298 | - if ($limit > 0) { |
|
299 | - $locations = $locations->limit($limit); |
|
300 | - } |
|
301 | - |
|
302 | - $this->locations = $locations; |
|
303 | - |
|
304 | - return $this; |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * @return ArrayData|boolean |
|
309 | - */ |
|
310 | - public function getAddressSearchCoords() |
|
311 | - { |
|
312 | - $addressVar = Config::inst()->get(DistanceDataExtension::class, 'address_var'); |
|
313 | - if (!$this->request->getVar($addressVar)) { |
|
314 | - return false; |
|
315 | - } |
|
316 | - if (class_exists(GoogleGeocoder::class)) { |
|
317 | - $geocoder = new GoogleGeocoder($this->request->getVar($addressVar)); |
|
318 | - $response = $geocoder->getResult(); |
|
319 | - $lat = $response->getLatitude(); |
|
320 | - $lng = $response->getLongitude(); |
|
321 | - |
|
322 | - return new ArrayData([ |
|
323 | - "Lat" => $lat, |
|
324 | - "Lng" => $lng, |
|
325 | - ]); |
|
326 | - } |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * @param HTTPRequest $request |
|
331 | - * |
|
332 | - * @return \SilverStripe\View\ViewableData_Customised |
|
333 | - */ |
|
334 | - public function index(HTTPRequest $request) |
|
335 | - { |
|
336 | - if ($this->getTrigger($request)) { |
|
337 | - $locations = $this->getLocations(); |
|
338 | - } else { |
|
339 | - $locations = ArrayList::create(); |
|
340 | - } |
|
341 | - |
|
342 | - return $this->customise([ |
|
343 | - 'Locations' => $locations, |
|
344 | - ]); |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * Renders locations in xml format |
|
349 | - * |
|
350 | - * @return \SilverStripe\ORM\FieldType\DBHTMLText |
|
351 | - */ |
|
352 | - public function xml() |
|
353 | - { |
|
354 | - $this->getResponse()->addHeader("Content-Type", "application/xml"); |
|
355 | - $data = new ArrayData([ |
|
356 | - "Locations" => $this->getLocations(), |
|
357 | - "AddressCoords" => $this->getAddressSearchCoords(), |
|
358 | - ]); |
|
359 | - |
|
360 | - return $data->renderWith('Dynamic/Locator/Data/XML'); |
|
361 | - } |
|
362 | - |
|
363 | - /** |
|
364 | - * Renders locations in json format |
|
365 | - * |
|
366 | - * @return \SilverStripe\ORM\FieldType\DBHTMLText |
|
367 | - */ |
|
368 | - public function json() |
|
369 | - { |
|
370 | - $this->getResponse()->addHeader("Content-Type", "application/json"); |
|
371 | - $data = new ArrayData([ |
|
372 | - "Locations" => $this->getLocations(), |
|
373 | - "AddressCoords" => $this->getAddressSearchCoords(), |
|
374 | - ]); |
|
375 | - |
|
376 | - return $data->renderWith('Dynamic/Locator/Data/JSON'); |
|
377 | - } |
|
378 | - |
|
379 | - /** |
|
380 | - * LocationSearch form. |
|
381 | - * |
|
382 | - * Search form for locations, updates map and results list via AJAX |
|
383 | - * |
|
384 | - * @return \SilverStripe\Forms\Form |
|
385 | - */ |
|
386 | - public function LocationSearch() |
|
387 | - { |
|
388 | - |
|
389 | - $form = LocatorForm::create($this, 'LocationSearch'); |
|
390 | - |
|
391 | - $this->extend('updateLocationSearch', $form); |
|
392 | - |
|
393 | - return $form |
|
394 | - ->setFormMethod('GET') |
|
395 | - ->setFormAction($this->Link()) |
|
396 | - ->disableSecurityToken() |
|
397 | - ->loadDataFrom($this->request->getVars()); |
|
398 | - } |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * @param HTTPRequest $request |
|
218 | + * |
|
219 | + * @return bool |
|
220 | + */ |
|
221 | + public function getTrigger(HTTPRequest $request = null) |
|
222 | + { |
|
223 | + if ($request === null) { |
|
224 | + $request = $this->getRequest(); |
|
225 | + } |
|
226 | + return !empty($this->getRequest()->getVars()) || $this->data()->ResultsOnLoad; |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * @return ArrayList|DataList |
|
231 | + */ |
|
232 | + public function getLocations() |
|
233 | + { |
|
234 | + if (!$this->locations) { |
|
235 | + $this->setLocations($this->request); |
|
236 | + } |
|
237 | + |
|
238 | + return $this->locations; |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * @param HTTPRequest|null $request |
|
243 | + * |
|
244 | + * @return $this |
|
245 | + */ |
|
246 | + public function setLocations(HTTPRequest $request = null) |
|
247 | + { |
|
248 | + |
|
249 | + if ($request === null) { |
|
250 | + $request = $this->request; |
|
251 | + } |
|
252 | + $filter = $this->config()->get('base_filter'); |
|
253 | + |
|
254 | + $categoryVar = $this->data()->config()->get('category_var'); |
|
255 | + if ($request->getVar($categoryVar)) { |
|
256 | + $filter['Categories.ID'] = $request->getVar($categoryVar); |
|
257 | + } else { |
|
258 | + if ($this->getPageCategories()->exists()) { |
|
259 | + foreach ($this->getPageCategories() as $category) { |
|
260 | + $filter['Categories.ID'][] = $category->ID; |
|
261 | + } |
|
262 | + } |
|
263 | + } |
|
264 | + |
|
265 | + $this->extend('updateLocatorFilter', $filter, $request); |
|
266 | + |
|
267 | + $filterAny = $this->config()->get('base_filter_any'); |
|
268 | + $this->extend('updateLocatorFilterAny', $filterAny, $request); |
|
269 | + |
|
270 | + $exclude = $this->config()->get('base_exclude'); |
|
271 | + $this->extend('updateLocatorExclude', $exclude, $request); |
|
272 | + |
|
273 | + $class = $this->data()->ClassName; |
|
274 | + $locations = $class::get_locations($filter, $filterAny, $exclude); |
|
275 | + $locations = DataToArrayListHelper::to_array_list($locations); |
|
276 | + |
|
277 | + //allow for adjusting list post possible distance calculation |
|
278 | + $this->extend('updateLocationList', $locations); |
|
279 | + |
|
280 | + if ($locations->canSortBy('Distance')) { |
|
281 | + $locations = $locations->sort('Distance'); |
|
282 | + } |
|
283 | + |
|
284 | + if ($this->getShowRadius()) { |
|
285 | + $radiusVar = $this->data()->config()->get('radius_var'); |
|
286 | + |
|
287 | + if ($radius = (int)$request->getVar($radiusVar)) { |
|
288 | + $locations = $locations->filterByCallback(function ($location) use (&$radius) { |
|
289 | + return $location->Distance <= $radius; |
|
290 | + }); |
|
291 | + } |
|
292 | + } |
|
293 | + |
|
294 | + //allow for returning list to be set as |
|
295 | + $this->extend('updateListType', $locations); |
|
296 | + |
|
297 | + $limit = $this->getLimit(); |
|
298 | + if ($limit > 0) { |
|
299 | + $locations = $locations->limit($limit); |
|
300 | + } |
|
301 | + |
|
302 | + $this->locations = $locations; |
|
303 | + |
|
304 | + return $this; |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * @return ArrayData|boolean |
|
309 | + */ |
|
310 | + public function getAddressSearchCoords() |
|
311 | + { |
|
312 | + $addressVar = Config::inst()->get(DistanceDataExtension::class, 'address_var'); |
|
313 | + if (!$this->request->getVar($addressVar)) { |
|
314 | + return false; |
|
315 | + } |
|
316 | + if (class_exists(GoogleGeocoder::class)) { |
|
317 | + $geocoder = new GoogleGeocoder($this->request->getVar($addressVar)); |
|
318 | + $response = $geocoder->getResult(); |
|
319 | + $lat = $response->getLatitude(); |
|
320 | + $lng = $response->getLongitude(); |
|
321 | + |
|
322 | + return new ArrayData([ |
|
323 | + "Lat" => $lat, |
|
324 | + "Lng" => $lng, |
|
325 | + ]); |
|
326 | + } |
|
327 | + } |
|
328 | + |
|
329 | + /** |
|
330 | + * @param HTTPRequest $request |
|
331 | + * |
|
332 | + * @return \SilverStripe\View\ViewableData_Customised |
|
333 | + */ |
|
334 | + public function index(HTTPRequest $request) |
|
335 | + { |
|
336 | + if ($this->getTrigger($request)) { |
|
337 | + $locations = $this->getLocations(); |
|
338 | + } else { |
|
339 | + $locations = ArrayList::create(); |
|
340 | + } |
|
341 | + |
|
342 | + return $this->customise([ |
|
343 | + 'Locations' => $locations, |
|
344 | + ]); |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * Renders locations in xml format |
|
349 | + * |
|
350 | + * @return \SilverStripe\ORM\FieldType\DBHTMLText |
|
351 | + */ |
|
352 | + public function xml() |
|
353 | + { |
|
354 | + $this->getResponse()->addHeader("Content-Type", "application/xml"); |
|
355 | + $data = new ArrayData([ |
|
356 | + "Locations" => $this->getLocations(), |
|
357 | + "AddressCoords" => $this->getAddressSearchCoords(), |
|
358 | + ]); |
|
359 | + |
|
360 | + return $data->renderWith('Dynamic/Locator/Data/XML'); |
|
361 | + } |
|
362 | + |
|
363 | + /** |
|
364 | + * Renders locations in json format |
|
365 | + * |
|
366 | + * @return \SilverStripe\ORM\FieldType\DBHTMLText |
|
367 | + */ |
|
368 | + public function json() |
|
369 | + { |
|
370 | + $this->getResponse()->addHeader("Content-Type", "application/json"); |
|
371 | + $data = new ArrayData([ |
|
372 | + "Locations" => $this->getLocations(), |
|
373 | + "AddressCoords" => $this->getAddressSearchCoords(), |
|
374 | + ]); |
|
375 | + |
|
376 | + return $data->renderWith('Dynamic/Locator/Data/JSON'); |
|
377 | + } |
|
378 | + |
|
379 | + /** |
|
380 | + * LocationSearch form. |
|
381 | + * |
|
382 | + * Search form for locations, updates map and results list via AJAX |
|
383 | + * |
|
384 | + * @return \SilverStripe\Forms\Form |
|
385 | + */ |
|
386 | + public function LocationSearch() |
|
387 | + { |
|
388 | + |
|
389 | + $form = LocatorForm::create($this, 'LocationSearch'); |
|
390 | + |
|
391 | + $this->extend('updateLocationSearch', $form); |
|
392 | + |
|
393 | + return $form |
|
394 | + ->setFormMethod('GET') |
|
395 | + ->setFormAction($this->Link()) |
|
396 | + ->disableSecurityToken() |
|
397 | + ->loadDataFrom($this->request->getVars()); |
|
398 | + } |
|
399 | 399 | } |
@@ -17,83 +17,83 @@ |
||
17 | 17 | class LocationAdmin extends ModelAdmin |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - private static $managed_models = [ |
|
24 | - Location::class, |
|
25 | - LocationCategory::class, |
|
26 | - ]; |
|
20 | + /** |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + private static $managed_models = [ |
|
24 | + Location::class, |
|
25 | + LocationCategory::class, |
|
26 | + ]; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - private static $model_importers = [ |
|
32 | - Location::class => LocationCsvBulkLoader::class, |
|
33 | - LocationCategory::class => CsvBulkLoader::class, |
|
34 | - ]; |
|
28 | + /** |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + private static $model_importers = [ |
|
32 | + Location::class => LocationCsvBulkLoader::class, |
|
33 | + LocationCategory::class => CsvBulkLoader::class, |
|
34 | + ]; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - private static $menu_title = 'Locator'; |
|
40 | - /** |
|
41 | - * @var string |
|
42 | - */ |
|
43 | - private static $url_segment = 'locator'; |
|
36 | + /** |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + private static $menu_title = 'Locator'; |
|
40 | + /** |
|
41 | + * @var string |
|
42 | + */ |
|
43 | + private static $url_segment = 'locator'; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @return array |
|
47 | - */ |
|
48 | - public function getExportFields() |
|
49 | - { |
|
50 | - if ($this->modelClass == Location::class) { |
|
51 | - $fields = [ |
|
52 | - 'Title' => 'Name', |
|
53 | - 'Address' => 'Address', |
|
54 | - 'Address2' => 'Address2', |
|
55 | - 'City' => 'City', |
|
56 | - 'State' => 'State', |
|
57 | - 'PostalCode' => 'PostalCode', |
|
58 | - 'CountryCode' => 'Country', |
|
59 | - 'Phone' => 'Phone', |
|
60 | - 'Fax' => 'Fax', |
|
61 | - 'Email' => 'Email', |
|
62 | - 'Website' => 'Website', |
|
63 | - 'Featured' => 'Featured', |
|
64 | - 'CategoryList' => 'Categories', |
|
65 | - 'Lat' => 'Lat', |
|
66 | - 'Lng' => 'Lng', |
|
67 | - 'Import_ID' => 'Import_ID', |
|
68 | - ]; |
|
69 | - } |
|
45 | + /** |
|
46 | + * @return array |
|
47 | + */ |
|
48 | + public function getExportFields() |
|
49 | + { |
|
50 | + if ($this->modelClass == Location::class) { |
|
51 | + $fields = [ |
|
52 | + 'Title' => 'Name', |
|
53 | + 'Address' => 'Address', |
|
54 | + 'Address2' => 'Address2', |
|
55 | + 'City' => 'City', |
|
56 | + 'State' => 'State', |
|
57 | + 'PostalCode' => 'PostalCode', |
|
58 | + 'CountryCode' => 'Country', |
|
59 | + 'Phone' => 'Phone', |
|
60 | + 'Fax' => 'Fax', |
|
61 | + 'Email' => 'Email', |
|
62 | + 'Website' => 'Website', |
|
63 | + 'Featured' => 'Featured', |
|
64 | + 'CategoryList' => 'Categories', |
|
65 | + 'Lat' => 'Lat', |
|
66 | + 'Lng' => 'Lng', |
|
67 | + 'Import_ID' => 'Import_ID', |
|
68 | + ]; |
|
69 | + } |
|
70 | 70 | |
71 | - if (!isset($fields)) { |
|
72 | - $fields = parent::getExportFields(); |
|
73 | - } |
|
71 | + if (!isset($fields)) { |
|
72 | + $fields = parent::getExportFields(); |
|
73 | + } |
|
74 | 74 | |
75 | - $this->extend('updateGetExportFields', $fields); |
|
75 | + $this->extend('updateGetExportFields', $fields); |
|
76 | 76 | |
77 | - return $fields; |
|
78 | - } |
|
77 | + return $fields; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @param null $id |
|
82 | - * @param null $fields |
|
83 | - * @return $this|Form |
|
84 | - */ |
|
85 | - public function getEditForm($id = null, $fields = null) |
|
86 | - { |
|
87 | - $form = parent::getEditForm($id, $fields); |
|
80 | + /** |
|
81 | + * @param null $id |
|
82 | + * @param null $fields |
|
83 | + * @return $this|Form |
|
84 | + */ |
|
85 | + public function getEditForm($id = null, $fields = null) |
|
86 | + { |
|
87 | + $form = parent::getEditForm($id, $fields); |
|
88 | 88 | |
89 | - if ($this->modelClass == Location::class) { |
|
90 | - /** @var GridField $gridField */ |
|
91 | - if ($gridField = $form->Fields()->fieldByName($this->sanitiseClassName($this->modelClass))) { |
|
92 | - $gridField->getConfig() |
|
93 | - ->removeComponentsByType('GridFieldDeleteAction'); |
|
94 | - } |
|
95 | - } |
|
89 | + if ($this->modelClass == Location::class) { |
|
90 | + /** @var GridField $gridField */ |
|
91 | + if ($gridField = $form->Fields()->fieldByName($this->sanitiseClassName($this->modelClass))) { |
|
92 | + $gridField->getConfig() |
|
93 | + ->removeComponentsByType('GridFieldDeleteAction'); |
|
94 | + } |
|
95 | + } |
|
96 | 96 | |
97 | - return $form; |
|
98 | - } |
|
97 | + return $form; |
|
98 | + } |
|
99 | 99 | } |
@@ -15,72 +15,72 @@ |
||
15 | 15 | */ |
16 | 16 | class LocationToPageTask extends BuildTask |
17 | 17 | { |
18 | - /** |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - protected $title = 'Locator - Location to Page Task'; |
|
18 | + /** |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + protected $title = 'Locator - Location to Page Task'; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - private static $segment = 'locator-location-to-page-task'; |
|
23 | + /** |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + private static $segment = 'locator-location-to-page-task'; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @var bool |
|
30 | - */ |
|
31 | - private static $auto_publish_location = false; |
|
28 | + /** |
|
29 | + * @var bool |
|
30 | + */ |
|
31 | + private static $auto_publish_location = false; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @param \SilverStripe\Control\HTTPRequest $request |
|
35 | - */ |
|
36 | - public function run($request) |
|
37 | - { |
|
38 | - $this->migrateLocations(); |
|
39 | - } |
|
33 | + /** |
|
34 | + * @param \SilverStripe\Control\HTTPRequest $request |
|
35 | + */ |
|
36 | + public function run($request) |
|
37 | + { |
|
38 | + $this->migrateLocations(); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * |
|
43 | - */ |
|
44 | - protected function migrateLocations() |
|
45 | - { |
|
46 | - if (!$parent = Locator::get()->first()) { |
|
47 | - $parent = Locator::create(); |
|
48 | - $parent->Title = "Locator"; |
|
49 | - $parent->writeToStage(Versioned::DRAFT); |
|
50 | - } |
|
41 | + /** |
|
42 | + * |
|
43 | + */ |
|
44 | + protected function migrateLocations() |
|
45 | + { |
|
46 | + if (!$parent = Locator::get()->first()) { |
|
47 | + $parent = Locator::create(); |
|
48 | + $parent->Title = "Locator"; |
|
49 | + $parent->writeToStage(Versioned::DRAFT); |
|
50 | + } |
|
51 | 51 | |
52 | - /** @var Location $location */ |
|
53 | - foreach ($this->getLocations() as $location) { |
|
54 | - if (!LocationPage::get()->filter('LegacyObjectID', $location->ID)->first()) { |
|
55 | - if ($location->hasMethod('isPublished')) { |
|
56 | - $published = $location->isPublished(); |
|
57 | - } |
|
52 | + /** @var Location $location */ |
|
53 | + foreach ($this->getLocations() as $location) { |
|
54 | + if (!LocationPage::get()->filter('LegacyObjectID', $location->ID)->first()) { |
|
55 | + if ($location->hasMethod('isPublished')) { |
|
56 | + $published = $location->isPublished(); |
|
57 | + } |
|
58 | 58 | |
59 | - /** @var LocationPage $newLocation */ |
|
60 | - $newLocation = Injector::inst()->create(LocationPage::class, $location->toMap(), false); |
|
61 | - $newLocation->setClassName(LocationPage::class); |
|
62 | - $newLocation->ID = null; |
|
63 | - $newLocation->ParentID = $parent->ID; |
|
64 | - $newLocation->LegacyObjectID = $location->ID; |
|
59 | + /** @var LocationPage $newLocation */ |
|
60 | + $newLocation = Injector::inst()->create(LocationPage::class, $location->toMap(), false); |
|
61 | + $newLocation->setClassName(LocationPage::class); |
|
62 | + $newLocation->ID = null; |
|
63 | + $newLocation->ParentID = $parent->ID; |
|
64 | + $newLocation->LegacyObjectID = $location->ID; |
|
65 | 65 | |
66 | - $this->extend('preLocationMigrationUpdate', $location, $newLocation); |
|
66 | + $this->extend('preLocationMigrationUpdate', $location, $newLocation); |
|
67 | 67 | |
68 | - $newLocation->writeToStage(Versioned::DRAFT); |
|
68 | + $newLocation->writeToStage(Versioned::DRAFT); |
|
69 | 69 | |
70 | - if ((isset($published) && $published) || $this->config()->get('auto_publish_location')) { |
|
71 | - $newLocation->publishSingle(); |
|
72 | - } |
|
73 | - } |
|
74 | - } |
|
75 | - } |
|
70 | + if ((isset($published) && $published) || $this->config()->get('auto_publish_location')) { |
|
71 | + $newLocation->publishSingle(); |
|
72 | + } |
|
73 | + } |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * @return \Generator |
|
79 | - */ |
|
80 | - protected function getLocations() |
|
81 | - { |
|
82 | - foreach (Location::get() as $location) { |
|
83 | - yield $location; |
|
84 | - } |
|
85 | - } |
|
77 | + /** |
|
78 | + * @return \Generator |
|
79 | + */ |
|
80 | + protected function getLocations() |
|
81 | + { |
|
82 | + foreach (Location::get() as $location) { |
|
83 | + yield $location; |
|
84 | + } |
|
85 | + } |
|
86 | 86 | } |
@@ -11,76 +11,76 @@ |
||
11 | 11 | */ |
12 | 12 | class LocationPublishTask extends BuildTask |
13 | 13 | { |
14 | - /** |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $title = 'Publish all Locations'; |
|
18 | - /** |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - protected $description = 'Migration task - pre versioning on Location'; |
|
22 | - /** |
|
23 | - * @var bool |
|
24 | - */ |
|
25 | - protected $enabled = true; |
|
14 | + /** |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $title = 'Publish all Locations'; |
|
18 | + /** |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + protected $description = 'Migration task - pre versioning on Location'; |
|
22 | + /** |
|
23 | + * @var bool |
|
24 | + */ |
|
25 | + protected $enabled = true; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @param $request |
|
29 | - */ |
|
30 | - public function run($request) |
|
31 | - { |
|
32 | - $class = ($request->getVar('locationclass')) ? $request->getVar('locationclass') : 'Location'; |
|
33 | - $this->publishLocations($class); |
|
34 | - } |
|
27 | + /** |
|
28 | + * @param $request |
|
29 | + */ |
|
30 | + public function run($request) |
|
31 | + { |
|
32 | + $class = ($request->getVar('locationclass')) ? $request->getVar('locationclass') : 'Location'; |
|
33 | + $this->publishLocations($class); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param string $class |
|
38 | - * @return \Generator |
|
39 | - */ |
|
40 | - protected function iterateLocations($class) |
|
41 | - { |
|
42 | - foreach ($class::get()->filter('ShowInLocator', true) as $location) { |
|
43 | - yield $location; |
|
44 | - } |
|
45 | - } |
|
36 | + /** |
|
37 | + * @param string $class |
|
38 | + * @return \Generator |
|
39 | + */ |
|
40 | + protected function iterateLocations($class) |
|
41 | + { |
|
42 | + foreach ($class::get()->filter('ShowInLocator', true) as $location) { |
|
43 | + yield $location; |
|
44 | + } |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * mark all ProductDetail records as ShowInMenus = 0. |
|
49 | - * |
|
50 | - * @param string $class |
|
51 | - */ |
|
52 | - public function publishLocations($class) |
|
53 | - { |
|
54 | - if (!isset($class) || !class_exists($class) || !$class instanceof Location) { |
|
55 | - $class = 'Location'; |
|
56 | - } |
|
57 | - $ct = 0; |
|
58 | - $publish = function ($location) use (&$ct) { |
|
59 | - if (!$location->isPublished()) { |
|
60 | - $title = $location->Title; |
|
61 | - $location->writeToStage('Stage'); |
|
62 | - $location->publish('Stage', 'Live'); |
|
63 | - static::write_message($title); |
|
64 | - ++$ct; |
|
65 | - } |
|
66 | - }; |
|
47 | + /** |
|
48 | + * mark all ProductDetail records as ShowInMenus = 0. |
|
49 | + * |
|
50 | + * @param string $class |
|
51 | + */ |
|
52 | + public function publishLocations($class) |
|
53 | + { |
|
54 | + if (!isset($class) || !class_exists($class) || !$class instanceof Location) { |
|
55 | + $class = 'Location'; |
|
56 | + } |
|
57 | + $ct = 0; |
|
58 | + $publish = function ($location) use (&$ct) { |
|
59 | + if (!$location->isPublished()) { |
|
60 | + $title = $location->Title; |
|
61 | + $location->writeToStage('Stage'); |
|
62 | + $location->publish('Stage', 'Live'); |
|
63 | + static::write_message($title); |
|
64 | + ++$ct; |
|
65 | + } |
|
66 | + }; |
|
67 | 67 | |
68 | - foreach ($this->iterateLocations($class) as $location) { |
|
69 | - $publish($location); |
|
70 | - } |
|
68 | + foreach ($this->iterateLocations($class) as $location) { |
|
69 | + $publish($location); |
|
70 | + } |
|
71 | 71 | |
72 | - static::write_message("{$ct} locations updated."); |
|
73 | - } |
|
72 | + static::write_message("{$ct} locations updated."); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @param $message |
|
77 | - */ |
|
78 | - protected static function write_message($message) |
|
79 | - { |
|
80 | - if (Director::is_cli()) { |
|
81 | - echo "{$message}\n"; |
|
82 | - } else { |
|
83 | - echo "{$message}<br><br>"; |
|
84 | - } |
|
85 | - } |
|
75 | + /** |
|
76 | + * @param $message |
|
77 | + */ |
|
78 | + protected static function write_message($message) |
|
79 | + { |
|
80 | + if (Director::is_cli()) { |
|
81 | + echo "{$message}\n"; |
|
82 | + } else { |
|
83 | + echo "{$message}<br><br>"; |
|
84 | + } |
|
85 | + } |
|
86 | 86 | } |
@@ -55,7 +55,7 @@ |
||
55 | 55 | $class = 'Location'; |
56 | 56 | } |
57 | 57 | $ct = 0; |
58 | - $publish = function ($location) use (&$ct) { |
|
58 | + $publish = function($location) use (&$ct) { |
|
59 | 59 | if (!$location->isPublished()) { |
60 | 60 | $title = $location->Title; |
61 | 61 | $location->writeToStage('Stage'); |
@@ -14,72 +14,72 @@ |
||
14 | 14 | class LocationCategoriesTask extends BuildTask |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - protected $title = 'Location categories to many_many'; |
|
21 | - |
|
22 | - /** |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - protected $description = 'Migration task - Converts locations to have multiple categories'; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var bool |
|
29 | - */ |
|
30 | - protected $enabled = true; |
|
31 | - |
|
32 | - /** |
|
33 | - * @param $request |
|
34 | - */ |
|
35 | - public function run($request) |
|
36 | - { |
|
37 | - /** @var DataObject $class */ |
|
38 | - $class = ($request->getVar('locationclass')) ? $request->getVar('locationclass') : Location::class; |
|
39 | - $class::add_extension(LocationCategoryExtension::class); |
|
40 | - |
|
41 | - |
|
42 | - $categories = []; |
|
43 | - |
|
44 | - $convert = function (DataObject $location) use (&$categories) { |
|
45 | - /** @var Location $location */ |
|
46 | - // skip if no category |
|
47 | - if ($location->CategoryID > 0) { |
|
48 | - $categories[$location->CategoryID][] = $location->ID; |
|
49 | - } |
|
50 | - }; |
|
51 | - |
|
52 | - foreach ($this->iterateLocations($class) as $location) { |
|
53 | - $convert($location); |
|
54 | - } |
|
55 | - |
|
56 | - $catCt = 0; |
|
57 | - $locCT = 0; |
|
58 | - |
|
59 | - foreach ($categories as $categoryID => $locations) { |
|
60 | - /** @var LocationCategory $category */ |
|
61 | - $category = LocationCategory::get()->byID($categoryID); |
|
62 | - $category->Locations()->addMany($locations); |
|
63 | - |
|
64 | - $catCt++; |
|
65 | - $locCT += count($locations); |
|
66 | - } |
|
67 | - |
|
68 | - echo "{$catCt} categories converted<br />"; |
|
69 | - echo "{$locCT} location relations converted<br />"; |
|
70 | - |
|
71 | - $time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]; |
|
72 | - echo "Process Time: {$time} seconds"; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * @param string $class |
|
77 | - * @return \Generator |
|
78 | - */ |
|
79 | - protected function iterateLocations($class) |
|
80 | - { |
|
81 | - foreach ($class::get() as $location) { |
|
82 | - yield $location; |
|
83 | - } |
|
84 | - } |
|
17 | + /** |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + protected $title = 'Location categories to many_many'; |
|
21 | + |
|
22 | + /** |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + protected $description = 'Migration task - Converts locations to have multiple categories'; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var bool |
|
29 | + */ |
|
30 | + protected $enabled = true; |
|
31 | + |
|
32 | + /** |
|
33 | + * @param $request |
|
34 | + */ |
|
35 | + public function run($request) |
|
36 | + { |
|
37 | + /** @var DataObject $class */ |
|
38 | + $class = ($request->getVar('locationclass')) ? $request->getVar('locationclass') : Location::class; |
|
39 | + $class::add_extension(LocationCategoryExtension::class); |
|
40 | + |
|
41 | + |
|
42 | + $categories = []; |
|
43 | + |
|
44 | + $convert = function (DataObject $location) use (&$categories) { |
|
45 | + /** @var Location $location */ |
|
46 | + // skip if no category |
|
47 | + if ($location->CategoryID > 0) { |
|
48 | + $categories[$location->CategoryID][] = $location->ID; |
|
49 | + } |
|
50 | + }; |
|
51 | + |
|
52 | + foreach ($this->iterateLocations($class) as $location) { |
|
53 | + $convert($location); |
|
54 | + } |
|
55 | + |
|
56 | + $catCt = 0; |
|
57 | + $locCT = 0; |
|
58 | + |
|
59 | + foreach ($categories as $categoryID => $locations) { |
|
60 | + /** @var LocationCategory $category */ |
|
61 | + $category = LocationCategory::get()->byID($categoryID); |
|
62 | + $category->Locations()->addMany($locations); |
|
63 | + |
|
64 | + $catCt++; |
|
65 | + $locCT += count($locations); |
|
66 | + } |
|
67 | + |
|
68 | + echo "{$catCt} categories converted<br />"; |
|
69 | + echo "{$locCT} location relations converted<br />"; |
|
70 | + |
|
71 | + $time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]; |
|
72 | + echo "Process Time: {$time} seconds"; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * @param string $class |
|
77 | + * @return \Generator |
|
78 | + */ |
|
79 | + protected function iterateLocations($class) |
|
80 | + { |
|
81 | + foreach ($class::get() as $location) { |
|
82 | + yield $location; |
|
83 | + } |
|
84 | + } |
|
85 | 85 | } |
@@ -41,7 +41,7 @@ |
||
41 | 41 | |
42 | 42 | $categories = []; |
43 | 43 | |
44 | - $convert = function (DataObject $location) use (&$categories) { |
|
44 | + $convert = function(DataObject $location) use (&$categories) { |
|
45 | 45 | /** @var Location $location */ |
46 | 46 | // skip if no category |
47 | 47 | if ($location->CategoryID > 0) { |
@@ -13,7 +13,7 @@ |
||
13 | 13 | */ |
14 | 14 | class LocationCategoryExtension extends DataExtension |
15 | 15 | { |
16 | - private static $has_one = [ |
|
17 | - 'Category' => LocationCategory::class, |
|
18 | - ]; |
|
16 | + private static $has_one = [ |
|
17 | + 'Category' => LocationCategory::class, |
|
18 | + ]; |
|
19 | 19 | } |
@@ -23,125 +23,125 @@ |
||
23 | 23 | */ |
24 | 24 | class LocationCategory extends DataObject |
25 | 25 | { |
26 | - /** |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - private static $singular_name = 'Category'; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - private static $plural_name = 'Categories'; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - private static $db = [ |
|
40 | - 'Name' => 'Varchar(100)', |
|
41 | - ]; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var array |
|
45 | - */ |
|
46 | - private static $belongs_many_many = [ |
|
47 | - 'Locators' => Locator::class, |
|
48 | - 'LocationSet' => Location::class, |
|
49 | - ]; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - private static $table_name = 'LocationCategory'; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - private static $default_sort = 'Name'; |
|
60 | - |
|
61 | - /** |
|
62 | - * @return \SilverStripe\Forms\FieldList |
|
63 | - */ |
|
64 | - public function getCMSFields() |
|
65 | - { |
|
66 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
67 | - $fields->removeByName([ |
|
68 | - 'Locations', |
|
69 | - 'LocationSet', |
|
70 | - 'Locators', |
|
71 | - 'LinkTracking', |
|
72 | - 'FileTracking', |
|
73 | - ]); |
|
74 | - |
|
75 | - if ($this->ID) { |
|
76 | - // Locations |
|
77 | - $config = GridFieldConfig_RelationEditor::create(); |
|
78 | - $config->removeComponentsByType([ |
|
79 | - GridFieldAddExistingAutocompleter::class, |
|
80 | - GridFieldAddNewButton::class, |
|
81 | - ]) |
|
82 | - ->addComponents([ |
|
83 | - new GridFieldAddExistingSearchButton(), |
|
84 | - ]); |
|
85 | - $locations = $this->Locations(); |
|
86 | - $locationField = GridField::create('Locations', 'Locations', $locations, $config); |
|
87 | - |
|
88 | - $fields->addFieldsToTab('Root.Main', [ |
|
89 | - $locationField, |
|
90 | - ]); |
|
91 | - } |
|
92 | - }); |
|
93 | - |
|
94 | - $fields = parent::getCMSFields(); |
|
95 | - |
|
96 | - return $fields; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * For backwards compatability |
|
101 | - * @return ManyManyList |
|
102 | - */ |
|
103 | - public function Locations() |
|
104 | - { |
|
105 | - return $this->LocationSet(); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @param null $member |
|
110 | - * @param array $context |
|
111 | - * @return bool |
|
112 | - */ |
|
113 | - public function canView($member = null, $context = []) |
|
114 | - { |
|
115 | - return true; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * @param null $member |
|
120 | - * @param array $context |
|
121 | - * @return bool|int |
|
122 | - */ |
|
123 | - public function canEdit($member = null, $context = []) |
|
124 | - { |
|
125 | - return Permission::check('Location_EDIT', 'any', $member); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * @param null $member |
|
130 | - * @param array $context |
|
131 | - * @return bool|int |
|
132 | - */ |
|
133 | - public function canDelete($member = null, $context = []) |
|
134 | - { |
|
135 | - return Permission::check('Location_DELETE', 'any', $member); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * @param null $member |
|
140 | - * @param array $context |
|
141 | - * @return bool|int |
|
142 | - */ |
|
143 | - public function canCreate($member = null, $context = []) |
|
144 | - { |
|
145 | - return Permission::check('Location_CREATE', 'any', $member); |
|
146 | - } |
|
26 | + /** |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + private static $singular_name = 'Category'; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + private static $plural_name = 'Categories'; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + private static $db = [ |
|
40 | + 'Name' => 'Varchar(100)', |
|
41 | + ]; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var array |
|
45 | + */ |
|
46 | + private static $belongs_many_many = [ |
|
47 | + 'Locators' => Locator::class, |
|
48 | + 'LocationSet' => Location::class, |
|
49 | + ]; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + private static $table_name = 'LocationCategory'; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + private static $default_sort = 'Name'; |
|
60 | + |
|
61 | + /** |
|
62 | + * @return \SilverStripe\Forms\FieldList |
|
63 | + */ |
|
64 | + public function getCMSFields() |
|
65 | + { |
|
66 | + $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
67 | + $fields->removeByName([ |
|
68 | + 'Locations', |
|
69 | + 'LocationSet', |
|
70 | + 'Locators', |
|
71 | + 'LinkTracking', |
|
72 | + 'FileTracking', |
|
73 | + ]); |
|
74 | + |
|
75 | + if ($this->ID) { |
|
76 | + // Locations |
|
77 | + $config = GridFieldConfig_RelationEditor::create(); |
|
78 | + $config->removeComponentsByType([ |
|
79 | + GridFieldAddExistingAutocompleter::class, |
|
80 | + GridFieldAddNewButton::class, |
|
81 | + ]) |
|
82 | + ->addComponents([ |
|
83 | + new GridFieldAddExistingSearchButton(), |
|
84 | + ]); |
|
85 | + $locations = $this->Locations(); |
|
86 | + $locationField = GridField::create('Locations', 'Locations', $locations, $config); |
|
87 | + |
|
88 | + $fields->addFieldsToTab('Root.Main', [ |
|
89 | + $locationField, |
|
90 | + ]); |
|
91 | + } |
|
92 | + }); |
|
93 | + |
|
94 | + $fields = parent::getCMSFields(); |
|
95 | + |
|
96 | + return $fields; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * For backwards compatability |
|
101 | + * @return ManyManyList |
|
102 | + */ |
|
103 | + public function Locations() |
|
104 | + { |
|
105 | + return $this->LocationSet(); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @param null $member |
|
110 | + * @param array $context |
|
111 | + * @return bool |
|
112 | + */ |
|
113 | + public function canView($member = null, $context = []) |
|
114 | + { |
|
115 | + return true; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * @param null $member |
|
120 | + * @param array $context |
|
121 | + * @return bool|int |
|
122 | + */ |
|
123 | + public function canEdit($member = null, $context = []) |
|
124 | + { |
|
125 | + return Permission::check('Location_EDIT', 'any', $member); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * @param null $member |
|
130 | + * @param array $context |
|
131 | + * @return bool|int |
|
132 | + */ |
|
133 | + public function canDelete($member = null, $context = []) |
|
134 | + { |
|
135 | + return Permission::check('Location_DELETE', 'any', $member); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * @param null $member |
|
140 | + * @param array $context |
|
141 | + * @return bool|int |
|
142 | + */ |
|
143 | + public function canCreate($member = null, $context = []) |
|
144 | + { |
|
145 | + return Permission::check('Location_CREATE', 'any', $member); |
|
146 | + } |
|
147 | 147 | } |
@@ -63,7 +63,7 @@ |
||
63 | 63 | */ |
64 | 64 | public function getCMSFields() |
65 | 65 | { |
66 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
66 | + $this->beforeUpdateCMSFields(function(FieldList $fields) { |
|
67 | 67 | $fields->removeByName([ |
68 | 68 | 'Locations', |
69 | 69 | 'LocationSet', |
@@ -28,256 +28,256 @@ |
||
28 | 28 | */ |
29 | 29 | class Location extends DataObject implements PermissionProvider |
30 | 30 | { |
31 | - /** |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - private static $singular_name = 'Location'; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - private static $plural_name = 'Locations'; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - private static $db = [ |
|
45 | - 'Title' => 'Varchar(255)', |
|
46 | - 'Featured' => 'Boolean', |
|
47 | - 'Website' => 'Varchar(255)', |
|
48 | - 'Phone' => 'Varchar(40)', |
|
49 | - 'Email' => 'Varchar(255)', |
|
50 | - 'Fax' => 'Varchar(45)', |
|
51 | - 'Import_ID' => 'Int', |
|
52 | - ]; |
|
53 | - |
|
54 | - private static $many_many = [ |
|
55 | - 'Categories' => LocationCategory::class, |
|
56 | - ]; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var string |
|
60 | - */ |
|
61 | - private static $table_name = 'Location'; |
|
62 | - |
|
63 | - /** |
|
64 | - * @var array |
|
65 | - */ |
|
66 | - private static $casting = [ |
|
67 | - 'distance' => 'Decimal(9,3)', |
|
68 | - ]; |
|
69 | - |
|
70 | - /** |
|
71 | - * @var string |
|
72 | - */ |
|
73 | - private static $default_sort = 'Title'; |
|
74 | - |
|
75 | - /** |
|
76 | - * api access via Restful Server module |
|
77 | - * |
|
78 | - * @var bool |
|
79 | - */ |
|
80 | - private static $api_access = true; |
|
81 | - |
|
82 | - /** |
|
83 | - * search fields for Model Admin |
|
84 | - * |
|
85 | - * @var array |
|
86 | - */ |
|
87 | - private static $searchable_fields = [ |
|
88 | - 'Title', |
|
89 | - 'Address', |
|
90 | - 'City', |
|
91 | - 'State', |
|
92 | - 'PostalCode', |
|
93 | - 'Country', |
|
94 | - 'Website', |
|
95 | - 'Phone', |
|
96 | - 'Email', |
|
97 | - 'Featured', |
|
98 | - ]; |
|
99 | - |
|
100 | - /** |
|
101 | - * columns for grid field |
|
102 | - * |
|
103 | - * @var array |
|
104 | - */ |
|
105 | - private static $summary_fields = [ |
|
106 | - 'Title', |
|
107 | - 'Address', |
|
108 | - 'Address2', |
|
109 | - 'City', |
|
110 | - 'State', |
|
111 | - 'PostalCode', |
|
112 | - 'CountryCode', |
|
113 | - 'Phone' => 'Phone', |
|
114 | - 'Fax' => 'Fax', |
|
115 | - 'Email' => 'Email', |
|
116 | - 'Website' => 'Website', |
|
117 | - 'Featured', |
|
118 | - 'CategoryList', |
|
119 | - 'Lat', |
|
120 | - 'Lng', |
|
121 | - 'Import_ID', |
|
122 | - ]; |
|
123 | - |
|
124 | - /** |
|
125 | - * Coords status for $summary_fields |
|
126 | - * |
|
127 | - * @return string |
|
128 | - */ |
|
129 | - public function getCoords() |
|
130 | - { |
|
131 | - return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false'; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * @return string |
|
136 | - */ |
|
137 | - public function getCategoryList() |
|
138 | - { |
|
139 | - if ($this->Categories()->count()) { |
|
140 | - return implode(', ', $this->Categories()->column('Name')); |
|
141 | - } |
|
142 | - |
|
143 | - return ''; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @return bool|string |
|
148 | - */ |
|
149 | - public function getCountryCode() |
|
150 | - { |
|
151 | - if ($this->Country) { |
|
152 | - return strtoupper($this->Country); |
|
153 | - } |
|
154 | - |
|
155 | - return false; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * custom labels for fields |
|
160 | - * |
|
161 | - * @param bool $includerelations |
|
162 | - * @return array|string |
|
163 | - */ |
|
164 | - public function fieldLabels($includerelations = true) |
|
165 | - { |
|
166 | - $labels = parent::fieldLabels($includerelations); |
|
167 | - $labels['Title'] = 'Name'; |
|
168 | - $labels['Address2'] = 'Address 2'; |
|
169 | - $labels['PostalCode'] = 'Postal Code'; |
|
170 | - $labels['Categories.Name'] = 'Categories'; |
|
171 | - $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
172 | - |
|
173 | - return $labels; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * @return FieldList |
|
178 | - */ |
|
179 | - public function getCMSFields() |
|
180 | - { |
|
181 | - $this->beforeUpdateCMSFields(function ($fields) { |
|
182 | - $fields->removeByName([ |
|
183 | - 'Import_ID', |
|
184 | - 'LinkTracking', |
|
185 | - 'FileTracking', |
|
186 | - ]); |
|
187 | - |
|
188 | - $fields->dataFieldByName('Website') |
|
189 | - ->setAttribute('placeholder', 'http://'); |
|
190 | - |
|
191 | - $fields->replaceField('Email', EmailField::create('Email')); |
|
192 | - |
|
193 | - $featured = $fields->dataFieldByName('Featured') |
|
194 | - ->setDescription('Location will display near the top of the results list'); |
|
195 | - $fields->insertAfter( |
|
196 | - 'Fax', |
|
197 | - $featured |
|
198 | - ); |
|
199 | - |
|
200 | - if ($this->ID) { |
|
201 | - $categories = $fields->dataFieldByName('Categories'); |
|
202 | - $config = $categories->getConfig(); |
|
203 | - $config->removeComponentsByType([ |
|
204 | - GridFieldAddExistingAutocompleter::class, |
|
205 | - ]) |
|
206 | - ->addComponents([ |
|
207 | - new GridFieldAddExistingSearchButton(), |
|
208 | - ]); |
|
209 | - } |
|
210 | - }); |
|
211 | - |
|
212 | - $fields = parent::getCMSFields(); |
|
213 | - |
|
214 | - // allow to be extended via DataExtension |
|
215 | - $this->extend('updateLocationFields', $fields); |
|
216 | - |
|
217 | - return $fields; |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * @param null $member |
|
222 | - * @param array $context |
|
223 | - * @return bool |
|
224 | - */ |
|
225 | - public function canView($member = null, $context = []) |
|
226 | - { |
|
227 | - return true; |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * @param null $member |
|
232 | - * @param array $context |
|
233 | - * @return bool|int |
|
234 | - */ |
|
235 | - public function canEdit($member = null, $context = []) |
|
236 | - { |
|
237 | - return Permission::check('Location_EDIT', 'any', $member); |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * @param null $member |
|
242 | - * @param array $context |
|
243 | - * @return bool|int |
|
244 | - */ |
|
245 | - public function canDelete($member = null, $context = []) |
|
246 | - { |
|
247 | - return Permission::check('Location_DELETE', 'any', $member); |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * @param null $member |
|
252 | - * @param array $context |
|
253 | - * @return bool|int |
|
254 | - */ |
|
255 | - public function canCreate($member = null, $context = []) |
|
256 | - { |
|
257 | - return Permission::check('Location_CREATE', 'any', $member); |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * @return array |
|
262 | - */ |
|
263 | - public function providePermissions() |
|
264 | - { |
|
265 | - return [ |
|
266 | - 'Location_EDIT' => 'Edit a Location', |
|
267 | - 'Location_DELETE' => 'Delete a Location', |
|
268 | - 'Location_CREATE' => 'Create a Location', |
|
269 | - ]; |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * @return string |
|
274 | - */ |
|
275 | - public function getWebsiteURL() |
|
276 | - { |
|
277 | - $url = $this->Website; |
|
278 | - |
|
279 | - $this->extend('updateWebsiteURL', $url); |
|
280 | - |
|
281 | - return $url; |
|
282 | - } |
|
31 | + /** |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + private static $singular_name = 'Location'; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + private static $plural_name = 'Locations'; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + private static $db = [ |
|
45 | + 'Title' => 'Varchar(255)', |
|
46 | + 'Featured' => 'Boolean', |
|
47 | + 'Website' => 'Varchar(255)', |
|
48 | + 'Phone' => 'Varchar(40)', |
|
49 | + 'Email' => 'Varchar(255)', |
|
50 | + 'Fax' => 'Varchar(45)', |
|
51 | + 'Import_ID' => 'Int', |
|
52 | + ]; |
|
53 | + |
|
54 | + private static $many_many = [ |
|
55 | + 'Categories' => LocationCategory::class, |
|
56 | + ]; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var string |
|
60 | + */ |
|
61 | + private static $table_name = 'Location'; |
|
62 | + |
|
63 | + /** |
|
64 | + * @var array |
|
65 | + */ |
|
66 | + private static $casting = [ |
|
67 | + 'distance' => 'Decimal(9,3)', |
|
68 | + ]; |
|
69 | + |
|
70 | + /** |
|
71 | + * @var string |
|
72 | + */ |
|
73 | + private static $default_sort = 'Title'; |
|
74 | + |
|
75 | + /** |
|
76 | + * api access via Restful Server module |
|
77 | + * |
|
78 | + * @var bool |
|
79 | + */ |
|
80 | + private static $api_access = true; |
|
81 | + |
|
82 | + /** |
|
83 | + * search fields for Model Admin |
|
84 | + * |
|
85 | + * @var array |
|
86 | + */ |
|
87 | + private static $searchable_fields = [ |
|
88 | + 'Title', |
|
89 | + 'Address', |
|
90 | + 'City', |
|
91 | + 'State', |
|
92 | + 'PostalCode', |
|
93 | + 'Country', |
|
94 | + 'Website', |
|
95 | + 'Phone', |
|
96 | + 'Email', |
|
97 | + 'Featured', |
|
98 | + ]; |
|
99 | + |
|
100 | + /** |
|
101 | + * columns for grid field |
|
102 | + * |
|
103 | + * @var array |
|
104 | + */ |
|
105 | + private static $summary_fields = [ |
|
106 | + 'Title', |
|
107 | + 'Address', |
|
108 | + 'Address2', |
|
109 | + 'City', |
|
110 | + 'State', |
|
111 | + 'PostalCode', |
|
112 | + 'CountryCode', |
|
113 | + 'Phone' => 'Phone', |
|
114 | + 'Fax' => 'Fax', |
|
115 | + 'Email' => 'Email', |
|
116 | + 'Website' => 'Website', |
|
117 | + 'Featured', |
|
118 | + 'CategoryList', |
|
119 | + 'Lat', |
|
120 | + 'Lng', |
|
121 | + 'Import_ID', |
|
122 | + ]; |
|
123 | + |
|
124 | + /** |
|
125 | + * Coords status for $summary_fields |
|
126 | + * |
|
127 | + * @return string |
|
128 | + */ |
|
129 | + public function getCoords() |
|
130 | + { |
|
131 | + return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false'; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * @return string |
|
136 | + */ |
|
137 | + public function getCategoryList() |
|
138 | + { |
|
139 | + if ($this->Categories()->count()) { |
|
140 | + return implode(', ', $this->Categories()->column('Name')); |
|
141 | + } |
|
142 | + |
|
143 | + return ''; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @return bool|string |
|
148 | + */ |
|
149 | + public function getCountryCode() |
|
150 | + { |
|
151 | + if ($this->Country) { |
|
152 | + return strtoupper($this->Country); |
|
153 | + } |
|
154 | + |
|
155 | + return false; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * custom labels for fields |
|
160 | + * |
|
161 | + * @param bool $includerelations |
|
162 | + * @return array|string |
|
163 | + */ |
|
164 | + public function fieldLabels($includerelations = true) |
|
165 | + { |
|
166 | + $labels = parent::fieldLabels($includerelations); |
|
167 | + $labels['Title'] = 'Name'; |
|
168 | + $labels['Address2'] = 'Address 2'; |
|
169 | + $labels['PostalCode'] = 'Postal Code'; |
|
170 | + $labels['Categories.Name'] = 'Categories'; |
|
171 | + $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
172 | + |
|
173 | + return $labels; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * @return FieldList |
|
178 | + */ |
|
179 | + public function getCMSFields() |
|
180 | + { |
|
181 | + $this->beforeUpdateCMSFields(function ($fields) { |
|
182 | + $fields->removeByName([ |
|
183 | + 'Import_ID', |
|
184 | + 'LinkTracking', |
|
185 | + 'FileTracking', |
|
186 | + ]); |
|
187 | + |
|
188 | + $fields->dataFieldByName('Website') |
|
189 | + ->setAttribute('placeholder', 'http://'); |
|
190 | + |
|
191 | + $fields->replaceField('Email', EmailField::create('Email')); |
|
192 | + |
|
193 | + $featured = $fields->dataFieldByName('Featured') |
|
194 | + ->setDescription('Location will display near the top of the results list'); |
|
195 | + $fields->insertAfter( |
|
196 | + 'Fax', |
|
197 | + $featured |
|
198 | + ); |
|
199 | + |
|
200 | + if ($this->ID) { |
|
201 | + $categories = $fields->dataFieldByName('Categories'); |
|
202 | + $config = $categories->getConfig(); |
|
203 | + $config->removeComponentsByType([ |
|
204 | + GridFieldAddExistingAutocompleter::class, |
|
205 | + ]) |
|
206 | + ->addComponents([ |
|
207 | + new GridFieldAddExistingSearchButton(), |
|
208 | + ]); |
|
209 | + } |
|
210 | + }); |
|
211 | + |
|
212 | + $fields = parent::getCMSFields(); |
|
213 | + |
|
214 | + // allow to be extended via DataExtension |
|
215 | + $this->extend('updateLocationFields', $fields); |
|
216 | + |
|
217 | + return $fields; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * @param null $member |
|
222 | + * @param array $context |
|
223 | + * @return bool |
|
224 | + */ |
|
225 | + public function canView($member = null, $context = []) |
|
226 | + { |
|
227 | + return true; |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * @param null $member |
|
232 | + * @param array $context |
|
233 | + * @return bool|int |
|
234 | + */ |
|
235 | + public function canEdit($member = null, $context = []) |
|
236 | + { |
|
237 | + return Permission::check('Location_EDIT', 'any', $member); |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * @param null $member |
|
242 | + * @param array $context |
|
243 | + * @return bool|int |
|
244 | + */ |
|
245 | + public function canDelete($member = null, $context = []) |
|
246 | + { |
|
247 | + return Permission::check('Location_DELETE', 'any', $member); |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * @param null $member |
|
252 | + * @param array $context |
|
253 | + * @return bool|int |
|
254 | + */ |
|
255 | + public function canCreate($member = null, $context = []) |
|
256 | + { |
|
257 | + return Permission::check('Location_CREATE', 'any', $member); |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * @return array |
|
262 | + */ |
|
263 | + public function providePermissions() |
|
264 | + { |
|
265 | + return [ |
|
266 | + 'Location_EDIT' => 'Edit a Location', |
|
267 | + 'Location_DELETE' => 'Delete a Location', |
|
268 | + 'Location_CREATE' => 'Create a Location', |
|
269 | + ]; |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * @return string |
|
274 | + */ |
|
275 | + public function getWebsiteURL() |
|
276 | + { |
|
277 | + $url = $this->Website; |
|
278 | + |
|
279 | + $this->extend('updateWebsiteURL', $url); |
|
280 | + |
|
281 | + return $url; |
|
282 | + } |
|
283 | 283 | } |
@@ -178,7 +178,7 @@ |
||
178 | 178 | */ |
179 | 179 | public function getCMSFields() |
180 | 180 | { |
181 | - $this->beforeUpdateCMSFields(function ($fields) { |
|
181 | + $this->beforeUpdateCMSFields(function($fields) { |
|
182 | 182 | $fields->removeByName([ |
183 | 183 | 'Import_ID', |
184 | 184 | 'LinkTracking', |