Completed
Push — master ( 5c8995...29ed75 )
by Jason
28s
created
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.
code/Locator.php 1 patch
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -2,141 +2,141 @@  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 = Locator::get()->byID($id)) {
81
-                return $locator->Categories();
82
-            }
83
-            return false;
84
-        }
85
-        return false;
86
-    }
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 = Locator::get()->byID($id)) {
81
+				return $locator->Categories();
82
+			}
83
+			return false;
84
+		}
85
+		return false;
86
+	}
87 87
 }
88 88
 
89 89
 class Locator_Controller extends Page_Controller
90 90
 {
91
-    // allowed actions
92
-    private static $allowed_actions = array('xml');
91
+	// allowed actions
92
+	private static $allowed_actions = array('xml');
93 93
 
94
-    // Set Requirements based on input from CMS
95
-    public function init()
96
-    {
97
-        parent::init();
94
+	// Set Requirements based on input from CMS
95
+	public function init()
96
+	{
97
+		parent::init();
98 98
 
99
-        $themeDir = SSViewer::get_theme_folder();
99
+		$themeDir = SSViewer::get_theme_folder();
100 100
 
101
-        Requirements::javascript('framework/thirdparty/jquery/jquery.js');
102
-        if (Locator::getLocations()) {
103
-            Requirements::javascript('http://maps.google.com/maps/api/js?sensor=false');
104
-            Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
105
-            Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
106
-        }
101
+		Requirements::javascript('framework/thirdparty/jquery/jquery.js');
102
+		if (Locator::getLocations()) {
103
+			Requirements::javascript('http://maps.google.com/maps/api/js?sensor=false');
104
+			Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
105
+			Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
106
+		}
107 107
 
108
-        Requirements::css('locator/css/map.css');
108
+		Requirements::css('locator/css/map.css');
109 109
 
110
-        $featured = (Locator::getLocations(array('Featured' => 1))->count() > 0) ?
111
-            'featuredLocations: true' :
112
-            'featuredLocations: false';
110
+		$featured = (Locator::getLocations(array('Featured' => 1))->count() > 0) ?
111
+			'featuredLocations: true' :
112
+			'featuredLocations: false';
113 113
 
114
-        // map config based on user input in Settings tab
115
-        // AutoGeocode or Full Map
116
-        $load = ($this->data()->AutoGeocode) ?
117
-            'autoGeocode: true, fullMapStart: false,' :
118
-            'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
114
+		// map config based on user input in Settings tab
115
+		// AutoGeocode or Full Map
116
+		$load = ($this->data()->AutoGeocode) ?
117
+			'autoGeocode: true, fullMapStart: false,' :
118
+			'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
119 119
 
120
-        $base = Director::baseFolder();
121
-        $themePath = $base.'/'.$themeDir;
120
+		$base = Director::baseFolder();
121
+		$themePath = $base.'/'.$themeDir;
122 122
 
123
-        $listTemplatePath = (file_exists($themePath.'/templates/location-list-description.html')) ?
124
-            $themeDir.'/templates/location-list-description.html' :
125
-            'locator/templates/location-list-description.html';
126
-        $infowindowTemplatePath = (file_exists($themePath.'/templates/infowindow-description.html')) ?
127
-            $themeDir.'/templates/infowindow-description.html' :
128
-            'locator/templates/infowindow-description.html';
123
+		$listTemplatePath = (file_exists($themePath.'/templates/location-list-description.html')) ?
124
+			$themeDir.'/templates/location-list-description.html' :
125
+			'locator/templates/location-list-description.html';
126
+		$infowindowTemplatePath = (file_exists($themePath.'/templates/infowindow-description.html')) ?
127
+			$themeDir.'/templates/infowindow-description.html' :
128
+			'locator/templates/infowindow-description.html';
129 129
 
130
-        // in page or modal
131
-        $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';
130
+		// in page or modal
131
+		$modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';
132 132
 
133
-        $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"';
133
+		$kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"';
134 134
 
135
-        $link = $this->Link().'xml.xml';
135
+		$link = $this->Link().'xml.xml';
136 136
 
137
-        // init map
138
-        if (Locator::getLocations()) {
139
-            Requirements::customScript("
137
+		// init map
138
+		if (Locator::getLocations()) {
139
+			Requirements::customScript("
140 140
                 $(function($) {
141 141
                     $('#map-container').storeLocator({
142 142
                         ".$load."
@@ -157,73 +157,73 @@  discard block
 block discarded – undo
157 157
                     });
158 158
                 });
159 159
             ');
160
-        }
161
-    }
162
-
163
-    /**
164
-     * Find all locations for map.
165
-     *
166
-     * Will return a XML feed of all locations marked "show in locator".
167
-     *
168
-     * @return XML file
169
-     *
170
-     * @todo rename/refactor to allow for json/xml
171
-     * @todo allow $filter to run off of getVars key/val pair
172
-     */
173
-    public function xml(SS_HTTPRequest $request)
174
-    {
175
-        $filter = array();
176
-        $exclude = array();
177
-        $filterAny = array();
178
-
179
-        //if a category filter selected
180
-        if ($this->Categories()->exists()) {
181
-            $categories = $this->Categories();
182
-            foreach ($categories as $category) {
183
-                $filterAny['CategoryID'] = $category->ID;
184
-            }
185
-        }
186
-
187
-        $Locations = Locator::getLocations($filter, $exclude, $filterAny);
188
-
189
-        return $this->customise(array(
190
-            'Locations' => $Locations,
191
-        ))->renderWith('LocationXML');
192
-    }
193
-
194
-    /**
195
-     * LocationSearch form.
196
-     *
197
-     * Search form for locations, updates map and results list via AJAX
198
-     *
199
-     * @return Form
200
-     */
201
-    public function LocationSearch()
202
-    {
203
-        $fields = FieldList::create(
204
-            $address = TextField::create('address', '')
205
-        );
206
-        $address->setAttribute('placeholder', 'address or zip code');
207
-
208
-        $locatorCategories = Locator::getPageCategories($this->ID);
209
-
210
-        if (LocationCategory::get()->Count() > 0 && $locatorCategories && $locatorCategories->Count() != 1) {
211
-            $categories = LocationCategory::get();
212
-
213
-            if ($categories->count() > 0) {
214
-                $fields->push(
215
-                    DropdownField::create(
216
-                        'category',
217
-                        '',
218
-                        $categories->map('Title', 'Title')
219
-                    )->setEmptyString('Select Category'));
220
-            }
221
-        }
222
-
223
-        $actions = FieldList::create(
224
-            FormAction::create('', 'Search')
225
-        );
226
-
227
-        return Form::create($this, 'LocationSearch', $fields, $actions);
228
-    }
160
+		}
161
+	}
162
+
163
+	/**
164
+	 * Find all locations for map.
165
+	 *
166
+	 * Will return a XML feed of all locations marked "show in locator".
167
+	 *
168
+	 * @return XML file
169
+	 *
170
+	 * @todo rename/refactor to allow for json/xml
171
+	 * @todo allow $filter to run off of getVars key/val pair
172
+	 */
173
+	public function xml(SS_HTTPRequest $request)
174
+	{
175
+		$filter = array();
176
+		$exclude = array();
177
+		$filterAny = array();
178
+
179
+		//if a category filter selected
180
+		if ($this->Categories()->exists()) {
181
+			$categories = $this->Categories();
182
+			foreach ($categories as $category) {
183
+				$filterAny['CategoryID'] = $category->ID;
184
+			}
185
+		}
186
+
187
+		$Locations = Locator::getLocations($filter, $exclude, $filterAny);
188
+
189
+		return $this->customise(array(
190
+			'Locations' => $Locations,
191
+		))->renderWith('LocationXML');
192
+	}
193
+
194
+	/**
195
+	 * LocationSearch form.
196
+	 *
197
+	 * Search form for locations, updates map and results list via AJAX
198
+	 *
199
+	 * @return Form
200
+	 */
201
+	public function LocationSearch()
202
+	{
203
+		$fields = FieldList::create(
204
+			$address = TextField::create('address', '')
205
+		);
206
+		$address->setAttribute('placeholder', 'address or zip code');
207
+
208
+		$locatorCategories = Locator::getPageCategories($this->ID);
209
+
210
+		if (LocationCategory::get()->Count() > 0 && $locatorCategories && $locatorCategories->Count() != 1) {
211
+			$categories = LocationCategory::get();
212
+
213
+			if ($categories->count() > 0) {
214
+				$fields->push(
215
+					DropdownField::create(
216
+						'category',
217
+						'',
218
+						$categories->map('Title', 'Title')
219
+					)->setEmptyString('Select Category'));
220
+			}
221
+		}
222
+
223
+		$actions = FieldList::create(
224
+			FormAction::create('', 'Search')
225
+		);
226
+
227
+		return Form::create($this, 'LocationSearch', $fields, $actions);
228
+	}
229 229
 }
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,69 +2,69 @@
 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'));
65
+		$form = $object->LocationSearch();
66
+		$fields = $form->Fields();
67
+		$this->assertNotNull($fields->fieldByName('category'));
68 68
         
69
-    }
69
+	}
70 70
 }
Please login to merge, or discard this patch.