Completed
Push — master ( 072c97...a0e23a )
by Jason
29s
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   +365 added lines, -365 removed lines patch added patch discarded remove patch
@@ -11,137 +11,137 @@  discard block
 block discarded – undo
11 11
 class Locator extends Page
12 12
 {
13 13
 
14
-    /**
15
-     * @var array
16
-     */
17
-    private static $db = array(
18
-        'AutoGeocode' => 'Boolean',
19
-        'ModalWindow' => 'Boolean',
20
-        'Unit' => 'Enum("m,km","m")',
21
-    );
22
-
23
-    /**
24
-     * @var array
25
-     */
26
-    private static $many_many = array(
27
-        'Categories' => 'LocationCategory',
28
-    );
29
-
30
-    /**
31
-     * @var array
32
-     */
33
-    private static $defaults = array(
34
-        'AutoGeocode' => true,
35
-    );
36
-
37
-    /**
38
-     * @var string
39
-     */
40
-    private static $singular_name = 'Locator';
41
-    /**
42
-     * @var string
43
-     */
44
-    private static $plural_name = 'Locators';
45
-    /**
46
-     * @var string
47
-     */
48
-    private static $description = 'Find locations on a map';
49
-
50
-    /**
51
-     * @return FieldList
52
-     */
53
-    public function getCMSFields()
54
-    {
55
-        $fields = parent::getCMSFields();
56
-
57
-        // Settings
58
-        $fields->addFieldsToTab('Root.Settings', array(
59
-            HeaderField::create('DisplayOptions', 'Display Options', 3),
60
-            OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')),
61
-            CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location')
62
-                ->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'),
63
-            CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'),
64
-        ));
65
-
66
-        // Filter categories
67
-        $config = GridFieldConfig_RelationEditor::create();
68
-        if (class_exists('GridFieldAddExistingSearchButton')) {
69
-            $config->removeComponentsByType('GridFieldAddExistingAutocompleter');
70
-            $config->addComponent(new GridFieldAddExistingSearchButton());
71
-        }
72
-        $categories = $this->Categories();
73
-        $categoriesField = GridField::create('Categories', 'Categories', $categories, $config)
74
-            ->setDescription('only show locations from the selected category');
75
-
76
-        // Filter
77
-        $fields->addFieldsToTab('Root.Filter', array(
78
-            HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3),
79
-            $categoriesField,
80
-        ));
81
-
82
-        $this->extend('updateCMSFields', $fields);
83
-
84
-        return $fields;
85
-    }
86
-
87
-    /**
88
-     * @param array $filter
89
-     * @param array $filterAny
90
-     * @param array $exclude
91
-     * @param null|callable $callback
92
-     * @return DataList|ArrayList
93
-     */
94
-    public static function get_locations(
95
-        $filter = [],
96
-        $filterAny = [],
97
-        $exclude = [],
98
-        $callback = null
99
-    )
100
-    {
101
-        $locations = Location::get()->filter($filter)->exclude($exclude);
102
-
103
-        if (!empty($filterAny)) {
104
-            $locations = $locations->filterAny($filterAny);
105
-        }
106
-        if (!empty($exclude)) {
107
-            $locations = $locations->exclude($exclude);
108
-        }
109
-
110
-        if ($callback !== null && is_callable($callback)) {
111
-            $locations->filterByCallback($callback);
112
-        }
113
-
114
-        return $locations;
115
-    }
116
-
117
-    /**
118
-     * @return DataList
119
-     */
120
-    public static function get_all_categories()
121
-    {
122
-        return LocationCategory::get();
123
-    }
124
-
125
-    /**
126
-     * @return bool
127
-     */
128
-    public function getPageCategories()
129
-    {
130
-        return self::locator_categories_by_locator($this->ID);
131
-    }
132
-
133
-    /**
134
-     * @param int $id
135
-     * @return bool|
136
-     */
137
-    public static function locator_categories_by_locator($id = 0)
138
-    {
139
-        if ($id == 0) {
140
-            return false;
141
-        }
142
-
143
-        return Locator::get()->byID($id)->Categories();
144
-    }
14
+	/**
15
+	 * @var array
16
+	 */
17
+	private static $db = array(
18
+		'AutoGeocode' => 'Boolean',
19
+		'ModalWindow' => 'Boolean',
20
+		'Unit' => 'Enum("m,km","m")',
21
+	);
22
+
23
+	/**
24
+	 * @var array
25
+	 */
26
+	private static $many_many = array(
27
+		'Categories' => 'LocationCategory',
28
+	);
29
+
30
+	/**
31
+	 * @var array
32
+	 */
33
+	private static $defaults = array(
34
+		'AutoGeocode' => true,
35
+	);
36
+
37
+	/**
38
+	 * @var string
39
+	 */
40
+	private static $singular_name = 'Locator';
41
+	/**
42
+	 * @var string
43
+	 */
44
+	private static $plural_name = 'Locators';
45
+	/**
46
+	 * @var string
47
+	 */
48
+	private static $description = 'Find locations on a map';
49
+
50
+	/**
51
+	 * @return FieldList
52
+	 */
53
+	public function getCMSFields()
54
+	{
55
+		$fields = parent::getCMSFields();
56
+
57
+		// Settings
58
+		$fields->addFieldsToTab('Root.Settings', array(
59
+			HeaderField::create('DisplayOptions', 'Display Options', 3),
60
+			OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')),
61
+			CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location')
62
+				->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'),
63
+			CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'),
64
+		));
65
+
66
+		// Filter categories
67
+		$config = GridFieldConfig_RelationEditor::create();
68
+		if (class_exists('GridFieldAddExistingSearchButton')) {
69
+			$config->removeComponentsByType('GridFieldAddExistingAutocompleter');
70
+			$config->addComponent(new GridFieldAddExistingSearchButton());
71
+		}
72
+		$categories = $this->Categories();
73
+		$categoriesField = GridField::create('Categories', 'Categories', $categories, $config)
74
+			->setDescription('only show locations from the selected category');
75
+
76
+		// Filter
77
+		$fields->addFieldsToTab('Root.Filter', array(
78
+			HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3),
79
+			$categoriesField,
80
+		));
81
+
82
+		$this->extend('updateCMSFields', $fields);
83
+
84
+		return $fields;
85
+	}
86
+
87
+	/**
88
+	 * @param array $filter
89
+	 * @param array $filterAny
90
+	 * @param array $exclude
91
+	 * @param null|callable $callback
92
+	 * @return DataList|ArrayList
93
+	 */
94
+	public static function get_locations(
95
+		$filter = [],
96
+		$filterAny = [],
97
+		$exclude = [],
98
+		$callback = null
99
+	)
100
+	{
101
+		$locations = Location::get()->filter($filter)->exclude($exclude);
102
+
103
+		if (!empty($filterAny)) {
104
+			$locations = $locations->filterAny($filterAny);
105
+		}
106
+		if (!empty($exclude)) {
107
+			$locations = $locations->exclude($exclude);
108
+		}
109
+
110
+		if ($callback !== null && is_callable($callback)) {
111
+			$locations->filterByCallback($callback);
112
+		}
113
+
114
+		return $locations;
115
+	}
116
+
117
+	/**
118
+	 * @return DataList
119
+	 */
120
+	public static function get_all_categories()
121
+	{
122
+		return LocationCategory::get();
123
+	}
124
+
125
+	/**
126
+	 * @return bool
127
+	 */
128
+	public function getPageCategories()
129
+	{
130
+		return self::locator_categories_by_locator($this->ID);
131
+	}
132
+
133
+	/**
134
+	 * @param int $id
135
+	 * @return bool|
136
+	 */
137
+	public static function locator_categories_by_locator($id = 0)
138
+	{
139
+		if ($id == 0) {
140
+			return false;
141
+		}
142
+
143
+		return Locator::get()->byID($id)->Categories();
144
+	}
145 145
 
