Completed
Pull Request — master (#125)
by Nic
07:40
created
tests/LocationTest.php 2 patches
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.
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -6,184 +6,184 @@
 block discarded – undo
6 6
 class LocationTest extends SapphireTest
7 7
 {
8 8
 
9
-    /**
10
-     * @var string
11
-     */
12
-    protected static $fixture_file = 'locator/tests/Locator_Test.yml';
13
-
14
-    /**
15
-     *
16
-     */
17
-    public function testGetCoords()
18
-    {
19
-        $location = $this->objFromFixture('Location', 'dynamic');
20
-
21
-        $coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false';
22
-
23
-        $this->assertEquals($coords, $location->getCoords());
24
-    }
25
-
26
-    /**
27
-     *
28
-     */
29
-    public function testFieldLabels()
30
-    {
31
-        $location = $this->objFromFixture('Location', 'dynamic');
32
-        $labels = $location->FieldLabels();
33
-        $expected = array(
34
-            'Title' => 'Name',
35
-            'Featured' => 'Featured',
36
-            'Website' => 'Website',
37
-            'Phone' => 'Phone',
38
-            'Email' => 'Email',
39
-            'EmailAddress' => 'Email Address',
40
-            'ShowInLocator' => 'Show',
41
-            'Address' => 'Address',
42
-            'Suburb' => 'City',
43
-            'State' => 'State',
44
-            'Postcode' => 'Postal Code',
45
-            'Country' => 'Country',
46
-            'Lat' => 'Lat',
47
-            'Lng' => 'Lng',
48
-            'Category' => 'Category',
49
-            'ShowInLocator.NiceAsBoolean' => 'Show',
50
-            'Category.Name' => 'Category',
51
-            'Category.ID' => 'Category',
52
-            'Featured.NiceAsBoolean' => 'Featured',
53
-            'Coords' => 'Coords',
54
-            'Import_ID' => 'Import_ID',
55
-        );
56
-        $this->assertEquals($expected, $labels);
57
-    }
58
-
59
-    /**
60
-     *
61
-     */
62
-    public function testGetCMSFields()
63
-    {
64
-        $object = new Location();
65
-        $fieldset = $object->getCMSFields();
66
-        $this->assertTrue(is_a($fieldset, 'FieldList'));
67
-    }
68
-
69
-    /**
70
-     *
71
-     */
72
-    public function testValidate()
73
-    {
74
-    }
75
-
76
-    /**
77
-     *
78
-     */
79
-    public function testEmailAddress()
80
-    {
81
-    }
82
-
83
-    /**
84
-     *
85
-     */
86
-    public function testCanView()
87
-    {
88
-        $object = $this->objFromFixture('Location', 'dynamic');
89
-        $object->write();
90
-
91
-        $this->assertTrue($object->canView());
92
-
93
-        $nullMember = Member::create();
94
-        $nullMember->write();
95
-
96
-        $this->assertTrue($object->canView($nullMember));
97
-
98
-        $nullMember->delete();
99
-    }
100
-
101
-    /**
102
-     *
103
-     */
104
-    public function testCanEdit()
105
-    {
106
-        $object = $this->objFromFixture('Location', 'dynamic');
107
-        $object->write();
108
-
109
-        $objectID = $object->ID;
110
-
111
-        //test permissions per permission setting
112
-        $create = $this->objFromFixture('Member', 'locationcreate');
113
-        $edit = $this->objFromFixture('Member', 'locationedit');
114
-        $delete = $this->objFromFixture('Member', 'locationdelete');
115
-
116
-        $originalTitle = $object->Title;
117
-        $this->assertEquals($originalTitle, 'Dynamic, Inc.');
118
-
119
-        $this->assertTrue($object->canEdit($edit));
120
-        $this->assertFalse($object->canEdit($create));
121
-        $this->assertFalse($object->canEdit($delete));
122
-
123
-        $object->Title = 'Changed Title';
124
-        $object->write();
125
-
126
-        $testEdit = Location::get()->byID($objectID);
127
-        $this->assertEquals($testEdit->Title, 'Changed Title');
128
-    }
129
-
130
-    /**
131
-     *
132
-     */
133
-    public function testCanDelete()
134
-    {
135
-        $object = $this->objFromFixture('Location', 'dynamic');
136
-        $object->write();
137
-
138
-        //test permissions per permission setting
139
-        $create = $this->objFromFixture('Member', 'locationcreate');
140
-        $edit = $this->objFromFixture('Member', 'locationedit');
141
-        $delete = $this->objFromFixture('Member', 'locationdelete');
142
-
143
-        $this->assertTrue($object->canDelete($delete));
144
-        $this->assertFalse($object->canDelete($create));
145
-        $this->assertFalse($object->canDelete($edit));
146
-
147
-        $checkObject = $object;
148
-        $object->delete();
149
-
150
-        $this->assertEquals($checkObject->ID, 0);
151
-    }
152
-
153
-    /**
154
-     *
155
-     */
156
-    public function testCanCreate()
157
-    {
158
-        $object = singleton('Location');
159
-
160
-        //test permissions per permission setting
161
-        $create = $this->objFromFixture('Member', 'locationcreate');
162
-        $edit = $this->objFromFixture('Member', 'locationedit');
163
-        $delete = $this->objFromFixture('Member', 'locationdelete');
164
-
165
-        $this->assertTrue($object->canCreate($create));
166
-        $this->assertFalse($object->canCreate($edit));
167
-        $this->assertFalse($object->canCreate($delete));
168
-
169
-        $nullMember = Member::create();
170
-        $nullMember->write();
171
-        $this->assertFalse($object->canCreate($nullMember));
172
-
173
-        $nullMember->delete();
174
-    }
175
-
176
-    /**
177
-     *
178
-     */
179
-    public function testProvidePermissions()
180
-    {
181
-        $object = Location::create();
182
-        $expected = array(
183
-            'Location_EDIT' => 'Edit a Location',
184
-            'Location_DELETE' => 'Delete a Location',
185
-            'Location_CREATE' => 'Create a Location',
186
-        );
187
-        $this->assertEquals($expected, $object->providePermissions());
188
-    }
9
+	/**
10
+	 * @var string
11
+	 */
12
+	protected static $fixture_file = 'locator/tests/Locator_Test.yml';
13
+
14
+	/**
15
+	 *
16
+	 */
17
+	public function testGetCoords()
18
+	{
19
+		$location = $this->objFromFixture('Location', 'dynamic');
20
+
21
+		$coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false';
22
+
23
+		$this->assertEquals($coords, $location->getCoords());
24
+	}
25
+
26
+	/**
27
+	 *
28
+	 */
29
+	public function testFieldLabels()
30
+	{
31
+		$location = $this->objFromFixture('Location', 'dynamic');
32
+		$labels = $location->FieldLabels();
33
+		$expected = array(
34
+			'Title' => 'Name',
35
+			'Featured' => 'Featured',
36
+			'Website' => 'Website',
37
+			'Phone' => 'Phone',
38
+			'Email' => 'Email',
39
+			'EmailAddress' => 'Email Address',
40
+			'ShowInLocator' => 'Show',
41
+			'Address' => 'Address',
42
+			'Suburb' => 'City',
43
+			'State' => 'State',
44
+			'Postcode' => 'Postal Code',
45
+			'Country' => 'Country',
46
+			'Lat' => 'Lat',
47
+			'Lng' => 'Lng',
48
+			'Category' => 'Category',
49
+			'ShowInLocator.NiceAsBoolean' => 'Show',
50
+			'Category.Name' => 'Category',
51
+			'Category.ID' => 'Category',
52
+			'Featured.NiceAsBoolean' => 'Featured',
53
+			'Coords' => 'Coords',
54
+			'Import_ID' => 'Import_ID',
55
+		);
56
+		$this->assertEquals($expected, $labels);
57
+	}
58
+
59
+	/**
60
+	 *
61
+	 */
62
+	public function testGetCMSFields()
63
+	{
64
+		$object = new Location();
65
+		$fieldset = $object->getCMSFields();
66
+		$this->assertTrue(is_a($fieldset, 'FieldList'));
67
+	}
68
+
69
+	/**
70
+	 *
71
+	 */
72
+	public function testValidate()
73
+	{
74
+	}
75
+
76
+	/**
77
+	 *
78
+	 */
79
+	public function testEmailAddress()
80
+	{
81
+	}
82
+
83
+	/**
84
+	 *
85
+	 */
86
+	public function testCanView()
87
+	{
88
+		$object = $this->objFromFixture('Location', 'dynamic');
89
+		$object->write();
90
+
91
+		$this->assertTrue($object->canView());
92
+
93
+		$nullMember = Member::create();
94
+		$nullMember->write();
95
+
96
+		$this->assertTrue($object->canView($nullMember));
97
+
98
+		$nullMember->delete();
99
+	}
100
+
101
+	/**
102
+	 *
103
+	 */
104
+	public function testCanEdit()
105
+	{
106
+		$object = $this->objFromFixture('Location', 'dynamic');
107
+		$object->write();
108
+
109
+		$objectID = $object->ID;
110
+
111
+		//test permissions per permission setting
112
+		$create = $this->objFromFixture('Member', 'locationcreate');
113
+		$edit = $this->objFromFixture('Member', 'locationedit');
114
+		$delete = $this->objFromFixture('Member', 'locationdelete');
115
+
116
+		$originalTitle = $object->Title;
117
+		$this->assertEquals($originalTitle, 'Dynamic, Inc.');
118
+
119
+		$this->assertTrue($object->canEdit($edit));
120
+		$this->assertFalse($object->canEdit($create));
121
+		$this->assertFalse($object->canEdit($delete));
122
+
123
+		$object->Title = 'Changed Title';
124
+		$object->write();
125
+
126
+		$testEdit = Location::get()->byID($objectID);
127
+		$this->assertEquals($testEdit->Title, 'Changed Title');
128
+	}
129
+
130
+	/**
131
+	 *
132
+	 */
133
+	public function testCanDelete()
134
+	{
135
+		$object = $this->objFromFixture('Location', 'dynamic');
136
+		$object->write();
137
+
138
+		//test permissions per permission setting
139
+		$create = $this->objFromFixture('Member', 'locationcreate');
140
+		$edit = $this->objFromFixture('Member', 'locationedit');
141
+		$delete = $this->objFromFixture('Member', 'locationdelete');
142
+
143
+		$this->assertTrue($object->canDelete($delete));
144
+		$this->assertFalse($object->canDelete($create));
145
+		$this->assertFalse($object->canDelete($edit));
146
+
147
+		$checkObject = $object;
148
+		$object->delete();
149
+
150
+		$this->assertEquals($checkObject->ID, 0);
151
+	}
152
+
153
+	/**
154
+	 *
155
+	 */
156
+	public function testCanCreate()
157
+	{
158
+		$object = singleton('Location');
159
+
160
+		//test permissions per permission setting
161
+		$create = $this->objFromFixture('Member', 'locationcreate');
162
+		$edit = $this->objFromFixture('Member', 'locationedit');
163
+		$delete = $this->objFromFixture('Member', 'locationdelete');
164
+
165
+		$this->assertTrue($object->canCreate($create));
166
+		$this->assertFalse($object->canCreate($edit));
167
+		$this->assertFalse($object->canCreate($delete));
168
+
169
+		$nullMember = Member::create();
170
+		$nullMember->write();
171
+		$this->assertFalse($object->canCreate($nullMember));
172
+
173
+		$nullMember->delete();
174
+	}
175
+
176
+	/**
177
+	 *
178
+	 */
179
+	public function testProvidePermissions()
180
+	{
181
+		$object = Location::create();
182
+		$expected = array(
183
+			'Location_EDIT' => 'Edit a Location',
184
+			'Location_DELETE' => 'Delete a Location',
185
+			'Location_CREATE' => 'Create a Location',
186
+		);
187
+		$this->assertEquals($expected, $object->providePermissions());
188
+	}
189 189
 }
Please login to merge, or discard this patch.
tests/Locator_Test.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -6,45 +6,45 @@
 block discarded – undo
6 6
 class Locator_Test extends FunctionalTest
7 7
 {
8 8
 
9
-    /**
10
-     * @var string
11
-     */
12
-    protected static $fixture_file = 'locator/tests/Locator_Test.yml';
13
-    /**
14
-     * @var bool
15
-     */
16
-    protected static $disable_themes = true;
17
-    /**
18
-     * @var bool
19
-     */
20
-    protected static $use_draft_site = false;
9
+	/**
10
+	 * @var string
11
+	 */
12
+	protected static $fixture_file = 'locator/tests/Locator_Test.yml';
13
+	/**
14
+	 * @var bool
15
+	 */
16
+	protected static $disable_themes = true;
17
+	/**
18
+	 * @var bool
19
+	 */
20
+	protected static $use_draft_site = false;
21 21
 
22
-    /**
23
-     *
24
-     */
25
-    public function setUp()
26
-    {
27
-        parent::setUp();
22
+	/**
23
+	 *
24
+	 */
25
+	public function setUp()
26
+	{
27
+		parent::setUp();
28 28
 
29
-        ini_set('display_errors', 1);
30
-        ini_set('log_errors', 1);
31
-        error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
32
-    }
29
+		ini_set('display_errors', 1);
30
+		ini_set('log_errors', 1);
31
+		error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
32
+	}
33 33
 
34
-    /**
35
-     *
36
-     */
37
-    public function logOut()
38
-    {
39
-        $this->session()->clear('loggedInAs');
40
-        $this->session()->clear('logInWithPermission');
41
-    }
34
+	/**
35
+	 *
36
+	 */
37
+	public function logOut()
38
+	{
39
+		$this->session()->clear('loggedInAs');
40
+		$this->session()->clear('logInWithPermission');
41
+	}
42 42
 
43
-    /**
44
-     *
45
-     */
46
-    public function testLocator_Test()
47
-    {
48
-    }
43
+	/**
44
+	 *
45
+	 */
46
+	public function testLocator_Test()
47
+	{
48
+	}
49 49
 
50 50
 }
Please login to merge, or discard this patch.
code/objects/Location.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -189,7 +189,7 @@
 block discarded – undo
189 189
     }
