Completed
Push — master ( 83571a...9e9b74 )
by Nic
30s
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   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -6,183 +6,183 @@
 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
-        );
55
-        $this->assertEquals($expected, $labels);
56
-    }
57
-
58
-    /**
59
-     *
60
-     */
61
-    public function testGetCMSFields()
62
-    {
63
-        $object = new Location();
64
-        $fieldset = $object->getCMSFields();
65
-        $this->assertTrue(is_a($fieldset, 'FieldList'));
66
-    }
67
-
68
-    /**
69
-     *
70
-     */
71
-    public function testValidate()
72
-    {
73
-    }
74
-
75
-    /**
76
-     *
77
-     */
78
-    public function testEmailAddress()
79
-    {
80
-    }
81
-
82
-    /**
83
-     *
84
-     */
85
-    public function testCanView()
86
-    {
87
-        $object = $this->objFromFixture('Location', 'dynamic');
88
-        $object->write();
89
-
90
-        $this->assertTrue($object->canView());
91
-
92
-        $nullMember = Member::create();
93
-        $nullMember->write();
94
-
95
-        $this->assertTrue($object->canView($nullMember));
96
-
97
-        $nullMember->delete();
98
-    }
99
-
100
-    /**
101
-     *
102
-     */
103
-    public function testCanEdit()
104
-    {
105
-        $object = $this->objFromFixture('Location', 'dynamic');
106
-        $object->write();
107
-
108
-        $objectID = $object->ID;
109
-
110
-        //test permissions per permission setting
111
-        $create = $this->objFromFixture('Member', 'locationcreate');
112
-        $edit = $this->objFromFixture('Member', 'locationedit');
113
-        $delete = $this->objFromFixture('Member', 'locationdelete');
114
-
115
-        $originalTitle = $object->Title;
116
-        $this->assertEquals($originalTitle, 'Dynamic, Inc.');
117
-
118
-        $this->assertTrue($object->canEdit($edit));
119
-        $this->assertFalse($object->canEdit($create));
120
-        $this->assertFalse($object->canEdit($delete));
121
-
122
-        $object->Title = 'Changed Title';
123
-        $object->write();
124
-
125
-        $testEdit = Location::get()->byID($objectID);
126
-        $this->assertEquals($testEdit->Title, 'Changed Title');
127
-    }
128
-
129
-    /**
130
-     *
131
-     */
132
-    public function testCanDelete()
133
-    {
134
-        $object = $this->objFromFixture('Location', 'dynamic');
135
-        $object->write();
136
-
137
-        //test permissions per permission setting
138
-        $create = $this->objFromFixture('Member', 'locationcreate');
139
-        $edit = $this->objFromFixture('Member', 'locationedit');
140
-        $delete = $this->objFromFixture('Member', 'locationdelete');
141
-
142
-        $this->assertTrue($object->canDelete($delete));
143
-        $this->assertFalse($object->canDelete($create));
144
-        $this->assertFalse($object->canDelete($edit));
145
-
146
-        $checkObject = $object;
147
-        $object->delete();
148
-
149
-        $this->assertEquals($checkObject->ID, 0);
150
-    }
151
-
152
-    /**
153
-     *
154
-     */
155
-    public function testCanCreate()
156
-    {
157
-        $object = singleton('Location');
158
-
159
-        //test permissions per permission setting
160
-        $create = $this->objFromFixture('Member', 'locationcreate');
161
-        $edit = $this->objFromFixture('Member', 'locationedit');
162
-        $delete = $this->objFromFixture('Member', 'locationdelete');
163
-
164
-        $this->assertTrue($object->canCreate($create));
165
-        $this->assertFalse($object->canCreate($edit));
166
-        $this->assertFalse($object->canCreate($delete));
167
-
168
-        $nullMember = Member::create();
169
-        $nullMember->write();
170
-        $this->assertFalse($object->canCreate($nullMember));
171
-
172
-        $nullMember->delete();
173
-    }
174
-
175
-    /**
176
-     *
177
-     */
178
-    public function testProvidePermissions()
179
-    {
180
-        $object = Location::create();
181
-        $expected = array(
182
-            'Location_EDIT' => 'Edit a Location',
183
-            'Location_DELETE' => 'Delete a Location',
184
-            'Location_CREATE' => 'Create a Location',
185
-        );
186
-        $this->assertEquals($expected, $object->providePermissions());
187
-    }
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
+		);
55
+		$this->assertEquals($expected, $labels);
56
+	}
57
+
58
+	/**
59
+	 *
60
+	 */
61
+	public function testGetCMSFields()
62
+	{
63
+		$object = new Location();
64
+		$fieldset = $object->getCMSFields();
65
+		$this->assertTrue(is_a($fieldset, 'FieldList'));
66
+	}
67
+
68
+	/**
69
+	 *
70
+	 */
71
+	public function testValidate()
72
+	{
73
+	}
74
+
75
+	/**
76
+	 *
77
+	 */
78
+	public function testEmailAddress()
79
+	{
80
+	}
81
+
82
+	/**
83
+	 *
84
+	 */
85
+	public function testCanView()
86
+	{
87
+		$object = $this->objFromFixture('Location', 'dynamic');
88
+		$object->write();
89
+
90
+		$this->assertTrue($object->canView());
91
+
92
+		$nullMember = Member::create();
93
+		$nullMember->write();
94
+
95
+		$this->assertTrue($object->canView($nullMember));
96
+
97
+		$nullMember->delete();
98
+	}
99
+
100
+	/**
101
+	 *
102
+	 */
103
+	public function testCanEdit()
104
+	{
105
+		$object = $this->objFromFixture('Location', 'dynamic');
106
+		$object->write();
107
+
108
+		$objectID = $object->ID;
109
+
110
+		//test permissions per permission setting
111
+		$create = $this->objFromFixture('Member', 'locationcreate');
112
+		$edit = $this->objFromFixture('Member', 'locationedit');
113
+		$delete = $this->objFromFixture('Member', 'locationdelete');
114
+
115
+		$originalTitle = $object->Title;
116
+		$this->assertEquals($originalTitle, 'Dynamic, Inc.');
117
+
118
+		$this->assertTrue($object->canEdit($edit));
119
+		$this->assertFalse($object->canEdit($create));
120
+		$this->assertFalse($object->canEdit($delete));
121
+
122
+		$object->Title = 'Changed Title';
123
+		$object->write();
124
+
125
+		$testEdit = Location::get()->byID($objectID);
126
+		$this->assertEquals($testEdit->Title, 'Changed Title');
127
+	}
128
+
129
+	/**
130
+	 *
131
+	 */
132
+	public function testCanDelete()
133
+	{
134
+		$object = $this->objFromFixture('Location', 'dynamic');
135
+		$object->write();
136
+
137
+		//test permissions per permission setting
138
+		$create = $this->objFromFixture('Member', 'locationcreate');
139
+		$edit = $this->objFromFixture('Member', 'locationedit');
140
+		$delete = $this->objFromFixture('Member', 'locationdelete');
141
+
142
+		$this->assertTrue($object->canDelete($delete));
143
+		$this->assertFalse($object->canDelete($create));
144
+		$this->assertFalse($object->canDelete($edit));
145
+
146
+		$checkObject = $object;
147
+		$object->delete();
148
+
149
+		$this->assertEquals($checkObject->ID, 0);
150
+	}
151
+
152
+	/**
153
+	 *
154
+	 */
155
+	public function testCanCreate()
156
+	{
157
+		$object = singleton('Location');
158
+
159
+		//test permissions per permission setting
160
+		$create = $this->objFromFixture('Member', 'locationcreate');
161
+		$edit = $this->objFromFixture('Member', 'locationedit');
162
+		$delete = $this->objFromFixture('Member', 'locationdelete');
163
+
164
+		$this->assertTrue($object->canCreate($create));
165
+		$this->assertFalse($object->canCreate($edit));
166
+		$this->assertFalse($object->canCreate($delete));
167
+
168
+		$nullMember = Member::create();
169
+		$nullMember->write();
170
+		$this->assertFalse($object->canCreate($nullMember));
171
+
172
+		$nullMember->delete();
173
+	}
174
+
175
+	/**
176
+	 *
177
+	 */
178
+	public function testProvidePermissions()
179
+	{
180
+		$object = Location::create();
181
+		$expected = array(
182
+			'Location_EDIT' => 'Edit a Location',
183
+			'Location_DELETE' => 'Delete a Location',
184
+			'Location_CREATE' => 'Create a Location',
185
+		);
186
+		$this->assertEquals($expected, $object->providePermissions());
187
+	}
188 188
 }
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   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -16,240 +16,240 @@
 block discarded – undo
