@@ -11,143 +11,143 @@ discard block |
||
| 11 | 11 | class Locator extends Page |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @var array |
|
| 16 | - */ |
|
| 17 | - private static $db = array( |
|
| 18 | - 'AutoGeocode' => 'Boolean', |
|
| 19 | - 'ModalWindow' => 'Boolean', |
|
| 20 | - 'Unit' => 'Enum("m,km","m")', |
|
| 21 | - ); |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @var array |
|
| 25 | - */ |
|
| 26 | - private static $many_many = array( |
|
| 27 | - 'Categories' => 'LocationCategory', |
|
| 28 | - ); |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var array |
|
| 32 | - */ |
|
| 33 | - private static $defaults = array( |
|
| 34 | - 'AutoGeocode' => true, |
|
| 35 | - ); |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var string |
|
| 39 | - */ |
|
| 40 | - private static $singular_name = 'Locator'; |
|
| 41 | - /** |
|
| 42 | - * @var string |
|
| 43 | - */ |
|
| 44 | - private static $plural_name = 'Locators'; |
|
| 45 | - /** |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 48 | - private static $description = 'Find locations on a map'; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var string |
|
| 52 | - */ |
|
| 53 | - private static $location_class = 'Location'; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @return FieldList |
|
| 57 | - */ |
|
| 58 | - public function getCMSFields() |
|
| 59 | - { |
|
| 60 | - $fields = parent::getCMSFields(); |
|
| 61 | - |
|
| 62 | - // Settings |
|
| 63 | - $fields->addFieldsToTab('Root.Settings', array( |
|
| 64 | - HeaderField::create('DisplayOptions', 'Display Options', 3), |
|
| 65 | - OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')), |
|
| 66 | - CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location') |
|
| 67 | - ->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'), |
|
| 68 | - CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'), |
|
| 69 | - )); |
|
| 70 | - |
|
| 71 | - // Filter categories |
|
| 72 | - $config = GridFieldConfig_RelationEditor::create(); |
|
| 73 | - if (class_exists('GridFieldAddExistingSearchButton')) { |
|
| 74 | - $config->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
|
| 75 | - $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
| 76 | - } |
|
| 77 | - $categories = $this->Categories(); |
|
| 78 | - $categoriesField = GridField::create('Categories', 'Categories', $categories, $config) |
|
| 79 | - ->setDescription('only show locations from the selected category'); |
|
| 80 | - |
|
| 81 | - // Filter |
|
| 82 | - $fields->addFieldsToTab('Root.Filter', array( |
|
| 83 | - HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
| 84 | - $categoriesField, |
|
| 85 | - )); |
|
| 86 | - |
|
| 87 | - $this->extend('updateCMSFields', $fields); |
|
| 88 | - |
|
| 89 | - return $fields; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @param array $filter |
|
| 94 | - * @param array $filterAny |
|
| 95 | - * @param array $exclude |
|
| 96 | - * @param null|callable $callback |
|
| 97 | - * @return DataList|ArrayList |
|
| 98 | - */ |
|
| 99 | - public static function get_locations( |
|
| 100 | - $filter = [], |
|
| 101 | - $filterAny = [], |
|
| 102 | - $exclude = [], |
|
| 103 | - $callback = null |
|
| 104 | - ) |
|
| 105 | - { |
|
| 106 | - $locationClass = Config::inst()->get('Locator', 'location_class'); |
|
| 107 | - $locations = $locationClass::get()->filter($filter)->exclude($exclude); |
|
| 108 | - |
|
| 109 | - if (!empty($filterAny)) { |
|
| 110 | - $locations = $locations->filterAny($filterAny); |
|
| 111 | - } |
|
| 112 | - if (!empty($exclude)) { |
|
| 113 | - $locations = $locations->exclude($exclude); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - if ($callback !== null && is_callable($callback)) { |
|
| 117 | - $locations->filterByCallback($callback); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - return $locations; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @return DataList |
|
| 125 | - */ |
|
| 126 | - public static function get_all_categories() |
|
| 127 | - { |
|
| 128 | - return LocationCategory::get(); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @return bool |
|
| 133 | - */ |
|
| 134 | - public function getPageCategories() |
|
| 135 | - { |
|
| 136 | - return self::locator_categories_by_locator($this->ID); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @param int $id |
|
| 141 | - * @return bool| |
|
| 142 | - */ |
|
| 143 | - public static function locator_categories_by_locator($id = 0) |
|
| 144 | - { |
|
| 145 | - if ($id == 0) { |
|
| 146 | - return false; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - return Locator::get()->byID($id)->Categories(); |
|
| 150 | - } |
|
| 14 | + /** |
|
| 15 | + * @var array |
|
| 16 | + */ |
|
| 17 | + private static $db = array( |
|
| 18 | + 'AutoGeocode' => 'Boolean', |
|
| 19 | + 'ModalWindow' => 'Boolean', |
|
| 20 | + 'Unit' => 'Enum("m,km","m")', |
|
| 21 | + ); |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @var array |
|
| 25 | + */ |
|
| 26 | + private static $many_many = array( |
|
| 27 | + 'Categories' => 'LocationCategory', |
|
| 28 | + ); |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var array |
|
| 32 | + */ |
|
| 33 | + private static $defaults = array( |
|
| 34 | + 'AutoGeocode' => true, |
|
| 35 | + ); |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var string |
|
| 39 | + */ |
|
| 40 | + private static $singular_name = 'Locator'; |
|
| 41 | + /** |
|
| 42 | + * @var string |
|
| 43 | + */ |
|
| 44 | + private static $plural_name = 'Locators'; |
|
| 45 | + /** |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | + private static $description = 'Find locations on a map'; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var string |
|
| 52 | + */ |
|
| 53 | + private static $location_class = 'Location'; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @return FieldList |
|
| 57 | + */ |
|
| 58 | + public function getCMSFields() |
|
| 59 | + { |
|
| 60 | + $fields = parent::getCMSFields(); |
|
| 61 | + |
|
| 62 | + // Settings |
|
| 63 | + $fields->addFieldsToTab('Root.Settings', array( |
|
| 64 | + HeaderField::create('DisplayOptions', 'Display Options', 3), |
|
| 65 | + OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')), |
|
| 66 | + CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location') |
|
| 67 | + ->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'), |
|
| 68 | + CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'), |
|
| 69 | + )); |
|
| 70 | + |
|
| 71 | + // Filter categories |
|
| 72 | + $config = GridFieldConfig_RelationEditor::create(); |
|
| 73 | + if (class_exists('GridFieldAddExistingSearchButton')) { |
|
| 74 | + $config->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
|
| 75 | + $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
| 76 | + } |
|
| 77 | + $categories = $this->Categories(); |
|
| 78 | + $categoriesField = GridField::create('Categories', 'Categories', $categories, $config) |
|
| 79 | + ->setDescription('only show locations from the selected category'); |
|
| 80 | + |
|
| 81 | + // Filter |
|
| 82 | + $fields->addFieldsToTab('Root.Filter', array( |
|
| 83 | + HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
| 84 | + $categoriesField, |
|
| 85 | + )); |
|
| 86 | + |
|
| 87 | + $this->extend('updateCMSFields', $fields); |
|
| 88 | + |
|
| 89 | + return $fields; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @param array $filter |
|
| 94 | + * @param array $filterAny |
|
| 95 | + * @param array $exclude |
|
| 96 | + * @param null|callable $callback |
|
| 97 | + * @return DataList|ArrayList |
|
| 98 | + */ |
|
| 99 | + public static function get_locations( |
|
| 100 | + $filter = [], |
|
| 101 | + $filterAny = [], |
|
| 102 | + $exclude = [], |
|
| 103 | + $callback = null |
|
| 104 | + ) |
|
| 105 | + { |
|
| 106 | + $locationClass = Config::inst()->get('Locator', 'location_class'); |
|
| 107 | + $locations = $locationClass::get()->filter($filter)->exclude($exclude); |
|
| 108 | + |
|
| 109 | + if (!empty($filterAny)) { |
|
| 110 | + $locations = $locations->filterAny($filterAny); |
|
| 111 | + } |
|
| 112 | + if (!empty($exclude)) { |
|
| 113 | + $locations = $locations->exclude($exclude); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + if ($callback !== null && is_callable($callback)) { |
|
| 117 | + $locations->filterByCallback($callback); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + return $locations; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @return DataList |
|
| 125 | + */ |
|
| 126 | + public static function get_all_categories() |
|
| 127 | + { |
|
| 128 | + return LocationCategory::get(); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @return bool |
|
| 133 | + */ |
|
| 134 | + public function getPageCategories() |
|
| 135 | + { |
|
| 136 | + return self::locator_categories_by_locator($this->ID); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @param int $id |
|
| 141 | + * @return bool| |
|
| 142 | + */ |
|
| 143 | + public static function locator_categories_by_locator($id = 0) |
|
| 144 | + { |
|
| 145 | + if ($id == 0) { |
|
| 146 | + return false; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + return Locator::get()->byID($id)->Categories(); |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | 152 | |
| 153 | 153 | } |
@@ -157,111 +157,111 @@ discard block |
||
| 157 | 157 | */ |
| 158 | 158 | class Locator_Controller extends Page_Controller |
| 159 | 159 | { |
| 160 | - /** |
|
| 161 | - * @var array |
|
| 162 | - */ |
|
| 163 | - private static $allowed_actions = array( |
|
| 164 | - 'xml', |
|
| 165 | - ); |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * @var array |
|
| 169 | - */ |
|
| 170 | - private static $base_filter = [ |
|
| 171 | - 'ShowInLocator' => true, |
|
| 172 | - ]; |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * @var array |
|
| 176 | - */ |
|
| 177 | - private static $base_exclude = [ |
|
| 178 | - 'Lat' => 0, |
|
| 179 | - 'Lng' => 0, |
|
| 180 | - ]; |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * @var array |
|
| 184 | - */ |
|
| 185 | - private static $base_filter_any = []; |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * @var string |
|
| 189 | - */ |
|
| 190 | - private static $list_template_path = 'locator/templates/location-list-description.html'; |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * @var string |
|
| 194 | - */ |
|
| 195 | - private static $info_window_template_path = 'locator/templates/infowindow-description.html'; |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * @var bool |
|
| 199 | - */ |
|
| 200 | - private static $bootstrapify = true; |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * @var DataList|ArrayList |
|
| 204 | - */ |
|
| 205 | - protected $locations; |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Set Requirements based on input from CMS |
|
| 209 | - */ |
|
| 210 | - public function init() |
|
| 211 | - { |
|
| 212 | - parent::init(); |
|
| 213 | - |
|
| 214 | - // google maps api key |
|
| 215 | - $key = Config::inst()->get('GoogleGeocoding', 'google_api_key'); |
|
| 216 | - |
|
| 217 | - $locations = $this->getLocations(); |
|
| 218 | - |
|
| 219 | - if ($locations) { |
|
| 220 | - |
|
| 221 | - Requirements::css('locator/css/map.css'); |
|
| 222 | - Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
|
| 223 | - Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key); |
|
| 224 | - Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); |
|
| 225 | - Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); |
|
| 226 | - |
|
| 227 | - $featuredInList = ($locations->filter('Featured', true)->count() > 0); |
|
| 228 | - $defaultCoords = $this->getAddressSearchCoords() ? $this->getAddressSearchCoords() : ''; |
|
| 229 | - $isChrome = (strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE); |
|
| 230 | - |
|
| 231 | - $featured = $featuredInList |
|
| 232 | - ? 'featuredLocations: true' |
|
| 233 | - : 'featuredLocations: false'; |
|
| 234 | - |
|
| 235 | - // map config based on user input in Settings tab |
|
| 236 | - // AutoGeocode or Full Map |
|
| 237 | - if ($this->data()->AutoGeocode) { |
|
| 238 | - $load = $featuredInList || $defaultCoords != '' || $isChrome |
|
| 239 | - ? 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,' |
|
| 240 | - : 'autoGeocode: true, fullMapStart: false,'; |
|
| 241 | - } else { |
|
| 242 | - $load = 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - $listTemplatePath = Config::inst()->get('Locator', 'list_template_path'); |
|
| 246 | - $infowindowTemplatePath = Config::inst()->get('Locator', 'info_window_template_path'); |
|
| 247 | - |
|
| 248 | - // in page or modal |
|
| 249 | - $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
|
| 250 | - |
|
| 251 | - $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; |
|
| 252 | - |
|
| 253 | - // pass GET variables to xml action |
|
| 254 | - $vars = $this->request->getVars(); |
|
| 255 | - unset($vars['url']); |
|
| 256 | - unset($vars['action_doFilterLocations']); |
|
| 257 | - $url = ''; |
|
| 258 | - if (count($vars)) { |
|
| 259 | - $url .= '?' . http_build_query($vars); |
|
| 260 | - } |
|
| 261 | - $link = $this->Link() . 'xml.xml' . $url; |
|
| 262 | - |
|
| 263 | - // init map |
|
| 264 | - Requirements::customScript(" |
|
| 160 | + /** |
|
| 161 | + * @var array |
|
| 162 | + */ |
|
| 163 | + private static $allowed_actions = array( |
|
| 164 | + 'xml', |
|
| 165 | + ); |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * @var array |
|
| 169 | + */ |
|
| 170 | + private static $base_filter = [ |
|
| 171 | + 'ShowInLocator' => true, |
|
| 172 | + ]; |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * @var array |
|
| 176 | + */ |
|
| 177 | + private static $base_exclude = [ |
|
| 178 | + 'Lat' => 0, |
|
| 179 | + 'Lng' => 0, |
|
| 180 | + ]; |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * @var array |
|
| 184 | + */ |
|
| 185 | + private static $base_filter_any = []; |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * @var string |
|
| 189 | + */ |
|
| 190 | + private static $list_template_path = 'locator/templates/location-list-description.html'; |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * @var string |
|
| 194 | + */ |
|
| 195 | + private static $info_window_template_path = 'locator/templates/infowindow-description.html'; |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * @var bool |
|
| 199 | + */ |
|
| 200 | + private static $bootstrapify = true; |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * @var DataList|ArrayList |
|
| 204 | + */ |
|
| 205 | + protected $locations; |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Set Requirements based on input from CMS |
|
| 209 | + */ |
|
| 210 | + public function init() |
|
| 211 | + { |
|
| 212 | + parent::init(); |
|
| 213 | + |
|
| 214 | + // google maps api key |
|
| 215 | + $key = Config::inst()->get('GoogleGeocoding', 'google_api_key'); |
|
| 216 | + |
|
| 217 | + $locations = $this->getLocations(); |
|
| 218 | + |
|
| 219 | + if ($locations) { |
|
| 220 | + |
|
| 221 | + Requirements::css('locator/css/map.css'); |
|
| 222 | + Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
|
| 223 | + Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key); |
|
| 224 | + Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); |
|
| 225 | + Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); |
|
| 226 | + |
|
| 227 | + $featuredInList = ($locations->filter('Featured', true)->count() > 0); |
|
| 228 | + $defaultCoords = $this->getAddressSearchCoords() ? $this->getAddressSearchCoords() : ''; |
|
| 229 | + $isChrome = (strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE); |
|
| 230 | + |
|
| 231 | + $featured = $featuredInList |
|
| 232 | + ? 'featuredLocations: true' |
|
| 233 | + : 'featuredLocations: false'; |
|
| 234 | + |
|
| 235 | + // map config based on user input in Settings tab |
|
| 236 | + // AutoGeocode or Full Map |
|
| 237 | + if ($this->data()->AutoGeocode) { |
|
| 238 | + $load = $featuredInList || $defaultCoords != '' || $isChrome |
|
| 239 | + ? 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,' |
|
| 240 | + : 'autoGeocode: true, fullMapStart: false,'; |
|
| 241 | + } else { |
|
| 242 | + $load = 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + $listTemplatePath = Config::inst()->get('Locator', 'list_template_path'); |
|
| 246 | + $infowindowTemplatePath = Config::inst()->get('Locator', 'info_window_template_path'); |
|
| 247 | + |
|
| 248 | + // in page or modal |
|
| 249 | + $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
|
| 250 | + |
|
| 251 | + $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; |
|
| 252 | + |
|
| 253 | + // pass GET variables to xml action |
|
| 254 | + $vars = $this->request->getVars(); |
|
| 255 | + unset($vars['url']); |
|
| 256 | + unset($vars['action_doFilterLocations']); |
|
| 257 | + $url = ''; |
|
| 258 | + if (count($vars)) { |
|
| 259 | + $url .= '?' . http_build_query($vars); |
|
| 260 | + } |
|
| 261 | + $link = $this->Link() . 'xml.xml' . $url; |
|
| 262 | + |
|
| 263 | + // init map |
|
| 264 | + Requirements::customScript(" |
|
| 265 | 265 | $(function(){ |
| 266 | 266 | $('#map-container').storeLocator({ |
| 267 | 267 | " . $load . " |
@@ -280,134 +280,134 @@ discard block |
||
| 280 | 280 | }); |
| 281 | 281 | }); |
| 282 | 282 | '); |
| 283 | - } |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * @param SS_HTTPRequest $request |
|
| 288 | - * |
|
| 289 | - * @return ViewableData_Customised |
|
| 290 | - */ |
|
| 291 | - public function index(SS_HTTPRequest $request) |
|
| 292 | - { |
|
| 293 | - $locations = $this->getLocations(); |
|
| 294 | - |
|
| 295 | - return $this->customise(array( |
|
| 296 | - 'Locations' => $locations, |
|
| 297 | - )); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * Return a XML feed of all locations marked "show in locator" |
|
| 302 | - * |
|
| 303 | - * @param SS_HTTPRequest $request |
|
| 304 | - * @return HTMLText |
|
| 305 | - */ |
|
| 306 | - public function xml(SS_HTTPRequest $request) |
|
| 307 | - { |
|
| 308 | - $locations = $this->getLocations(); |
|
| 309 | - |
|
| 310 | - return $this->customise(array( |
|
| 311 | - 'Locations' => $locations, |
|
| 312 | - ))->renderWith('LocationXML'); |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * @return ArrayList|DataList |
|
| 317 | - */ |
|
| 318 | - public function getLocations() |
|
| 319 | - { |
|
| 320 | - if (!$this->locations) { |
|
| 321 | - $this->setLocations($this->request); |
|
| 322 | - } |
|
| 323 | - return $this->locations; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * @param SS_HTTPRequest|null $request |
|
| 328 | - * @return $this |
|
| 329 | - */ |
|
| 330 | - public function setLocations(SS_HTTPRequest $request = null) |
|
| 331 | - { |
|
| 332 | - |
|
| 333 | - if ($request === null) { |
|
| 334 | - $request = $this->request; |
|
| 335 | - } |
|
| 336 | - $filter = $this->config()->get('base_filter'); |
|
| 337 | - |
|
| 338 | - if ($request->getVar('CategoryID')) { |
|
| 339 | - $filter['CategoryID'] = $request->getVar('CategoryID'); |
|
| 340 | - } else { |
|
| 341 | - if ($this->getPageCategories()->exists()) { |
|
| 342 | - foreach ($this->getPageCategories() as $category) { |
|
| 343 | - $filter['CategoryID'][] = $category->ID; |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - $this->extend('updateLocatorFilter', $filter, $request); |
|
| 349 | - |
|
| 350 | - $filterAny = $this->config()->get('base_filter_any'); |
|
| 351 | - $this->extend('updateLocatorFilterAny', $filterAny, $request); |
|
| 352 | - |
|
| 353 | - $exclude = $this->config()->get('base_exclude'); |
|
| 354 | - $this->extend('updateLocatorExclude', $exclude, $request); |
|
| 355 | - |
|
| 356 | - $locations = Locator::get_locations($filter, $filterAny, $exclude); |
|
| 357 | - $locations = DataToArrayListHelper::to_array_list($locations); |
|
| 358 | - |
|
| 359 | - //allow for adjusting list post possible distance calculation |
|
| 360 | - $this->extend('updateLocationList', $locations); |
|
| 361 | - |
|
| 362 | - if ($locations->canSortBy('distance')) { |
|
| 363 | - $locations = $locations->sort('distance'); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - //allow for returning list to be set as |
|
| 367 | - $this->extend('updateListType', $locations); |
|
| 368 | - |
|
| 369 | - $this->locations = $locations; |
|
| 370 | - return $this; |
|
| 371 | - |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * @return bool|string |
|
| 376 | - */ |
|
| 377 | - public function getAddressSearchCoords() |
|
| 378 | - { |
|
| 379 | - if (!$this->request->getVar('Address')) { |
|
| 380 | - return false; |
|
| 381 | - } |
|
| 382 | - $coords = GoogleGeocoding::address_to_point(Controller::curr()->getRequest()->getVar('Address')); |
|
| 383 | - |
|
| 384 | - $lat = $coords['lat']; |
|
| 385 | - $lng = $coords['lng']; |
|
| 386 | - |
|
| 387 | - return "defaultLat: {$lat}, defaultLng: {$lng},"; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * LocationSearch form. |
|
| 392 | - * |
|
| 393 | - * Search form for locations, updates map and results list via AJAX |
|
| 394 | - * |
|
| 395 | - * @return Form |
|
| 396 | - */ |
|
| 397 | - public function LocationSearch() |
|
| 398 | - { |
|
| 399 | - |
|
| 400 | - $form = LocatorForm::create($this, 'LocationSearch'); |
|
| 401 | - if (class_exists('BootstrapForm') && $this->config()->get('bootstrapify')) { |
|
| 402 | - $form->Fields()->bootstrapify(); |
|
| 403 | - $form->Actions()->bootstrapify(); |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - return $form |
|
| 407 | - ->setFormMethod('GET') |
|
| 408 | - ->setFormAction($this->Link()) |
|
| 409 | - ->disableSecurityToken() |
|
| 410 | - ->loadDataFrom($this->request->getVars()); |
|
| 411 | - } |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * @param SS_HTTPRequest $request |
|
| 288 | + * |
|
| 289 | + * @return ViewableData_Customised |
|
| 290 | + */ |
|
| 291 | + public function index(SS_HTTPRequest $request) |
|
| 292 | + { |
|
| 293 | + $locations = $this->getLocations(); |
|
| 294 | + |
|
| 295 | + return $this->customise(array( |
|
| 296 | + 'Locations' => $locations, |
|
| 297 | + )); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * Return a XML feed of all locations marked "show in locator" |
|
| 302 | + * |
|
| 303 | + * @param SS_HTTPRequest $request |
|
| 304 | + * @return HTMLText |
|
| 305 | + */ |
|
| 306 | + public function xml(SS_HTTPRequest $request) |
|
| 307 | + { |
|
| 308 | + $locations = $this->getLocations(); |
|
| 309 | + |
|
| 310 | + return $this->customise(array( |
|
| 311 | + 'Locations' => $locations, |
|
| 312 | + ))->renderWith('LocationXML'); |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * @return ArrayList|DataList |
|
| 317 | + */ |
|
| 318 | + public function getLocations() |
|
| 319 | + { |
|
| 320 | + if (!$this->locations) { |
|
| 321 | + $this->setLocations($this->request); |
|
| 322 | + } |
|
| 323 | + return $this->locations; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * @param SS_HTTPRequest|null $request |
|
| 328 | + * @return $this |
|
| 329 | + */ |
|
| 330 | + public function setLocations(SS_HTTPRequest $request = null) |
|
| 331 | + { |
|
| 332 | + |
|
| 333 | + if ($request === null) { |
|
| 334 | + $request = $this->request; |
|
| 335 | + } |
|
| 336 | + $filter = $this->config()->get('base_filter'); |
|
| 337 | + |
|
| 338 | + if ($request->getVar('CategoryID')) { |
|
| 339 | + $filter['CategoryID'] = $request->getVar('CategoryID'); |
|
| 340 | + } else { |
|
| 341 | + if ($this->getPageCategories()->exists()) { |
|
| 342 | + foreach ($this->getPageCategories() as $category) { |
|
| 343 | + $filter['CategoryID'][] = $category->ID; |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + $this->extend('updateLocatorFilter', $filter, $request); |
|
| 349 | + |
|
| 350 | + $filterAny = $this->config()->get('base_filter_any'); |
|
| 351 | + $this->extend('updateLocatorFilterAny', $filterAny, $request); |
|
| 352 | + |
|
| 353 | + $exclude = $this->config()->get('base_exclude'); |
|
| 354 | + $this->extend('updateLocatorExclude', $exclude, $request); |
|
| 355 | + |
|
| 356 | + $locations = Locator::get_locations($filter, $filterAny, $exclude); |
|
| 357 | + $locations = DataToArrayListHelper::to_array_list($locations); |
|
| 358 | + |
|
| 359 | + //allow for adjusting list post possible distance calculation |
|
| 360 | + $this->extend('updateLocationList', $locations); |
|
| 361 | + |
|
| 362 | + if ($locations->canSortBy('distance')) { |
|
| 363 | + $locations = $locations->sort('distance'); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + //allow for returning list to be set as |
|
| 367 | + $this->extend('updateListType', $locations); |
|
| 368 | + |
|
| 369 | + $this->locations = $locations; |
|
| 370 | + return $this; |
|
| 371 | + |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * @return bool|string |
|
| 376 | + */ |
|
| 377 | + public function getAddressSearchCoords() |
|
| 378 | + { |
|
| 379 | + if (!$this->request->getVar('Address')) { |
|
| 380 | + return false; |
|
| 381 | + } |
|
| 382 | + $coords = GoogleGeocoding::address_to_point(Controller::curr()->getRequest()->getVar('Address')); |
|
| 383 | + |
|
| 384 | + $lat = $coords['lat']; |
|
| 385 | + $lng = $coords['lng']; |
|
| 386 | + |
|
| 387 | + return "defaultLat: {$lat}, defaultLng: {$lng},"; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * LocationSearch form. |
|
| 392 | + * |
|
| 393 | + * Search form for locations, updates map and results list via AJAX |
|
| 394 | + * |
|
| 395 | + * @return Form |
|
| 396 | + */ |
|
| 397 | + public function LocationSearch() |
|
| 398 | + { |
|
| 399 | + |
|
| 400 | + $form = LocatorForm::create($this, 'LocationSearch'); |
|
| 401 | + if (class_exists('BootstrapForm') && $this->config()->get('bootstrapify')) { |
|
| 402 | + $form->Fields()->bootstrapify(); |
|
| 403 | + $form->Actions()->bootstrapify(); |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + return $form |
|
| 407 | + ->setFormMethod('GET') |
|
| 408 | + ->setFormAction($this->Link()) |
|
| 409 | + ->disableSecurityToken() |
|
| 410 | + ->loadDataFrom($this->request->getVars()); |
|
| 411 | + } |
|
| 412 | 412 | |
| 413 | 413 | } |