Completed
Push — master ( 29ed75...a64902 )
by Jason
29s
created
code/Locator.php 1 patch
Indentation   +190 added lines, -190 removed lines patch added patch discarded remove patch
@@ -2,143 +2,143 @@  discard block
 block discarded – undo
2 2
 
3 3
 class Locator extends Page
4 4
 {
5
-    private static $db = array(
6
-        'AutoGeocode' => 'Boolean',
7
-        'ModalWindow' => 'Boolean',
8
-        'Unit' => 'Enum("m,km","m")',
9
-    );
10
-
11
-    private static $many_many = array(
12
-        'Categories' => 'LocationCategory',
13
-    );
14
-
15
-    private static $defaults = array(
16
-        'AutoGeocode' => true,
17
-    );
18
-
19
-    private static $singular_name = 'Locator';
20
-    private static $plural_name = 'Locators';
21
-    private static $description = 'Find locations on a map';
22
-
23
-    public function getCMSFields()
24
-    {
25
-        $fields = parent::getCMSFields();
26
-
27
-        // Settings
28
-        $fields->addFieldsToTab('Root.Settings', array(
29
-            HeaderField::create('DisplayOptions', 'Display Options', 3),
30
-            OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')),
31
-            CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location')
32
-                ->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'),
33
-            CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'),
34
-        ));
35
-
36
-        // Filter categories
37
-        $config = GridFieldConfig_RelationEditor::create();
38
-        if (class_exists('GridFieldAddExistingSearchButton')) {
39
-            $config->removeComponentsByType('GridFieldAddExistingAutocompleter');
40
-            $config->addComponent(new GridFieldAddExistingSearchButton());
41
-        }
42
-        $categories = $this->Categories();
43
-        $categoriesField = GridField::create('Categories', 'Categories', $categories, $config)
44
-            ->setDescription('only show locations from the selected category');
45
-
46
-            // Filter
47
-            $fields->addFieldsToTab('Root.Filter', array(
48
-                HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3),
49
-                $categoriesField,
50
-            ));
51
-
52
-        $this->extend('updateCMSFields', $fields);
53
-
54
-        return $fields;
55
-    }
56
-
57
-    public static function getLocations($filter = array(), $exclude = array(), $filterAny = array())
58
-    {
59
-        $filter['ShowInLocator'] = true;
60
-        $exclude['Lat'] = 0;
61
-
62
-        $Locations = Location::get()->exclude($exclude)->filter($filter)->filterAny($filterAny);
63
-
64
-        return $Locations;
65
-    }
66
-
67
-    public function getAreLocations()
68
-    {
69
-        return self::getLocations();
70
-    }
71
-
72
-    public function getAllCategories()
73
-    {
74
-        return LocationCategory::get();
75
-    }
76
-
77
-    public static function getPageCategories($id = null)
78
-    {
79
-        if ($id) {
80
-            if ($locator = self::get()->byID($id)) {
81
-                return $locator->Categories();
82
-            }
83
-
84
-            return false;
85
-        }
86
-
87
-        return false;
88
-    }
5
+	private static $db = array(
6
+		'AutoGeocode' => 'Boolean',
7
+		'ModalWindow' => 'Boolean',
8
+		'Unit' => 'Enum("m,km","m")',
9
+	);
10
+
11
+	private static $many_many = array(
12
+		'Categories' => 'LocationCategory',
13
+	);
14
+
15
+	private static $defaults = array(
16
+		'AutoGeocode' => true,
17
+	);
18
+
19
+	private static $singular_name = 'Locator';
20
+	private static $plural_name = 'Locators';
21
+	private static $description = 'Find locations on a map';
22
+
23
+	public function getCMSFields()
24
+	{
25
+		$fields = parent::getCMSFields();
26
+
27
+		// Settings
28
+		$fields->addFieldsToTab('Root.Settings', array(
29
+			HeaderField::create('DisplayOptions', 'Display Options', 3),
30
+			OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')),
31
+			CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location')
32
+				->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'),
33
+			CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'),
34
+		));
35
+
36
+		// Filter categories
37
+		$config = GridFieldConfig_RelationEditor::create();
38
+		if (class_exists('GridFieldAddExistingSearchButton')) {
39
+			$config->removeComponentsByType('GridFieldAddExistingAutocompleter');
40
+			$config->addComponent(new GridFieldAddExistingSearchButton());
41
+		}
42
+		$categories = $this->Categories();
43
+		$categoriesField = GridField::create('Categories', 'Categories', $categories, $config)
44
+			->setDescription('only show locations from the selected category');
45
+
46
+			// Filter
47
+			$fields->addFieldsToTab('Root.Filter', array(
48
+				HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3),
49
+				$categoriesField,
50
+			));
51
+
52
+		$this->extend('updateCMSFields', $fields);
53
+
54
+		return $fields;
55
+	}
56
+
57
+	public static function getLocations($filter = array(), $exclude = array(), $filterAny = array())
58
+	{
59
+		$filter['ShowInLocator'] = true;
60
+		$exclude['Lat'] = 0;
61
+
62
+		$Locations = Location::get()->exclude($exclude)->filter($filter)->filterAny($filterAny);
63
+
64
+		return $Locations;
65
+	}
66
+
67
+	public function getAreLocations()
68
+	{
69
+		return self::getLocations();
70
+	}
71
+
72
+	public function getAllCategories()
73
+	{
74
+		return LocationCategory::get();
75
+	}
76
+
77
+	public static function getPageCategories($id = null)
78
+	{
79
+		if ($id) {
80
+			if ($locator = self::get()->byID($id)) {
81
+				return $locator->Categories();
82
+			}
83
+
84
+			return false;
85
+		}
86
+
87
+		return false;
88
+	}
89 89
 }