16 16
 class Location extends DataObject implements PermissionProvider
17 17
 {
18 18
 
19
-    /**
20
-     * @var array
21
-     */
22
-    private static $db = array(
23
-        'Title' => 'Varchar(255)',
24
-        'Featured' => 'Boolean',
25
-        'Website' => 'Varchar(255)',
26
-        'Phone' => 'Varchar(40)',
27
-        'Email' => 'Varchar(255)',
28
-        'EmailAddress' => 'Varchar(255)',
29
-        'ShowInLocator' => 'Boolean',
30
-    );
31
-
32
-    /**
33
-     * @var array
34
-     */
35
-    private static $has_one = array(
36
-        'Category' => 'LocationCategory',
37
-    );
38
-
39
-    /**
40
-     * @var array
41
-     */
42
-    private static $casting = array(
43
-        'distance' => 'Int',
44
-    );
45
-
46
-    /**
47
-     * @var string
48
-     */
49
-    private static $default_sort = 'Title';
50
-
51
-    /**
52
-     * @var array
53
-     */
54
-    private static $defaults = array(
55
-        'ShowInLocator' => true,
56
-    );
57
-
58
-    /**
59
-     * @var string
60
-     */
61
-    private static $singular_name = 'Location';
62
-    /**
63
-     * @var string
64
-     */
65
-    private static $plural_name = 'Locations';
66
-
67
-    /**
68
-     * api access via Restful Server module
69
-     *
70
-     * @var bool
71
-     */
72
-    private static $api_access = true;
73
-
74
-    /**
75
-     * search fields for Model Admin
76
-     *
77
-     * @var array
78
-     */
79
-    private static $searchable_fields = array(
80
-        'Title',
81
-        'Address',
82
-        'Suburb',
83
-        'State',
84
-        'Postcode',
85
-        'Country',
86
-        'Website',
87
-        'Phone',
88
-        'Email',
89
-        'Category.ID',
90
-        'ShowInLocator',
91
-        'Featured',
92
-    );
93
-
94
-    /**
95
-     * columns for grid field
96
-     *
97
-     * @var array
98
-     */
99
-    private static $summary_fields = array(
100
-        'Title',
101
-        'Address',
102
-        'Suburb',
103
-        'State',
104
-        'Postcode',
105
-        'Country',
106
-        'Category.Name',
107
-        'ShowInLocator.NiceAsBoolean',
108
-        'Featured.NiceAsBoolean',
109
-        'Coords',
110
-    );
111
-
112
-    /**
113
-     * Coords status for $summary_fields
114
-     *
115
-     * @return string
116
-     */
117
-    public function getCoords()
118
-    {
119
-        return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false';
120
-    }
121
-
122
-    /**
123
-     * custom labels for fields
124
-     *
125
-     * @param bool $includerelations
126
-     * @return array|string
127
-     */
128
-    public function fieldLabels($includerelations = true)
129
-    {
130
-        $labels = parent::fieldLabels($includerelations);
131
-
132
-        $labels['Title'] = 'Name';
133
-        $labels['Suburb'] = 'City';
134
-        $labels['Postcode'] = 'Postal Code';
135
-        $labels['ShowInLocator'] = 'Show';
136
-        $labels['ShowInLocator.NiceAsBoolean'] = 'Show';
137
-        $labels['Category.Name'] = 'Category';
138
-        $labels['Category.ID'] = 'Category';
139
-        $labels['Email'] = 'Email';
140
-        $labels['Featured.NiceAsBoolean'] = 'Featured';
141
-        $labels['Coords'] = 'Coords';
142
-
143
-        return $labels;
144
-    }
145
-
146
-    /**
147
-     * @return FieldList
148
-     */
149
-    public function getCMSFields()
150
-    {
151
-        $fields = FieldList::create(
152
-            new TabSet(
153
-                $name = 'Root',
154
-                new Tab(
155
-                    $title = 'Main',
156
-                    HeaderField::create('ContactHD', 'Contact Information'),
157
-                    TextField::create('Title', 'Name'),
158
-                    TextField::create('Phone'),
159
-                    EmailField::create('Email', 'Email'),
160
-                    TextField::create('Website')
161
-                        ->setAttribute('placeholder', 'http://'),
162
-                    DropdownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title'))
163
-                        ->setEmptyString('-- select --'),
164
-                    CheckboxField::create('ShowInLocator', 'Show in results')
165
-                        ->setDescription('Location will be included in results list'),
166
-                    CheckboxField::create('Featured')
167
-                        ->setDescription('Location will show at/near the top of the results list')
168
-                )
169
-            )
170
-        );
171
-
172
-        // allow to be extended via DataExtension
173
-        $this->extend('updateCMSFields', $fields);
174
-
175
-        // override Suburb field name
176
-        $fields->dataFieldByName('Suburb')->setTitle('City');
177
-
178
-        return $fields;
179
-    }
180
-
181
-    /**
182
-     * @return ValidationResult
183
-     */
184
-    public function validate()
185
-    {
186
-        $result = parent::validate();
187
-
188
-        return $result;
189
-    }
190
-
191
-    /**
192
-     * @return bool|string
193
-     */
194
-    public function EmailAddress()
195
-    {
196
-        Deprecation::notice('3.0', 'Use "$Email" instead.');
197
-        if ($this->Email) {
198
-            return $this->Email;
199
-        } elseif ($this->EmailAddress) {
200
-            return $this->EmailAddress;
201
-        }
202
-
203
-        return false;
204
-    }
205
-
206
-    /**
207
-     * @param null|Member $member
208
-     *
209
-     * @return bool
210
-     */
211
-    public function canView($member = null)
212
-    {
213
-        return true;
214
-    }
215
-
216
-    /**
217
-     * @param null|Member $member
218
-     * @return bool|int
219
-     */
220
-    public function canEdit($member = null)
221
-    {
222
-        return Permission::check('Location_EDIT', 'any', $member);
223
-    }
224
-
225
-    /**
226
-     * @param null|Member $member
227
-     * @return bool|int
228
-     */
229
-    public function canDelete($member = null)
230
-    {
231
-        return Permission::check('Location_DELETE', 'any', $member);
232
-    }
233
-
234
-    /**
235
-     * @param null|Member $member
236
-     * @return bool|int
237
-     */
238
-    public function canCreate($member = null)
239
-    {
240
-        return Permission::check('Location_CREATE', 'any', $member);
241
-    }
242
-
243
-    /**
244
-     * @return array
245
-     */
246
-    public function providePermissions()
247
-    {
248
-        return array(
249
-            'Location_EDIT' => 'Edit a Location',
250
-            'Location_DELETE' => 'Delete a Location',
251
-            'Location_CREATE' => 'Create a Location',
252
-        );
253
-    }
19
+	/**
20
+	 * @var array
21
+	 */
22
+	private static $db = array(
23
+		'Title' => 'Varchar(255)',
24
+		'Featured' => 'Boolean',
25
+		'Website' => 'Varchar(255)',
26
+		'Phone' => 'Varchar(40)',
27
+		'Email' => 'Varchar(255)',
28
+		'EmailAddress' => 'Varchar(255)',
29
+		'ShowInLocator' => 'Boolean',
30
+	);
31
+
32
+	/**
33
+	 * @var array
34
+	 */
35
+	private static $has_one = array(
36
+		'Category' => 'LocationCategory',
37
+	);
38
+
39
+	/**
40
+	 * @var array
41
+	 */
42
+	private static $casting = array(
43
+		'distance' => 'Int',
44
+	);
45
+
46
+	/**
47
+	 * @var string
48
+	 */
49
+	private static $default_sort = 'Title';
50
+
51
+	/**
52
+	 * @var array
53
+	 */
54
+	private static $defaults = array(
55
+		'ShowInLocator' => true,
56
+	);
57
+
58
+	/**
59
+	 * @var string
60
+	 */
61
+	private static $singular_name = 'Location';
62
+	/**
63
+	 * @var string
64
+	 */
65
+	private static $plural_name = 'Locations';
66
+
67
+	/**
68
+	 * api access via Restful Server module
69
+	 *
70
+	 * @var bool
71
+	 */
72
+	private static $api_access = true;
73
+
74
+	/**
75
+	 * search fields for Model Admin
76
+	 *
77
+	 * @var array
78
+	 */
79
+	private static $searchable_fields = array(
80
+		'Title',
81
+		'Address',
82
+		'Suburb',
83
+		'State',
84
+		'Postcode',
85
+		'Country',
86
+		'Website',
87
+		'Phone',
88
+		'Email',
89
+		'Category.ID',
90
+		'ShowInLocator',
91
+		'Featured',
92
+	);
93
+
94
+	/**
95
+	 * columns for grid field
96
+	 *
97
+	 * @var array
98
+	 */
99
+	private static $summary_fields = array(
100
+		'Title',
101
+		'Address',
102
+		'Suburb',
103
+		'State',
104
+		'Postcode',
105
+		'Country',
106
+		'Category.Name',
107
+		'ShowInLocator.NiceAsBoolean',
108
+		'Featured.NiceAsBoolean',
109
+		'Coords',
110
+	);
111
+
112
+	/**
113
+	 * Coords status for $summary_fields
114
+	 *
115
+	 * @return string
116
+	 */
117
+	public function getCoords()
118
+	{
119
+		return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false';
120
+	}
121
+
122
+	/**
123
+	 * custom labels for fields
124
+	 *
125
+	 * @param bool $includerelations
126
+	 * @return array|string
127
+	 */
128
+	public function fieldLabels($includerelations = true)
129
+	{
130
+		$labels = parent::fieldLabels($includerelations);
131
+
132
+		$labels['Title'] = 'Name';
133
+		$labels['Suburb'] = 'City';
134
+		$labels['Postcode'] = 'Postal Code';
135
+		$labels['ShowInLocator'] = 'Show';
136
+		$labels['ShowInLocator.NiceAsBoolean'] = 'Show';
137
+		$labels['Category.Name'] = 'Category';
138
+		$labels['Category.ID'] = 'Category';
139
+		$labels['Email'] = 'Email';
140
+		$labels['Featured.NiceAsBoolean'] = 'Featured';
141
+		$labels['Coords'] = 'Coords';
142
+
143
+		return $labels;
144
+	}
145
+
146
+	/**
147
+	 * @return FieldList
148
+	 */
149
+	public function getCMSFields()
150
+	{
151
+		$fields = FieldList::create(
152
+			new TabSet(
153
+				$name = 'Root',
154
+				new Tab(
155
+					$title = 'Main',
156
+					HeaderField::create('ContactHD', 'Contact Information'),
157
+					TextField::create('Title', 'Name'),
158
+					TextField::create('Phone'),
159
+					EmailField::create('Email', 'Email'),
160
+					TextField::create('Website')
161
+						->setAttribute('placeholder', 'http://'),
162
+					DropdownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title'))
163
+						->setEmptyString('-- select --'),
164
+					CheckboxField::create('ShowInLocator', 'Show in results')
165
+						->setDescription('Location will be included in results list'),
166
+					CheckboxField::create('Featured')
167
+						->setDescription('Location will show at/near the top of the results list')
168
+				)
169
+			)
170
+		);
171
+
172
+		// allow to be extended via DataExtension
173
+		$this->extend('updateCMSFields', $fields);
174
+
175
+		// override Suburb field name
176
+		$fields->dataFieldByName('Suburb')->setTitle('City');
177
+
178
+		return $fields;
179
+	}
180
+
181
+	/**
182
+	 * @return ValidationResult
183
+	 */
184
+	public function validate()
185
+	{
186
+		$result = parent::validate();
187
+
188
+		return $result;
189
+	}
190
+
191
+	/**
192
+	 * @return bool|string
193
+	 */
194
+	public function EmailAddress()
195
+	{
196
+		Deprecation::notice('3.0', 'Use "$Email" instead.');
197
+		if ($this->Email) {
198
+			return $this->Email;
199
+		} elseif ($this->EmailAddress) {
200
+			return $this->EmailAddress;
201
+		}
202
+
203
+		return false;
204
+	}
205
+
206
+	/**
207
+	 * @param null|Member $member
208
+	 *
209
+	 * @return bool
210
+	 */
211
+	public function canView($member = null)
212
+	{
213
+		return true;
214
+	}
215
+
216
+	/**
217
+	 * @param null|Member $member
218
+	 * @return bool|int
219
+	 */
220
+	public function canEdit($member = null)
221
+	{
222
+		return Permission::check('Location_EDIT', 'any', $member);
223
+	}
224
+
225
+	/**
226
+	 * @param null|Member $member
227
+	 * @return bool|int
228
+	 */
229
+	public function canDelete($member = null)
230
+	{
231
+		return Permission::check('Location_DELETE', 'any', $member);
232
+	}
233
+
234
+	/**
235
+	 * @param null|Member $member
236
+	 * @return bool|int
237
+	 */
238
+	public function canCreate($member = null)
239
+	{
240
+		return Permission::check('Location_CREATE', 'any', $member);
241
+	}
242
+
243
+	/**
244
+	 * @return array
245
+	 */
246
+	public function providePermissions()
247
+	{
248
+		return array(
249
+			'Location_EDIT' => 'Edit a Location',
250
+			'Location_DELETE' => 'Delete a Location',
251
+			'Location_CREATE' => 'Create a Location',
252
+		);
253
+	}
254 254
 
255 255
 }
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/bulkloader/LocationCsvBulkLoader.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -6,43 +6,43 @@
 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
