@@ -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', |
@@ -11,12 +11,12 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class LocationExtension extends DataExtension implements TestOnly |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @param $url |
|
| 16 | - * @return string |
|
| 17 | - */ |
|
| 18 | - public function updateWebsiteURL(&$url) |
|
| 19 | - { |
|
| 20 | - $url = 'foo'; |
|
| 21 | - } |
|
| 14 | + /** |
|
| 15 | + * @param $url |
|
| 16 | + * @return string |
|
| 17 | + */ |
|
| 18 | + public function updateWebsiteURL(&$url) |
|
| 19 | + { |
|
| 20 | + $url = 'foo'; |
|
| 21 | + } |
|
| 22 | 22 | } |
@@ -12,10 +12,10 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class ExtendedLocation extends Location implements TestOnly |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @var array |
|
| 17 | - */ |
|
| 18 | - private static $extensions = [ |
|
| 19 | - LocationExtension::class, |
|
| 20 | - ]; |
|
| 15 | + /** |
|
| 16 | + * @var array |
|
| 17 | + */ |
|
| 18 | + private static $extensions = [ |
|
| 19 | + LocationExtension::class, |
|
| 20 | + ]; |
|
| 21 | 21 | } |
@@ -18,131 +18,131 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | class LocatorController extends \PageController |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - private static $allowed_actions = [ |
|
| 25 | - 'xml', |
|
| 26 | - 'json', |
|
| 27 | - ]; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - private static $base_filter = []; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var array |
|
| 36 | - */ |
|
| 37 | - private static $base_exclude = [ |
|
| 38 | - 'Lat' => 0, |
|
| 39 | - 'Lng' => 0, |
|
| 40 | - ]; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var array |
|
| 44 | - */ |
|
| 45 | - private static $base_filter_any = []; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var bool |
|
| 49 | - */ |
|
| 50 | - private static $bootstrapify = true; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * ID of map container |
|
| 54 | - * |
|
| 55 | - * @var string |
|
| 56 | - */ |
|
| 57 | - private static $map_container = 'map'; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * class of location list container |
|
| 61 | - * |
|
| 62 | - * @var string |
|
| 63 | - */ |
|
| 64 | - private static $list_container = 'loc-list'; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * GET variable which, if isset, will trigger storeLocator init and return XML |
|
| 68 | - * |
|
| 69 | - * @var string |
|
| 70 | - */ |
|
| 71 | - private static $query_trigger = 'action_doFilterLocations'; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @var DataList|ArrayList |
|
| 75 | - */ |
|
| 76 | - protected $locations; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Set Requirements based on input from CMS |
|
| 80 | - */ |
|
| 81 | - public function init() |
|
| 82 | - { |
|
| 83 | - parent::init(); |
|
| 84 | - // google maps api key |
|
| 85 | - $key = Config::inst()->get(GoogleGeocoder::class, 'map_api_key'); |
|
| 86 | - Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key); |
|
| 87 | - |
|
| 88 | - // prevent init of map if no query |
|
| 89 | - $request = Controller::curr()->getRequest(); |
|
| 90 | - |
|
| 91 | - if ($this->getTrigger($request)) { |
|
| 92 | - $locations = $this->getLocations(); |
|
| 93 | - |
|
| 94 | - if ($locations) { |
|
| 95 | - $featuredInList = ($locations->filter('Featured', true)->count() > 0); |
|
| 96 | - $defaultCoords = $this->getAddressSearchCoords() ? |
|
| 97 | - $this->getAddressSearchCoords() : |
|
| 98 | - new ArrayData([ |
|
| 99 | - "Lat" => 0, |
|
| 100 | - "Lng" => 0, |
|
| 101 | - ]); |
|
| 102 | - |
|
| 103 | - $featured = $featuredInList |
|
| 104 | - ? 'featuredLocations: true' |
|
| 105 | - : 'featuredLocations: false'; |
|
| 106 | - |
|
| 107 | - // map config based on user input in Settings tab |
|
| 108 | - $limit = Config::inst()->get(LocatorController::class, 'limit'); |
|
| 109 | - if ($limit < 1) { |
|
| 110 | - $limit = -1; |
|
| 111 | - } |
|
| 112 | - $load = 'fullMapStart: true, storeLimit: ' . $limit . ', maxDistance: true,'; |
|
| 113 | - |
|
| 114 | - $listTemplatePath = $this->getListTemplate(); |
|
| 115 | - $infowindowTemplatePath = $this->getInfoWindowTemplate(); |
|
| 116 | - |
|
| 117 | - $kilometer = ($this->data()->Unit == 'km') ? "lengthUnit: 'km'" : "lengthUnit: 'm'"; |
|
| 118 | - |
|
| 119 | - // pass GET variables to xml action |
|
| 120 | - $vars = $this->request->getVars(); |
|
| 121 | - unset($vars['url']); |
|
| 122 | - $url = ''; |
|
| 123 | - if (count($vars)) { |
|
| 124 | - $url .= '?' . http_build_query($vars); |
|
| 125 | - } |
|
| 126 | - $link = Controller::join_links($this->Link(), 'xml.xml', $url); |
|
| 127 | - |
|
| 128 | - // containers |
|
| 129 | - $map_id = Config::inst()->get(LocatorController::class, 'map_container'); |
|
| 130 | - $list_class = Config::inst()->get(LocatorController::class, 'list_container'); |
|
| 131 | - |
|
| 132 | - $mapStyle = ''; |
|
| 133 | - if ($stylePath = $this->getMapStyleJSONPath()) { |
|
| 134 | - if ($style = file_get_contents($stylePath)) { |
|
| 135 | - $mapStyle = "styles: {$style},"; |
|
| 136 | - } |
|
| 137 | - }; |
|
| 138 | - |
|
| 139 | - $markerImage = ''; |
|
| 140 | - if ($imagePath = $this->getMarkerIcon()) { |
|
| 141 | - $markerImage = "markerImg: '{$imagePath}',"; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - // init map |
|
| 145 | - Requirements::customScript(" |
|
| 21 | + /** |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + private static $allowed_actions = [ |
|
| 25 | + 'xml', |
|
| 26 | + 'json', |
|
| 27 | + ]; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + private static $base_filter = []; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var array |
|
| 36 | + */ |
|
| 37 | + private static $base_exclude = [ |
|
| 38 | + 'Lat' => 0, |
|
| 39 | + 'Lng' => 0, |
|
| 40 | + ]; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var array |
|
| 44 | + */ |
|
| 45 | + private static $base_filter_any = []; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var bool |
|
| 49 | + */ |
|
| 50 | + private static $bootstrapify = true; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * ID of map container |
|
| 54 | + * |
|
| 55 | + * @var string |
|
| 56 | + */ |
|
| 57 | + private static $map_container = 'map'; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * class of location list container |
|
| 61 | + * |
|
| 62 | + * @var string |
|
| 63 | + */ |
|
| 64 | + private static $list_container = 'loc-list'; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * GET variable which, if isset, will trigger storeLocator init and return XML |
|
| 68 | + * |
|
| 69 | + * @var string |
|
| 70 | + */ |
|
| 71 | + private static $query_trigger = 'action_doFilterLocations'; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @var DataList|ArrayList |
|
| 75 | + */ |
|
| 76 | + protected $locations; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Set Requirements based on input from CMS |
|
| 80 | + */ |
|
| 81 | + public function init() |
|
| 82 | + { |
|
| 83 | + parent::init(); |
|
| 84 | + // google maps api key |
|
| 85 | + $key = Config::inst()->get(GoogleGeocoder::class, 'map_api_key'); |
|
| 86 | + Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key); |
|
| 87 | + |
|
| 88 | + // prevent init of map if no query |
|
| 89 | + $request = Controller::curr()->getRequest(); |
|
| 90 | + |
|
| 91 | + if ($this->getTrigger($request)) { |
|
| 92 | + $locations = $this->getLocations(); |
|
| 93 | + |
|
| 94 | + if ($locations) { |
|
| 95 | + $featuredInList = ($locations->filter('Featured', true)->count() > 0); |
|
| 96 | + $defaultCoords = $this->getAddressSearchCoords() ? |
|
| 97 | + $this->getAddressSearchCoords() : |
|
| 98 | + new ArrayData([ |
|
| 99 | + "Lat" => 0, |
|
| 100 | + "Lng" => 0, |
|
| 101 | + ]); |
|
| 102 | + |
|
| 103 | + $featured = $featuredInList |
|
| 104 | + ? 'featuredLocations: true' |
|
| 105 | + : 'featuredLocations: false'; |
|
| 106 | + |
|
| 107 | + // map config based on user input in Settings tab |
|
| 108 | + $limit = Config::inst()->get(LocatorController::class, 'limit'); |
|
| 109 | + if ($limit < 1) { |
|
| 110 | + $limit = -1; |
|
| 111 | + } |
|
| 112 | + $load = 'fullMapStart: true, storeLimit: ' . $limit . ', maxDistance: true,'; |
|
| 113 | + |
|
| 114 | + $listTemplatePath = $this->getListTemplate(); |
|
| 115 | + $infowindowTemplatePath = $this->getInfoWindowTemplate(); |
|
| 116 | + |
|
| 117 | + $kilometer = ($this->data()->Unit == 'km') ? "lengthUnit: 'km'" : "lengthUnit: 'm'"; |
|
| 118 | + |
|
| 119 | + // pass GET variables to xml action |
|
| 120 | + $vars = $this->request->getVars(); |
|
| 121 | + unset($vars['url']); |
|
| 122 | + $url = ''; |
|
| 123 | + if (count($vars)) { |
|
| 124 | + $url .= '?' . http_build_query($vars); |
|
| 125 | + } |
|
| 126 | + $link = Controller::join_links($this->Link(), 'xml.xml', $url); |
|
| 127 | + |
|
| 128 | + // containers |
|
| 129 | + $map_id = Config::inst()->get(LocatorController::class, 'map_container'); |
|
| 130 | + $list_class = Config::inst()->get(LocatorController::class, 'list_container'); |
|
| 131 | + |
|
| 132 | + $mapStyle = ''; |
|
| 133 | + if ($stylePath = $this->getMapStyleJSONPath()) { |
|
| 134 | + if ($style = file_get_contents($stylePath)) { |
|
| 135 | + $mapStyle = "styles: {$style},"; |
|
| 136 | + } |
|
| 137 | + }; |
|
| 138 | + |
|
| 139 | + $markerImage = ''; |
|
| 140 | + if ($imagePath = $this->getMarkerIcon()) { |
|
| 141 | + $markerImage = "markerImg: '{$imagePath}',"; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + // init map |
|
| 145 | + Requirements::customScript(" |
|
| 146 | 146 | $(function(){ |
| 147 | 147 | $('#map-container').storeLocator({ |
| 148 | 148 | {$load} |
@@ -171,195 +171,195 @@ discard block |
||
| 171 | 171 | }); |
| 172 | 172 | }); |
| 173 | 173 | ", 'jquery-locator'); |
| 174 | - } |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * @param HTTPRequest $request |
|
| 180 | - * |
|
| 181 | - * @return bool |
|
| 182 | - */ |
|
| 183 | - public function getTrigger(HTTPRequest $request = null) |
|
| 184 | - { |
|
| 185 | - if ($request === null) { |
|
| 186 | - $request = $this->getRequest(); |
|
| 187 | - } |
|
| 188 | - $trigger = $request->getVar(Config::inst()->get(LocatorController::class, 'query_trigger')); |
|
| 189 | - |
|
| 190 | - return isset($trigger); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * @return ArrayList|DataList |
|
| 195 | - */ |
|
| 196 | - public function getLocations() |
|
| 197 | - { |
|
| 198 | - if (!$this->locations) { |
|
| 199 | - $this->setLocations($this->request); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - return $this->locations; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * @param HTTPRequest|null $request |
|
| 207 | - * |
|
| 208 | - * @return $this |
|
| 209 | - */ |
|
| 210 | - public function setLocations(HTTPRequest $request = null) |
|
| 211 | - { |
|
| 212 | - |
|
| 213 | - if ($request === null) { |
|
| 214 | - $request = $this->request; |
|
| 215 | - } |
|
| 216 | - $filter = $this->config()->get('base_filter'); |
|
| 217 | - |
|
| 218 | - $categoryVar = $this->data()->config()->get('category_var'); |
|
| 219 | - if ($request->getVar($categoryVar)) { |
|
| 220 | - $filter['Categories.ID'] = $request->getVar($categoryVar); |
|
| 221 | - } else { |
|
| 222 | - if ($this->getPageCategories()->exists()) { |
|
| 223 | - foreach ($this->getPageCategories() as $category) { |
|
| 224 | - $filter['Categories.ID'][] = $category->ID; |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - $this->extend('updateLocatorFilter', $filter, $request); |
|
| 230 | - |
|
| 231 | - $filterAny = $this->config()->get('base_filter_any'); |
|
| 232 | - $this->extend('updateLocatorFilterAny', $filterAny, $request); |
|
| 233 | - |
|
| 234 | - $exclude = $this->config()->get('base_exclude'); |
|
| 235 | - $this->extend('updateLocatorExclude', $exclude, $request); |
|
| 236 | - |
|
| 237 | - $class = $this->data()->ClassName; |
|
| 238 | - $locations = $class::get_locations($filter, $filterAny, $exclude); |
|
| 239 | - $locations = DataToArrayListHelper::to_array_list($locations); |
|
| 240 | - |
|
| 241 | - //allow for adjusting list post possible distance calculation |
|
| 242 | - $this->extend('updateLocationList', $locations); |
|
| 243 | - |
|
| 244 | - if ($locations->canSortBy('Distance')) { |
|
| 245 | - $locations = $locations->sort('Distance'); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - if ($this->getShowRadius()) { |
|
| 249 | - $radiusVar = $this->data()->config()->get('radius_var'); |
|
| 250 | - |
|
| 251 | - if ($radius = (int)$request->getVar($radiusVar)) { |
|
| 252 | - $locations = $locations->filterByCallback(function ($location) use (&$radius) { |
|
| 253 | - return $location->Distance <= $radius; |
|
| 254 | - }); |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - //allow for returning list to be set as |
|
| 259 | - $this->extend('updateListType', $locations); |
|
| 260 | - |
|
| 261 | - $limit = $this->getLimit(); |
|
| 262 | - if ($limit > 0) { |
|
| 263 | - $locations = $locations->limit($limit); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - $this->locations = $locations; |
|
| 267 | - |
|
| 268 | - return $this; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * @return ArrayData|boolean |
|
| 273 | - */ |
|
| 274 | - public function getAddressSearchCoords() |
|
| 275 | - { |
|
| 276 | - $addressVar = Config::inst()->get(DistanceDataExtension::class, 'address_var'); |
|
| 277 | - if (!$this->request->getVar($addressVar)) { |
|
| 278 | - return false; |
|
| 279 | - } |
|
| 280 | - if (class_exists(GoogleGeocoder::class)) { |
|
| 281 | - $geocoder = new GoogleGeocoder($this->request->getVar($addressVar)); |
|
| 282 | - $response = $geocoder->getResult(); |
|
| 283 | - $lat = $response->getLatitude(); |
|
| 284 | - $lng = $response->getLongitude(); |
|
| 285 | - |
|
| 286 | - return new ArrayData([ |
|
| 287 | - "Lat" => $lat, |
|
| 288 | - "Lng" => $lng, |
|
| 289 | - ]); |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * @param HTTPRequest $request |
|
| 295 | - * |
|
| 296 | - * @return \SilverStripe\View\ViewableData_Customised |
|
| 297 | - */ |
|
| 298 | - public function index(HTTPRequest $request) |
|
| 299 | - { |
|
| 300 | - if ($this->getTrigger($request)) { |
|
| 301 | - $locations = $this->getLocations(); |
|
| 302 | - } else { |
|
| 303 | - $locations = ArrayList::create(); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - return $this->customise(array( |
|
| 307 | - 'Locations' => $locations, |
|
| 308 | - )); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Renders locations in xml format |
|
| 313 | - * |
|
| 314 | - * @return \SilverStripe\ORM\FieldType\DBHTMLText |
|
| 315 | - */ |
|
| 316 | - public function xml() |
|
| 317 | - { |
|
| 318 | - $this->getResponse()->addHeader("Content-Type", "application/xml"); |
|
| 319 | - $data = new ArrayData(array( |
|
| 320 | - "Locations" => $this->getLocations(), |
|
| 321 | - "AddressCoords" => $this->getAddressSearchCoords(), |
|
| 322 | - )); |
|
| 323 | - |
|
| 324 | - return $data->renderWith('Dynamic/Locator/Data/XML'); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * Renders locations in json format |
|
| 329 | - * |
|
| 330 | - * @return \SilverStripe\ORM\FieldType\DBHTMLText |
|
| 331 | - */ |
|
| 332 | - public function json() |
|
| 333 | - { |
|
| 334 | - $this->getResponse()->addHeader("Content-Type", "application/json"); |
|
| 335 | - $data = new ArrayData(array( |
|
| 336 | - "Locations" => $this->getLocations(), |
|
| 337 | - "AddressCoords" => $this->getAddressSearchCoords(), |
|
| 338 | - )); |
|
| 339 | - |
|
| 340 | - return $data->renderWith('Dynamic/Locator/Data/JSON'); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * LocationSearch form. |
|
| 345 | - * |
|
| 346 | - * Search form for locations, updates map and results list via AJAX |
|
| 347 | - * |
|
| 348 | - * @return \SilverStripe\Forms\Form |
|
| 349 | - */ |
|
| 350 | - public function LocationSearch() |
|
| 351 | - { |
|
| 352 | - |
|
| 353 | - $form = LocatorForm::create($this, 'LocationSearch'); |
|
| 354 | - if (class_exists(BootstrapForm::class) && $this->config()->get('bootstrapify')) { |
|
| 355 | - $form->Fields()->bootstrapify(); |
|
| 356 | - $form->Actions()->bootstrapify(); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - return $form |
|
| 360 | - ->setFormMethod('GET') |
|
| 361 | - ->setFormAction($this->Link()) |
|
| 362 | - ->disableSecurityToken() |
|
| 363 | - ->loadDataFrom($this->request->getVars()); |
|
| 364 | - } |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * @param HTTPRequest $request |
|
| 180 | + * |
|
| 181 | + * @return bool |
|
| 182 | + */ |
|
| 183 | + public function getTrigger(HTTPRequest $request = null) |
|
| 184 | + { |
|
| 185 | + if ($request === null) { |
|
| 186 | + $request = $this->getRequest(); |
|
| 187 | + } |
|
| 188 | + $trigger = $request->getVar(Config::inst()->get(LocatorController::class, 'query_trigger')); |
|
| 189 | + |
|
| 190 | + return isset($trigger); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * @return ArrayList|DataList |
|
| 195 | + */ |
|
| 196 | + public function getLocations() |
|
| 197 | + { |
|
| 198 | + if (!$this->locations) { |
|
| 199 | + $this->setLocations($this->request); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return $this->locations; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * @param HTTPRequest|null $request |
|
| 207 | + * |
|
| 208 | + * @return $this |
|
| 209 | + */ |
|
| 210 | + public function setLocations(HTTPRequest $request = null) |
|
| 211 | + { |
|
| 212 | + |
|
| 213 | + if ($request === null) { |
|
| 214 | + $request = $this->request; |
|
| 215 | + } |
|
| 216 | + $filter = $this->config()->get('base_filter'); |
|
| 217 | + |
|
| 218 | + $categoryVar = $this->data()->config()->get('category_var'); |
|
| 219 | + if ($request->getVar($categoryVar)) { |
|
| 220 | + $filter['Categories.ID'] = $request->getVar($categoryVar); |
|
| 221 | + } else { |
|
| 222 | + if ($this->getPageCategories()->exists()) { |
|
| 223 | + foreach ($this->getPageCategories() as $category) { |
|
| 224 | + $filter['Categories.ID'][] = $category->ID; |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + $this->extend('updateLocatorFilter', $filter, $request); |
|
| 230 | + |
|
| 231 | + $filterAny = $this->config()->get('base_filter_any'); |
|
| 232 | + $this->extend('updateLocatorFilterAny', $filterAny, $request); |
|
| 233 | + |
|
| 234 | + $exclude = $this->config()->get('base_exclude'); |
|
| 235 | + $this->extend('updateLocatorExclude', $exclude, $request); |
|
| 236 | + |
|
| 237 | + $class = $this->data()->ClassName; |
|
| 238 | + $locations = $class::get_locations($filter, $filterAny, $exclude); |
|
| 239 | + $locations = DataToArrayListHelper::to_array_list($locations); |
|
| 240 | + |
|
| 241 | + //allow for adjusting list post possible distance calculation |
|
| 242 | + $this->extend('updateLocationList', $locations); |
|
| 243 | + |
|
| 244 | + if ($locations->canSortBy('Distance')) { |
|
| 245 | + $locations = $locations->sort('Distance'); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + if ($this->getShowRadius()) { |
|
| 249 | + $radiusVar = $this->data()->config()->get('radius_var'); |
|
| 250 | + |
|
| 251 | + if ($radius = (int)$request->getVar($radiusVar)) { |
|
| 252 | + $locations = $locations->filterByCallback(function ($location) use (&$radius) { |
|
| 253 | + return $location->Distance <= $radius; |
|
| 254 | + }); |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + //allow for returning list to be set as |
|
| 259 | + $this->extend('updateListType', $locations); |
|
| 260 | + |
|
| 261 | + $limit = $this->getLimit(); |
|
| 262 | + if ($limit > 0) { |
|
| 263 | + $locations = $locations->limit($limit); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + $this->locations = $locations; |
|
| 267 | + |
|
| 268 | + return $this; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * @return ArrayData|boolean |
|
| 273 | + */ |
|
| 274 | + public function getAddressSearchCoords() |
|
| 275 | + { |
|
| 276 | + $addressVar = Config::inst()->get(DistanceDataExtension::class, 'address_var'); |
|
| 277 | + if (!$this->request->getVar($addressVar)) { |
|
| 278 | + return false; |
|
| 279 | + } |
|
| 280 | + if (class_exists(GoogleGeocoder::class)) { |
|
| 281 | + $geocoder = new GoogleGeocoder($this->request->getVar($addressVar)); |
|
| 282 | + $response = $geocoder->getResult(); |
|
| 283 | + $lat = $response->getLatitude(); |
|
| 284 | + $lng = $response->getLongitude(); |
|
| 285 | + |
|
| 286 | + return new ArrayData([ |
|
| 287 | + "Lat" => $lat, |
|
| 288 | + "Lng" => $lng, |
|
| 289 | + ]); |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * @param HTTPRequest $request |
|
| 295 | + * |
|
| 296 | + * @return \SilverStripe\View\ViewableData_Customised |
|
| 297 | + */ |
|
| 298 | + public function index(HTTPRequest $request) |
|
| 299 | + { |
|
| 300 | + if ($this->getTrigger($request)) { |
|
| 301 | + $locations = $this->getLocations(); |
|
| 302 | + } else { |
|
| 303 | + $locations = ArrayList::create(); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + return $this->customise(array( |
|
| 307 | + 'Locations' => $locations, |
|
| 308 | + )); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Renders locations in xml format |
|
| 313 | + * |
|
| 314 | + * @return \SilverStripe\ORM\FieldType\DBHTMLText |
|
| 315 | + */ |
|
| 316 | + public function xml() |
|
| 317 | + { |
|
| 318 | + $this->getResponse()->addHeader("Content-Type", "application/xml"); |
|
| 319 | + $data = new ArrayData(array( |
|
| 320 | + "Locations" => $this->getLocations(), |
|
| 321 | + "AddressCoords" => $this->getAddressSearchCoords(), |
|
| 322 | + )); |
|
| 323 | + |
|
| 324 | + return $data->renderWith('Dynamic/Locator/Data/XML'); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * Renders locations in json format |
|
| 329 | + * |
|
| 330 | + * @return \SilverStripe\ORM\FieldType\DBHTMLText |
|
| 331 | + */ |
|
| 332 | + public function json() |
|
| 333 | + { |
|
| 334 | + $this->getResponse()->addHeader("Content-Type", "application/json"); |
|
| 335 | + $data = new ArrayData(array( |
|
| 336 | + "Locations" => $this->getLocations(), |
|
| 337 | + "AddressCoords" => $this->getAddressSearchCoords(), |
|
| 338 | + )); |
|
| 339 | + |
|
| 340 | + return $data->renderWith('Dynamic/Locator/Data/JSON'); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * LocationSearch form. |
|
| 345 | + * |
|
| 346 | + * Search form for locations, updates map and results list via AJAX |
|
| 347 | + * |
|
| 348 | + * @return \SilverStripe\Forms\Form |
|
| 349 | + */ |
|
| 350 | + public function LocationSearch() |
|
| 351 | + { |
|
| 352 | + |
|
| 353 | + $form = LocatorForm::create($this, 'LocationSearch'); |
|
| 354 | + if (class_exists(BootstrapForm::class) && $this->config()->get('bootstrapify')) { |
|
| 355 | + $form->Fields()->bootstrapify(); |
|
| 356 | + $form->Actions()->bootstrapify(); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + return $form |
|
| 360 | + ->setFormMethod('GET') |
|
| 361 | + ->setFormAction($this->Link()) |
|
| 362 | + ->disableSecurityToken() |
|
| 363 | + ->loadDataFrom($this->request->getVars()); |
|
| 364 | + } |
|
| 365 | 365 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | parent::init(); |
| 84 | 84 | // google maps api key |
| 85 | 85 | $key = Config::inst()->get(GoogleGeocoder::class, 'map_api_key'); |
| 86 | - Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key); |
|
| 86 | + Requirements::javascript('https://maps.google.com/maps/api/js?key='.$key); |
|
| 87 | 87 | |
| 88 | 88 | // prevent init of map if no query |
| 89 | 89 | $request = Controller::curr()->getRequest(); |
@@ -94,8 +94,7 @@ discard block |
||
| 94 | 94 | if ($locations) { |
| 95 | 95 | $featuredInList = ($locations->filter('Featured', true)->count() > 0); |
| 96 | 96 | $defaultCoords = $this->getAddressSearchCoords() ? |
| 97 | - $this->getAddressSearchCoords() : |
|
| 98 | - new ArrayData([ |
|
| 97 | + $this->getAddressSearchCoords() : new ArrayData([ |
|
| 99 | 98 | "Lat" => 0, |
| 100 | 99 | "Lng" => 0, |
| 101 | 100 | ]); |
@@ -109,7 +108,7 @@ discard block |
||
| 109 | 108 | if ($limit < 1) { |
| 110 | 109 | $limit = -1; |
| 111 | 110 | } |
| 112 | - $load = 'fullMapStart: true, storeLimit: ' . $limit . ', maxDistance: true,'; |
|
| 111 | + $load = 'fullMapStart: true, storeLimit: '.$limit.', maxDistance: true,'; |
|
| 113 | 112 | |
| 114 | 113 | $listTemplatePath = $this->getListTemplate(); |
| 115 | 114 | $infowindowTemplatePath = $this->getInfoWindowTemplate(); |
@@ -121,7 +120,7 @@ discard block |
||
| 121 | 120 | unset($vars['url']); |
| 122 | 121 | $url = ''; |
| 123 | 122 | if (count($vars)) { |
| 124 | - $url .= '?' . http_build_query($vars); |
|
| 123 | + $url .= '?'.http_build_query($vars); |
|
| 125 | 124 | } |
| 126 | 125 | $link = Controller::join_links($this->Link(), 'xml.xml', $url); |
| 127 | 126 | |
@@ -248,8 +247,8 @@ discard block |
||
| 248 | 247 | if ($this->getShowRadius()) { |
| 249 | 248 | $radiusVar = $this->data()->config()->get('radius_var'); |
| 250 | 249 | |
| 251 | - if ($radius = (int)$request->getVar($radiusVar)) { |
|
| 252 | - $locations = $locations->filterByCallback(function ($location) use (&$radius) { |
|
| 250 | + if ($radius = (int) $request->getVar($radiusVar)) { |
|
| 251 | + $locations = $locations->filterByCallback(function($location) use (&$radius) { |
|
| 253 | 252 | return $location->Distance <= $radius; |
| 254 | 253 | }); |
| 255 | 254 | } |