Completed
Pull Request — master (#105)
by Nic
26:42
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.
tests/LocatorTest.php 1 patch
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -6,121 +6,121 @@
 block discarded – undo
6 6
 class LocatorTest extends Locator_Test
7 7
 {
8 8
 
9
-    /**
10
-     *
11
-     */
12
-    public function testGetCMSFields()
13
-    {
14
-        $object = new Locator();
15
-        $fieldset = $object->getCMSFields();
16
-        $this->assertInstanceOf('FieldList', $fieldset);
17
-    }
18
-
19
-    /**
20
-     *
21
-     */
22
-    public function testLocations()
23
-    {
24
-        $filter = Config::inst()->get('Locator_Controller', 'base_filter');
25
-        $filterAny = Config::inst()->get('Locator_Controller', 'base_filter_any');
26
-        $exclude = Config::inst()->get('Locator_Controller', 'base_exclude');
27
-
28
-        $locator = $this->objFromFixture('Locator', 'locator1');
29
-
30
-        $locatorController = new Locator_Controller($locator);
31
-
32
-        $locations = Locator::get_locations($locatorController->getRequest(), $locator->ID, $filter, $filterAny, $exclude);
33
-        $locations2 = Location::get()->filter($filter)->filterAny($filterAny)->exclude($exclude);
34
-        $this->assertEquals($locations->count(), $locations2->count());
35
-    }
36
-
37
-    /**
38
-     *
39
-     */
40
-    public function testGetAllCategories()
41
-    {
42
-        $locator = singleton('Locator');
43
-        $count = LocationCategory::get();
44
-        $this->assertEquals($locator->getAllCategories(), $count);
45
-    }
46
-
47
-    /**
48
-     *
49
-     */
50
-    public function testGetPageCategories()
51
-    {
52
-        $locator = Locator::create();
53
-        $this->assertFalse($locator->getPageCategories());
54
-
55
-        $this->assertFalse($locator->getPageCategories(500));
56
-
57
-        $locator->write();
58
-        $category = $this->objFromFixture('LocationCategory', 'service');
59
-        $locator->Categories()->add($category);
60
-        $this->assertEquals($locator->getPageCategories($locator->ID), $locator->Categories());
61
-    }
62
-
63
-    /**
64
-     *
65
-     */
66
-    public function testInit()
67
-    {
68
-    }
69
-
70
-    /**
71
-     *
72
-     */
73
-    public function testIndex()
74
-    {
75
-        $locator = $this->objFromFixture('Locator', 'locator1');
76
-        $controller = Locator_Controller::create($locator);
77
-        $this->assertInstanceOf('ViewableData', $controller->index($controller->request));
78
-    }
79
-
80
-    /**
81
-     *
82
-     */
83
-    public function testXml()
84
-    {
85
-        $locator = $this->objFromFixture('Locator', 'locator1');
86
-        $controller = Locator_Controller::create($locator);
87
-        $this->assertInstanceOf('HTMLText', $controller->xml($controller->request));
88
-    }
89
-
90
-    /**
91
-     *
92
-     */
93
-    public function testItems()
94
-    {
95
-        $locator = $this->objFromFixture('Locator', 'locator1');
96
-        $controller = Locator_Controller::create($locator);
97
-
98
-        $filter = array('ShowInLocator' => 1);
99
-        $exclude = ['Lat' => 0.00000, 'Lng' => 0.00000];
100
-
101
-        $locations = $controller->getLocations();
102
-        $locations2 = Location::get()->filter($filter)->exclude($exclude);
103
-        $this->assertEquals($locations->count(), $locations2->count());
104
-    }
105
-
106
-    /**
107
-     *
108
-     */
109
-    public function testLocationSearch()
110
-    {
111
-        $locator = $this->objFromFixture('Locator', 'locator1');
112
-        $object = Locator_Controller::create($locator);
113
-        $form = $object->LocationSearch();
114
-        $this->assertTrue(is_a($form, 'Form'));
115
-
116
-        $category = $this->objFromFixture('LocationCategory', 'service');
117
-        $category2 = $this->objFromFixture('LocationCategory', 'manufacturing');
118
-        $locator->Categories()->add($category);
119
-        $locator->Categories()->add($category2);
120
-
121
-        $form = $object->LocationSearch();
122
-        $fields = $form->Fields();
123
-        $this->assertNotNull($fields->fieldByName('CategoryID'));
124
-    }
9
+	/**
10
+	 *
11
+	 */
12
+	public function testGetCMSFields()
13
+	{
14
+		$object = new Locator();
15
+		$fieldset = $object->getCMSFields();
16
+		$this->assertInstanceOf('FieldList', $fieldset);
17
+	}
18
+
19
+	/**
20
+	 *
21
+	 */
22
+	public function testLocations()
23
+	{
24
+		$filter = Config::inst()->get('Locator_Controller', 'base_filter');
25
+		$filterAny = Config::inst()->get('Locator_Controller', 'base_filter_any');
26
+		$exclude = Config::inst()->get('Locator_Controller', 'base_exclude');
27
+
28
+		$locator = $this->objFromFixture('Locator', 'locator1');
29
+
30
+		$locatorController = new Locator_Controller($locator);
31
+
32
+		$locations = Locator::get_locations($locatorController->getRequest(), $locator->ID, $filter, $filterAny, $exclude);
33
+		$locations2 = Location::get()->filter($filter)->filterAny($filterAny)->exclude($exclude);
34
+		$this->assertEquals($locations->count(), $locations2->count());
35
+	}
36
+
37
+	/**
38
+	 *
39
+	 */
40
+	public function testGetAllCategories()
41
+	{
42
+		$locator = singleton('Locator');
43
+		$count = LocationCategory::get();
44
+		$this->assertEquals($locator->getAllCategories(), $count);
45
+	}
46
+
47
+	/**
48
+	 *
49
+	 */
50
+	public function testGetPageCategories()
51
+	{
52
+		$locator = Locator::create();
53
+		$this->assertFalse($locator->getPageCategories());
54
+
55
+		$this->assertFalse($locator->getPageCategories(500));
56
+
57
+		$locator->write();
58
+		$category = $this->objFromFixture('LocationCategory', 'service');
59
+		$locator->Categories()->add($category);
60
+		$this->assertEquals($locator->getPageCategories($locator->ID), $locator->Categories());
61
+	}
62
+
63
+	/**
64
+	 *
65
+	 */
66
+	public function testInit()
67
+	{
68
+	}
69
+
70
+	/**
71
+	 *
72
+	 */
73
+	public function testIndex()
74
+	{
75
+		$locator = $this->objFromFixture('Locator', 'locator1');
76
+		$controller = Locator_Controller::create($locator);
77
+		$this->assertInstanceOf('ViewableData', $controller->index($controller->request));
78
+	}
79
+
80
+	/**
81
+	 *
82
+	 */
83
+	public function testXml()
84
+	{
85
+		$locator = $this->objFromFixture('Locator', 'locator1');
86
+		$controller = Locator_Controller::create($locator);
87
+		$this->assertInstanceOf('HTMLText', $controller->xml($controller->request));
88
+	}
89
+
90
+	/**
91
+	 *
92
+	 */
93
+	public function testItems()
94
+	{
95
+		$locator = $this->objFromFixture('Locator', 'locator1');
96
+		$controller = Locator_Controller::create($locator);
97
+
98
+		$filter = array('ShowInLocator' => 1);
99
+		$exclude = ['Lat' => 0.00000, 'Lng' => 0.00000];
100
+
101
+		$locations = $controller->getLocations();
102
+		$locations2 = Location::get()->filter($filter)->exclude($exclude);
103
+		$this->assertEquals($locations->count(), $locations2->count());
104
+	}
105
+
106
+	/**
107
+	 *
108
+	 */
109
+	public function testLocationSearch()
110
+	{
111
+		$locator = $this->objFromFixture('Locator', 'locator1');
112
+		$object = Locator_Controller::create($locator);
113
+		$form = $object->LocationSearch();
114
+		$this->assertTrue(is_a($form, 'Form'));
115
+
116
+		$category = $this->objFromFixture('LocationCategory', 'service');
117
+		$category2 = $this->objFromFixture('LocationCategory', 'manufacturing');
118
+		$locator->Categories()->add($category);
119
+		$locator->Categories()->add($category2);
120
+
121
+		$form = $object->LocationSearch();
122
+		$fields = $form->Fields();
123
+		$this->assertNotNull($fields->fieldByName('CategoryID'));
124
+	}
125 125
 
126 126
 }
Please login to merge, or discard this patch.
code/pages/Locator.php 2 patches
Indentation   +349 added lines, -349 removed lines patch added patch discarded remove patch
@@ -11,168 +11,168 @@  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 SS_HTTPRequest|null $request
89
-     * @param int $locatorID
90
-     * @param array $filter
91
-     * @param array $filterAny
92
-     * @param array $exclude
93
-     * @param string $locationClass
94
-     * @param null $filterByCallback
95
-     * @return ArrayList
96
-     */
97
-    public static function get_locations(
98
-        SS_HTTPRequest $request = null,
99
-        $locatorID,
100
-        $filter = [],
101
-        $filterAny = [],
102
-        $exclude = [],
103
-        $locationClass = 'Location',
104
-        $filterByCallback = null
105
-    )
106
-    {
107
-
108
-        $request = ($request != null) ? $request : Controller::curr()->getRequest();
109
-
110
-        // search across all address related fields
111
-        $address = ($request->getVar('Address')) ? $request->getVar('Address') : false;
112
-        if ($address && !Locator::get()->byID($locatorID)->AutoGeocode) {
113
-            $filterAny['Address:PartialMatch'] = $address;
114
-            $filterAny['Suburb:PartialMatch'] = $address;
115
-            $filterAny['State:PartialMatch'] = $address;
116
-            $filterAny['Postcode:PartialMatch'] = $address;
117
-            $filterAny['Country:PartialMatch'] = $address;
118
-        }
119
-
120
-        // search for category from form, else categories from Locator
121
-        $category = ($request->getVar('CategoryID')) ? $request->getVar('CategoryID') : false;
122
-        if ($category) {
123
-            $filter['CategoryID:ExactMatch'] = $category;
124
-        } elseif (Locator::get()->byID($locatorID)->Categories()->exists()) {
125
-            $categories = Locator::get()->byID($locatorID)->Categories();
126
-            $categoryArray = array();
127
-            foreach ($categories as $category) {
128
-                array_push($categoryArray, $category->ID);
129
-            }
130
-            $filter['CategoryID'] = $categoryArray;
131
-        }
132
-
133
-        $locationsList = ArrayList::create();
134
-
135
-        $locations = $locationClass::get()->filter($filter)->exclude($exclude);
136
-
137
-        if (!empty($filterAny)) {
138
-            $locations = $locations->filterAny($filterAny);
139
-        }
140
-
141
-        if ($filterByCallback !== null && is_callable($filterByCallback)) {
142
-            $locations = $locations->filterByCallback($filterByCallback);
143
-        }
144
-
145
-        if ($locations->exists()) {
146
-            $locationsList->merge($locations);
147
-        }
148
-
149
-        return $locationsList;
150
-    }
151
-
152
-    /**
153
-     * @return DataList
154
-     */
155
-    public static function getAllCategories()
156
-    {
157
-        return LocationCategory::get();
158
-    }
159
-
160
-    /**
161
-     * @param null $id
162
-     * @return bool
163
-     */
164
-    public static function getPageCategories($id = null)
165
-    {
166
-        if ($id) {
167
-            if ($locator = self::get()->byID($id)) {
168
-                return $locator->Categories();
169
-            }
170
-
171
-            return false;
172
-        }
173
-
174
-        return false;
175
-    }
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 SS_HTTPRequest|null $request
89
+	 * @param int $locatorID
90
+	 * @param array $filter
91
+	 * @param array $filterAny
92
+	 * @param array $exclude
93
+	 * @param string $locationClass
94
+	 * @param null $filterByCallback
95
+	 * @return ArrayList
96
+	 */
97
+	public static function get_locations(
98
+		SS_HTTPRequest $request = null,
99
+		$locatorID,
100
+		$filter = [],
101
+		$filterAny = [],
102
+		$exclude = [],
103
+		$locationClass = 'Location',
104
+		$filterByCallback = null
105
+	)
106
+	{
107
+
108
+		$request = ($request != null) ? $request : Controller::curr()->getRequest();
109
+
110
+		// search across all address related fields
111
+		$address = ($request->getVar('Address')) ? $request->getVar('Address') : false;
112
+		if ($address && !Locator::get()->byID($locatorID)->AutoGeocode) {
113
+			$filterAny['Address:PartialMatch'] = $address;
114
+			$filterAny['Suburb:PartialMatch'] = $address;
115
+			$filterAny['State:PartialMatch'] = $address;
116
+			$filterAny['Postcode:PartialMatch'] = $address;
117
+			$filterAny['Country:PartialMatch'] = $address;
118
+		}
119
+
120
+		// search for category from form, else categories from Locator
121
+		$category = ($request->getVar('CategoryID')) ? $request->getVar('CategoryID') : false;
122
+		if ($category) {
123
+			$filter['CategoryID:ExactMatch'] = $category;
124
+		} elseif (Locator::get()->byID($locatorID)->Categories()->exists()) {
125
+			$categories = Locator::get()->byID($locatorID)->Categories();
126
+			$categoryArray = array();
127
+			foreach ($categories as $category) {
128
+				array_push($categoryArray, $category->ID);
129
+			}
130
+			$filter['CategoryID'] = $categoryArray;
131
+		}
132
+
133
+		$locationsList = ArrayList::create();
134
+
135
+		$locations = $locationClass::get()->filter($filter)->exclude($exclude);
136
+
137
+		if (!empty($filterAny)) {
138
+			$locations = $locations->filterAny($filterAny);
139
+		}
140
+
141
+		if ($filterByCallback !== null && is_callable($filterByCallback)) {
142
+			$locations = $locations->filterByCallback($filterByCallback);
143
+		}
144
+
145
+		if ($locations->exists()) {
146
+			$locationsList->merge($locations);
147
+		}
148
+
149
+		return $locationsList;
150
+	}
151
+
152
+	/**
153
+	 * @return DataList
154
+	 */
155
+	public static function getAllCategories()
156
+	{
157
+		return LocationCategory::get();
158
+	}
159
+
160
+	/**
161
+	 * @param null $id
162
+	 * @return bool
163
+	 */
164
+	public static function getPageCategories($id = null)
165
+	{
166
+		if ($id) {
167
+			if ($locator = self::get()->byID($id)) {
168
+				return $locator->Categories();
169
+			}
170
+
171
+			return false;
172
+		}
173
+
174
+		return false;
175
+	}
176 176
 
177 177
 
178 178
 }