-    );
9
+	/**
10
+	 * @var array
11
+	 */
12
+	public $columnMap = array(
13
+		'Name' => 'Title',
14
+		'City' => 'Suburb',
15
+		'EmailAddress' => 'Email',
16
+		'Category' => 'Category.Name',
17
+	);
18 18
 
19
-    /**
20
-     * @var array
21
-     */
22
-    public $relationCallbacks = array(
23
-       'Category.Name' => array(
24
-           'relationname' => 'Category',
25
-           'callback' => 'getCategoryByName',
26
-        ),
27
-    );
19
+	/**
20
+	 * @var array
21
+	 */
22
+	public $relationCallbacks = array(
23
+	   'Category.Name' => array(
24
+		   'relationname' => 'Category',
25
+		   'callback' => 'getCategoryByName',
26
+		),
27
+	);
28 28
 
29
-    /**
30
-     * @param $obj
31
-     * @param $val
32
-     * @param $record
33
-     * @return DataObject|static
34
-     */
35
-    public static function getCategoryByName(&$obj, $val, $record)
36
-    {
37
-        $val = Convert::raw2sql($val);
38
-        $category = LocationCategory::get()->filter(array('Name' => $val))->First();
39
-        if (!$category) {
40
-            $category = LocationCategory::create();
41
-            $category->Name = $val;
42
-            $category->write();
43
-        }
29
+	/**
30
+	 * @param $obj
31
+	 * @param $val
32
+	 * @param $record
33
+	 * @return DataObject|static
34
+	 */
35
+	public static function getCategoryByName(&$obj, $val, $record)
36
+	{
37
+		$val = Convert::raw2sql($val);
38
+		$category = LocationCategory::get()->filter(array('Name' => $val))->First();
39
+		if (!$category) {
40
+			$category = LocationCategory::create();
41
+			$category->Name = $val;
42
+			$category->write();
43
+		}
44 44
 
45
-        return $category;
46
-    }
45
+		return $category;
46
+	}
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/extensions/DistanceDataExtension.php 2 patches
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -2,21 +2,21 @@
 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
