Completed
Pull Request — master (#88)
by Nic
04:59
created
code/Location.php 1 patch
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -2,173 +2,173 @@
 block discarded – undo
2 2
 
3 3
 class Location extends DataObject implements PermissionProvider
4 4
 {
5
-    private static $db = array(
6
-        'Title' => 'Varchar(255)',
7
-        'Featured' => 'Boolean',
8
-        'Website' => 'Varchar(255)',
9
-        'Phone' => 'Varchar(40)',
10
-        'Email' => 'Varchar(255)',
11
-        'EmailAddress' => 'Varchar(255)',
12
-        'ShowInLocator' => 'Boolean',
13
-    );
14
-
15
-    private static $has_one = array(
16
-        'Category' => 'LocationCategory',
17
-    );
18
-
19
-    private static $casting = array(
20
-        'distance' => 'Int',
21
-    );
22
-
23
-    private static $default_sort = 'Title';
24
-
25
-    private static $defaults = array(
26
-        'ShowInLocator' => true,
27
-    );
28
-
29
-    private static $singular_name = 'Location';
30
-    private static $plural_name = 'Locations';
31
-
32
-    // api access via Restful Server module
33
-    private static $api_access = true;
34
-
35
-    // search fields for Model Admin
36
-    private static $searchable_fields = array(
37
-        'Title',
38
-        'Address',
39
-        'Suburb',
40
-        'State',
41
-        'Postcode',
42
-        'Country',
43
-        'Website',
44
-        'Phone',
45
-        'Email',
46
-        'Category.ID',
47
-        'ShowInLocator',
48
-        'Featured',
49
-    );
50
-
51
-    // columns for grid field
52
-    private static $summary_fields = array(
53
-        'Title',
54
-        'Address',
55
-        'Suburb',
56
-        'State',
57
-        'Postcode',
58
-        'Country',
59
-        'Category.Name',
60
-        'ShowInLocator.NiceAsBoolean',
61
-        'Featured.NiceAsBoolean',
62
-        'Coords',
63
-    );
64
-
65
-    // Coords status for $summary_fields
66
-    public function getCoords()
67
-    {
68
-        return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false';
69
-    }
70
-
71
-    // custom labels for fields
72
-    public function fieldLabels($includerelations = true)
73
-    {
74
-        $labels = parent::fieldLabels();
75
-
76
-        $labels['Title'] = 'Name';
77
-        $labels['Suburb'] = 'City';
78
-        $labels['Postcode'] = 'Postal Code';
79
-        $labels['ShowInLocator'] = 'Show';
80
-        $labels['ShowInLocator.NiceAsBoolean'] = 'Show';
81
-        $labels['Category.Name'] = 'Category';
82
-        $labels['Category.ID'] = 'Category';
83
-        $labels['Email'] = 'Email';
84
-        $labels['Featured.NiceAsBoolean'] = 'Featured';
85
-        $labels['Coords'] = 'Coords';
86
-
87
-        return $labels;
88
-    }
89
-
90
-    public function getCMSFields()
91
-    {
92
-        $fields = FieldList::create(
93
-            new TabSet(
94
-                $name = 'Root',
95
-                new Tab(
96
-                    $title = 'Main',
97
-                    HeaderField::create('ContactHD', 'Contact Information'),
98
-                    TextField::create('Title', 'Name'),
99
-                    TextField::create('Phone'),
100
-                    EmailField::create('Email', 'Email'),
101
-                    TextField::create('Website')
102
-                        ->setAttribute('placeholder', 'http://'),
103
-                    DropDownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title'))
104
-                        ->setEmptyString('-- select --'),
105
-                    CheckboxField::create('ShowInLocator', 'Show in results')
106
-                        ->setDescription('Location will be included in results list'),
107
-                    CheckboxField::create('Featured')
108
-                        ->setDescription('Location will show at/near the top of the results list')
109
-                )
110
-            )
111
-        );
112
-
113
-        // allow to be extended via DataExtension
114
-        $this->extend('updateCMSFields', $fields);
115
-
116
-        // override Suburb field name
117
-        $fields->dataFieldByName('Suburb')->setTitle('City');
118
-
119
-        return $fields;
120
-    }
121
-
122
-    public function validate()
123
-    {
124
-        $result = parent::validate();
125
-
126
-        return $result;
127
-    }
128
-
129
-    public function EmailAddress()
130
-    {
131
-        Deprecation::notice('3.0', 'Use "$Email" instead.');
132
-        if ($this->Email) {
133
-            return $this->Email;
134
-        } elseif ($this->EmailAddress) {
135
-            return $this->EmailAddress;
136
-        }
137
-
138
-        return false;
139
-    }
140
-
141
-    /**
142
-     * @param Member $member
143
-     *
144
-     * @return bool
145
-     */
146
-    public function canView($member = false)
147
-    {
148
-        return true;
149
-    }
150
-
151
-    public function canEdit($member = false)
152
-    {
153
-        return Permission::check('Location_EDIT');
154
-    }
155
-
156
-    public function canDelete($member = false)
157
-    {
158
-        return Permission::check('Location_DELETE');
159
-    }
160
-
161
-    public function canCreate($member = false)
162
-    {
163
-        return Permission::check('Location_CREATE');
164
-    }
165
-
166
-    public function providePermissions()
167
-    {
168
-        return array(
169
-            'Location_EDIT' => 'Edit a Location',
170
-            'Location_DELETE' => 'Delete a Location',
171
-            'Location_CREATE' => 'Create a Location',
172
-        );
173
-    }
5
+	private static $db = array(
6
+		'Title' => 'Varchar(255)',
7
+		'Featured' => 'Boolean',
8
+		'Website' => 'Varchar(255)',
9
+		'Phone' => 'Varchar(40)',
10
+		'Email' => 'Varchar(255)',
11
+		'EmailAddress' => 'Varchar(255)',
12
+		'ShowInLocator' => 'Boolean',
13
+	);
14
+
15
+	private static $has_one = array(
16
+		'Category' => 'LocationCategory',
17
+	);
18
+
19
+	private static $casting = array(
20
+		'distance' => 'Int',
21
+	);
22
+
23
+	private static $default_sort = 'Title';
24
+
25
+	private static $defaults = array(
26
+		'ShowInLocator' => true,
27
+	);
28
+
29
+	private static $singular_name = 'Location';
30
+	private static $plural_name = 'Locations';
31
+
32
+	// api access via Restful Server module
33
+	private static $api_access = true;
34
+
35
+	// search fields for Model Admin
36
+	private static $searchable_fields = array(
37
+		'Title',
38
+		'Address',
39
+		'Suburb',
40
+		'State',
41
+		'Postcode',
42
+		'Country',
43
+		'Website',
44
+		'Phone',
45
+		'Email',
46
+		'Category.ID',
47
+		'ShowInLocator',
48
+		'Featured',
49
+	);
50
+
51
+	// columns for grid field
52
+	private static $summary_fields = array(
53
+		'Title',
54
+		'Address',
55
+		'Suburb',
56
+		'State',
57
+		'Postcode',
58
+		'Country',
59
+		'Category.Name',
60
+		'ShowInLocator.NiceAsBoolean',
61
+		'Featured.NiceAsBoolean',
62
+		'Coords',
63
+	);
64
+
65
+	// Coords status for $summary_fields
66
+	public function getCoords()
67
+	{
68
+		return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false';
69
+	}
70
+
71
+	// custom labels for fields
72
+	public function fieldLabels($includerelations = true)
73
+	{
74
+		$labels = parent::fieldLabels();
75
+
76
+		$labels['Title'] = 'Name';
77
+		$labels['Suburb'] = 'City';
78
+		$labels['Postcode'] = 'Postal Code';
79
+		$labels['ShowInLocator'] = 'Show';
80
+		$labels['ShowInLocator.NiceAsBoolean'] = 'Show';
81
+		$labels['Category.Name'] = 'Category';
82
+		$labels['Category.ID'] = 'Category';
83
+		$labels['Email'] = 'Email';
84
+		$labels['Featured.NiceAsBoolean'] = 'Featured';
85
+		$labels['Coords'] = 'Coords';
86
+
87
+		return $labels;
88
+	}
89
+
90
+	public function getCMSFields()
91
+	{
92
+		$fields = FieldList::create(
93
+			new TabSet(
94
+				$name = 'Root',
95
+				new Tab(
96
+					$title = 'Main',
97
+					HeaderField::create('ContactHD', 'Contact Information'),
98
+					TextField::create('Title', 'Name'),
99
+					TextField::create('Phone'),
100
+					EmailField::create('Email', 'Email'),
101
+					TextField::create('Website')
102
+						->setAttribute('placeholder', 'http://'),
103
+					DropDownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title'))
104
+						->setEmptyString('-- select --'),
105
+					CheckboxField::create('ShowInLocator', 'Show in results')
106
+						->setDescription('Location will be included in results list'),
107
+					CheckboxField::create('Featured')
108
+						->setDescription('Location will show at/near the top of the results list')
109
+				)
110
+			)
111
+		);
112
+
113
+		// allow to be extended via DataExtension
114
+		$this->extend('updateCMSFields', $fields);
115
+
116
+		// override Suburb field name
117
+		$fields->dataFieldByName('Suburb')->setTitle('City');
118
+
119
+		return $fields;
120
+	}
121
+
122
+	public function validate()
123
+	{
124
+		$result = parent::validate();
125
+
126
+		return $result;
127
+	}
128
+
129
+	public function EmailAddress()
130
+	{
131
+		Deprecation::notice('3.0', 'Use "$Email" instead.');
132
+		if ($this->Email) {
133
+			return $this->Email;
134
+		} elseif ($this->EmailAddress) {
135
+			return $this->EmailAddress;
136
+		}
137
+
138
+		return false;
139
+	}
140
+
141
+	/**
142
+	 * @param Member $member
143
+	 *
144
+	 * @return bool
145
+	 */
146
+	public function canView($member = false)
147
+	{
148
+		return true;
149
+	}
150
+
151
+	public function canEdit($member = false)
152
+	{
153
+		return Permission::check('Location_EDIT');
154
+	}
155
+
156
+	public function canDelete($member = false)
157
+	{
158
+		return Permission::check('Location_DELETE');
159
+	}
160
+
161
+	public function canCreate($member = false)
162
+	{
163
+		return Permission::check('Location_CREATE');
164
+	}
165
+
166
+	public function providePermissions()
167
+	{
168
+		return array(
169
+			'Location_EDIT' => 'Edit a Location',
170
+			'Location_DELETE' => 'Delete a Location',
171
+			'Location_CREATE' => 'Create a Location',
172
+		);
173
+	}
174 174
 }
Please login to merge, or discard this patch.
tests/LocatorTest.php 1 patch
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -2,88 +2,88 @@
 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 testLocations()
13
-    {
14
-        $filter = array('ShowInLocator' => 1);
15
-        $filterAny = array('Suburb' => 'Sheboygan');
16
-        $exclude = array('Suburb' => 'Milwaukee');
17
-        $locations = Locator::locations($filter, $filterAny, $exclude);
18
-        $locations2 = Location::get()->filter($filter)->filterAny($filterAny)->exclude($exclude);
19
-        $this->assertEquals($locations->Count(), $locations2->Count());
20
-    }
12
+	public function testLocations()
13
+	{
14
+		$filter = array('ShowInLocator' => 1);
15
+		$filterAny = array('Suburb' => 'Sheboygan');
16
+		$exclude = array('Suburb' => 'Milwaukee');
17
+		$locations = Locator::locations($filter, $filterAny, $exclude);
18
+		$locations2 = Location::get()->filter($filter)->filterAny($filterAny)->exclude($exclude);
19
+		$this->assertEquals($locations->Count(), $locations2->Count());
20
+	}
21 21
 
22
-    public function testGetAllCategories()
23
-    {
24
-        $locator = singleton('Locator');
25
-        $count = LocationCategory::get();
26
-        $this->assertEquals($locator->getAllCategories(), $count);
27
-    }
22
+	public function testGetAllCategories()
23
+	{
24
+		$locator = singleton('Locator');
25
+		$count = LocationCategory::get();
26
+		$this->assertEquals($locator->getAllCategories(), $count);
27
+	}
28 28
 
29
-    public function testGetPageCategories()
30
-    {
31
-        $locator = Locator::create();
32
-        $this->assertFalse($locator->getPageCategories());
29
+	public function testGetPageCategories()
30
+	{
31
+		$locator = Locator::create();
32
+		$this->assertFalse($locator->getPageCategories());
33 33
 
34
-        $this->assertFalse($locator->getPageCategories(500));
34
+		$this->assertFalse($locator->getPageCategories(500));
35 35
 
36
-        $locator->write();
37
-        $category = $this->objFromFixture('LocationCategory', 'service');
38
-        $locator->Categories()->add($category);
39
-        $this->assertEquals($locator->getPageCategories($locator->ID), $locator->Categories());
40
-    }
36
+		$locator->write();
37
+		$category = $this->objFromFixture('LocationCategory', 'service');
38
+		$locator->Categories()->add($category);
39
+		$this->assertEquals($locator->getPageCategories($locator->ID), $locator->Categories());
40
+	}
41 41
 
42
-    public function testInit()
43
-    {
44
-    }
42
+	public function testInit()
43
+	{
44
+	}
45 45
 
46
-    public function testIndex()
47
-    {
48
-        $locator = $this->objFromFixture('Locator', 'locator1');
49
-        $controller = Locator_Controller::create($locator);
50
-        $this->assertInstanceOf('ViewableData', $controller->index($controller->request));
51
-    }
46
+	public function testIndex()
47
+	{
48
+		$locator = $this->objFromFixture('Locator', 'locator1');
49
+		$controller = Locator_Controller::create($locator);
50
+		$this->assertInstanceOf('ViewableData', $controller->index($controller->request));
51
+	}
52 52
 
53
-    public function testXml()
54
-    {
55
-        $locator = $this->objFromFixture('Locator', 'locator1');
56
-        $controller = Locator_Controller::create($locator);
57
-        $this->assertInstanceOf('HTMLText', $controller->xml($controller->request));
58
-    }
53
+	public function testXml()
54
+	{
55
+		$locator = $this->objFromFixture('Locator', 'locator1');
56
+		$controller = Locator_Controller::create($locator);
57
+		$this->assertInstanceOf('HTMLText', $controller->xml($controller->request));
58
+	}
59 59
 
60
-    public function testItems()
61
-    {
62
-        $locator = $this->objFromFixture('Locator', 'locator1');
63
-        $controller = Locator_Controller::create($locator);
60
+	public function testItems()
61
+	{
62
+		$locator = $this->objFromFixture('Locator', 'locator1');
63
+		$controller = Locator_Controller::create($locator);
64 64
 
65
-        $filter = array('ShowInLocator' => 1);
66
-        $exclude = ['Lat' => 0.00000, 'Lng' => 0.00000];
65
+		$filter = array('ShowInLocator' => 1);
66
+		$exclude = ['Lat' => 0.00000, 'Lng' => 0.00000];
67 67
 
68
-        $locations = $controller->Items($controller->request);
69
-        $locations2 = Location::get()->filter($filter)->exclude($exclude);
70
-        $this->assertEquals($locations->count(), $locations2->count());
71
-    }
68
+		$locations = $controller->Items($controller->request);
69
+		$locations2 = Location::get()->filter($filter)->exclude($exclude);
70
+		$this->assertEquals($locations->count(), $locations2->count());
71
+	}
72 72
 
73
-    public function testLocationSearch()
74
-    {
75
-        $locator = $this->objFromFixture('Locator', 'locator1');
76
-        $object = Locator_Controller::create($locator);
77
-        $form = $object->LocationSearch();
78
-        $this->assertTrue(is_a($form, 'Form'));
73
+	public function testLocationSearch()
74
+	{
75
+		$locator = $this->objFromFixture('Locator', 'locator1');
76
+		$object = Locator_Controller::create($locator);
77
+		$form = $object->LocationSearch();
78
+		$this->assertTrue(is_a($form, 'Form'));
79 79
 
80
-        $category = $this->objFromFixture('LocationCategory', 'service');
81
-        $category2 = $this->objFromFixture('LocationCategory', 'manufacturing');
82
-        $locator->Categories()->add($category);
83
-        $locator->Categories()->add($category2);
80
+		$category = $this->objFromFixture('LocationCategory', 'service');
81
+		$category2 = $this->objFromFixture('LocationCategory', 'manufacturing');
82
+		$locator->Categories()->add($category);
83
+		$locator->Categories()->add($category2);
84 84
 
85
-        $form = $object->LocationSearch();
86
-        $fields = $form->Fields();
87
-        $this->assertNotNull($fields->fieldByName('CategoryID'));
88
-    }
85
+		$form = $object->LocationSearch();
86
+		$fields = $form->Fields();
87
+		$this->assertNotNull($fields->fieldByName('CategoryID'));
88
+	}
89 89
 }
