Completed
Pull Request — 1.2 (#194)
by Matthew
03:19
created
code/Locator.php 2 patches
Indentation   +233 added lines, -233 removed lines patch added patch discarded remove patch
@@ -11,127 +11,127 @@  discard block
 block discarded – undo
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
-     * @return FieldList
52
-     */
53
-    public function getCMSFields()
54
-    {
55
-        $fields = parent::getCMSFields();
56
-
57
-        // Settings
58
-        $fields->addFieldsToTab('Root.Settings', array(
59
-            HeaderField::create('DisplayOptions', 'Display Options', 3),
60
-            OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')),
61
-            CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location')
62
-                ->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'),
63
-            CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'),
64
-        ));
65
-
66
-        // Filter categories
67
-        $config = GridFieldConfig_RelationEditor::create();
68
-        if (class_exists('GridFieldAddExistingSearchButton')) {
69
-            $config->removeComponentsByType('GridFieldAddExistingAutocompleter');
70
-            $config->addComponent(new GridFieldAddExistingSearchButton());
71
-        }
72
-        $categories = $this->Categories();
73
-        $categoriesField = GridField::create('Categories', 'Categories', $categories, $config)
74
-            ->setDescription('only show locations from the selected category');
75
-
76
-        // Filter
77
-        $fields->addFieldsToTab('Root.Settings', array(
78
-            HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3),
79
-            $categoriesField,
80
-        ));
81
-
82
-        $this->extend('updateCMSFields', $fields);
83
-
84
-        return $fields;
85
-    }
86
-
87
-    /**
88
-     * @param array $filter
89
-     * @param array $exclude
90
-     * @param array $filterAny
91
-     * @return DataList
92
-     */
93
-    public static function getLocations($filter = array(), $exclude = array(), $filterAny = array())
94
-    {
95
-        $filter['ShowInLocator'] = true;
96
-        $exclude['Lat'] = 0;
97
-
98
-        $Locations = Location::get()->exclude($exclude)->filter($filter)->filterAny($filterAny);
99
-
100
-        return $Locations;
101
-    }
102
-
103
-    /**
104
-     * @return DataList
105
-     */
106
-    public function getAreLocations()
107
-    {
108
-        return self::getLocations();
109
-    }
110
-
111
-    /**
112
-     * @return DataList
113
-     */
114
-    public function getAllCategories()
115
-    {
116
-        return LocationCategory::get();
117
-    }
118
-
119
-    /**
120
-     * @param null $id
121
-     * @return bool
122
-     */
123
-    public static function getPageCategories($id = null)
124
-    {
125
-        if ($id) {
126
-            if ($locator = self::get()->byID($id)) {
127
-                return $locator->Categories();
128
-            }
129
-
130
-            return false;
131
-        }
132
-
133
-        return false;
134
-    }
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
+	 * @return FieldList
52
+	 */
53
+	public function getCMSFields()
54
+	{
55
+		$fields = parent::getCMSFields();
56
+
57
+		// Settings
58
+		$fields->addFieldsToTab('Root.Settings', array(
59
+			HeaderField::create('DisplayOptions', 'Display Options', 3),
60
+			OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')),
61
+			CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location')
62
+				->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'),
63
+			CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'),
64
+		));
65
+
66
+		// Filter categories
67
+		$config = GridFieldConfig_RelationEditor::create();
68
+		if (class_exists('GridFieldAddExistingSearchButton')) {
69
+			$config->removeComponentsByType('GridFieldAddExistingAutocompleter');
70
+			$config->addComponent(new GridFieldAddExistingSearchButton());
71
+		}
72
+		$categories = $this->Categories();
73
+		$categoriesField = GridField::create('Categories', 'Categories', $categories, $config)
74
+			->setDescription('only show locations from the selected category');
75
+
76
+		// Filter
77
+		$fields->addFieldsToTab('Root.Settings', array(
78
+			HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3),
79
+			$categoriesField,
80
+		));
81
+
82
+		$this->extend('updateCMSFields', $fields);
83
+
84
+		return $fields;
85
+	}
86
+
87
+	/**
88
+	 * @param array $filter
89
+	 * @param array $exclude
90
+	 * @param array $filterAny
91
+	 * @return DataList
92
+	 */
93
+	public static function getLocations($filter = array(), $exclude = array(), $filterAny = array())
94
+	{
95
+		$filter['ShowInLocator'] = true;
96
+		$exclude['Lat'] = 0;
97
+
98
+		$Locations = Location::get()->exclude($exclude)->filter($filter)->filterAny($filterAny);
99
+
100
+		return $Locations;
101
+	}
102
+
103
+	/**
104
+	 * @return DataList
105
+	 */
106
+	public function getAreLocations()
107
+	{
108
+		return self::getLocations();
109
+	}
110
+
111
+	/**
112
+	 * @return DataList
113
+	 */
114
+	public function getAllCategories()
115
+	{
116
+		return LocationCategory::get();
117
+	}
118
+
119
+	/**
120
+	 * @param null $id
121
+	 * @return bool
122
+	 */
123
+	public static function getPageCategories($id = null)
124
+	{
125
+		if ($id) {
126
+			if ($locator = self::get()->byID($id)) {
127
+				return $locator->Categories();
128
+			}
129
+
130
+			return false;
131
+		}
132
+
133
+		return false;
134
+	}
135 135
 }