-        if (Controller::curr()->getRequest()->getVar('Address')) { // on frontend
11
-            $coords = GoogleGeocoding::address_to_point(Controller::curr()->getRequest()->getVar('Address'));
5
+	/**
6
+	 * @param SQLQuery $query
7
+	 */
8
+	public function augmentSQL(SQLQuery &$query)
9
+	{
10
+		if (Controller::curr()->getRequest()->getVar('Address')) { // on frontend
11
+			$coords = GoogleGeocoding::address_to_point(Controller::curr()->getRequest()->getVar('Address'));
12 12
 
13
-            $Lat = $coords['lat'];
14
-            $Lng = $coords['lng'];
13
+			$Lat = $coords['lat'];
14
+			$Lng = $coords['lng'];
15 15
 
16
-            $query
17
-                ->addSelect(array(
18
-                    '( 3959 * acos( cos( radians('.$Lat.') ) * cos( radians( `Lat` ) ) * cos( radians( `Lng` ) - radians('.$Lng.') ) + sin( radians('.$Lat.') ) * sin( radians( `Lat` ) ) ) ) AS distance',
19
-                ));
20
-        }
21
-    }
16
+			$query
17
+				->addSelect(array(
18
+					'( 3959 * acos( cos( radians('.$Lat.') ) * cos( radians( `Lat` ) ) * cos( radians( `Lng` ) - radians('.$Lng.') ) + sin( radians('.$Lat.') ) * sin( radians( `Lat` ) ) ) ) AS distance',
19
+				));
20
+		}
21
+	}
22 22
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@
 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
         if (Controller::curr()->getRequest()->getVar('Address')) { // on frontend
11 11
             $coords = GoogleGeocoding::address_to_point(Controller::curr()->getRequest()->getVar('Address'));
Please login to merge, or discard this patch.
code/form/LocatorForm.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -6,45 +6,45 @@
 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
-    {
9
+	/**
10
+	 * LocatorForm constructor.
11
+	 * @param Controller $controller
12
+	 * @param string $name
13
+	 */
14
+	public function __construct(Controller $controller, $name)
15
+	{
16 16
 
17
-        $fields = FieldList::create(
18
-            TextField::create('Address')
19
-                ->setTitle('')
20
-                ->setAttribute('placeholder', 'address or zip code')
21
-        );
17
+		$fields = FieldList::create(
18
+			TextField::create('Address')
19
+				->setTitle('')
20
+				->setAttribute('placeholder', 'address or zip code')
21
+		);
22 22
 
23
-        $categories = (Locator::locator_categories_by_locator($controller->data()->ID)->count() > 0)
24
-            ? Locator::locator_categories_by_locator($controller->data()->ID)
25
-            : Locator::get_all_categories();
23
+		$categories = (Locator::locator_categories_by_locator($controller->data()->ID)->count() > 0)
24
+			? Locator::locator_categories_by_locator($controller->data()->ID)
25
+			: Locator::get_all_categories();
26 26
 
27
-        $categoriesField = DropdownField::create('CategoryID')
28
-            ->setTitle('')
29
-            ->setEmptyString('All Categories')
30
-            ->setSource($categories->map());
27
+		$categoriesField = DropdownField::create('CategoryID')
28
+			->setTitle('')
29
+			->setEmptyString('All Categories')
30
+			->setSource($categories->map());
31 31
 
32
-        $fields->push($categoriesField);
32
+		$fields->push($categoriesField);
33 33
 
34
-        $this->extend('updateLocatorFormFields', $fields);
34
+		$this->extend('updateLocatorFormFields', $fields);
35 35
 
36
-        $actions = FieldList::create(
37
-            FormAction::create('doFilterLocations')
38
-                ->setTitle('Search')
39
-        );
36
+		$actions = FieldList::create(
37
+			FormAction::create('doFilterLocations')
38
+				->setTitle('Search')
39
+		);
40 40
 
41
-        $this->extend('updateLocatorFormActions', $actions);
41
+		$this->extend('updateLocatorFormActions', $actions);
42 42
 
43
-        $validator = RequiredFields::create();
43
+		$validator = RequiredFields::create();
44 44
 
45
-        $this->extend('updateLocatorFormRequiredFields', $validator);
45
+		$this->extend('updateLocatorFormRequiredFields', $validator);
46 46
 
47
-        parent::__construct($controller, $name, $fields, $actions, $validator);
48
-    }
47
+		parent::__construct($controller, $name, $fields, $actions, $validator);
48
+	}
49 49
 
50 50
 }