90 90
 
91 91
 class Locator_Controller extends Page_Controller
92 92
 {
93
-    // allowed actions
94
-    private static $allowed_actions = array('xml');
93
+	// allowed actions
94
+	private static $allowed_actions = array('xml');
95 95
 
96
-    // Set Requirements based on input from CMS
97
-    public function init()
98
-    {
99
-        parent::init();
96
+	// Set Requirements based on input from CMS
97
+	public function init()
98
+	{
99
+		parent::init();
100 100
 
101
-        $themeDir = SSViewer::get_theme_folder();
101
+		$themeDir = SSViewer::get_theme_folder();
102 102
 
103
-        Requirements::javascript('framework/thirdparty/jquery/jquery.js');
104
-        if (Locator::getLocations()) {
105
-            Requirements::javascript('http://maps.google.com/maps/api/js?sensor=false');
106
-            Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
107
-            Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
108
-        }
103
+		Requirements::javascript('framework/thirdparty/jquery/jquery.js');
104
+		if (Locator::getLocations()) {
105
+			Requirements::javascript('http://maps.google.com/maps/api/js?sensor=false');
106
+			Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
107
+			Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
108
+		}
109 109
 
110
-        Requirements::css('locator/css/map.css');
110
+		Requirements::css('locator/css/map.css');
111 111
 
112
-        $featured = (Locator::getLocations(array('Featured' => 1))->count() > 0) ?
113
-            'featuredLocations: true' :
114
-            'featuredLocations: false';
112
+		$featured = (Locator::getLocations(array('Featured' => 1))->count() > 0) ?
113
+			'featuredLocations: true' :
114
+			'featuredLocations: false';
115 115
 
116
-        // map config based on user input in Settings tab
117
-        // AutoGeocode or Full Map
118
-        $load = ($this->data()->AutoGeocode) ?
119
-            'autoGeocode: true, fullMapStart: false,' :
120
-            'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
116
+		// map config based on user input in Settings tab
117
+		// AutoGeocode or Full Map
118
+		$load = ($this->data()->AutoGeocode) ?
119
+			'autoGeocode: true, fullMapStart: false,' :
120
+			'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
121 121
 
122
-        $base = Director::baseFolder();
123
-        $themePath = $base.'/'.$themeDir;
122
+		$base = Director::baseFolder();
123
+		$themePath = $base.'/'.$themeDir;
124 124
 
125
-        $listTemplatePath = (file_exists($themePath.'/templates/location-list-description.html')) ?
126
-            $themeDir.'/templates/location-list-description.html' :
127
-            'locator/templates/location-list-description.html';
128
-        $infowindowTemplatePath = (file_exists($themePath.'/templates/infowindow-description.html')) ?
129
-            $themeDir.'/templates/infowindow-description.html' :
130
-            'locator/templates/infowindow-description.html';
125
+		$listTemplatePath = (file_exists($themePath.'/templates/location-list-description.html')) ?
126
+			$themeDir.'/templates/location-list-description.html' :
127
+			'locator/templates/location-list-description.html';
128
+		$infowindowTemplatePath = (file_exists($themePath.'/templates/infowindow-description.html')) ?
129
+			$themeDir.'/templates/infowindow-description.html' :
130
+			'locator/templates/infowindow-description.html';
131 131
 
132
-        // in page or modal
133
-        $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';
132
+		// in page or modal
133
+		$modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';
134 134
 
135
-        $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"';
135
+		$kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"';
136 136
 
137
-        $link = $this->Link().'xml.xml';
137
+		$link = $this->Link().'xml.xml';
138 138
 
139
-        // init map
140
-        if (Locator::getLocations()) {
141
-            Requirements::customScript("
139
+		// init map
140
+		if (Locator::getLocations()) {
141
+			Requirements::customScript("
142 142
                 $(function($) {
143 143
                     $('#map-container').storeLocator({
144 144
                         ".$load."
@@ -159,73 +159,73 @@  discard block
 block discarded – undo
159 159
                     });
160 160
                 });
161 161
             ');
162
-        }
163
-    }
164
-
165
-    /**
166
-     * Find all locations for map.
167
-     *
168
-     * Will return a XML feed of all locations marked "show in locator".
169
-     *
170
-     * @return XML file
171
-     *
172
-     * @todo rename/refactor to allow for json/xml
173
-     * @todo allow $filter to run off of getVars key/val pair
174
-     */
175
-    public function xml(SS_HTTPRequest $request)
176
-    {
177
-        $filter = array();
178
-        $exclude = array();
179
-        $filterAny = array();
180
-
181
-        //if a category filter selected
182
-        if ($this->Categories()->exists()) {
183
-            $categories = $this->Categories();
184
-            foreach ($categories as $category) {
185
-                $filterAny['CategoryID'] = $category->ID;
186
-            }
187
-        }
188
-
189
-        $Locations = Locator::getLocations($filter, $exclude, $filterAny);
190
-
191
-        return $this->customise(array(
192
-            'Locations' => $Locations,
193
-        ))->renderWith('LocationXML');
194
-    }
195
-
196
-    /**
197
-     * LocationSearch form.
198
-     *
199
-     * Search form for locations, updates map and results list via AJAX
200
-     *
201
-     * @return Form
202
-     */
203
-    public function LocationSearch()
204
-    {
205
-        $fields = FieldList::create(
206
-            $address = TextField::create('address', '')
207
-        );
208
-        $address->setAttribute('placeholder', 'address or zip code');
209
-
210
-        $locatorCategories = Locator::getPageCategories($this->ID);
211
-
212
-        if (LocationCategory::get()->Count() > 0 && $locatorCategories && $locatorCategories->Count() != 1) {
213
-            $categories = LocationCategory::get();
214
-
215
-            if ($categories->count() > 0) {
216
-                $fields->push(
217
-                    DropdownField::create(
218
-                        'category',
219
-                        '',
220
-                        $categories->map('Title', 'Title')
221
-                    )->setEmptyString('Select Category'));
222
-            }
223
-        }
224
-
225
-        $actions = FieldList::create(
226
-            FormAction::create('', 'Search')
227
-        );
228
-
229
-        return Form::create($this, 'LocationSearch', $fields, $actions);
230
-    }
162
+		}
163
+	}
164
+
165
+	/**
166
+	 * Find all locations for map.
167
+	 *
168
+	 * Will return a XML feed of all locations marked "show in locator".
169
+	 *
170
+	 * @return XML file
171
+	 *
172
+	 * @todo rename/refactor to allow for json/xml
173
+	 * @todo allow $filter to run off of getVars key/val pair
174
+	 */
175
+	public function xml(SS_HTTPRequest $request)
176
+	{
177
+		$filter = array();
178
+		$exclude = array();
179
+		$filterAny = array();
180
+
181
+		//if a category filter selected
182
+		if ($this->Categories()->exists()) {
183
+			$categories = $this->Categories();
184
+			foreach ($categories as $category) {
185
+				$filterAny['CategoryID'] = $category->ID;
186
+			}
187
+		}
188
+
189
+		$Locations = Locator::getLocations($filter, $exclude, $filterAny);
190
+
191
+		return $this->customise(array(
192
+			'Locations' => $Locations,
193
+		))->renderWith('LocationXML');
194
+	}
195
+
196
+	/**
197
+	 * LocationSearch form.
198
+	 *
199
+	 * Search form for locations, updates map and results list via AJAX
200
+	 *
201
+	 * @return Form
202
+	 */
203
+	public function LocationSearch()
204
+	{
205
+		$fields = FieldList::create(
206
+			$address = TextField::create('address', '')
207
+		);
208
+		$address->setAttribute('placeholder', 'address or zip code');
209
+
210
+		$locatorCategories = Locator::getPageCategories($this->ID);
211
+
212
+		if (LocationCategory::get()->Count() > 0 && $locatorCategories && $locatorCategories->Count() != 1) {
213
+			$categories = LocationCategory::get();
214
+
215
+			if ($categories->count() > 0) {
216
+				$fields->push(
217
+					DropdownField::create(
218
+						'category',
219
+						'',
220
+						$categories->map('Title', 'Title')
221
+					)->setEmptyString('Select Category'));
222
+			}
223
+		}
224
+
225
+		$actions = FieldList::create(
226
+			FormAction::create('', 'Search')
227
+		);
228
+
229
+		return Form::create($this, 'LocationSearch', $fields, $actions);
230
+	}
231 231
 }
Please login to merge, or discard this patch.
code/LocationCategory.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -2,20 +2,20 @@
 block discarded – undo
2 2
 
3 3
 class LocationCategory extends DataObject
4 4
 {
5
-    private static $db = array(
6
-        'Name' => 'Varchar(100)',
7
-    );
5
+	private static $db = array(
6
+		'Name' => 'Varchar(100)',
7
+	);
8 8
 
9
-    private static $has_many = array(
10
-        'Locations' => 'Location',
11
-    );
9
+	private static $has_many = array(
10
+		'Locations' => 'Location',
11
+	);
12 12
 
13
-    private static $belogs_many_many = array(
14
-        'Locators' => 'Locator',
15
-    );
13
+	private static $belogs_many_many = array(
14
+		'Locators' => 'Locator',
15
+	);
16 16
 
17
-    private static $singular_name = 'Category';
18
-    private static $plural_name = 'Categories';
17
+	private static $singular_name = 'Category';
18
+	private static $plural_name = 'Categories';
19 19
 
20
-    private static $default_sort = 'Name';
20
+	private static $default_sort = 'Name';
21 21
 }
Please login to merge, or discard this patch.
tests/LocatorTest.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -2,68 +2,68 @@
 block discarded – undo
2 2
 
3 3
 class LocatorTest extends Locator_Test
4 4
 {
5
-    public function testGetCMSFields()
6
-    {
7
-        $object = new Locator();
8
-        $fieldset = $object->getCMSFields();
9
-        $this->assertTrue(is_a($fieldset, 'FieldList'));
10
-    }
5
+	public function testGetCMSFields()
6
+	{
7
+		$object = new Locator();
8
+		$fieldset = $object->getCMSFields();
9
+		$this->assertTrue(is_a($fieldset, 'FieldList'));
10
+	}
11 11
 
12
-    public function testGetLocations()
13
-    {
14
-        $locator = singleton('Locator');
15
-        $count = Location::get()->filter('ShowInLocator', 1)->exclude('Lat', 0)->Count();
16
-        $this->assertEquals($locator->getLocations()->Count(), $count);
17
-    }
12
+	public function testGetLocations()
13
+	{
14
+		$locator = singleton('Locator');
15
+		$count = Location::get()->filter('ShowInLocator', 1)->exclude('Lat', 0)->Count();
16
+		$this->assertEquals($locator->getLocations()->Count(), $count);
17
+	}
18 18
 
19
-    public function testGetAreLocations()
20
-    {
21
-        $locator = singleton('Locator');
22
-        $this->assertEquals($locator->getLocations(), $locator->getAreLocations());
23
-    }
19
+	public function testGetAreLocations()
20
+	{
21
+		$locator = singleton('Locator');
22
+		$this->assertEquals($locator->getLocations(), $locator->getAreLocations());
23
+	}
24 24
 
25
-    public function testGetAllCategories()
26
-    {
27
-        $locator = singleton('Locator');
28
-        $count = LocationCategory::get();
29
-        $this->assertEquals($locator->getAllCategories(), $count);
30
-    }
25
+	public function testGetAllCategories()
26
+	{
27
+		$locator = singleton('Locator');
28
+		$count = LocationCategory::get();
29
+		$this->assertEquals($locator->getAllCategories(), $count);
30
+	}
31 31
 
32
-    public function testGetPageCategories()
33
-    {
34
-        $locator = Locator::create();
35
-        $this->assertFalse($locator->getPageCategories());
32
+	public function testGetPageCategories()
33
+	{
34
+		$locator = Locator::create();
35
+		$this->assertFalse($locator->getPageCategories());
36 36
 
37
-        $this->assertFalse($locator->getPageCategories(500));
37
+		$this->assertFalse($locator->getPageCategories(500));
38 38
 
39
-        $locator->write();
40
-        $category = $this->objFromFixture('LocationCategory', 'service');
41
-        $locator->Categories()->add($category);
42
-        $this->assertEquals($locator->getPageCategories($locator->ID), $locator->Categories());
43
-    }
39
+		$locator->write();
40
+		$category = $this->objFromFixture('LocationCategory', 'service');
41
+		$locator->Categories()->add($category);
42
+		$this->assertEquals($locator->getPageCategories($locator->ID), $locator->Categories());
43
+	}
44 44
 
45
-    public function testInit()
46
-    {
47
-    }
45
+	public function testInit()
46
+	{
47
+	}
48 48
 
49
-    public function testXml()
50
-    {
51
-    }
49
+	public function testXml()
50
+	{
51
+	}
52 52
 
53
-    public function testLocationSearch()
54
-    {
55
-        $locator = $this->objFromFixture('Locator', 'locator1');
56
-        $object = Locator_Controller::create($locator);
57
-        $form = $object->LocationSearch();
58
-        $this->assertTrue(is_a($form, 'Form'));
53
+	public function testLocationSearch()
54
+	{
55
+		$locator = $this->objFromFixture('Locator', 'locator1');
56
+		$object = Locator_Controller::create($locator);
57
+		$form = $object->LocationSearch();
58
+		$this->assertTrue(is_a($form, 'Form'));
59 59
 
60
-        $category = $this->objFromFixture('LocationCategory', 'service');
61
-        $category2 = $this->objFromFixture('LocationCategory', 'manufacturing');
62
-        $locator->Categories()->add($category);
63
-        $locator->Categories()->add($category2);
60
+		$category = $this->objFromFixture('LocationCategory', 'service');
61
+		$category2 = $this->objFromFixture('LocationCategory', 'manufacturing');
62
+		$locator->Categories()->add($category);
63
+		$locator->Categories()->add($category2);
64 64
 
65
-        $form = $object->LocationSearch();
66
-        $fields = $form->Fields();
67
-        $this->assertNotNull($fields->fieldByName('category'));
68
-    }
65
+		$form = $object->LocationSearch();
66
+		$fields = $form->Fields();
67
+		$this->assertNotNull($fields->fieldByName('category'));
68
+	}
69 69
 }
Please login to merge, or discard this patch.