Please login to merge, or discard this patch.
tests/LocationTest.php 2 patches
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -2,119 +2,119 @@
 block discarded – undo
2 2
 
3 3
 class LocationTest extends Locator_Test
4 4
 {
5
-    public function testGetCoords()
6
-    {
7
-        $location = $this->objFromFixture('Location', 'dynamic');
5
+	public function testGetCoords()
6
+	{
7
+		$location = $this->objFromFixture('Location', 'dynamic');
8 8
 
9
-        $coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false';
9
+		$coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false';
10 10
 
11
-        $this->assertEquals($coords, $location->getCoords());
12
-    }
11
+		$this->assertEquals($coords, $location->getCoords());
12
+	}
13 13
 
14
-    public function testFieldLabels()
15
-    {
16
-        $location = $this->objFromFixture('Location', 'dynamic');
17
-        $labels = $location->FieldLabels();
18
-        $expected = array(
19
-            'Title' => 'Name',
20
-            'Featured' => 'Featured',
21
-            'Website' => 'Website',
22
-            'Phone' => 'Phone',
23
-            'Email' => 'Email',
24
-            'EmailAddress' => 'Email Address',
25
-            'ShowInLocator' => 'Show',
26
-            'Address' => 'Address',
27
-            'Suburb' => 'City',
28
-            'State' => 'State',
29
-            'Postcode' => 'Postal Code',
30
-            'Country' => 'Country',
31
-            'Lat' => 'Lat',
32
-            'Lng' => 'Lng',
33
-            'Category' => 'Category',
34
-            'ShowInLocator.NiceAsBoolean' => 'Show',
35
-            'Category.Name' => 'Category',
36
-            'Category.ID' => 'Category',
37
-            'Featured.NiceAsBoolean' => 'Featured',
38
-            'Coords' => 'Coords',
39
-        );
40
-        $this->assertEquals($expected, $labels);
41
-    }
14
+	public function testFieldLabels()
15
+	{
16
+		$location = $this->objFromFixture('Location', 'dynamic');
17
+		$labels = $location->FieldLabels();
18
+		$expected = array(
19
+			'Title' => 'Name',
20
+			'Featured' => 'Featured',
21
+			'Website' => 'Website',
22
+			'Phone' => 'Phone',
23
+			'Email' => 'Email',
24
+			'EmailAddress' => 'Email Address',
25
+			'ShowInLocator' => 'Show',
26
+			'Address' => 'Address',
27
+			'Suburb' => 'City',
28
+			'State' => 'State',
29
+			'Postcode' => 'Postal Code',
30
+			'Country' => 'Country',
31
+			'Lat' => 'Lat',
32
+			'Lng' => 'Lng',
33
+			'Category' => 'Category',
34
+			'ShowInLocator.NiceAsBoolean' => 'Show',
35
+			'Category.Name' => 'Category',
36
+			'Category.ID' => 'Category',
37
+			'Featured.NiceAsBoolean' => 'Featured',
38
+			'Coords' => 'Coords',
39
+		);
40
+		$this->assertEquals($expected, $labels);
41
+	}
42 42
 
43
-    public function testGetCMSFields()
44
-    {
45
-        $object = new Location();
46
-        $fieldset = $object->getCMSFields();
47
-        $this->assertTrue(is_a($fieldset, 'FieldList'));
48
-    }
43
+	public function testGetCMSFields()
44
+	{
45
+		$object = new Location();
46
+		$fieldset = $object->getCMSFields();
47
+		$this->assertTrue(is_a($fieldset, 'FieldList'));
48
+	}
49 49
 
50
-    public function testValidate()
51
-    {
52
-    }
50
+	public function testValidate()
51
+	{
52
+	}
53 53
 
54
-    public function testEmailAddress()
55
-    {
56
-    }
54
+	public function testEmailAddress()
55
+	{
56
+	}
57 57
 
58
-    public function testCanView()
59
-    {
60
-        $object = $this->objFromFixture('Location', 'dynamic');
61
-        $object->write();
62
-        $this->logInWithPermission('ADMIN');
63
-        $this->assertTrue($object->canView());
64
-        $this->logOut();
65
-        $nullMember = Member::create();
66
-        $nullMember->write();
67
-        $this->assertTrue($object->canView($nullMember));
68
-        $nullMember->delete();
69
-    }
58
+	public function testCanView()
59
+	{
60
+		$object = $this->objFromFixture('Location', 'dynamic');
61
+		$object->write();
62
+		$this->logInWithPermission('ADMIN');
63
+		$this->assertTrue($object->canView());
64
+		$this->logOut();
65
+		$nullMember = Member::create();
66
+		$nullMember->write();
67
+		$this->assertTrue($object->canView($nullMember));
68
+		$nullMember->delete();
69
+	}
70 70
 
71
-    public function testCanEdit()
72
-    {
73
-        $object = $this->objFromFixture('Location', 'dynamic');
74
-        $object->write();
75
-        $objectID = $object->ID;
76
-        $this->logInWithPermission('Location_EDIT');
77
-        $originalTitle = $object->Title;
78
-        $this->assertEquals($originalTitle, 'Dynamic, Inc.');
79
-        $this->assertTrue($object->canEdit());
80
-        $object->Title = 'Changed Title';
81
-        $object->write();
82
-        $testEdit = Location::get()->byID($objectID);
83
-        $this->assertEquals($testEdit->Title, 'Changed Title');
84
-        $this->logOut();
85
-    }
71
+	public function testCanEdit()
72
+	{
73
+		$object = $this->objFromFixture('Location', 'dynamic');
74
+		$object->write();
75
+		$objectID = $object->ID;
76
+		$this->logInWithPermission('Location_EDIT');
77
+		$originalTitle = $object->Title;
78
+		$this->assertEquals($originalTitle, 'Dynamic, Inc.');
79
+		$this->assertTrue($object->canEdit());
80
+		$object->Title = 'Changed Title';
81
+		$object->write();
82
+		$testEdit = Location::get()->byID($objectID);
83
+		$this->assertEquals($testEdit->Title, 'Changed Title');
84
+		$this->logOut();
85
+	}
86 86
 
87
-    public function testCanDelete()
88
-    {
89
-        $object = $this->objFromFixture('Location', 'dynamic');
90
-        $object->write();
91
-        $this->logInWithPermission('Location_DELETE');
92
-        $this->assertTrue($object->canDelete());
93
-        $checkObject = $object;
94
-        $object->delete();
95
-        $this->assertEquals($checkObject->ID, 0);
96
-    }
87
+	public function testCanDelete()
88
+	{
89
+		$object = $this->objFromFixture('Location', 'dynamic');
90
+		$object->write();
91
+		$this->logInWithPermission('Location_DELETE');
92
+		$this->assertTrue($object->canDelete());
93
+		$checkObject = $object;
94
+		$object->delete();
95
+		$this->assertEquals($checkObject->ID, 0);
96
+	}
97 97
 
98
-    public function testCanCreate()
99
-    {
100
-        $object = singleton('Location');
101
-        $this->logInWithPermission('Location_CREATE');
102
-        $this->assertTrue($object->canCreate());
103
-        $this->logOut();
104
-        $nullMember = Member::create();
105
-        $nullMember->write();
106
-        $this->assertFalse($object->canCreate($nullMember));
107
-        $nullMember->delete();
108
-    }
98
+	public function testCanCreate()
99
+	{
100
+		$object = singleton('Location');
101
+		$this->logInWithPermission('Location_CREATE');
102
+		$this->assertTrue($object->canCreate());
103
+		$this->logOut();
104
+		$nullMember = Member::create();
105
+		$nullMember->write();
106
+		$this->assertFalse($object->canCreate($nullMember));
107
+		$nullMember->delete();
108
+	}
109 109
 
110
-    public function testProvidePermissions()
111
-    {
112
-        $object = Location::create();
113
-        $expected = array(
114
-            'Location_EDIT' => 'Edit a Location',
115
-            'Location_DELETE' => 'Delete a Location',
116
-            'Location_CREATE' => 'Create a Location',
117
-        );
118
-        $this->assertEquals($expected, $object->providePermissions());
119
-    }
110
+	public function testProvidePermissions()
111
+	{
112
+		$object = Location::create();
113
+		$expected = array(
114
+			'Location_EDIT' => 'Edit a Location',
115
+			'Location_DELETE' => 'Delete a Location',
116
+			'Location_CREATE' => 'Create a Location',
117
+		);
118
+		$this->assertEquals($expected, $object->providePermissions());
119
+	}
120 120
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
     {
7 7
         $location = $this->objFromFixture('Location', 'dynamic');
8 8
 
9
-        $coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false';
9
+        $coords = ((int) $location->Lat != 0 && (int) $location->Lng != 0) ? 'true' : 'false';
10 10
 
11 11
         $this->assertEquals($coords, $location->getCoords());
12 12
     }
Please login to merge, or discard this patch.
code/Locator.php 2 patches
Indentation   +324 added lines, -324 removed lines patch added patch discarded remove patch
@@ -2,208 +2,208 @@  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
-    /**
24
-     * @return FieldList
25
-     */
26
-    public function getCMSFields()
27
-    {
28
-        $fields = parent::getCMSFields();
29
-
30
-        // Settings
31
-        $fields->addFieldsToTab('Root.Settings', array(
32
-            HeaderField::create('DisplayOptions', 'Display Options', 3),
33
-            OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')),
34
-            CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location')
35
-                ->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'),
36
-            CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'),
37
-        ));
38
-
39
-        // Filter categories
40
-        $config = GridFieldConfig_RelationEditor::create();
41
-        if (class_exists('GridFieldAddExistingSearchButton')) {
42
-            $config->removeComponentsByType('GridFieldAddExistingAutocompleter');
43
-            $config->addComponent(new GridFieldAddExistingSearchButton());
44
-        }
45
-        $categories = $this->Categories();
46
-        $categoriesField = GridField::create('Categories', 'Categories', $categories, $config)
47
-            ->setDescription('only show locations from the selected category');
48
-
49
-        // Filter
50
-        $fields->addFieldsToTab('Root.Filter', array(
51
-            HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3),
52
-            $categoriesField,
53
-        ));
54
-
55
-        $this->extend('updateCMSFields', $fields);
56
-
57
-        return $fields;
58
-    }
59
-
60
-    /**
61
-     * @param array $filter
62
-     * @param array $filterAny
63
-     * @param array $exclude
64
-     * @param null $filterByCallback
65
-     * @return ArrayList
66
-     */
67
-    public static function locations(
68
-        $filter = array(),
69
-        $filterAny = array(),
70
-        $exclude = array(),
71
-        $filterByCallback = null
72
-    )
73
-    {
74
-        $locationsList = ArrayList::create();
75
-
76
-        // filter by ShowInLocator
77
-        $filter['ShowInLocator'] = 1;
78
-
79
-        $locations = Location::get()->filter($filter);
80
-
81
-        if (!empty($filterAny)) {
82
-            $locations = $locations->filterAny($filterAny);
83
-        }
84
-        if (!empty($exclude)) {
85
-            $locations = $locations->exclude($exclude);
86
-        }
87
-
88
-        if ($filterByCallback !== null && is_callable($filterByCallback)) {
89
-            $locations = $locations->filterByCallback($filterByCallback);
90
-        }
91
-
92
-        if ($locations->exists()) {
93
-            $locationsList->merge($locations);
94
-        }
95
-
96
-        return $locationsList;
97
-    }
98
-
99
-    /**
100
-     * @return DataList
101
-     */
102
-    public static function getAllCategories()
103
-    {
104
-        return LocationCategory::get();
105
-    }
106
-
107
-    /**
108
-     * @param null $id
109
-     * @return bool
110
-     */
111
-    public static function getPageCategories($id = null)
112
-    {
113
-        if ($id) {
114
-            if ($locator = self::get()->byID($id)) {
115
-                return $locator->Categories();
116
-            }
117
-
118
-            return false;
119
-        }
120
-
121
-        return false;
122
-    }
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
+	/**
24
+	 * @return FieldList
25
+	 */
26
+	public function getCMSFields()
27
+	{
28
+		$fields = parent::getCMSFields();
29
+
30
+		// Settings
31
+		$fields->addFieldsToTab('Root.Settings', array(
32
+			HeaderField::create('DisplayOptions', 'Display Options', 3),
33
+			OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')),
34
+			CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location')
35
+				->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'),
36
+			CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'),
37
+		));
38
+
39
+		// Filter categories
40
+		$config = GridFieldConfig_RelationEditor::create();
41
+		if (class_exists('GridFieldAddExistingSearchButton')) {
42
+			$config->removeComponentsByType('GridFieldAddExistingAutocompleter');
43
+			$config->addComponent(new GridFieldAddExistingSearchButton());
44
+		}
45
+		$categories = $this->Categories();
46
+		$categoriesField = GridField::create('Categories', 'Categories', $categories, $config)
47
+			->setDescription('only show locations from the selected category');
48
+
49
+		// Filter
50
+		$fields->addFieldsToTab('Root.Filter', array(
51
+			HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3),
52
+			$categoriesField,
53
+		));
54
+
55
+		$this->extend('updateCMSFields', $fields);
56
+
57
+		return $fields;
58
+	}
59
+
60
+	/**
61
+	 * @param array $filter
62
+	 * @param array $filterAny
63
+	 * @param array $exclude
64
+	 * @param null $filterByCallback
65
+	 * @return ArrayList
66
+	 */
67
+	public static function locations(
68
+		$filter = array(),
69
+		$filterAny = array(),
70
+		$exclude = array(),
71
+		$filterByCallback = null
72
+	)
73
+	{
74
+		$locationsList = ArrayList::create();
75
+
76
+		// filter by ShowInLocator
77
+		$filter['ShowInLocator'] = 1;
78
+
79
+		$locations = Location::get()->filter($filter);
80
+
81
+		if (!empty($filterAny)) {
82
+			$locations = $locations->filterAny($filterAny);
83
+		}
84
+		if (!empty($exclude)) {
85
+			$locations = $locations->exclude($exclude);
86
+		}
87
+
88
+		if ($filterByCallback !== null && is_callable($filterByCallback)) {
89
+			$locations = $locations->filterByCallback($filterByCallback);
90
+		}
91
+
92
+		if ($locations->exists()) {
93
+			$locationsList->merge($locations);
94
+		}
95
+
96
+		return $locationsList;
97
+	}
98
+
99
+	/**
100
+	 * @return DataList
101
+	 */
102
+	public static function getAllCategories()
103
+	{
104
+		return LocationCategory::get();
105
+	}
106
+
107
+	/**
108
+	 * @param null $id
109
+	 * @return bool
110
+	 */
111
+	public static function getPageCategories($id = null)
112
+	{
113
+		if ($id) {
114
+			if ($locator = self::get()->byID($id)) {
115
+				return $locator->Categories();
116
+			}
117
+
118
+			return false;
119
+		}
120
+
121
+		return false;
122
+	}
123 123
 
