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