@@ -182,105 +182,105 @@  discard block
 block discarded – undo
182 182
  */
183 183
 class Locator_Controller extends Page_Controller
184 184
 {
185
-    /**
186
-     * @var array
187
-     */
188
-    private static $allowed_actions = [
189
-        'xml',
190
-    ];
191
-
192
-    /**
193
-     * @var array
194
-     */
195
-    private static $base_filter = [
196
-        'ShowInLocator' => true,
197
-    ];
198
-
199
-    /**
200
-     * @var array
201
-     */
202
-    private static $base_filter_any = [];
203
-
204
-    /**
205
-     * @var array
206
-     */
207
-    private static $base_exclude = [
208
-        'Lat' => 0.00000,
209
-        'Lng' => 0.00000,
210
-    ];
211
-
212
-    /**
213
-     * @var
214
-     */
215
-    private $locations;
216
-
217
-    /**
218
-     * Set Requirements based on input from CMS
219
-     */
220
-    public function init()
221
-    {
222
-        parent::init();
223
-
224
-        $themeDir = SSViewer::get_theme_folder();
225
-
226
-        // google maps api key
227
-        $key = Config::inst()->get('GoogleGeocoding', 'google_api_key');
228
-
229
-        $locations = $this->getLocations();
230
-
231
-        Requirements::javascript('framework/thirdparty/jquery/jquery.js');
232
-        if ($locations) {
233
-            Requirements::javascript('http://maps.google.com/maps/api/js?key=' . $key);
234
-            Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
235
-            Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
236
-        }
237
-
238
-        Requirements::css('locator/css/map.css');
239
-
240
-        $featuredInList = ($locations->filter('Featured', true)->count() > 0);
241
-
242
-        $featured = $featuredInList
243
-            ? 'featuredLocations: true'
244
-            : 'featuredLocations: false';
245
-
246
-        // map config based on user input in Settings tab
247
-        // AutoGeocode or Full Map
248
-        if ($this->data()->AutoGeocode) {
249
-            $load = $featuredInList
250
-                ? 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'
251
-                : 'autoGeocode: true, fullMapStart: false,';
252
-        } else {
253
-            $load = 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
254
-        }
255
-
256
-        $base = Director::baseFolder();
257
-        $themePath = $base . '/' . $themeDir;
258
-
259
-        $listTemplatePath = (file_exists($themePath . '/templates/location-list-description.html')) ?
260
-            $themeDir . '/templates/location-list-description.html' :
261
-            'locator/templates/location-list-description.html';
262
-        $infowindowTemplatePath = (file_exists($themePath . '/templates/infowindow-description.html')) ?
263
-            $themeDir . '/templates/infowindow-description.html' :
264
-            'locator/templates/infowindow-description.html';
265
-
266
-        // in page or modal
267
-        $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';
268
-
269
-        $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"';
270
-
271
-        // pass GET variables to xml action
272
-        $vars = $this->request->getVars();
273
-        unset($vars['url']);
274
-        unset($vars['action_index']);
275
-        $url = '';
276
-        if (count($vars)) {
277
-            $url .= '?' . http_build_query($vars);
278
-        }
279
-        $link = $this->Link() . 'xml.xml' . $url;
280
-
281
-        // init map
282
-        if ($locations) {
283
-            Requirements::customScript("
185
+	/**
186
+	 * @var array
187
+	 */
188
+	private static $allowed_actions = [
189
+		'xml',
190
+	];
191
+
192
+	/**
193
+	 * @var array
194
+	 */
195
+	private static $base_filter = [
196
+		'ShowInLocator' => true,
197
+	];
198
+
199
+	/**
200
+	 * @var array
201
+	 */
202
+	private static $base_filter_any = [];
203
+
204
+	/**
205
+	 * @var array
206
+	 */
207
+	private static $base_exclude = [
208
+		'Lat' => 0.00000,
209
+		'Lng' => 0.00000,
210
+	];
211
+
212
+	/**
213
+	 * @var
214
+	 */
215
+	private $locations;
216
+
217
+	/**
218
+	 * Set Requirements based on input from CMS
219
+	 */
220
+	public function init()
221
+	{
222
+		parent::init();
223
+
224
+		$themeDir = SSViewer::get_theme_folder();
225
+
226
+		// google maps api key
227
+		$key = Config::inst()->get('GoogleGeocoding', 'google_api_key');
228
+
229
+		$locations = $this->getLocations();
230
+
231
+		Requirements::javascript('framework/thirdparty/jquery/jquery.js');
232
+		if ($locations) {
233
+			Requirements::javascript('http://maps.google.com/maps/api/js?key=' . $key);
234
+			Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
235
+			Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
236
+		}
237
+
238
+		Requirements::css('locator/css/map.css');
239
+
240
+		$featuredInList = ($locations->filter('Featured', true)->count() > 0);
241
+
242
+		$featured = $featuredInList
243
+			? 'featuredLocations: true'
244
+			: 'featuredLocations: false';
245
+
246
+		// map config based on user input in Settings tab
247
+		// AutoGeocode or Full Map
248
+		if ($this->data()->AutoGeocode) {
249
+			$load = $featuredInList
250
+				? 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'
251
+				: 'autoGeocode: true, fullMapStart: false,';
252
+		} else {
253
+			$load = 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
254
+		}
255
+
256
+		$base = Director::baseFolder();
257
+		$themePath = $base . '/' . $themeDir;
258
+
259
+		$listTemplatePath = (file_exists($themePath . '/templates/location-list-description.html')) ?
260
+			$themeDir . '/templates/location-list-description.html' :
261
+			'locator/templates/location-list-description.html';
262
+		$infowindowTemplatePath = (file_exists($themePath . '/templates/infowindow-description.html')) ?
263
+			$themeDir . '/templates/infowindow-description.html' :
264
+			'locator/templates/infowindow-description.html';
265
+
266
+		// in page or modal
267
+		$modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';
268
+
269
+		$kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"';
270
+
271
+		// pass GET variables to xml action
272
+		$vars = $this->request->getVars();
273
+		unset($vars['url']);
274
+		unset($vars['action_index']);
275
+		$url = '';
276
+		if (count($vars)) {
277
+			$url .= '?' . http_build_query($vars);
278
+		}
279
+		$link = $this->Link() . 'xml.xml' . $url;
280
+
281
+		// init map
282
+		if ($locations) {
283
+			Requirements::customScript("
284 284
                 $(function($) {
285 285
                     $('#map-container').storeLocator({
286 286
                         " . $load . "
@@ -301,93 +301,93 @@  discard block
 block discarded – undo
301 301
                     });
302 302
                 });
303 303
             ');
304
-        }
305
-    }
306
-
307
-    /**
308
-     * @param SS_HTTPRequest $request
309
-     *
310
-     * @return ViewableData_Customised
311
-     */
312
-    public function index(SS_HTTPRequest $request)
313
-    {
314
-        $locations = $this->getLocations();
315
-
316
-        return $this->customise(array(
317
-            'Locations' => $locations,
318
-        ));
319
-    }
320
-
321
-    /**
322
-     * Return a XML feed of all locations marked "show in locator"
323
-     *
324
-     * @param SS_HTTPRequest $request
325
-     * @return HTMLText
326
-     */
327
-    public function xml(SS_HTTPRequest $request)
328
-    {
329
-        $this->setLocations($request);
330
-        $locations = $this->getLocations();
331
-
332
-        return $this->customise(array(
333
-            'Locations' => $locations,
334
-        ))->renderWith('LocationXML');
335
-    }
336
-
337
-    /**
338
-     * @return mixed
339
-     */
340
-    public function getLocations()
341
-    {
342
-        if (!$this->locations) {
343
-            $this->setLocations($this->request);
344
-        }
345
-        return $this->locations;
346
-    }
347
-
348
-    /**
349
-     * @param SS_HTTPRequest|null $request
350
-     * @return $this
351
-     */
352
-    public function setLocations(SS_HTTPRequest $request = null)
353
-    {
354
-        if ($request === null) {
355
-            $request = $this->request;
356
-        }
357
-        $filter = $this->config()->get('base_filter');
358
-        $this->extend('updateLocatorFilter', $filter, $request);
359
-
360
-        $filterAny = $this->config()->get('base_filter_any');
361
-        $this->extend('updateLocatorFilterAny', $filterAny, $request);
362
-
363
-        $exclude = $this->config()->get('base_exclude');
364
-        $this->extend('updateLocatorExclude', $exclude, $request);
365
-
366
-        $this->locations = Locator::get_locations($request, $this->data()->ID, $filter, $filterAny, $exclude);
367
-        return $this;
368
-    }
369
-
370
-    /**
371
-     * LocationSearch form.
372
-     *
373
-     * Search form for locations, updates map and results list via AJAX
374
-     *
375
-     * @return Form
376
-     */
377
-    public function LocationSearch()
378
-    {
379
-
380
-        if (class_exists('BootstrapForm')) {
381
-            $form = LocatorBootstrapForm::create($this, 'LocationSearch');
382
-        } else {
383
-            $form = LocatorForm::create($this, 'LocationSearch');
384
-        }
385
-
386
-        return $form
387
-            ->setFormMethod('GET')
388
-            ->setFormAction($this->Link())
389
-            ->disableSecurityToken()
390
-            ->loadDataFrom($this->request->getVars());
391
-    }
304
+		}
305
+	}
306
+
307
+	/**
308
+	 * @param SS_HTTPRequest $request
309
+	 *
310
+	 * @return ViewableData_Customised
311
+	 */
312
+	public function index(SS_HTTPRequest $request)
313
+	{
314
+		$locations = $this->getLocations();
315
+
316
+		return $this->customise(array(
317
+			'Locations' => $locations,
318
+		));
319
+	}
320
+
321
+	/**
322
+	 * Return a XML feed of all locations marked "show in locator"
323
+	 *
324
+	 * @param SS_HTTPRequest $request
325
+	 * @return HTMLText
326
+	 */
327
+	public function xml(SS_HTTPRequest $request)
328
+	{
329
+		$this->setLocations($request);
330
+		$locations = $this->getLocations();
331
+
332
+		return $this->customise(array(
333
+			'Locations' => $locations,
334
+		))->renderWith('LocationXML');
335
+	}
336
+
337
+	/**
338
+	 * @return mixed
339
+	 */
340
+	public function getLocations()
341
+	{
342
+		if (!$this->locations) {
343
+			$this->setLocations($this->request);
344
+		}
345
+		return $this->locations;
346
+	}
347
+
348
+	/**
349
+	 * @param SS_HTTPRequest|null $request
350
+	 * @return $this
351
+	 */
352
+	public function setLocations(SS_HTTPRequest $request = null)
353
+	{
354
+		if ($request === null) {
355
+			$request = $this->request;
356
+		}
357
+		$filter = $this->config()->get('base_filter');
358
+		$this->extend('updateLocatorFilter', $filter, $request);
359
+
360
+		$filterAny = $this->config()->get('base_filter_any');
361
+		$this->extend('updateLocatorFilterAny', $filterAny, $request);
362
+
363
+		$exclude = $this->config()->get('base_exclude');
364
+		$this->extend('updateLocatorExclude', $exclude, $request);
365
+
366
+		$this->locations = Locator::get_locations($request, $this->data()->ID, $filter, $filterAny, $exclude);
367
+		return $this;
368
+	}
369
+
370
+	/**
371
+	 * LocationSearch form.
372
+	 *
373
+	 * Search form for locations, updates map and results list via AJAX
374
+	 *
375
+	 * @return Form
376
+	 */
377
+	public function LocationSearch()
378
+	{
379
+
380
+		if (class_exists('BootstrapForm')) {
381
+			$form = LocatorBootstrapForm::create($this, 'LocationSearch');
382
+		} else {
383
+			$form = LocatorForm::create($this, 'LocationSearch');
384
+		}
385
+
386
+		return $form
387
+			->setFormMethod('GET')
388
+			->setFormAction($this->Link())
389
+			->disableSecurityToken()
390
+			->loadDataFrom($this->request->getVars());
391
+	}
392 392
 
393 393
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -17 removed lines patch added patch discarded remove patch
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 
150 150
         Requirements::javascript('framework/thirdparty/jquery/jquery.js');
151 151
         if ($locations) {
152
-            Requirements::javascript('http://maps.google.com/maps/api/js?key=' . $key);
152
+            Requirements::javascript('http://maps.google.com/maps/api/js?key='.$key);
153 153
             Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
154 154
             Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
155 155
         }
@@ -177,14 +177,12 @@  discard block
 block discarded – undo
177 177
             'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';*/
178 178
 
179 179
         $base = Director::baseFolder();
180
-        $themePath = $base . '/' . $themeDir;
180
+        $themePath = $base.'/'.$themeDir;
181 181
 
182
-        $listTemplatePath = (file_exists($themePath . '/templates/location-list-description.html')) ?
183
-            $themeDir . '/templates/location-list-description.html' :
184
-            'locator/templates/location-list-description.html';
185
-        $infowindowTemplatePath = (file_exists($themePath . '/templates/infowindow-description.html')) ?
186
-            $themeDir . '/templates/infowindow-description.html' :
187
-            'locator/templates/infowindow-description.html';
182
+        $listTemplatePath = (file_exists($themePath.'/templates/location-list-description.html')) ?
183
+            $themeDir.'/templates/location-list-description.html' : 'locator/templates/location-list-description.html';
184
+        $infowindowTemplatePath = (file_exists($themePath.'/templates/infowindow-description.html')) ?
185
+            $themeDir.'/templates/infowindow-description.html' : 'locator/templates/infowindow-description.html';
188 186
 
189 187
         // in page or modal
190 188
         $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';
@@ -197,22 +195,22 @@  discard block
 block discarded – undo
197 195
         unset($vars['action_index']);
198 196
         $url = '';
199 197
         if (count($vars)) {
200
-            $url .= '?' . http_build_query($vars);
198
+            $url .= '?'.http_build_query($vars);
201 199
         }
202
-        $link = $this->Link() . 'xml.xml' . $url;
200
+        $link = $this->Link().'xml.xml'.$url;
203 201
 
204 202
         // init map
205 203
         if ($locations) {
206 204
             Requirements::customScript("
207 205
                 $(function($) {
208 206
                     $('#map-container').storeLocator({
209
-                        " . $load . "
210
-                        dataLocation: '" . $link . "',
211
-                        listTemplatePath: '" . $listTemplatePath . "',
212
-                        infowindowTemplatePath: '" . $infowindowTemplatePath . "',
207
+                        " . $load."
208
+                        dataLocation: '" . $link."',
209
+                        listTemplatePath: '" . $listTemplatePath."',
210
+                        infowindowTemplatePath: '" . $infowindowTemplatePath."',
213 211
                         originMarker: true,
214
-                        " . $modal . ',
215
-                        ' . $featured . ",
212
+                        " . $modal.',
213
+                        ' . $featured.",
216 214
                         slideMap: false,
217 215
                         zoomLevel: 0,
218 216
                         noForm: true,
@@ -220,7 +218,7 @@  discard block
 block discarded – undo
220 218
                         inputID: 'Form_LocationSearch_Address',
221 219
                         categoryID: 'Form_LocationSearch_category',
222 220
                         distanceAlert: -1,
223
-                        " . $kilometer . '
221
+                        " . $kilometer.'
224 222
                     });
225 223
                 });
226 224
             ');
Please login to merge, or discard this patch.
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/form/LocatorBootstrapForm.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -2,50 +2,50 @@
 block discarded – undo
2 2
 
3 3
 if (class_exists('BootstrapForm')) {
4 4
 
5
-    /**
6
-     * Class LocatorForm
7
-     */
8
-    class LocatorBootstrapForm extends BootstrapForm
9
-    {
10
-
11
-        /**
12
-         * LocatorForm constructor.
13
-         * @param Controller $controller
14
-         * @param string $name
15
-         */
16
-        public function __construct(Controller $controller, $name)
17
-        {
18
-
19
-            $fields = FieldList::create(
20
-                TextField::create('Address')
21
-                    ->setTitle('')
22
-                    ->setAttribute('placeholder', 'address or zip code')
23
-            );
24
-
25
-            if (LocationCategory::get()->count() > 0) {
26
-                $categories = DropdownField::create('CategoryID')
27
-                    ->setTitle('')
28
-                    ->setEmptyString('All Categories')
29
-                    ->setSource(LocationCategory::get()->map());
30
-                $fields->push($categories);
31
-            }
32
-
33
-            $this->extend('updateLocatorFormFields', $fields);
34
-
35
-            $actions = FieldList::create(
36
-                FormAction::create('doFilterLocations')
37
-                    ->setTitle('Search')
38
-            );
39
-
40
-            $this->extend('updateLocatorFormActions', $actions);
41
-
42
-            $validator = RequiredFields::create();
43
-
44
-            $this->extend('updateLocatorFormRequiredFields', $validator);
45
-
46
-            parent::__construct($controller, $name, $fields, $actions, $validator);
47
-        }
48
-
49
-    }
5
+	/**
6
+	 * Class LocatorForm
7
+	 */
8
+	class LocatorBootstrapForm extends BootstrapForm
9
+	{
10
+
11
+		/**
12
+		 * LocatorForm constructor.
13
+		 * @param Controller $controller
14
+		 * @param string $name
15
+		 */
16
+		public function __construct(Controller $controller, $name)
17
+		{
18
+
19
+			$fields = FieldList::create(
20
+				TextField::create('Address')
21
+					->setTitle('')
22
+					->setAttribute('placeholder', 'address or zip code')
23
+			);
24
+
25
+			if (LocationCategory::get()->count() > 0) {
26
+				$categories = DropdownField::create('CategoryID')
27
+					->setTitle('')
28
+					->setEmptyString('All Categories')
29
+					->setSource(LocationCategory::get()->map());
30
+				$fields->push($categories);
31
+			}
32
+
33
+			$this->extend('updateLocatorFormFields', $fields);
34
+
35
+			$actions = FieldList::create(
36
+				FormAction::create('doFilterLocations')
37
+					->setTitle('Search')
38
+			);
39
+
40
+			$this->extend('updateLocatorFormActions', $actions);
41
+
42
+			$validator = RequiredFields::create();
43
+
44
+			$this->extend('updateLocatorFormRequiredFields', $validator);
45
+
46
+			parent::__construct($controller, $name, $fields, $actions, $validator);
47
+		}
48
+
49
+	}
50 50
 
51 51
 }
52 52
\ No newline at end of file
Please login to merge, or discard this patch.
code/form/LocatorForm.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -6,42 +6,42 @@
 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
-        if (LocationCategory::get()->count() > 0) {
24
-            $categories = DropdownField::create('CategoryID')
25
-                ->setTitle('')
26
-                ->setEmptyString('All Categories')
27
-                ->setSource(LocationCategory::get()->map());
28
-            $fields->push($categories);
29
-        }
30
-
31
-        $this->extend('updateLocatorFormFields', $fields);
32
-
33
-        $actions = FieldList::create(
34
-            FormAction::create('doFilterLocations')
35
-                ->setTitle('Search')
36
-        );
37
-
38
-        $this->extend('updateLocatorFormActions', $actions);
39
-
40
-        $validator = RequiredFields::create();
41
-
42
-        $this->extend('updateLocatorFormRequiredFields', $validator);
43
-
44
-        parent::__construct($controller, $name, $fields, $actions, $validator);
45
-    }
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
+		if (LocationCategory::get()->count() > 0) {
24
+			$categories = DropdownField::create('CategoryID')
25
+				->setTitle('')
26
+				->setEmptyString('All Categories')
27
+				->setSource(LocationCategory::get()->map());
28
+			$fields->push($categories);
29
+		}
30
+
31
+		$this->extend('updateLocatorFormFields', $fields);
32
+
33
+		$actions = FieldList::create(
34
+			FormAction::create('doFilterLocations')
35
+				->setTitle('Search')
36
+		);
37
+
38
+		$this->extend('updateLocatorFormActions', $actions);
39
+
40
+		$validator = RequiredFields::create();
41
+
42
+		$this->extend('updateLocatorFormRequiredFields', $validator);
43
+
44
+		parent::__construct($controller, $name, $fields, $actions, $validator);
45
+	}
46 46
 
47 47
 }
48 48
\ No newline at end of file
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.