146 146
 
147 147
 }
@@ -151,111 +151,111 @@  discard block
 block discarded – undo
151 151
  */
152 152
 class Locator_Controller extends Page_Controller
153 153
 {
154
-    /**
155
-     * @var array
156
-     */
157
-    private static $allowed_actions = array(
158
-        'xml',
159
-    );
160
-
161
-    /**
162
-     * @var array
163
-     */
164
-    private static $base_filter = [
165
-        'ShowInLocator' => true,
166
-    ];
167
-
168
-    /**
169
-     * @var array
170
-     */
171
-    private static $base_exclude = [
172
-        'Lat' => 0,
173
-        'Lng' => 0,
174
-    ];
175
-
176
-    /**
177
-     * @var array
178
-     */
179
-    private static $base_filter_any = [];
180
-
181
-    /**
182
-     * @var string
183
-     */
184
-    private static $list_template_path = 'locator/templates/location-list-description.html';
185
-
186
-    /**
187
-     * @var string
188
-     */
189
-    private static $info_window_template_path = 'locator/templates/infowindow-description.html';
190
-
191
-    /**
192
-     * @var bool
193
-     */
194
-    private static $bootstrapify = true;
195
-
196
-    /**
197
-     * @var DataList|ArrayList
198
-     */
199
-    private $locations;
200
-
201
-    /**
202
-     * Set Requirements based on input from CMS
203
-     */
204
-    public function init()
205
-    {
206
-        parent::init();
207
-
208
-        // google maps api key
209
-        $key = Config::inst()->get('GoogleGeocoding', 'google_api_key');
210
-
211
-        $locations = $this->getLocations();
212
-
213
-        if ($locations) {
214
-
215
-            Requirements::css('locator/css/map.css');
216
-            Requirements::javascript('framework/thirdparty/jquery/jquery.js');
217
-            Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key);
218
-            Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
219
-            Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
220
-
221
-            $featuredInList = ($locations->filter('Featured', true)->count() > 0);
222
-            $defaultCoords = $this->getAddressSearchCoords() ? $this->getAddressSearchCoords() : '';
223
-            $isChrome = (strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE);
224
-
225
-            $featured = $featuredInList
226
-                ? 'featuredLocations: true'
227
-                : 'featuredLocations: false';
228
-
229
-            // map config based on user input in Settings tab
230
-            // AutoGeocode or Full Map
231
-            if ($this->data()->AutoGeocode) {
232
-                $load = $featuredInList || $defaultCoords != '' || $isChrome
233
-                    ? 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'
234
-                    : 'autoGeocode: true, fullMapStart: false,';
235
-            } else {
236
-                $load = 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
237
-            }
238
-
239
-            $listTemplatePath = $this->config()->get('list_template_path');
240
-            $infowindowTemplatePath = $this->config()->get('info_window_template_path');
241
-
242
-            // in page or modal
243
-            $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';
244
-
245
-            $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"';
246
-
247
-            // pass GET variables to xml action
248
-            $vars = $this->request->getVars();
249
-            unset($vars['url']);
250
-            unset($vars['action_doFilterLocations']);
251
-            $url = '';
252
-            if (count($vars)) {
253
-                $url .= '?' . http_build_query($vars);
254
-            }
255
-            $link = $this->Link() . 'xml.xml' . $url;
256
-
257
-            // init map
258
-            Requirements::customScript("
154
+	/**
155
+	 * @var array
156
+	 */
157
+	private static $allowed_actions = array(
158
+		'xml',
159
+	);
160
+
161
+	/**
162
+	 * @var array
163
+	 */
164
+	private static $base_filter = [
165
+		'ShowInLocator' => true,
166
+	];
167
+
168
+	/**
169
+	 * @var array
170
+	 */
171
+	private static $base_exclude = [
172
+		'Lat' => 0,
173
+		'Lng' => 0,
174
+	];
175
+
176
+	/**
177
+	 * @var array
178
+	 */
179
+	private static $base_filter_any = [];
180
+
181
+	/**
182
+	 * @var string
183
+	 */
184
+	private static $list_template_path = 'locator/templates/location-list-description.html';
185
+
186
+	/**
187
+	 * @var string
188
+	 */
189
+	private static $info_window_template_path = 'locator/templates/infowindow-description.html';
190
+
191
+	/**
192
+	 * @var bool
193
+	 */
194
+	private static $bootstrapify = true;
195
+
196
+	/**
197
+	 * @var DataList|ArrayList
198
+	 */
199
+	private $locations;
200
+
201
+	/**
202
+	 * Set Requirements based on input from CMS
203
+	 */
204
+	public function init()
205
+	{
206
+		parent::init();
207
+
208
+		// google maps api key
209
+		$key = Config::inst()->get('GoogleGeocoding', 'google_api_key');
210
+
211
+		$locations = $this->getLocations();
212
+
213
+		if ($locations) {
214
+
215
+			Requirements::css('locator/css/map.css');
216
+			Requirements::javascript('framework/thirdparty/jquery/jquery.js');
217
+			Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key);
218
+			Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
219
+			Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
220
+
221
+			$featuredInList = ($locations->filter('Featured', true)->count() > 0);
222
+			$defaultCoords = $this->getAddressSearchCoords() ? $this->getAddressSearchCoords() : '';
223
+			$isChrome = (strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE);
224
+
225
+			$featured = $featuredInList
226
+				? 'featuredLocations: true'
227
+				: 'featuredLocations: false';
228
+
229
+			// map config based on user input in Settings tab
230
+			// AutoGeocode or Full Map
231
+			if ($this->data()->AutoGeocode) {
232
+				$load = $featuredInList || $defaultCoords != '' || $isChrome
233
+					? 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'
234
+					: 'autoGeocode: true, fullMapStart: false,';
235
+			} else {
236
+				$load = 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
237
+			}
238
+
239
+			$listTemplatePath = $this->config()->get('list_template_path');
240
+			$infowindowTemplatePath = $this->config()->get('info_window_template_path');
241
+
242
+			// in page or modal
243
+			$modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';
244
+
245
+			$kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"';
246
+
247
+			// pass GET variables to xml action
248
+			$vars = $this->request->getVars();
249
+			unset($vars['url']);
250
+			unset($vars['action_doFilterLocations']);
251
+			$url = '';
252
+			if (count($vars)) {
253
+				$url .= '?' . http_build_query($vars);
254
+			}
255
+			$link = $this->Link() . 'xml.xml' . $url;
256
+
257
+			// init map
258
+			Requirements::customScript("
259 259
                 $(function(){
260 260
                     $('#map-container').storeLocator({
261 261
                         " . $load . "
@@ -274,134 +274,134 @@  discard block
 block discarded – undo
274 274
                     });
275 275
                 });
276 276
             ');
277
-        }
278
-    }
279
-
280
-    /**
281
-     * @param SS_HTTPRequest $request
282
-     *
283
-     * @return ViewableData_Customised
284
-     */
285
-    public function index(SS_HTTPRequest $request)
286
-    {
287
-        $locations = $this->getLocations();
288
-
289
-        return $this->customise(array(
290
-            'Locations' => $locations,
291
-        ));
292
-    }
293
-
294
-    /**
295
-     * Return a XML feed of all locations marked "show in locator"
296
-     *
297
-     * @param SS_HTTPRequest $request
298
-     * @return HTMLText
299
-     */
300
-    public function xml(SS_HTTPRequest $request)
301
-    {
302
-        $locations = $this->getLocations();
303
-
304
-        return $this->customise(array(
305
-            'Locations' => $locations,
306
-        ))->renderWith('LocationXML');
307
-    }
308
-
309
-    /**
310
-     * @return ArrayList|DataList
311
-     */
312
-    public function getLocations()
313
-    {
314
-        if (!$this->locations) {
315
-            $this->setLocations($this->request);
316
-        }
317
-        return $this->locations;
318
-    }
319
-
320
-    /**
321
-     * @param SS_HTTPRequest|null $request
322
-     * @return $this
323
-     */
324
-    public function setLocations(SS_HTTPRequest $request = null)
325
-    {
326
-
327
-        if ($request === null) {
328
-            $request = $this->request;
329
-        }
330
-        $filter = $this->config()->get('base_filter');
331
-
332
-        if ($request->getVar('CategoryID')) {
333
-            $filter['CategoryID'] = $request->getVar('CategoryID');
334
-        } else {
335
-            if ($this->getPageCategories()->exists()) {
336
-                foreach ($this->getPageCategories() as $category) {
337
-                    $filter['CategoryID'][] = $category->ID;
338
-                }
339
-            }
340
-        }
341
-
342
-        $this->extend('updateLocatorFilter', $filter, $request);
343
-
344
-        $filterAny = $this->config()->get('base_filter_any');
345
-        $this->extend('updateLocatorFilterAny', $filterAny, $request);
346
-
347
-        $exclude = $this->config()->get('base_exclude');
348
-        $this->extend('updateLocatorExclude', $exclude, $request);
349
-
350
-        $locations = Locator::get_locations($filter, $filterAny, $exclude);
351
-        $locations = DataToArrayListHelper::to_array_list($locations);
352
-
353
-        //allow for adjusting list post possible distance calculation
354
-        $this->extend('updateLocationList', $locations);
355
-
356
-        if ($locations->canSortBy('distance')) {
357
-            $locations = $locations->sort('distance');
358
-        }
359
-
360
-        //allow for returning list to be set as
361
-        $this->extend('updateListType', $locations);
362
-
363
-        $this->locations = $locations;
364
-        return $this;
365
-
366
-    }
367
-
368
-    /**
369
-     * @return bool|string
370
-     */
371
-    public function getAddressSearchCoords()
372
-    {
373
-        if (!$this->request->getVar('Address')) {
374
-            return false;
375
-        }
376
-        $coords = GoogleGeocoding::address_to_point(Controller::curr()->getRequest()->getVar('Address'));
377
-
378
-        $lat = $coords['lat'];
379
-        $lng = $coords['lng'];
380
-
381
-        return "defaultLat: {$lat}, defaultLng: {$lng},";
382
-    }
383
-
384
-    /**
385
-     * LocationSearch form.
386
-     *
387
-     * Search form for locations, updates map and results list via AJAX
388
-     *
389
-     * @return Form
390
-     */
391
-    public function LocationSearch()
392
-    {
393
-
394
-        $form = LocatorForm::create($this, 'LocationSearch');
395
-        if (class_exists('BootstrapForm') && $this->config()->get('bootstrapify')) {
396
-            $form->Fields()->bootstrapify();
397
-            $form->Actions()->bootstrapify();
398
-        }
399
-
400
-        return $form
401
-            ->setFormMethod('GET')
402
-            ->setFormAction($this->Link())
403
-            ->disableSecurityToken()
404
-            ->loadDataFrom($this->request->getVars());
405
-    }
277
+		}
278
+	}
279
+
280
+	/**
281
+	 * @param SS_HTTPRequest $request
282
+	 *
283
+	 * @return ViewableData_Customised
284
+	 */
285
+	public function index(SS_HTTPRequest $request)
286
+	{
287
+		$locations = $this->getLocations();
288
+
289
+		return $this->customise(array(
290
+			'Locations' => $locations,
291
+		));
292
+	}
293
+
294
+	/**
295
+	 * Return a XML feed of all locations marked "show in locator"
296
+	 *
297
+	 * @param SS_HTTPRequest $request
298
+	 * @return HTMLText
299
+	 */
300
+	public function xml(SS_HTTPRequest $request)
301
+	{
302
+		$locations = $this->getLocations();
303
+
304
+		return $this->customise(array(
305
+			'Locations' => $locations,
306
+		))->renderWith('LocationXML');
307
+	}
308
+
309
+	/**
310
+	 * @return ArrayList|DataList
311
+	 */
312
+	public function getLocations()
313
+	{
314
+		if (!$this->locations) {
315
+			$this->setLocations($this->request);
316
+		}
317
+		return $this->locations;
318
+	}
319
+
320
+	/**
321
+	 * @param SS_HTTPRequest|null $request
322
+	 * @return $this
323
+	 */
324
+	public function setLocations(SS_HTTPRequest $request = null)
325
+	{
326
+
327
+		if ($request === null) {
328
+			$request = $this->request;
329
+		}
330
+		$filter = $this->config()->get('base_filter');
331
+
332
+		if ($request->getVar('CategoryID')) {
333
+			$filter['CategoryID'] = $request->getVar('CategoryID');
334
+		} else {
335
+			if ($this->getPageCategories()->exists()) {
336
+				foreach ($this->getPageCategories() as $category) {
337
+					$filter['CategoryID'][] = $category->ID;
338
+				}
339
+			}
340
+		}
341
+
342
+		$this->extend('updateLocatorFilter', $filter, $request);
343
+
344
+		$filterAny = $this->config()->get('base_filter_any');
345
+		$this->extend('updateLocatorFilterAny', $filterAny, $request);
346
+
347
+		$exclude = $this->config()->get('base_exclude');
348
+		$this->extend('updateLocatorExclude', $exclude, $request);
349
+
350
+		$locations = Locator::get_locations($filter, $filterAny, $exclude);
351
+		$locations = DataToArrayListHelper::to_array_list($locations);
352
+
353
+		//allow for adjusting list post possible distance calculation
354
+		$this->extend('updateLocationList', $locations);
355
+
356
+		if ($locations->canSortBy('distance')) {
357
+			$locations = $locations->sort('distance');
358
+		}
359
+
360
+		//allow for returning list to be set as
361
+		$this->extend('updateListType', $locations);
362
+
363
+		$this->locations = $locations;
364
+		return $this;
365
+
366
+	}
367
+
368
+	/**
369
+	 * @return bool|string
370
+	 */
371
+	public function getAddressSearchCoords()
372
+	{
373
+		if (!$this->request->getVar('Address')) {
374
+			return false;
375
+		}
376
+		$coords = GoogleGeocoding::address_to_point(Controller::curr()->getRequest()->getVar('Address'));
377
+
378
+		$lat = $coords['lat'];
379
+		$lng = $coords['lng'];
380
+
381
+		return "defaultLat: {$lat}, defaultLng: {$lng},";
382
+	}
383
+
384
+	/**
385
+	 * LocationSearch form.
386
+	 *
387
+	 * Search form for locations, updates map and results list via AJAX
388
+	 *
389
+	 * @return Form
390
+	 */
391
+	public function LocationSearch()
392
+	{
393
+
394
+		$form = LocatorForm::create($this, 'LocationSearch');
395
+		if (class_exists('BootstrapForm') && $this->config()->get('bootstrapify')) {
396
+			$form->Fields()->bootstrapify();
397
+			$form->Actions()->bootstrapify();
398
+		}
399
+
400
+		return $form
401
+			->setFormMethod('GET')
402
+			->setFormAction($this->Link())
403
+			->disableSecurityToken()
404
+			->loadDataFrom($this->request->getVars());
405
+	}
406 406
 
407 407
 }
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.