51 51
\ No newline at end of file
Please login to merge, or discard this patch.
code/form/LocatorBootstrapForm.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -2,53 +2,53 @@
 block discarded – undo
2 2
 
3 3
 if (class_exists('BootstrapForm')) {
4 4
 
5
-    /**
6
-     * Class LocatorForm
7
-     */
8
-    class LocatorBootstrapForm extends BootstrapForm
9
-    {
5
+	/**
6
+	 * Class LocatorForm
7
+	 */
8
+	class LocatorBootstrapForm extends BootstrapForm
9
+	{
10 10
 
11
-        /**
12
-         * LocatorForm constructor.
13
-         * @param Controller $controller
14
-         * @param string $name
15
-         */
16
-        public function __construct(Controller $controller, $name)
17
-        {
11
+		/**
12
+		 * LocatorForm constructor.
13
+		 * @param Controller $controller
14
+		 * @param string $name
15
+		 */
16
+		public function __construct(Controller $controller, $name)
17
+		{
18 18
 
19
-            $fields = FieldList::create(
20
-                TextField::create('Address')
21
-                    ->setTitle('')
22
-                    ->setAttribute('placeholder', 'address or zip code')
23
-            );
19
+			$fields = FieldList::create(
20
+				TextField::create('Address')
21
+					->setTitle('')
22
+					->setAttribute('placeholder', 'address or zip code')
23
+			);
24 24
 
25
-            $categories = (Locator::locator_categories_by_locator($controller->data()->ID)->count() > 0)
26
-                ? Locator::locator_categories_by_locator($controller->data()->ID)
27
-                : Locator::get_all_categories();
25
+			$categories = (Locator::locator_categories_by_locator($controller->data()->ID)->count() > 0)
26
+				? Locator::locator_categories_by_locator($controller->data()->ID)
27
+				: Locator::get_all_categories();
28 28
 
29
-            $categoriesField = DropdownField::create('CategoryID')
30
-                ->setTitle('')
31
-                ->setEmptyString('All Categories')
32
-                ->setSource($categories->map());
29
+			$categoriesField = DropdownField::create('CategoryID')
30
+				->setTitle('')
31
+				->setEmptyString('All Categories')
32
+				->setSource($categories->map());
33 33
 
34
-            $fields->push($categoriesField);
34
+			$fields->push($categoriesField);
35 35
 
36
-            $this->extend('updateLocatorFormFields', $fields);
36
+			$this->extend('updateLocatorFormFields', $fields);
37 37
 
38
-            $actions = FieldList::create(
39
-                FormAction::create('doFilterLocations')
40
-                    ->setTitle('Search')
41
-            );
38
+			$actions = FieldList::create(
39
+				FormAction::create('doFilterLocations')
40
+					->setTitle('Search')
41
+			);
42 42
 
43
-            $this->extend('updateLocatorFormActions', $actions);
43
+			$this->extend('updateLocatorFormActions', $actions);
44 44
 
45
-            $validator = RequiredFields::create();
45
+			$validator = RequiredFields::create();
46 46
 
47
-            $this->extend('updateLocatorFormRequiredFields', $validator);
47
+			$this->extend('updateLocatorFormRequiredFields', $validator);
48 48
 
49
-            parent::__construct($controller, $name, $fields, $actions, $validator);
50
-        }
49
+			parent::__construct($controller, $name, $fields, $actions, $validator);
50
+		}
51 51
 
52
-    }
52
+	}
53 53
 
54 54
 }
55 55
\ No newline at end of file
Please login to merge, or discard this patch.