124 124
 
125 125
 }
126 126
 
127 127
 class Locator_Controller extends Page_Controller
128 128
 {
129
-    /**
130
-     * @var array
131
-     */
132
-    private static $allowed_actions = array(
133
-        'xml',
134
-    );
135
-
136
-    /**
137
-     * Set Requirements based on input from CMS
138
-     */
139
-    public function init()
140
-    {
141
-        parent::init();
142
-
143
-        $themeDir = SSViewer::get_theme_folder();
144
-
145
-        // google maps api key
146
-        $key = Config::inst()->get('GoogleGeocoding', 'google_api_key');
147
-
148
-        $locations = $this->Items($this->request);
149
-
150
-        Requirements::javascript('framework/thirdparty/jquery/jquery.js');
151
-        if ($locations) {
152
-            Requirements::javascript('http://maps.google.com/maps/api/js?key=' . $key);
153
-            Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
154
-            Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
155
-        }
156
-
157
-        Requirements::css('locator/css/map.css');
158
-
159
-        $featuredInList = ($locations->filter('Featured', true)->count() > 0);
160
-
161
-        $featured = $featuredInList
162
-            ? 'featuredLocations: true'
163
-            : 'featuredLocations: false';
164
-
165
-        // map config based on user input in Settings tab
166
-        // AutoGeocode or Full Map
167
-        if ($this->data()->AutoGeocode) {
168
-            $load = $featuredInList
169
-                ? 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'
170
-                : 'autoGeocode: true, fullMapStart: false,';
171
-        } else {
172
-            $load = 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
173
-        }
174
-
175
-        /*$load = ($this->data()->AutoGeocode) ?
129
+	/**
130
+	 * @var array
131
+	 */
132
+	private static $allowed_actions = array(
133
+		'xml',
134
+	);
135
+
136
+	/**
137
+	 * Set Requirements based on input from CMS
138
+	 */
139
+	public function init()
140
+	{
141
+		parent::init();
142
+
143
+		$themeDir = SSViewer::get_theme_folder();
144
+
145
+		// google maps api key
146
+		$key = Config::inst()->get('GoogleGeocoding', 'google_api_key');
147
+
148
+		$locations = $this->Items($this->request);
149
+
150
+		Requirements::javascript('framework/thirdparty/jquery/jquery.js');
151
+		if ($locations) {
152
+			Requirements::javascript('http://maps.google.com/maps/api/js?key=' . $key);
153
+			Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
154
+			Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
155
+		}
156
+
157
+		Requirements::css('locator/css/map.css');
158
+
159
+		$featuredInList = ($locations->filter('Featured', true)->count() > 0);
160
+
161
+		$featured = $featuredInList
162
+			? 'featuredLocations: true'
163
+			: 'featuredLocations: false';
164
+
165
+		// map config based on user input in Settings tab
166
+		// AutoGeocode or Full Map
167
+		if ($this->data()->AutoGeocode) {
168
+			$load = $featuredInList
169
+				? 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'
170
+				: 'autoGeocode: true, fullMapStart: false,';
171
+		} else {
172
+			$load = 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
173
+		}
174
+
175
+		/*$load = ($this->data()->AutoGeocode) ?
176 176
             'autoGeocode: true, fullMapStart: false,' :
177 177
             'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';*/
178 178
 
179
-        $base = Director::baseFolder();
180
-        $themePath = $base . '/' . $themeDir;
181
-
182
-        $listTemplatePath = (file_exists($themePath . '/templates/location-list-description.html')) ?
183
-            $themeDir . '/templates/location-list-description.html' :
184
-            'locator/templates/location-list-description.html';
185
-        $infowindowTemplatePath = (file_exists($themePath . '/templates/infowindow-description.html')) ?
186
-            $themeDir . '/templates/infowindow-description.html' :
187
-            'locator/templates/infowindow-description.html';
188
-
189
-        // in page or modal
190
-        $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';
191
-
192
-        $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"';
193
-
194
-        // pass GET variables to xml action
195
-        $vars = $this->request->getVars();
196
-        unset($vars['url']);
197
-        unset($vars['action_index']);
198
-        $url = '';
199
-        if (count($vars)) {
200
-            $url .= '?' . http_build_query($vars);
201
-        }
202
-        $link = $this->Link() . 'xml.xml' . $url;
203
-
204
-        // init map
205
-        if ($locations) {
206
-            Requirements::customScript("
179
+		$base = Director::baseFolder();
180
+		$themePath = $base . '/' . $themeDir;
181
+
182
+		$listTemplatePath = (file_exists($themePath . '/templates/location-list-description.html')) ?
183
+			$themeDir . '/templates/location-list-description.html' :
184
+			'locator/templates/location-list-description.html';
185
+		$infowindowTemplatePath = (file_exists($themePath . '/templates/infowindow-description.html')) ?
186
+			$themeDir . '/templates/infowindow-description.html' :
187
+			'locator/templates/infowindow-description.html';
188
+
189
+		// in page or modal
190
+		$modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';
191
+
192
+		$kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"';
193
+
194
+		// pass GET variables to xml action
195
+		$vars = $this->request->getVars();
196
+		unset($vars['url']);
197
+		unset($vars['action_index']);
198
+		$url = '';
199
+		if (count($vars)) {
200
+			$url .= '?' . http_build_query($vars);
201
+		}
202
+		$link = $this->Link() . 'xml.xml' . $url;
203
+
204
+		// init map
205
+		if ($locations) {
206
+			Requirements::customScript("
207 207
                 $(function($) {
208 208
                     $('#map-container').storeLocator({
209 209
                         " . $load . "
@@ -224,135 +224,135 @@  discard block
 block discarded – undo
224 224
                     });
225 225
                 });
226 226
             ');
227
-        }
228
-    }
229
-
230
-    /**
231
-     * @param SS_HTTPRequest $request
232
-     *
233
-     * @return ViewableData_Customised
234
-     */
235
-    public function index(SS_HTTPRequest $request)
236
-    {
237
-        $locations = $this->Items($request);
238
-
239
-        return $this->customise(array(
240
-            'Locations' => $locations,
241
-        ));
242
-    }
243
-
244
-    /**
245
-     * Return a XML feed of all locations marked "show in locator"
246
-     *
247
-     * @param SS_HTTPRequest $request
248
-     * @return HTMLText
249
-     */
250
-    public function xml(SS_HTTPRequest $request)
251
-    {
252
-        $locations = $this->Items($request);
253
-
254
-        return $this->customise(array(
255
-            'Locations' => $locations,
256
-        ))->renderWith('LocationXML');
257
-    }
258
-
259
-    /**
260
-     * @param SS_HTTPRequest $request
261
-     *
262
-     * @return ArrayList
263
-     */
264
-    public function Items(SS_HTTPRequest $request)
265
-    {
266
-        $request = ($request) ? $request : $this->request;
267
-
268
-        $filter = array();
269
-        $filterAny = array();
270
-        $exclude = ['Lat' => 0.00000, 'Lng' => 0.00000];
271
-
272
-        // only show locations marked as ShowInLocator
273
-        $filter['ShowInLocator'] = 1;
274
-
275
-        // search across all address related fields
276
-        $address = ($request->getVar('Address')) ? $request->getVar('Address') : false;
277
-        if ($address && $this->data()->AutoGeocode == 0) {
278
-            $filterAny['Address:PartialMatch'] = $address;
279
-            $filterAny['Suburb:PartialMatch'] = $address;
280
-            $filterAny['State:PartialMatch'] = $address;
281
-            $filterAny['Postcode:PartialMatch'] = $address;
282
-            $filterAny['Country:PartialMatch'] = $address;
283
-        } else {
284
-            unset($filter['Address']);
285
-        }
286
-
287
-        // search for category from form, else categories from Locator
288
-        $category = ($request->getVar('CategoryID')) ? $request->getVar('CategoryID') : false;
289
-        if ($category) {
290
-            $filter['CategoryID:ExactMatch'] = $category;
291
-        } elseif ($this->Categories()->exists()) {
292
-            $categories = $this->Categories();
293
-            $categoryArray = array();
294
-            foreach ($categories as $category) {
295
-                array_push($categoryArray, $category->ID);
296
-            }
297
-            $filter['CategoryID'] = $categoryArray;
298
-        }
299
-
300
-        $locations = Locator::locations($filter, $filterAny, $exclude);
301
-
302
-        return $locations;
303
-    }
304
-
305
-    /**
306
-     * LocationSearch form.
307
-     *
308
-     * Search form for locations, updates map and results list via AJAX
309
-     *
310
-     * @return Form
311
-     */
312
-    public function LocationSearch()
313
-    {
314
-        $fields = FieldList::create(
315
-            $address = TextField::create('Address', '')
316
-                ->setAttribute('placeholder', 'address or zip code')
317
-        );
318
-
319
-        $filterCategories = Locator::getPageCategories($this->ID);
320
-        $allCategories = Locator::getAllCategories();
321
-
322
-        if ($allCategories->Count() > 0) {
323
-            $categories = ArrayList::create();
324
-            if ($filterCategories->Count() > 0) {
325
-                if ($filterCategories->Count() != 1) {
326
-                    $categories = $filterCategories;
327
-                }
328
-            } else {
329
-                $categories = $allCategories;
330
-            }
331
-
332
-            if ($categories->count() > 0) {
333
-                $fields->push(
334
-                    DropdownField::create(
335
-                        'CategoryID',
336
-                        '',
337
-                        $categories->map()
338
-                    )->setEmptyString('All Categories'));
339
-            }
340
-        }
341
-
342
-        $actions = FieldList::create(
343
-            FormAction::create('index', 'Search')
344
-        );
345
-
346
-        if (class_exists('BootstrapForm')) {
347
-            $form = BootstrapForm::create($this, 'LocationSearch', $fields, $actions);
348
-        } else {
349
-            $form = Form::create($this, 'LocationSearch', $fields, $actions);
350
-        }
351
-
352
-        return $form
353
-            ->setFormMethod('GET')
354
-            ->setFormAction($this->Link())
355
-            ->disableSecurityToken()
356
-            ->loadDataFrom($this->request->getVars());
357
-    }
227
+		}
228
+	}
229
+
230
+	/**
231
+	 * @param SS_HTTPRequest $request
232
+	 *
233
+	 * @return ViewableData_Customised
234
+	 */
235
+	public function index(SS_HTTPRequest $request)
236
+	{
237
+		$locations = $this->Items($request);
238
+
239
+		return $this->customise(array(
240
+			'Locations' => $locations,
241
+		));
242
+	}
243
+
244
+	/**
245
+	 * Return a XML feed of all locations marked "show in locator"
246
+	 *
247
+	 * @param SS_HTTPRequest $request
248
+	 * @return HTMLText
249
+	 */
250
+	public function xml(SS_HTTPRequest $request)
251
+	{
252
+		$locations = $this->Items($request);
253
+
254
+		return $this->customise(array(
255
+			'Locations' => $locations,
256
+		))->renderWith('LocationXML');
257
+	}
258
+
259
+	/**
260
+	 * @param SS_HTTPRequest $request
261
+	 *
262
+	 * @return ArrayList
263
+	 */
264
+	public function Items(SS_HTTPRequest $request)
265
+	{
266
+		$request = ($request) ? $request : $this->request;
267
+
268
+		$filter = array();
269
+		$filterAny = array();
270
+		$exclude = ['Lat' => 0.00000, 'Lng' => 0.00000];
271
+
272
+		// only show locations marked as ShowInLocator
273
+		$filter['ShowInLocator'] = 1;
274
+
275
+		// search across all address related fields
276
+		$address = ($request->getVar('Address')) ? $request->getVar('Address') : false;
277
+		if ($address && $this->data()->AutoGeocode == 0) {
278
+			$filterAny['Address:PartialMatch'] = $address;
279
+			$filterAny['Suburb:PartialMatch'] = $address;
280
+			$filterAny['State:PartialMatch'] = $address;
281
+			$filterAny['Postcode:PartialMatch'] = $address;
282
+			$filterAny['Country:PartialMatch'] = $address;
283
+		} else {
284
+			unset($filter['Address']);
285
+		}
286
+
287
+		// search for category from form, else categories from Locator
288
+		$category = ($request->getVar('CategoryID')) ? $request->getVar('CategoryID') : false;
289
+		if ($category) {
290
+			$filter['CategoryID:ExactMatch'] = $category;
291
+		} elseif ($this->Categories()->exists()) {
292
+			$categories = $this->Categories();
293
+			$categoryArray = array();
294
+			foreach ($categories as $category) {
295
+				array_push($categoryArray, $category->ID);
296
+			}
297
+			$filter['CategoryID'] = $categoryArray;
298
+		}
299
+
300
+		$locations = Locator::locations($filter, $filterAny, $exclude);
301
+
302
+		return $locations;
303
+	}
304
+
305
+	/**
306
+	 * LocationSearch form.
307
+	 *
308
+	 * Search form for locations, updates map and results list via AJAX
309
+	 *
310
+	 * @return Form
311
+	 */
312
+	public function LocationSearch()
313
+	{
314
+		$fields = FieldList::create(
315
+			$address = TextField::create('Address', '')
316
+				->setAttribute('placeholder', 'address or zip code')
317
+		);
318
+
319
+		$filterCategories = Locator::getPageCategories($this->ID);
320
+		$allCategories = Locator::getAllCategories();
321
+
322
+		if ($allCategories->Count() > 0) {
323
+			$categories = ArrayList::create();
324
+			if ($filterCategories->Count() > 0) {
325
+				if ($filterCategories->Count() != 1) {
326
+					$categories = $filterCategories;
327
+				}
328
+			} else {
329
+				$categories = $allCategories;
330
+			}
331
+
332
+			if ($categories->count() > 0) {
333
+				$fields->push(
334
+					DropdownField::create(
335
+						'CategoryID',
336
+						'',
337
+						$categories->map()
338
+					)->setEmptyString('All Categories'));
339
+			}
340
+		}
341
+
342
+		$actions = FieldList::create(
343
+			FormAction::create('index', 'Search')
344
+		);
345
+
346
+		if (class_exists('BootstrapForm')) {
347
+			$form = BootstrapForm::create($this, 'LocationSearch', $fields, $actions);
348
+		} else {
349
+			$form = Form::create($this, 'LocationSearch', $fields, $actions);
350
+		}
351
+
352
+		return $form
353
+			->setFormMethod('GET')
354
+			->setFormAction($this->Link())
355
+			->disableSecurityToken()
356
+			->loadDataFrom($this->request->getVars());
357
+	}
358 358
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -17 removed lines patch added patch discarded remove patch
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 
150 150
         Requirements::javascript('framework/thirdparty/jquery/jquery.js');
151 151
         if ($locations) {
152
-            Requirements::javascript('http://maps.google.com/maps/api/js?key=' . $key);
152
+            Requirements::javascript('http://maps.google.com/maps/api/js?key='.$key);
153 153
             Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
154 154
             Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
155 155
         }
@@ -177,14 +177,12 @@  discard block
 block discarded – undo
177 177
             'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';*/
178 178
 
179 179
         $base = Director::baseFolder();
180
-        $themePath = $base . '/' . $themeDir;
180
+        $themePath = $base.'/'.$themeDir;
181 181
 
182
-        $listTemplatePath = (file_exists($themePath . '/templates/location-list-description.html')) ?
183
-            $themeDir . '/templates/location-list-description.html' :
184
-            'locator/templates/location-list-description.html';
185
-        $infowindowTemplatePath = (file_exists($themePath . '/templates/infowindow-description.html')) ?
186
-            $themeDir . '/templates/infowindow-description.html' :
187
-            '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';
188 186
 
189 187
         // in page or modal
190 188
         $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';
@@ -197,22 +195,22 @@  discard block
 block discarded – undo
197 195
         unset($vars['action_index']);
198 196
         $url = '';
199 197
         if (count($vars)) {
200
-            $url .= '?' . http_build_query($vars);
198
+            $url .= '?'.http_build_query($vars);
201 199
         }
202
-        $link = $this->Link() . 'xml.xml' . $url;
200
+        $link = $this->Link().'xml.xml'.$url;
203 201
 
204 202
         // init map
205 203
         if ($locations) {
206 204
             Requirements::customScript("
207 205
                 $(function($) {
208 206
                     $('#map-container').storeLocator({
209
-                        " . $load . "
210
-                        dataLocation: '" . $link . "',
211
-                        listTemplatePath: '" . $listTemplatePath . "',
212
-                        infowindowTemplatePath: '" . $infowindowTemplatePath . "',
207
+                        " . $load."
208
+                        dataLocation: '" . $link."',
209
+                        listTemplatePath: '" . $listTemplatePath."',
210
+                        infowindowTemplatePath: '" . $infowindowTemplatePath."',
213 211
                         originMarker: true,
214
-                        " . $modal . ',
215
-                        ' . $featured . ",
212
+                        " . $modal.',
213
+                        ' . $featured.",
216 214
                         slideMap: false,
217 215
                         zoomLevel: 0,
218 216
                         noForm: true,
@@ -220,7 +218,7 @@  discard block
 block discarded – undo
220 218
                         inputID: 'Form_LocationSearch_Address',
221 219
                         categoryID: 'Form_LocationSearch_category',
222 220
                         distanceAlert: -1,
223
-                        " . $kilometer . '
221
+                        " . $kilometer.'
224 222
                     });
225 223
                 });
226 224
             ');
Please login to merge, or discard this patch.