190 190
 
191 191
     /**
192
-     * @return bool|string
192
+     * @return string|false
193 193
      */
194 194
     public function EmailAddress()
195 195
     {
Please login to merge, or discard this patch.
Indentation   +214 added lines, -214 removed lines patch added patch discarded remove patch
@@ -17,245 +17,245 @@
 block discarded – undo
17 17
 class Location extends DataObject implements PermissionProvider
18 18
 {
19 19
 
20
-    /**
21
-     * @var array
22
-     */
23
-    private static $db = array(
24
-        'Title' => 'Varchar(255)',
25
-        'Featured' => 'Boolean',
26
-        'Website' => 'Varchar(255)',
27
-        'Phone' => 'Varchar(40)',
28
-        'Email' => 'Varchar(255)',
29
-        'EmailAddress' => 'Varchar(255)',
30
-        'ShowInLocator' => 'Boolean',
31
-        'Import_ID' => 'Int',
32
-    );
20
+	/**
21
+	 * @var array
22
+	 */
23
+	private static $db = array(
24
+		'Title' => 'Varchar(255)',
25
+		'Featured' => 'Boolean',
26
+		'Website' => 'Varchar(255)',
27
+		'Phone' => 'Varchar(40)',
28
+		'Email' => 'Varchar(255)',
29
+		'EmailAddress' => 'Varchar(255)',
30
+		'ShowInLocator' => 'Boolean',
31
+		'Import_ID' => 'Int',
32
+	);
33 33
 
34
-    /**
35
-     * @var array
36
-     */
37
-    private static $has_one = array(
38
-        'Category' => 'LocationCategory',
39
-    );
34
+	/**
35
+	 * @var array
36
+	 */
37
+	private static $has_one = array(
38
+		'Category' => 'LocationCategory',
39
+	);
40 40
 
41
-    /**
42
-     * @var array
43
-     */
44
-    private static $casting = array(
45
-        'distance' => 'Decimal(9,3)',
46
-    );
41
+	/**
42
+	 * @var array
43
+	 */
44
+	private static $casting = array(
45
+		'distance' => 'Decimal(9,3)',
46
+	);
47 47
 
48
-    /**
49
-     * @var string
50
-     */
51
-    private static $default_sort = 'Title';
48
+	/**
49
+	 * @var string
50
+	 */
51
+	private static $default_sort = 'Title';
52 52
 
53
-    /**
54
-     * @var array
55
-     */
56
-    private static $defaults = array(
57
-        'ShowInLocator' => true,
58
-    );
53
+	/**
54
+	 * @var array
55
+	 */
56
+	private static $defaults = array(
57
+		'ShowInLocator' => true,
58
+	);
59 59
 
60
-    /**
61
-     * @var string
62
-     */
63
-    private static $singular_name = 'Location';
64
-    /**
65
-     * @var string
66
-     */
67
-    private static $plural_name = 'Locations';
60
+	/**
61
+	 * @var string
62
+	 */
63
+	private static $singular_name = 'Location';
64
+	/**
65
+	 * @var string
66
+	 */
67
+	private static $plural_name = 'Locations';
68 68
 
69
-    /**
70
-     * api access via Restful Server module
71
-     *
72
-     * @var bool
73
-     */
74
-    private static $api_access = true;
69
+	/**
70
+	 * api access via Restful Server module
71
+	 *
72
+	 * @var bool
73
+	 */
74
+	private static $api_access = true;
75 75
 
76
-    /**
77
-     * search fields for Model Admin
78
-     *
79
-     * @var array
80
-     */
81
-    private static $searchable_fields = array(
82
-        'Title',
83
-        'Address',
84
-        'Suburb',
85
-        'State',
86
-        'Postcode',
87
-        'Country',
88
-        'Website',
89
-        'Phone',
90
-        'Email',
91
-        'Category.ID',
92
-        'ShowInLocator',
93
-        'Featured',
94
-    );
76
+	/**
77
+	 * search fields for Model Admin
78
+	 *
79
+	 * @var array
80
+	 */
81
+	private static $searchable_fields = array(
82
+		'Title',
83
+		'Address',
84
+		'Suburb',
85
+		'State',
86
+		'Postcode',
87
+		'Country',
88
+		'Website',
89
+		'Phone',
90
+		'Email',
91
+		'Category.ID',
92
+		'ShowInLocator',
93
+		'Featured',
94
+	);
95 95
 
96
-    /**
97
-     * columns for grid field
98
-     *
99
-     * @var array
100
-     */
101
-    private static $summary_fields = array(
102
-        'Title',
103
-        'Address',
104
-        'Suburb',
105
-        'State',
106
-        'Postcode',
107
-        'Country',
108
-        'Category.Name',
109
-        'ShowInLocator.NiceAsBoolean',
110
-        'Featured.NiceAsBoolean',
111
-        'Coords',
112
-    );
96
+	/**
97
+	 * columns for grid field
98
+	 *
99
+	 * @var array
100
+	 */
101
+	private static $summary_fields = array(
102
+		'Title',
103
+		'Address',
104
+		'Suburb',
105
+		'State',
106
+		'Postcode',
107
+		'Country',
108
+		'Category.Name',
109
+		'ShowInLocator.NiceAsBoolean',
110
+		'Featured.NiceAsBoolean',
111
+		'Coords',
112
+	);
113 113
 
114
-    /**
115
-     * Coords status for $summary_fields
116
-     *
117
-     * @return string
118
-     */
119
-    public function getCoords()
120
-    {
121
-        return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false';
122
-    }
114
+	/**
115
+	 * Coords status for $summary_fields
116
+	 *
117
+	 * @return string
118
+	 */
119
+	public function getCoords()
120
+	{
121
+		return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false';
122
+	}
123 123
 
124
-    /**
125
-     * custom labels for fields
126
-     *
127
-     * @param bool $includerelations
128
-     * @return array|string
129
-     */
130
-    public function fieldLabels($includerelations = true)
131
-    {
132
-        $labels = parent::fieldLabels($includerelations);
124
+	/**
125
+	 * custom labels for fields
126
+	 *
127
+	 * @param bool $includerelations
128
+	 * @return array|string
129
+	 */
130
+	public function fieldLabels($includerelations = true)
131
+	{
132
+		$labels = parent::fieldLabels($includerelations);
133 133
 
134
-        $labels['Title'] = 'Name';
135
-        $labels['Suburb'] = 'City';
136
-        $labels['Postcode'] = 'Postal Code';
137
-        $labels['ShowInLocator'] = 'Show';
138
-        $labels['ShowInLocator.NiceAsBoolean'] = 'Show';
139
-        $labels['Category.Name'] = 'Category';
140
-        $labels['Category.ID'] = 'Category';
141
-        $labels['Email'] = 'Email';
142
-        $labels['Featured.NiceAsBoolean'] = 'Featured';
143
-        $labels['Coords'] = 'Coords';
134
+		$labels['Title'] = 'Name';
135
+		$labels['Suburb'] = 'City';
136
+		$labels['Postcode'] = 'Postal Code';
137
+		$labels['ShowInLocator'] = 'Show';
138
+		$labels['ShowInLocator.NiceAsBoolean'] = 'Show';
139
+		$labels['Category.Name'] = 'Category';
140
+		$labels['Category.ID'] = 'Category';
141
+		$labels['Email'] = 'Email';
142
+		$labels['Featured.NiceAsBoolean'] = 'Featured';
143
+		$labels['Coords'] = 'Coords';
144 144
 
145
-        return $labels;
146
-    }
145
+		return $labels;
146
+	}
147 147
 
148
-    /**
149
-     * @return FieldList
150
-     */
151
-    public function getCMSFields()
152
-    {
153
-        $fields = FieldList::create(
154
-            new TabSet(
155
-                $name = 'Root',
156
-                new Tab(
157
-                    $title = 'Main',
158
-                    HeaderField::create('ContactHD', 'Contact Information'),
159
-                    TextField::create('Title', 'Name'),
160
-                    TextField::create('Phone'),
161
-                    EmailField::create('Email', 'Email'),
162
-                    TextField::create('Website')
163
-                        ->setAttribute('placeholder', 'http://'),
164
-                    DropdownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title'))
165
-                        ->setEmptyString('-- select --'),
166
-                    CheckboxField::create('ShowInLocator', 'Show in results')
167
-                        ->setDescription('Location will be included in results list'),
168
-                    CheckboxField::create('Featured')
169
-                        ->setDescription('Location will show at/near the top of the results list')
170
-                )
171
-            )
172
-        );
148
+	/**
149
+	 * @return FieldList
150
+	 */
151
+	public function getCMSFields()
152
+	{
153
+		$fields = FieldList::create(
154
+			new TabSet(
155
+				$name = 'Root',
156
+				new Tab(
157
+					$title = 'Main',
158
+					HeaderField::create('ContactHD', 'Contact Information'),
159
+					TextField::create('Title', 'Name'),
160
+					TextField::create('Phone'),
161
+					EmailField::create('Email', 'Email'),
162
+					TextField::create('Website')
163
+						->setAttribute('placeholder', 'http://'),
164
+					DropdownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title'))
165
+						->setEmptyString('-- select --'),
166
+					CheckboxField::create('ShowInLocator', 'Show in results')
167
+						->setDescription('Location will be included in results list'),
168
+					CheckboxField::create('Featured')
169
+						->setDescription('Location will show at/near the top of the results list')
170
+				)
171
+			)
172
+		);
173 173
 
174
-        // allow to be extended via DataExtension
175
-        $this->extend('updateCMSFields', $fields);
174
+		// allow to be extended via DataExtension
175
+		$this->extend('updateCMSFields', $fields);
176 176
 
177
-        // override Suburb field name
178
-        $fields->dataFieldByName('Suburb')->setTitle('City');
177
+		// override Suburb field name
178
+		$fields->dataFieldByName('Suburb')->setTitle('City');
179 179
 
180
-        $fields->removeByName(array(
181
-            'Import_ID',
182
-        ));
180
+		$fields->removeByName(array(
181
+			'Import_ID',
182
+		));
183 183
 
184
-        return $fields;
185
-    }
184
+		return $fields;
185
+	}
186 186
 
187
-    /**
188
-     * @return ValidationResult
189
-     */
190
-    public function validate()
191
-    {
192
-        $result = parent::validate();
187
+	/**
188
+	 * @return ValidationResult
189
+	 */
190
+	public function validate()
191
+	{
192
+		$result = parent::validate();
193 193
 
194
-        return $result;
195
-    }
194
+		return $result;
195
+	}
196 196
 
197
-    /**
198
-     * @return bool|string
199
-     */
200
-    public function EmailAddress()
201
-    {
202
-        Deprecation::notice('3.0', 'Use "$Email" instead.');
203
-        if ($this->Email) {
204
-            return $this->Email;
205
-        } elseif ($this->EmailAddress) {
206
-            return $this->EmailAddress;
207
-        }
197
+	/**
198
+	 * @return bool|string
199
+	 */
200
+	public function EmailAddress()
201
+	{
202
+		Deprecation::notice('3.0', 'Use "$Email" instead.');
203
+		if ($this->Email) {
204
+			return $this->Email;
205
+		} elseif ($this->EmailAddress) {
206
+			return $this->EmailAddress;
207
+		}
208 208
 
209
-        return false;
210
-    }
209
+		return false;
210
+	}
211 211
 
212
-    /**
213
-     * @param null|Member $member
214
-     *
215
-     * @return bool
216
-     */
217
-    public function canView($member = null)
218
-    {
219
-        return true;
220
-    }
212
+	/**
213
+	 * @param null|Member $member
214
+	 *
215
+	 * @return bool
216
+	 */
217
+	public function canView($member = null)
218
+	{
219
+		return true;
220
+	}
221 221
 
222
-    /**
223
-     * @param null|Member $member
224
-     * @return bool|int
225
-     */
226
-    public function canEdit($member = null)
227
-    {
228
-        return Permission::check('Location_EDIT', 'any', $member);
229
-    }
222
+	/**
223
+	 * @param null|Member $member
224
+	 * @return bool|int
225
+	 */
226
+	public function canEdit($member = null)
227
+	{
228
+		return Permission::check('Location_EDIT', 'any', $member);
229
+	}
230 230
 
231
-    /**
232
-     * @param null|Member $member
233
-     * @return bool|int
234
-     */
235
-    public function canDelete($member = null)
236
-    {
237
-        return Permission::check('Location_DELETE', 'any', $member);
238
-    }
231
+	/**
232
+	 * @param null|Member $member
233
+	 * @return bool|int
234
+	 */
235
+	public function canDelete($member = null)
236
+	{
237
+		return Permission::check('Location_DELETE', 'any', $member);
238
+	}
239 239
 
240
-    /**
241
-     * @param null|Member $member
242
-     * @return bool|int
243
-     */
244
-    public function canCreate($member = null)
245
-    {
246
-        return Permission::check('Location_CREATE', 'any', $member);
247
-    }
240
+	/**
241
+	 * @param null|Member $member
242
+	 * @return bool|int
243
+	 */
244
+	public function canCreate($member = null)
245
+	{
246
+		return Permission::check('Location_CREATE', 'any', $member);
247
+	}
248 248
 
249
-    /**
250
-     * @return array
251
-     */
252
-    public function providePermissions()
253
-    {
254
-        return array(
255
-            'Location_EDIT' => 'Edit a Location',
256
-            'Location_DELETE' => 'Delete a Location',
257
-            'Location_CREATE' => 'Create a Location',
258
-        );
259
-    }
249
+	/**
250
+	 * @return array
251
+	 */
252
+	public function providePermissions()
253
+	{
254
+		return array(
255
+			'Location_EDIT' => 'Edit a Location',
256
+			'Location_DELETE' => 'Delete a Location',
257
+			'Location_CREATE' => 'Create a Location',
258
+		);
259
+	}
260 260
 
261 261
 }
Please login to merge, or discard this patch.
code/objects/LocationCategory.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -10,39 +10,39 @@
 block discarded – undo
10 10
 class LocationCategory extends DataObject
11 11
 {
12 12
 
13
-    /**
14
-     * @var array
15
-     */
16
-    private static $db = array(
17
-        'Name' => 'Varchar(100)',
18
-    );
13
+	/**
14
+	 * @var array
15
+	 */
16
+	private static $db = array(
17
+		'Name' => 'Varchar(100)',
18
+	);
19 19
 
20
-    /**
21
-     * @var array
22
-     */
23
-    private static $has_many = array(
24
-        'Locations' => 'Location',
25
-    );
20
+	/**
21
+	 * @var array
22
+	 */
23
+	private static $has_many = array(
24
+		'Locations' => 'Location',
25
+	);
26 26
 
27
-    /**
28
-     * @var array
29
-     */
30
-    private static $belogs_many_many = array(
31
-        'Locators' => 'Locator',
32
-    );
27
+	/**
28
+	 * @var array
29
+	 */
30
+	private static $belogs_many_many = array(
31
+		'Locators' => 'Locator',
32
+	);
33 33
 
34
-    /**
35
-     * @var string
36
-     */
37
-    private static $singular_name = 'Category';
38
-    /**
39
-     * @var string
40
-     */
41
-    private static $plural_name = 'Categories';
34
+	/**
35
+	 * @var string
36
+	 */
37
+	private static $singular_name = 'Category';
38
+	/**
39
+	 * @var string
40
+	 */
41
+	private static $plural_name = 'Categories';
42 42
 
43
-    /**
44
-     * @var string
45
-     */
46
-    private static $default_sort = 'Name';
43
+	/**
44
+	 * @var string
45
+	 */
46
+	private static $default_sort = 'Name';
47 47
 
48 48
 }
Please login to merge, or discard this patch.
code/admin/LocationAdmin.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -6,56 +6,56 @@
 block discarded – undo
6 6
 class LocationAdmin extends ModelAdmin
7 7
 {
8 8
 
9
-    /**
10
-     * @var array
11
-     */
12
-    private static $managed_models = array(
13
-        'Location',
14
-        'LocationCategory',
15
-    );
9
+	/**
10
+	 * @var array
11
+	 */
12
+	private static $managed_models = array(
13
+		'Location',
14
+		'LocationCategory',
15
+	);
16 16
 
17
-    /**
18
-     * @var array
19
-     */
20
-    private static $model_importers = array(
21
-        'Location' => 'LocationCsvBulkLoader',
22
-        'LocationCategory' => 'CsvBulkLoader',
23
-    );
17
+	/**
18
+	 * @var array
19
+	 */
20
+	private static $model_importers = array(
21
+		'Location' => 'LocationCsvBulkLoader',
22
+		'LocationCategory' => 'CsvBulkLoader',
23
+	);
24 24
 
25
-    /**
26
-     * @var string
27
-     */
28
-    private static $menu_title = 'Locator';
29
-    /**
30
-     * @var string
31
-     */
32
-    private static $url_segment = 'locator';
25
+	/**
26
+	 * @var string
27
+	 */
28
+	private static $menu_title = 'Locator';
29
+	/**
30
+	 * @var string
31
+	 */
32
+	private static $url_segment = 'locator';
33 33
 
34
-    /**
35
-     * @return array
36
-     */
37
-    public function getExportFields()
38
-    {
39
-        if ($this->modelClass == 'Location') {
40
-            return array(
41
-                'Title' => 'Name',
42
-                'Address' => 'Address',
43
-                'Suburb' => 'City',
44
-                'State' => 'State',
45
-                'Postcode' => 'Postcode',
46
-                'Country' => 'Country',
47
-                'Website' => 'Website',
48
-                'Phone' => 'Phone',
49
-                'Fax' => 'Fax',
50
-                'Email' => 'Email',
51
-                'Category.Name' => 'Category',
52
-                'ShowInLocator' => 'ShowInLocator',
53
-                'Featured' => 'Featured',
54
-                'Lat' => 'Lat',
55
-                'Lng' => 'Lng',
56
-            );
57
-        }
34
+	/**
35
+	 * @return array
36
+	 */
37
+	public function getExportFields()
38
+	{
39
+		if ($this->modelClass == 'Location') {
40
+			return array(
41
+				'Title' => 'Name',
42
+				'Address' => 'Address',
43
+				'Suburb' => 'City',
44
+				'State' => 'State',
45
+				'Postcode' => 'Postcode',
46
+				'Country' => 'Country',
47
+				'Website' => 'Website',
48
+				'Phone' => 'Phone',
49
+				'Fax' => 'Fax',
50
+				'Email' => 'Email',
51
+				'Category.Name' => 'Category',
52
+				'ShowInLocator' => 'ShowInLocator',
53
+				'Featured' => 'Featured',
54
+				'Lat' => 'Lat',
55
+				'Lng' => 'Lng',
56
+			);
57
+		}
58 58
 
59
-        return parent::getExportFields();
60
-    }
59
+		return parent::getExportFields();
60
+	}
61 61
 }
Please login to merge, or discard this patch.
code/pages/Locator.php 3 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
         if ($locations) {
209 209
 
210 210
             Requirements::javascript('framework/thirdparty/jquery/jquery.js');
211
-            Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key);
211
+            Requirements::javascript('https://maps.google.com/maps/api/js?key='.$key);
212 212
             Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
213 213
             Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
214 214
             Requirements::css('locator/css/map.css');
@@ -245,27 +245,27 @@  discard block
 block discarded – undo
245 245
             unset($vars['action_doFilterLocations']);
246 246
             $url = '';
247 247
             if (count($vars)) {
248
-                $url .= '?' . http_build_query($vars);
248
+                $url .= '?'.http_build_query($vars);
249 249
             }
250
-            $link = $this->Link() . 'xml.xml' . $url;
250
+            $link = $this->Link().'xml.xml'.$url;
251 251
 
252 252
             // init map
253 253
             Requirements::customScript("
254 254
                 $(function(){
255 255
                     $('#map-container').storeLocator({
256
-                        " . $load . "
257
-                        dataLocation: '" . $link . "',
258
-                        listTemplatePath: '" . $listTemplatePath . "',
259
-                        infowindowTemplatePath: '" . $infowindowTemplatePath . "',
256
+                        " . $load."
257
+                        dataLocation: '" . $link."',
258
+                        listTemplatePath: '" . $listTemplatePath."',
259
+                        infowindowTemplatePath: '" . $infowindowTemplatePath."',
260 260
                         originMarker: true,
261
-                        " . $modal . ',
262
-                        ' . $featured . ",
261
+                        " . $modal.',
262
+                        ' . $featured.",
263 263
                         slideMap: false,
264 264
                         zoomLevel: 0,
265 265
                         noForm: true,
266 266
                         distanceAlert: -1,
267
-                        " . $kilometer . ',
268
-                        ' . $defaultCoords . '
267
+                        " . $kilometer.',
268
+                        ' . $defaultCoords.'
269 269
                     });
270 270
                 });
271 271
             ');
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@
 block discarded – undo
89 89
      * @param array $filterAny
90 90
      * @param array $exclude
91 91
      * @param null|callable $callback
92
-     * @return DataList|ArrayList
92
+     * @return DataList
93 93
      */
94 94
     public static function get_locations(
95 95
         $filter = [],
Please login to merge, or discard this patch.
Indentation   +371 added lines, -371 removed lines patch added patch discarded remove patch
@@ -11,143 +11,143 @@  discard block
 block discarded – undo
11 11
 class Locator extends Page
12 12
 {
13 13
 
14
-    /**
15
-     * @var array
16
-     */
17
-    private static $db = array(
18
-        'AutoGeocode' => 'Boolean',
19
-        'ModalWindow' => 'Boolean',
20
-        'Unit' => 'Enum("m,km","m")',
21
-    );
22
-
23
-    /**
24
-     * @var array
25
-     */
26
-    private static $many_many = array(
27
-        'Categories' => 'LocationCategory',
28
-    );
29
-
30
-    /**
31
-     * @var array
32
-     */
33
-    private static $defaults = array(
34
-        'AutoGeocode' => true,
35
-    );
36
-
37
-    /**
38
-     * @var string
39
-     */
40
-    private static $singular_name = 'Locator';
41
-    /**
42
-     * @var string
43
-     */
44
-    private static $plural_name = 'Locators';
45
-    /**
46
-     * @var string
47
-     */
48
-    private static $description = 'Find locations on a map';
49
-
50
-    /**
51
-     * @var string
52
-     */
53
-    private static $location_class = 'Location';
54
-
55
-    /**
56
-     * @return FieldList
57
-     */
58
-    public function getCMSFields()
59
-    {
60
-        $fields = parent::getCMSFields();
61
-
62
-        // Settings
63
-        $fields->addFieldsToTab('Root.Settings', array(
64
-            HeaderField::create('DisplayOptions', 'Display Options', 3),
65
-            OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')),
66
-            CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location')
67
-                ->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'),
68
-            CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'),
69
-        ));
70
-
71
-        // Filter categories
72
-        $config = GridFieldConfig_RelationEditor::create();
73
-        if (class_exists('GridFieldAddExistingSearchButton')) {
74
-            $config->removeComponentsByType('GridFieldAddExistingAutocompleter');
75
-            $config->addComponent(new GridFieldAddExistingSearchButton());
76
-        }
77
-        $categories = $this->Categories();
78
-        $categoriesField = GridField::create('Categories', 'Categories', $categories, $config)
79
-            ->setDescription('only show locations from the selected category');
80
-
81
-        // Filter
82
-        $fields->addFieldsToTab('Root.Filter', array(
83
-            HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3),
84
-            $categoriesField,
85
-        ));
86
-
87
-        $this->extend('updateCMSFields', $fields);
88
-
89
-        return $fields;
90
-    }
91
-
92
-    /**
93
-     * @param array $filter
94
-     * @param array $filterAny
95
-     * @param array $exclude
96
-     * @param null|callable $callback
97
-     * @return DataList|ArrayList
98
-     */
99
-    public static function get_locations(
100
-        $filter = [],
101
-        $filterAny = [],
102
-        $exclude = [],
103
-        $callback = null
104
-    )
105
-    {
106
-        $locationClass = Config::inst()->get('Locator', 'location_class');
107
-        $locations = $locationClass::get()->filter($filter)->exclude($exclude);
108
-
109
-        if (!empty($filterAny)) {
110
-            $locations = $locations->filterAny($filterAny);
111
-        }
112
-        if (!empty($exclude)) {
113
-            $locations = $locations->exclude($exclude);
114
-        }
115
-
116
-        if ($callback !== null && is_callable($callback)) {
117
-            $locations->filterByCallback($callback);
118
-        }
119
-
120
-        return $locations;
121
-    }
122
-
123
-    /**
124
-     * @return DataList
125
-     */
126
-    public static function get_all_categories()
127
-    {
128
-        return LocationCategory::get();
129
-    }
130
-
131
-    /**
132
-     * @return bool
133
-     */
134
-    public function getPageCategories()
135
-    {
136
-        return self::locator_categories_by_locator($this->ID);
137
-    }
138
-
139
-    /**
140
-     * @param int $id
141
-     * @return bool|
142
-     */
143
-    public static function locator_categories_by_locator($id = 0)
144
-    {
145
-        if ($id == 0) {
146
-            return false;
147
-        }
148
-
149
-        return Locator::get()->byID($id)->Categories();
150
-    }
14
+	/**
15
+	 * @var array
16
+	 */
17
+	private static $db = array(
18
+		'AutoGeocode' => 'Boolean',
19
+		'ModalWindow' => 'Boolean',
20
+		'Unit' => 'Enum("m,km","m")',
21
+	);
22
+
23
+	/**
24
+	 * @var array
25
+	 */
26
+	private static $many_many = array(
27
+		'Categories' => 'LocationCategory',
28
+	);
29
+
30
+	/**
31
+	 * @var array
32
+	 */
33
+	private static $defaults = array(
34
+		'AutoGeocode' => true,
35
+	);
36
+
37
+	/**
38
+	 * @var string
39
+	 */
40
+	private static $singular_name = 'Locator';
41
+	/**
42
+	 * @var string
43
+	 */
44
+	private static $plural_name = 'Locators';
45
+	/**
46
+	 * @var string
47
+	 */
48
+	private static $description = 'Find locations on a map';
49
+
50
+	/**
51
+	 * @var string
52
+	 */
53
+	private static $location_class = 'Location';
54
+
55
+	/**
56
+	 * @return FieldList
57
+	 */
58
+	public function getCMSFields()
59
+	{
60
+		$fields = parent::getCMSFields();
61
+
62
+		// Settings
63
+		$fields->addFieldsToTab('Root.Settings', array(
64
+			HeaderField::create('DisplayOptions', 'Display Options', 3),
65
+			OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')),
66
+			CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location')
67
+				->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'),
68
+			CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'),
69
+		));
70
+
71
+		// Filter categories
72
+		$config = GridFieldConfig_RelationEditor::create();
73
+		if (class_exists('GridFieldAddExistingSearchButton')) {
74
+			$config->removeComponentsByType('GridFieldAddExistingAutocompleter');
75
+			$config->addComponent(new GridFieldAddExistingSearchButton());
76
+		}
77
+		$categories = $this->Categories();
78
+		$categoriesField = GridField::create('Categories', 'Categories', $categories, $config)
79
+			->setDescription('only show locations from the selected category');
80
+
81
+		// Filter
82
+		$fields->addFieldsToTab('Root.Filter', array(
83
+			HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3),
84
+			$categoriesField,
85
+		));
86
+
87
+		$this->extend('updateCMSFields', $fields);
88
+
89
+		return $fields;
90
+	}
91
+
92
+	/**
93
+	 * @param array $filter
94
+	 * @param array $filterAny
95
+	 * @param array $exclude
96
+	 * @param null|callable $callback
97
+	 * @return DataList|ArrayList
98
+	 */
99
+	public static function get_locations(
100
+		$filter = [],
101
+		$filterAny = [],
102
+		$exclude = [],
103
+		$callback = null
104
+	)
105
+	{
106
+		$locationClass = Config::inst()->get('Locator', 'location_class');
107
+		$locations = $locationClass::get()->filter($filter)->exclude($exclude);
108
+
109
+		if (!empty($filterAny)) {
110
+			$locations = $locations->filterAny($filterAny);
111
+		}
112
+		if (!empty($exclude)) {
113
+			$locations = $locations->exclude($exclude);
114
+		}
115
+
116
+		if ($callback !== null && is_callable($callback)) {
117
+			$locations->filterByCallback($callback);
118
+		}
119
+
120
+		return $locations;
121
+	}
122
+
123
+	/**
124
+	 * @return DataList
125
+	 */
126
+	public static function get_all_categories()
127
+	{
128
+		return LocationCategory::get();
129
+	}
130
+
131
+	/**
132
+	 * @return bool
133
+	 */
134
+	public function getPageCategories()
135
+	{
136
+		return self::locator_categories_by_locator($this->ID);
137
+	}
138
+
139
+	/**
140
+	 * @param int $id
141
+	 * @return bool|
142
+	 */
143
+	public static function locator_categories_by_locator($id = 0)
144
+	{
145
+		if ($id == 0) {
146
+			return false;
147
+		}
148
+
149
+		return Locator::get()->byID($id)->Categories();
150
+	}
151 151
 
152 152
 
153 153
 }
@@ -157,111 +157,111 @@  discard block
 block discarded – undo
157 157
  */
158 158
 class Locator_Controller extends Page_Controller
159 159
 {
160
-    /**
161
-     * @var array
162
-     */
163
-    private static $allowed_actions = array(
164
-        'xml',
165
-    );
166
-
167
-    /**
168
-     * @var array
169
-     */
170
-    private static $base_filter = [
171
-        'ShowInLocator' => true,
172
-    ];
173
-
174
-    /**
175
-     * @var array
176
-     */
177
-    private static $base_exclude = [
178
-        'Lat' => 0,
179
-        'Lng' => 0,
180
-    ];
181
-
182
-    /**
183
-     * @var array
184
-     */
185
-    private static $base_filter_any = [];
186
-
187
-    /**
188
-     * @var string
189
-     */
190
-    private static $list_template_path = 'locator/templates/location-list-description.html';
191
-
192
-    /**
193
-     * @var string
194
-     */
195
-    private static $info_window_template_path = 'locator/templates/infowindow-description.html';
196
-
197
-    /**
198
-     * @var bool
199
-     */
200
-    private static $bootstrapify = true;
201
-
202
-    /**
203
-     * @var DataList|ArrayList
204
-     */
205
-    protected $locations;
206
-
207
-    /**
208
-     * Set Requirements based on input from CMS
209
-     */
210
-    public function init()
211
-    {
212
-        parent::init();
213
-
214
-        // google maps api key
215
-        $key = Config::inst()->get('GoogleGeocoding', 'google_api_key');
216
-
217
-        $locations = $this->getLocations();
218
-
219
-        if ($locations) {
220
-
221
-            Requirements::css('locator/css/map.css');
222
-            Requirements::javascript('framework/thirdparty/jquery/jquery.js');
223
-            Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key);
224
-            Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
225
-            Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
226
-
227
-            $featuredInList = ($locations->filter('Featured', true)->count() > 0);
228
-            $defaultCoords = $this->getAddressSearchCoords() ? $this->getAddressSearchCoords() : '';
229
-            $isChrome = (strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE);
230
-
231
-            $featured = $featuredInList
232
-                ? 'featuredLocations: true'
233
-                : 'featuredLocations: false';
234
-
235
-            // map config based on user input in Settings tab
236
-            // AutoGeocode or Full Map
237
-            if ($this->data()->AutoGeocode) {
238
-                $load = $featuredInList || $defaultCoords != '' || $isChrome
239
-                    ? 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'
240
-                    : 'autoGeocode: true, fullMapStart: false,';
241
-            } else {
242
-                $load = 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
243
-            }
244
-
245
-            $listTemplatePath = $this->config()->get('list_template_path');
246
-            $infowindowTemplatePath = $this->config()->get('info_window_template_path');
247
-
248
-            // in page or modal
249
-            $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';
250
-
251
-            $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"';
252
-
253
-            // pass GET variables to xml action
254
-            $vars = $this->request->getVars();
255
-            unset($vars['url']);
256
-            unset($vars['action_doFilterLocations']);
257
-            $url = '';
258
-            if (count($vars)) {
259
-                $url .= '?' . http_build_query($vars);
260
-            }
261
-            $link = $this->Link() . 'xml.xml' . $url;
262
-
263
-            // init map
264
-            Requirements::customScript("
160
+	/**
161
+	 * @var array
162
+	 */
163
+	private static $allowed_actions = array(
164
+		'xml',
165
+	);
166
+
167
+	/**
168
+	 * @var array
169
+	 */
170
+	private static $base_filter = [
171
+		'ShowInLocator' => true,
172
+	];
173
+
174
+	/**
175
+	 * @var array
176
+	 */
177
+	private static $base_exclude = [
178
+		'Lat' => 0,
179
+		'Lng' => 0,
180
+	];
181
+
182
+	/**
183
+	 * @var array
184
+	 */
185
+	private static $base_filter_any = [];
186
+
187
+	/**
188
+	 * @var string
189
+	 */
190
+	private static $list_template_path = 'locator/templates/location-list-description.html';
191
+
192
+	/**
193
+	 * @var string
194
+	 */
195
+	private static $info_window_template_path = 'locator/templates/infowindow-description.html';
196
+
197
+	/**
198
+	 * @var bool
199
+	 */
200
+	private static $bootstrapify = true;
201
+
202
+	/**
203
+	 * @var DataList|ArrayList
204
+	 */
205
+	protected $locations;
206
+
207
+	/**
208
+	 * Set Requirements based on input from CMS
209
+	 */
210
+	public function init()
211
+	{
212
+		parent::init();
213
+
214
+		// google maps api key
215
+		$key = Config::inst()->get('GoogleGeocoding', 'google_api_key');
216
+
217
+		$locations = $this->getLocations();
218
+
219
+		if ($locations) {
220
+
221
+			Requirements::css('locator/css/map.css');
222
+			Requirements::javascript('framework/thirdparty/jquery/jquery.js');
223
+			Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key);
224
+			Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
225
+			Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
226
+
227
+			$featuredInList = ($locations->filter('Featured', true)->count() > 0);
228
+			$defaultCoords = $this->getAddressSearchCoords() ? $this->getAddressSearchCoords() : '';
229
+			$isChrome = (strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE);
230
+
231
+			$featured = $featuredInList
232
+				? 'featuredLocations: true'
233
+				: 'featuredLocations: false';
234
+
235
+			// map config based on user input in Settings tab
236
+			// AutoGeocode or Full Map
237
+			if ($this->data()->AutoGeocode) {
238
+				$load = $featuredInList || $defaultCoords != '' || $isChrome
239
+					? 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'
240
+					: 'autoGeocode: true, fullMapStart: false,';
241
+			} else {
242
+				$load = 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
243
+			}
244
+
245
+			$listTemplatePath = $this->config()->get('list_template_path');
246
+			$infowindowTemplatePath = $this->config()->get('info_window_template_path');
247
+
248
+			// in page or modal
249
+			$modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';
250
+
251
+			$kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"';
252
+
253
+			// pass GET variables to xml action
254
+			$vars = $this->request->getVars();
255
+			unset($vars['url']);
256
+			unset($vars['action_doFilterLocations']);
257
+			$url = '';
258
+			if (count($vars)) {
259
+				$url .= '?' . http_build_query($vars);
260
+			}
261
+			$link = $this->Link() . 'xml.xml' . $url;
262
+
263
+			// init map
264
+			Requirements::customScript("
265 265
                 $(function(){
266 266
                     $('#map-container').storeLocator({
267 267
                         " . $load . "
@@ -280,134 +280,134 @@  discard block
 block discarded – undo
280 280
                     });
281 281
                 });
282 282
             ');
283
-        }
284
-    }
285
-
286
-    /**
287
-     * @param SS_HTTPRequest $request
288
-     *
289
-     * @return ViewableData_Customised
290
-     */
291
-    public function index(SS_HTTPRequest $request)
292
-    {
293
-        $locations = $this->getLocations();
294
-
295
-        return $this->customise(array(
296
-            'Locations' => $locations,
297
-        ));
298
-    }
299
-
300
-    /**
301
-     * Return a XML feed of all locations marked "show in locator"
302
-     *
303
-     * @param SS_HTTPRequest $request
304
-     * @return HTMLText
305
-     */
306
-    public function xml(SS_HTTPRequest $request)
307
-    {
308
-        $locations = $this->getLocations();
309
-
310
-        return $this->customise(array(
311
-            'Locations' => $locations,
312
-        ))->renderWith('LocationXML');
313
-    }
314
-
315
-    /**
316
-     * @return ArrayList|DataList
317
-     */
318
-    public function getLocations()
319
-    {
320
-        if (!$this->locations) {
321
-            $this->setLocations($this->request);
322
-        }
323
-        return $this->locations;
324
-    }
325
-
326
-    /**
327
-     * @param SS_HTTPRequest|null $request
328
-     * @return $this
329
-     */
330
-    public function setLocations(SS_HTTPRequest $request = null)
331
-    {
332
-
333
-        if ($request === null) {
334
-            $request = $this->request;
335
-        }
336
-        $filter = $this->config()->get('base_filter');
337
-
338
-        if ($request->getVar('CategoryID')) {
339
-            $filter['CategoryID'] = $request->getVar('CategoryID');
340
-        } else {
341
-            if ($this->getPageCategories()->exists()) {
342
-                foreach ($this->getPageCategories() as $category) {
343
-                    $filter['CategoryID'][] = $category->ID;
344
-                }
345
-            }
346
-        }
347
-
348
-        $this->extend('updateLocatorFilter', $filter, $request);
349
-
350
-        $filterAny = $this->config()->get('base_filter_any');
351
-        $this->extend('updateLocatorFilterAny', $filterAny, $request);
352
-
353
-        $exclude = $this->config()->get('base_exclude');
354
-        $this->extend('updateLocatorExclude', $exclude, $request);
355
-
356
-        $locations = Locator::get_locations($filter, $filterAny, $exclude);
357
-        $locations = DataToArrayListHelper::to_array_list($locations);
358
-
359
-        //allow for adjusting list post possible distance calculation
360
-        $this->extend('updateLocationList', $locations);
361
-
362
-        if ($locations->canSortBy('distance')) {
363
-            $locations = $locations->sort('distance');
364
-        }
365
-
366
-        //allow for returning list to be set as
367
-        $this->extend('updateListType', $locations);
368
-
369
-        $this->locations = $locations;
370
-        return $this;
371
-
372
-    }
373
-
374
-    /**
375
-     * @return bool|string
376
-     */
377
-    public function getAddressSearchCoords()
378
-    {
379
-        if (!$this->request->getVar('Address')) {
380
-            return false;
381
-        }
382
-        $coords = GoogleGeocoding::address_to_point(Controller::curr()->getRequest()->getVar('Address'));
383
-
384
-        $lat = $coords['lat'];
385
-        $lng = $coords['lng'];
386
-
387
-        return "defaultLat: {$lat}, defaultLng: {$lng},";
388
-    }
389
-
390
-    /**
391
-     * LocationSearch form.
392
-     *
393
-     * Search form for locations, updates map and results list via AJAX
394
-     *
395
-     * @return Form
396
-     */
397
-    public function LocationSearch()
398
-    {
399
-
400
-        $form = LocatorForm::create($this, 'LocationSearch');
401
-        if (class_exists('BootstrapForm') && $this->config()->get('bootstrapify')) {
402
-            $form->Fields()->bootstrapify();
403
-            $form->Actions()->bootstrapify();
404
-        }
405
-
406
-        return $form
407
-            ->setFormMethod('GET')
408
-            ->setFormAction($this->Link())
409
-            ->disableSecurityToken()
410
-            ->loadDataFrom($this->request->getVars());
411
-    }
283
+		}
284
+	}
285
+
286
+	/**
287
+	 * @param SS_HTTPRequest $request
288
+	 *
289
+	 * @return ViewableData_Customised
290
+	 */
291
+	public function index(SS_HTTPRequest $request)
292
+	{
293
+		$locations = $this->getLocations();
294
+
295
+		return $this->customise(array(
296
+			'Locations' => $locations,
297
+		));
298
+	}
299
+
300
+	/**
301
+	 * Return a XML feed of all locations marked "show in locator"
302
+	 *
303
+	 * @param SS_HTTPRequest $request
304
+	 * @return HTMLText
305
+	 */
306
+	public function xml(SS_HTTPRequest $request)
307
+	{
308
+		$locations = $this->getLocations();
309
+
310
+		return $this->customise(array(
311
+			'Locations' => $locations,
312
+		))->renderWith('LocationXML');
313
+	}
314
+
315
+	/**
316
+	 * @return ArrayList|DataList
317
+	 */
318
+	public function getLocations()
319
+	{
320
+		if (!$this->locations) {
321
+			$this->setLocations($this->request);
322
+		}
323
+		return $this->locations;
324
+	}
325
+
326
+	/**
327
+	 * @param SS_HTTPRequest|null $request
328
+	 * @return $this
329
+	 */
330
+	public function setLocations(SS_HTTPRequest $request = null)
331
+	{
332
+
333
+		if ($request === null) {
334
+			$request = $this->request;
335
+		}
336
+		$filter = $this->config()->get('base_filter');
337
+
338
+		if ($request->getVar('CategoryID')) {
339
+			$filter['CategoryID'] = $request->getVar('CategoryID');
340
+		} else {
341
+			if ($this->getPageCategories()->exists()) {
342
+				foreach ($this->getPageCategories() as $category) {
343
+					$filter['CategoryID'][] = $category->ID;
344
+				}
345
+			}
346
+		}
347
+
348
+		$this->extend('updateLocatorFilter', $filter, $request);
349
+
350
+		$filterAny = $this->config()->get('base_filter_any');
351
+		$this->extend('updateLocatorFilterAny', $filterAny, $request);
352
+
353
+		$exclude = $this->config()->get('base_exclude');
354
+		$this->extend('updateLocatorExclude', $exclude, $request);
355
+
356
+		$locations = Locator::get_locations($filter, $filterAny, $exclude);
357
+		$locations = DataToArrayListHelper::to_array_list($locations);
358
+
359
+		//allow for adjusting list post possible distance calculation
360
+		$this->extend('updateLocationList', $locations);
361
+
362
+		if ($locations->canSortBy('distance')) {
363
+			$locations = $locations->sort('distance');
364
+		}
365
+
366
+		//allow for returning list to be set as
367
+		$this->extend('updateListType', $locations);
368
+
369
+		$this->locations = $locations;
370
+		return $this;
371
+
372
+	}
373
+
374
+	/**
375
+	 * @return bool|string
376
+	 */
377
+	public function getAddressSearchCoords()
378
+	{
379
+		if (!$this->request->getVar('Address')) {
380
+			return false;
381
+		}
382
+		$coords = GoogleGeocoding::address_to_point(Controller::curr()->getRequest()->getVar('Address'));
383
+
384
+		$lat = $coords['lat'];
385
+		$lng = $coords['lng'];
386
+
387
+		return "defaultLat: {$lat}, defaultLng: {$lng},";
388
+	}
389
+
390
+	/**
391
+	 * LocationSearch form.
392
+	 *
393
+	 * Search form for locations, updates map and results list via AJAX
394
+	 *
395
+	 * @return Form
396
+	 */
397
+	public function LocationSearch()
398
+	{
399
+
400
+		$form = LocatorForm::create($this, 'LocationSearch');
401
+		if (class_exists('BootstrapForm') && $this->config()->get('bootstrapify')) {
402
+			$form->Fields()->bootstrapify();
403
+			$form->Actions()->bootstrapify();
404
+		}
405
+
406
+		return $form
407
+			->setFormMethod('GET')
408
+			->setFormAction($this->Link())
409
+			->disableSecurityToken()
410
+			->loadDataFrom($this->request->getVars());
411
+	}
412 412
 
413 413
 }
Please login to merge, or discard this patch.
code/extensions/DistanceDataExtension.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -2,25 +2,25 @@
 block discarded – undo
2 2
 
3 3
 class DistanceDataExtension extends DataExtension
4 4
 {
5
-    /**
6
-     * @param SQLQuery $query
7
-     */
8
-    public function augmentSQL(SQLQuery &$query)
9
-    {
10
-        $address = Controller::curr()->getRequest()->getVar('Address');
11
-        if ($this->owner->hasMethod('updateAddressValue')) {
12
-            $address = $this->owner->updateAddressValue($address);
13
-        }
14
-        if ($address) { // on frontend
15
-            $coords = GoogleGeocoding::address_to_point($address);
5
+	/**
6
+	 * @param SQLQuery $query
7
+	 */
8
+	public function augmentSQL(SQLQuery &$query)
9
+	{
10
+		$address = Controller::curr()->getRequest()->getVar('Address');
11
+		if ($this->owner->hasMethod('updateAddressValue')) {
12
+			$address = $this->owner->updateAddressValue($address);
13
+		}
14
+		if ($address) { // on frontend
15
+			$coords = GoogleGeocoding::address_to_point($address);
16 16
 
17
-            $Lat = $coords['lat'];
18
-            $Lng = $coords['lng'];
17
+			$Lat = $coords['lat'];
18
+			$Lng = $coords['lng'];
19 19
 
20
-            $query
21
-                ->addSelect(array(
22
-                    '( 3959 * acos( cos( radians(' . $Lat . ') ) * cos( radians( `Lat` ) ) * cos( radians( `Lng` ) - radians(' . $Lng . ') ) + sin( radians(' . $Lat . ') ) * sin( radians( `Lat` ) ) ) ) AS distance',
23
-                ));
24
-        }
25
-    }
20
+			$query
21
+				->addSelect(array(
22
+					'( 3959 * acos( cos( radians(' . $Lat . ') ) * cos( radians( `Lat` ) ) * cos( radians( `Lng` ) - radians(' . $Lng . ') ) + sin( radians(' . $Lat . ') ) * sin( radians( `Lat` ) ) ) ) AS distance',
23
+				));
24
+		}
25
+	}
26 26
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
     /**
6 6
      * @param SQLQuery $query
7 7
      */
8
-    public function augmentSQL(SQLQuery &$query)
8
+    public function augmentSQL(SQLQuery & $query)
9 9
     {
10 10
         $address = Controller::curr()->getRequest()->getVar('Address');
11 11
         if ($this->owner->hasMethod('updateAddressValue')) {
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 
20 20
             $query
21 21
                 ->addSelect(array(
22
-                    '( 3959 * acos( cos( radians(' . $Lat . ') ) * cos( radians( `Lat` ) ) * cos( radians( `Lng` ) - radians(' . $Lng . ') ) + sin( radians(' . $Lat . ') ) * sin( radians( `Lat` ) ) ) ) AS distance',
22
+                    '( 3959 * acos( cos( radians('.$Lat.') ) * cos( radians( `Lat` ) ) * cos( radians( `Lng` ) - radians('.$Lng.') ) + sin( radians('.$Lat.') ) * sin( radians( `Lat` ) ) ) ) AS distance',
23 23
                 ));
24 24
         }
25 25
     }
Please login to merge, or discard this patch.
code/bulkloader/LocationCsvBulkLoader.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -6,51 +6,51 @@
 block discarded – undo
6 6
 class LocationCsvBulkLoader extends CsvBulkLoader
7 7
 {
8 8
 
9
-    /**
10
-     * @var array
11
-     */
12
-    public $columnMap = array(
13
-        'Name' => 'Title',
14
-        'City' => 'Suburb',
15
-        'EmailAddress' => 'Email',
16
-        'Category' => 'Category.Name',
17
-        'Import_ID' => 'Import_ID',
18
-    );
9
+	/**
10
+	 * @var array
11
+	 */
12
+	public $columnMap = array(
13
+		'Name' => 'Title',
14
+		'City' => 'Suburb',
15
+		'EmailAddress' => 'Email',
16
+		'Category' => 'Category.Name',
17
+		'Import_ID' => 'Import_ID',
18
+	);
19 19
 
20
-    /**
21
-     * @var array
22
-     */
23
-    public $duplicateChecks = array(
24
-        'Import_ID' => 'Import_ID'
25
-    );
20
+	/**
21
+	 * @var array
22
+	 */
23
+	public $duplicateChecks = array(
24
+		'Import_ID' => 'Import_ID'
25
+	);
26 26
 
27
-    /**
28
-     * @var array
29
-     */
30
-    public $relationCallbacks = array(
31
-       'Category.Name' => array(
32
-           'relationname' => 'Category',
33
-           'callback' => 'getCategoryByName',
34
-        ),
35
-    );
27
+	/**
28
+	 * @var array
29
+	 */
30
+	public $relationCallbacks = array(
31
+	   'Category.Name' => array(
32
+		   'relationname' => 'Category',
33
+		   'callback' => 'getCategoryByName',
34
+		),
35
+	);
36 36
 
37
-    /**
38
-     * @param $obj
39
-     * @param $val
40
-     * @param $record
41
-     * @return DataObject|static
42
-     */
43
-    public static function getCategoryByName(&$obj, $val, $record)
44
-    {
45
-        $val = Convert::raw2sql($val);
46
-        $category = LocationCategory::get()->filter(array('Name' => $val))->First();
47
-        if (!$category) {
48
-            $category = LocationCategory::create();
49
-            $category->Name = $val;
50
-            $category->write();
51
-        }
37
+	/**
38
+	 * @param $obj
39
+	 * @param $val
40
+	 * @param $record
41
+	 * @return DataObject|static
42
+	 */
43
+	public static function getCategoryByName(&$obj, $val, $record)
44
+	{
45
+		$val = Convert::raw2sql($val);
46
+		$category = LocationCategory::get()->filter(array('Name' => $val))->First();
47
+		if (!$category) {
48
+			$category = LocationCategory::create();
49
+			$category->Name = $val;
50
+			$category->write();
51
+		}
52 52
 
53
-        return $category;
54
-    }
53
+		return $category;
54
+	}
55 55
 
56 56
 }
Please login to merge, or discard this patch.
code/form/LocatorForm.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -6,43 +6,43 @@
 block discarded – undo
6 6
 class LocatorForm extends Form
7 7
 {
8 8
 
9
-    /**
10
-     * LocatorForm constructor.
11
-     * @param Controller $controller
12
-     * @param string $name
13
-     */
14
-    public function __construct(Controller $controller, $name)
15
-    {
16
-
17
-        $fields = FieldList::create(
18
-            TextField::create('Address')
19
-                ->setTitle('')
20
-                ->setAttribute('placeholder', 'address or zip code')
21
-        );
22
-
23
-        $pageCategories = Locator::locator_categories_by_locator($controller->data()->ID);
24
-        if ($pageCategories && $pageCategories->count() > 0) {
25
-            $categories = false;
26
-        } else {
27
-            $categories = Locator::get_all_categories();
28
-        }
29
-
30
-        if ($categories) {
31
-            $categoriesField = DropdownField::create('CategoryID')
32
-                ->setTitle('')
33
-                ->setEmptyString('All Categories')
34
-                ->setSource($categories->map());
35
-            $fields->push($categoriesField);
36
-        }
37
-
38
-        $actions = FieldList::create(
39
-            FormAction::create('doFilterLocations')
40
-                ->setTitle('Search')
41
-        );
42
-
43
-        $validator = RequiredFields::create();
44
-
45
-        parent::__construct($controller, $name, $fields, $actions, $validator);
46
-    }
9
+	/**
10
+	 * LocatorForm constructor.
11
+	 * @param Controller $controller
12
+	 * @param string $name
13
+	 */
14
+	public function __construct(Controller $controller, $name)
15
+	{
16
+
17
+		$fields = FieldList::create(
18
+			TextField::create('Address')
19
+				->setTitle('')
20
+				->setAttribute('placeholder', 'address or zip code')
21
+		);
22
+
23
+		$pageCategories = Locator::locator_categories_by_locator($controller->data()->ID);
24
+		if ($pageCategories && $pageCategories->count() > 0) {
25
+			$categories = false;
26
+		} else {
27
+			$categories = Locator::get_all_categories();
28
+		}
29
+
30
+		if ($categories) {
31
+			$categoriesField = DropdownField::create('CategoryID')
32
+				->setTitle('')
33
+				->setEmptyString('All Categories')
34
+				->setSource($categories->map());
35
+			$fields->push($categoriesField);
36
+		}
37
+
38
+		$actions = FieldList::create(
39
+			FormAction::create('doFilterLocations')
40
+				->setTitle('Search')
41
+		);
42
+
43
+		$validator = RequiredFields::create();
44
+
45
+		parent::__construct($controller, $name, $fields, $actions, $validator);
46
+	}
47 47
 
48 48
 }
49 49
\ No newline at end of file
Please login to merge, or discard this patch.