136 136
 
137 137
 /**
@@ -140,64 +140,64 @@  discard block
 block discarded – undo
140 140
 class Locator_Controller extends Page_Controller
141 141
 {
142 142
 
143
-    /**
144
-     * allowed actions
145
-     *
146
-     * @var array
147
-     */
148
-    private static $allowed_actions = array('xml');
143
+	/**
144
+	 * allowed actions
145
+	 *
146
+	 * @var array
147
+	 */
148
+	private static $allowed_actions = array('xml');
149 149
 
150
-    /**
151
-     * Set Requirements based on input from CMS
152
-     */
153
-    public function init()
154
-    {
155
-        parent::init();
150
+	/**
151
+	 * Set Requirements based on input from CMS
152
+	 */
153
+	public function init()
154
+	{
155
+		parent::init();
156 156
 
157
-        $themeDir = SSViewer::get_theme_folder();
157
+		$themeDir = SSViewer::get_theme_folder();
158 158
 
159
-        // google maps api key
160
-        $key = Config::inst()->get('GoogleGeocoding', 'google_api_key');
159
+		// google maps api key
160
+		$key = Config::inst()->get('GoogleGeocoding', 'google_api_key');
161 161
 
162
-        Requirements::javascript('framework/thirdparty/jquery/jquery.js');
163
-        if (Locator::getLocations()) {
164
-            Requirements::javascript('//maps.google.com/maps/api/js?key=' . $key);
165
-            Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
166
-            Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
167
-        }
162
+		Requirements::javascript('framework/thirdparty/jquery/jquery.js');
163
+		if (Locator::getLocations()) {
164
+			Requirements::javascript('//maps.google.com/maps/api/js?key=' . $key);
165
+			Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
166
+			Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
167
+		}
168 168
 
169
-        Requirements::css('locator/css/map.css');
169
+		Requirements::css('locator/css/map.css');
170 170
 
171
-        $featured = (Locator::getLocations(array('Featured' => 1))->count() > 0) ?
172
-            'featuredLocations: true' :
173
-            'featuredLocations: false';
171
+		$featured = (Locator::getLocations(array('Featured' => 1))->count() > 0) ?
172
+			'featuredLocations: true' :
173
+			'featuredLocations: false';
174 174
 
175
-        // map config based on user input in Settings tab
176
-        // AutoGeocode or Full Map
177
-        $load = ($this->data()->AutoGeocode) ?
178
-            'autoGeocode: true, fullMapStart: false,' :
179
-            'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
175
+		// map config based on user input in Settings tab
176
+		// AutoGeocode or Full Map
177
+		$load = ($this->data()->AutoGeocode) ?
178
+			'autoGeocode: true, fullMapStart: false,' :
179
+			'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
180 180
 
181
-        $base = Director::baseFolder();
182
-        $themePath = $base . '/' . $themeDir;
181
+		$base = Director::baseFolder();
182
+		$themePath = $base . '/' . $themeDir;
183 183
 
184
-        $listTemplatePath = (file_exists($themePath . '/templates/location-list-description.html')) ?
185
-            $themeDir . '/templates/location-list-description.html' :
186
-            'locator/templates/location-list-description.html';
187
-        $infowindowTemplatePath = (file_exists($themePath . '/templates/infowindow-description.html')) ?
188
-            $themeDir . '/templates/infowindow-description.html' :
189
-            'locator/templates/infowindow-description.html';
184
+		$listTemplatePath = (file_exists($themePath . '/templates/location-list-description.html')) ?
185
+			$themeDir . '/templates/location-list-description.html' :
186
+			'locator/templates/location-list-description.html';
187
+		$infowindowTemplatePath = (file_exists($themePath . '/templates/infowindow-description.html')) ?
188
+			$themeDir . '/templates/infowindow-description.html' :
189
+			'locator/templates/infowindow-description.html';
190 190
 
191
-        // in page or modal
192
-        $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';
191
+		// in page or modal
192
+		$modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';
193 193
 
194
-        $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"';
194
+		$kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"';
195 195
 
196
-        $link = $this->Link() . 'xml.xml';
196
+		$link = $this->Link() . 'xml.xml';
197 197
 
198
-        // init map
199
-        if (Locator::getLocations()) {
200
-            Requirements::customScript("
198
+		// init map
199
+		if (Locator::getLocations()) {
200
+			Requirements::customScript("
201 201
                 $(function($) {
202 202
                     $('#map-container').storeLocator({
203 203
                         " . $load . "
@@ -218,72 +218,72 @@  discard block
 block discarded – undo
218 218
                     });
219 219
                 });
220 220
             ');
221
-        }
222
-    }
223
-
224
-    /**
225
-     * Find all locations for map.
226
-     *
227
-     * Will return a XML feed of all locations marked "show in locator".
228
-     *
229
-     * @param SS_HTTPRequest $request
230
-     * @return HTMLText
231
-     */
232
-    public function xml(SS_HTTPRequest $request)
233
-    {
234
-        $filter = array();
235
-        $exclude = array();
236
-        $filterAny = array();
237
-
238
-        //if a category filter selected
239
-        if ($this->Categories()->exists()) {
240
-            $categories = $this->Categories();
241
-            foreach ($categories as $category) {
242
-                $filterAny['CategoryID'] = $category->ID;
243
-            }
244
-        }
245
-
246
-        $Locations = Locator::getLocations($filter, $exclude, $filterAny);
247
-
248
-        return $this->customise(array(
249
-            'Locations' => $Locations,
250
-        ))->renderWith('LocationXML');
251
-    }
252
-
253
-    /**
254
-     * LocationSearch form.
255
-     *
256
-     * Search form for locations, updates map and results list via AJAX
257
-     *
258
-     * @return Form
259
-     */
260
-    public function LocationSearch()
261
-    {
262
-        $fields = FieldList::create(
263
-            $address = TextField::create('address', '')
264
-        );
265
-        $address->setAttribute('placeholder', 'address or zip code');
266
-
267
-        $locatorCategories = Locator::getPageCategories($this->ID);
268
-
269
-        if (LocationCategory::get()->count() > 0 && $locatorCategories && $locatorCategories->count() != 1) {
270
-            $categories = LocationCategory::get();
271
-
272
-            if ($categories->count() > 0) {
273
-                $fields->push(
274
-                    DropdownField::create(
275
-                        'category',
276
-                        '',
277
-                        $categories->map('Title', 'Title')
278
-                    )->setEmptyString('Select Category'));
279
-            }
280
-        }
281
-
282
-        $actions = FieldList::create(
283
-            FormAction::create('', 'Search')
284
-        );
285
-
286
-        return Form::create($this, 'LocationSearch', $fields, $actions);
287
-    }
221
+		}
222
+	}
223
+
224
+	/**
225
+	 * Find all locations for map.
226
+	 *
227
+	 * Will return a XML feed of all locations marked "show in locator".
228
+	 *
229
+	 * @param SS_HTTPRequest $request
230
+	 * @return HTMLText
231
+	 */
232
+	public function xml(SS_HTTPRequest $request)
233
+	{
234
+		$filter = array();
235
+		$exclude = array();
236
+		$filterAny = array();
237
+
238
+		//if a category filter selected
239
+		if ($this->Categories()->exists()) {
240
+			$categories = $this->Categories();
241
+			foreach ($categories as $category) {
242
+				$filterAny['CategoryID'] = $category->ID;
243
+			}
244
+		}
245
+
246
+		$Locations = Locator::getLocations($filter, $exclude, $filterAny);
247
+
248
+		return $this->customise(array(
249
+			'Locations' => $Locations,
250
+		))->renderWith('LocationXML');
251
+	}
252
+
253
+	/**
254
+	 * LocationSearch form.
255
+	 *
256
+	 * Search form for locations, updates map and results list via AJAX
257
+	 *
258
+	 * @return Form
259
+	 */
260
+	public function LocationSearch()
261
+	{
262
+		$fields = FieldList::create(
263
+			$address = TextField::create('address', '')
264
+		);
265
+		$address->setAttribute('placeholder', 'address or zip code');
266
+
267
+		$locatorCategories = Locator::getPageCategories($this->ID);
268
+
269
+		if (LocationCategory::get()->count() > 0 && $locatorCategories && $locatorCategories->count() != 1) {
270
+			$categories = LocationCategory::get();
271
+
272
+			if ($categories->count() > 0) {
273
+				$fields->push(
274
+					DropdownField::create(
275
+						'category',
276
+						'',
277
+						$categories->map('Title', 'Title')
278
+					)->setEmptyString('Select Category'));
279
+			}
280
+		}
281
+
282
+		$actions = FieldList::create(
283
+			FormAction::create('', 'Search')
284
+		);
285
+
286
+		return Form::create($this, 'LocationSearch', $fields, $actions);
287
+	}
288 288
 
289 289
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -20 removed lines patch added patch discarded remove patch
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 
162 162
         Requirements::javascript('framework/thirdparty/jquery/jquery.js');
163 163
         if (Locator::getLocations()) {
164
-            Requirements::javascript('//maps.google.com/maps/api/js?key=' . $key);
164
+            Requirements::javascript('//maps.google.com/maps/api/js?key='.$key);
165 165
             Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
166 166
             Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
167 167
         }
@@ -169,44 +169,40 @@  discard block
 block discarded – undo
169 169
         Requirements::css('locator/css/map.css');
170 170
 
171 171
         $featured = (Locator::getLocations(array('Featured' => 1))->count() > 0) ?
172
-            'featuredLocations: true' :
173
-            'featuredLocations: false';
172
+            'featuredLocations: true' : 'featuredLocations: false';
174 173
 
175 174
         // map config based on user input in Settings tab
176 175
         // AutoGeocode or Full Map
177 176
         $load = ($this->data()->AutoGeocode) ?
178
-            'autoGeocode: true, fullMapStart: false,' :
179
-            'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
177
+            'autoGeocode: true, fullMapStart: false,' : 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
180 178
 
181 179
         $base = Director::baseFolder();
182
-        $themePath = $base . '/' . $themeDir;
180
+        $themePath = $base.'/'.$themeDir;
183 181
 
184
-        $listTemplatePath = (file_exists($themePath . '/templates/location-list-description.html')) ?
185
-            $themeDir . '/templates/location-list-description.html' :
186
-            'locator/templates/location-list-description.html';
187
-        $infowindowTemplatePath = (file_exists($themePath . '/templates/infowindow-description.html')) ?
188
-            $themeDir . '/templates/infowindow-description.html' :
189
-            'locator/templates/infowindow-description.html';
182
+        $listTemplatePath = (file_exists($themePath.'/templates/location-list-description.html')) ?
183
+            $themeDir.'/templates/location-list-description.html' : 'locator/templates/location-list-description.html';
184
+        $infowindowTemplatePath = (file_exists($themePath.'/templates/infowindow-description.html')) ?
185
+            $themeDir.'/templates/infowindow-description.html' : 'locator/templates/infowindow-description.html';
190 186
 
191 187
         // in page or modal
192 188
         $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';
193 189
 
194 190
         $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"';
195 191
 
196
-        $link = $this->Link() . 'xml.xml';
192
+        $link = $this->Link().'xml.xml';
197 193
 
198 194
         // init map
199 195
         if (Locator::getLocations()) {
200 196
             Requirements::customScript("
201 197
                 $(function($) {
202 198
                     $('#map-container').storeLocator({
203
-                        " . $load . "
204
-                        dataLocation: '" . $link . "',
205
-                        listTemplatePath: '" . $listTemplatePath . "',
206
-                        infowindowTemplatePath: '" . $infowindowTemplatePath . "',
199
+                        " . $load."
200
+                        dataLocation: '" . $link."',
201
+                        listTemplatePath: '" . $listTemplatePath."',
202
+                        infowindowTemplatePath: '" . $infowindowTemplatePath."',
207 203
                         originMarker: true,
208
-                        " . $modal . ',
209
-                        ' . $featured . ",
204
+                        " . $modal.',
205
+                        ' . $featured.",
210 206
                         slideMap: false,
211 207
                         zoomLevel: 0,
212 208
                         distanceAlert: 120,
@@ -214,7 +210,7 @@  discard block
 block discarded – undo
214 210
                         inputID: 'Form_LocationSearch_address',
215 211
                         categoryID: 'Form_LocationSearch_category',
216 212
                         distanceAlert: -1,
217
-                        " . $kilometer . '
213
+                        " . $kilometer.'
218 214
                     });
219 215
                 });
220 216
             ');
Please login to merge, or discard this patch.