@@ -2,26 +2,26 @@ |
||
2 | 2 | |
3 | 3 | class Locator_Test extends FunctionalTest |
4 | 4 | { |
5 | - protected static $fixture_file = 'locator/tests/Locator_Test.yml'; |
|
6 | - protected static $disable_themes = true; |
|
7 | - protected static $use_draft_site = false; |
|
5 | + protected static $fixture_file = 'locator/tests/Locator_Test.yml'; |
|
6 | + protected static $disable_themes = true; |
|
7 | + protected static $use_draft_site = false; |
|
8 | 8 | |
9 | - public function setUp() |
|
10 | - { |
|
11 | - parent::setUp(); |
|
9 | + public function setUp() |
|
10 | + { |
|
11 | + parent::setUp(); |
|
12 | 12 | |
13 | - ini_set('display_errors', 1); |
|
14 | - ini_set('log_errors', 1); |
|
15 | - error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED); |
|
16 | - } |
|
13 | + ini_set('display_errors', 1); |
|
14 | + ini_set('log_errors', 1); |
|
15 | + error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED); |
|
16 | + } |
|
17 | 17 | |
18 | - public function logOut() |
|
19 | - { |
|
20 | - $this->session()->clear('loggedInAs'); |
|
21 | - $this->session()->clear('logInWithPermission'); |
|
22 | - } |
|
18 | + public function logOut() |
|
19 | + { |
|
20 | + $this->session()->clear('loggedInAs'); |
|
21 | + $this->session()->clear('logInWithPermission'); |
|
22 | + } |
|
23 | 23 | |
24 | - public function testLocator_Test() |
|
25 | - { |
|
26 | - } |
|
24 | + public function testLocator_Test() |
|
25 | + { |
|
26 | + } |
|
27 | 27 | } |
@@ -2,68 +2,68 @@ |
||
2 | 2 | |
3 | 3 | class LocatorTest extends Locator_Test |
4 | 4 | { |
5 | - public function testGetCMSFields() |
|
6 | - { |
|
7 | - $object = new Locator(); |
|
8 | - $fieldset = $object->getCMSFields(); |
|
9 | - $this->assertTrue(is_a($fieldset, 'FieldList')); |
|
10 | - } |
|
5 | + public function testGetCMSFields() |
|
6 | + { |
|
7 | + $object = new Locator(); |
|
8 | + $fieldset = $object->getCMSFields(); |
|
9 | + $this->assertTrue(is_a($fieldset, 'FieldList')); |
|
10 | + } |
|
11 | 11 | |
12 | - public function testGetLocations() |
|
13 | - { |
|
14 | - $locator = singleton('Locator'); |
|
15 | - $count = Location::get()->filter('ShowInLocator', 1)->exclude('Lat', 0)->Count(); |
|
16 | - $this->assertEquals($locator->getLocations()->Count(), $count); |
|
17 | - } |
|
12 | + public function testGetLocations() |
|
13 | + { |
|
14 | + $locator = singleton('Locator'); |
|
15 | + $count = Location::get()->filter('ShowInLocator', 1)->exclude('Lat', 0)->Count(); |
|
16 | + $this->assertEquals($locator->getLocations()->Count(), $count); |
|
17 | + } |
|
18 | 18 | |
19 | - public function testGetAreLocations() |
|
20 | - { |
|
21 | - $locator = singleton('Locator'); |
|
22 | - $this->assertEquals($locator->getLocations(), $locator->getAreLocations()); |
|
23 | - } |
|
19 | + public function testGetAreLocations() |
|
20 | + { |
|
21 | + $locator = singleton('Locator'); |
|
22 | + $this->assertEquals($locator->getLocations(), $locator->getAreLocations()); |
|
23 | + } |
|
24 | 24 | |
25 | - public function testGetAllCategories() |
|
26 | - { |
|
27 | - $locator = singleton('Locator'); |
|
28 | - $count = LocationCategory::get(); |
|
29 | - $this->assertEquals($locator->getAllCategories(), $count); |
|
30 | - } |
|
25 | + public function testGetAllCategories() |
|
26 | + { |
|
27 | + $locator = singleton('Locator'); |
|
28 | + $count = LocationCategory::get(); |
|
29 | + $this->assertEquals($locator->getAllCategories(), $count); |
|
30 | + } |
|
31 | 31 | |
32 | - public function testGetPageCategories() |
|
33 | - { |
|
34 | - $locator = Locator::create(); |
|
35 | - $this->assertFalse($locator->getPageCategories()); |
|
32 | + public function testGetPageCategories() |
|
33 | + { |
|
34 | + $locator = Locator::create(); |
|
35 | + $this->assertFalse($locator->getPageCategories()); |
|
36 | 36 | |
37 | - $this->assertFalse($locator->getPageCategories(500)); |
|
37 | + $this->assertFalse($locator->getPageCategories(500)); |
|
38 | 38 | |
39 | - $locator->write(); |
|
40 | - $category = $this->objFromFixture('LocationCategory', 'service'); |
|
41 | - $locator->Categories()->add($category); |
|
42 | - $this->assertEquals($locator->getPageCategories($locator->ID), $locator->Categories()); |
|
43 | - } |
|
39 | + $locator->write(); |
|
40 | + $category = $this->objFromFixture('LocationCategory', 'service'); |
|
41 | + $locator->Categories()->add($category); |
|
42 | + $this->assertEquals($locator->getPageCategories($locator->ID), $locator->Categories()); |
|
43 | + } |
|
44 | 44 | |
45 | - public function testInit() |
|
46 | - { |
|
47 | - } |
|
45 | + public function testInit() |
|
46 | + { |
|
47 | + } |
|
48 | 48 | |
49 | - public function testXml() |
|
50 | - { |
|
51 | - } |
|
49 | + public function testXml() |
|
50 | + { |
|
51 | + } |
|
52 | 52 | |
53 | - public function testLocationSearch() |
|
54 | - { |
|
55 | - $locator = $this->objFromFixture('Locator', 'locator1'); |
|
56 | - $object = Locator_Controller::create($locator); |
|
57 | - $form = $object->LocationSearch(); |
|
58 | - $this->assertTrue(is_a($form, 'Form')); |
|
53 | + public function testLocationSearch() |
|
54 | + { |
|
55 | + $locator = $this->objFromFixture('Locator', 'locator1'); |
|
56 | + $object = Locator_Controller::create($locator); |
|
57 | + $form = $object->LocationSearch(); |
|
58 | + $this->assertTrue(is_a($form, 'Form')); |
|
59 | 59 | |
60 | - $category = $this->objFromFixture('LocationCategory', 'service'); |
|
61 | - $category2 = $this->objFromFixture('LocationCategory', 'manufacturing'); |
|
62 | - $locator->Categories()->add($category); |
|
63 | - $locator->Categories()->add($category2); |
|
60 | + $category = $this->objFromFixture('LocationCategory', 'service'); |
|
61 | + $category2 = $this->objFromFixture('LocationCategory', 'manufacturing'); |
|
62 | + $locator->Categories()->add($category); |
|
63 | + $locator->Categories()->add($category2); |
|
64 | 64 | |
65 | - $form = $object->LocationSearch(); |
|
66 | - $fields = $form->Fields(); |
|
67 | - $this->assertNotNull($fields->fieldByName('category')); |
|
68 | - } |
|
65 | + $form = $object->LocationSearch(); |
|
66 | + $fields = $form->Fields(); |
|
67 | + $this->assertNotNull($fields->fieldByName('category')); |
|
68 | + } |
|
69 | 69 | } |
@@ -189,7 +189,7 @@ |
||
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
192 | - * @return bool|string |
|
192 | + * @return string|false |
|
193 | 193 | */ |
194 | 194 | public function EmailAddress() |
195 | 195 | { |
@@ -16,246 +16,246 @@ |
||
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 | - ); |
|
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 | 31 | |
32 | - /** |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - private static $has_one = array( |
|
36 | - 'Category' => 'LocationCategory', |
|
37 | - ); |
|
32 | + /** |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + private static $has_one = array( |
|
36 | + 'Category' => 'LocationCategory', |
|
37 | + ); |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - private static $casting = array( |
|
43 | - 'distance' => 'Int', |
|
44 | - ); |
|
39 | + /** |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + private static $casting = array( |
|
43 | + 'distance' => 'Int', |
|
44 | + ); |
|
45 | 45 | |
46 | - /** |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - private static $default_sort = 'Title'; |
|
46 | + /** |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + private static $default_sort = 'Title'; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @var array |
|
53 | - */ |
|
54 | - private static $defaults = array( |
|
55 | - 'ShowInLocator' => true, |
|
56 | - ); |
|
51 | + /** |
|
52 | + * @var array |
|
53 | + */ |
|
54 | + private static $defaults = array( |
|
55 | + 'ShowInLocator' => true, |
|
56 | + ); |
|
57 | 57 | |
58 | - /** |
|
59 | - * @var string |
|
60 | - */ |
|
61 | - private static $singular_name = 'Location'; |
|
62 | - /** |
|
63 | - * @var string |
|
64 | - */ |
|
65 | - private static $plural_name = 'Locations'; |
|
58 | + /** |
|
59 | + * @var string |
|
60 | + */ |
|
61 | + private static $singular_name = 'Location'; |
|
62 | + /** |
|
63 | + * @var string |
|
64 | + */ |
|
65 | + private static $plural_name = 'Locations'; |
|
66 | 66 | |
67 | - /** |
|
68 | - * api access via Restful Server module |
|
69 | - * |
|
70 | - * @var bool |
|
71 | - */ |
|
72 | - private static $api_access = true; |
|
67 | + /** |
|
68 | + * api access via Restful Server module |
|
69 | + * |
|
70 | + * @var bool |
|
71 | + */ |
|
72 | + private static $api_access = true; |
|
73 | 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 | - ); |
|
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 | 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 | - ); |
|
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 | 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 | - } |
|
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 | 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); |
|
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 | 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['Email'] = 'Email'; |
|
139 | - $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
140 | - $labels['Coords'] = 'Coords'; |
|
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['Email'] = 'Email'; |
|
139 | + $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
140 | + $labels['Coords'] = 'Coords'; |
|
141 | 141 | |
142 | - return $labels; |
|
143 | - } |
|
142 | + return $labels; |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * @return FieldList |
|
147 | - */ |
|
148 | - public function getCMSFields() |
|
149 | - { |
|
150 | - $fields = FieldList::create( |
|
151 | - new TabSet( |
|
152 | - $name = 'Root', |
|
153 | - new Tab( |
|
154 | - $title = 'Main', |
|
155 | - HeaderField::create('ContactHD', 'Contact Information'), |
|
156 | - TextField::create('Title', 'Name'), |
|
157 | - TextField::create('Phone'), |
|
158 | - EmailField::create('Email', 'Email'), |
|
159 | - TextField::create('Website') |
|
160 | - ->setAttribute('placeholder', 'http://'), |
|
161 | - DropdownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title')) |
|
162 | - ->setEmptyString('-- select --'), |
|
163 | - CheckboxField::create('ShowInLocator', 'Show in results') |
|
164 | - ->setDescription('Location will be included in results list'), |
|
165 | - CheckboxField::create('Featured') |
|
166 | - ->setDescription('Location will show at/near the top of the results list') |
|
167 | - ) |
|
168 | - ) |
|
169 | - ); |
|
145 | + /** |
|
146 | + * @return FieldList |
|
147 | + */ |
|
148 | + public function getCMSFields() |
|
149 | + { |
|
150 | + $fields = FieldList::create( |
|
151 | + new TabSet( |
|
152 | + $name = 'Root', |
|
153 | + new Tab( |
|
154 | + $title = 'Main', |
|
155 | + HeaderField::create('ContactHD', 'Contact Information'), |
|
156 | + TextField::create('Title', 'Name'), |
|
157 | + TextField::create('Phone'), |
|
158 | + EmailField::create('Email', 'Email'), |
|
159 | + TextField::create('Website') |
|
160 | + ->setAttribute('placeholder', 'http://'), |
|
161 | + DropdownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title')) |
|
162 | + ->setEmptyString('-- select --'), |
|
163 | + CheckboxField::create('ShowInLocator', 'Show in results') |
|
164 | + ->setDescription('Location will be included in results list'), |
|
165 | + CheckboxField::create('Featured') |
|
166 | + ->setDescription('Location will show at/near the top of the results list') |
|
167 | + ) |
|
168 | + ) |
|
169 | + ); |
|
170 | 170 | |
171 | - // allow to be extended via DataExtension |
|
172 | - $this->extend('updateCMSFields', $fields); |
|
171 | + // allow to be extended via DataExtension |
|
172 | + $this->extend('updateCMSFields', $fields); |
|
173 | 173 | |
174 | - // override Suburb field name |
|
175 | - $fields->dataFieldByName('Suburb')->setTitle('City'); |
|
174 | + // override Suburb field name |
|
175 | + $fields->dataFieldByName('Suburb')->setTitle('City'); |
|
176 | 176 | |
177 | - return $fields; |
|
178 | - } |
|
177 | + return $fields; |
|
178 | + } |
|
179 | 179 | |
180 | - /** |
|
181 | - * @return ValidationResult |
|
182 | - */ |
|
183 | - public function validate() |
|
184 | - { |
|
185 | - $result = parent::validate(); |
|
180 | + /** |
|
181 | + * @return ValidationResult |
|
182 | + */ |
|
183 | + public function validate() |
|
184 | + { |
|
185 | + $result = parent::validate(); |
|
186 | 186 | |
187 | - return $result; |
|
188 | - } |
|
187 | + return $result; |
|
188 | + } |
|
189 | 189 | |
190 | - /** |
|
191 | - * @return bool|string |
|
192 | - */ |
|
193 | - public function EmailAddress() |
|
194 | - { |
|
195 | - Deprecation::notice('3.0', 'Use "$Email" instead.'); |
|
196 | - if ($this->Email) { |
|
197 | - return $this->Email; |
|
198 | - } elseif ($this->EmailAddress) { |
|
199 | - return $this->EmailAddress; |
|
200 | - } |
|
190 | + /** |
|
191 | + * @return bool|string |
|
192 | + */ |
|
193 | + public function EmailAddress() |
|
194 | + { |
|
195 | + Deprecation::notice('3.0', 'Use "$Email" instead.'); |
|
196 | + if ($this->Email) { |
|
197 | + return $this->Email; |
|
198 | + } elseif ($this->EmailAddress) { |
|
199 | + return $this->EmailAddress; |
|
200 | + } |
|
201 | 201 | |
202 | - return false; |
|
203 | - } |
|
202 | + return false; |
|
203 | + } |
|
204 | 204 | |
205 | - /** |
|
206 | - * @param Member $member |
|
207 | - * |
|
208 | - * @return bool |
|
209 | - */ |
|
210 | - public function canView($member = null) |
|
211 | - { |
|
212 | - return true; |
|
213 | - } |
|
205 | + /** |
|
206 | + * @param Member $member |
|
207 | + * |
|
208 | + * @return bool |
|
209 | + */ |
|
210 | + public function canView($member = null) |
|
211 | + { |
|
212 | + return true; |
|
213 | + } |
|
214 | 214 | |
215 | - /** |
|
216 | - * @param null $member |
|
217 | - * @return bool|int |
|
218 | - */ |
|
219 | - public function canEdit($member = null) |
|
220 | - { |
|
221 | - return Permission::check('Location_EDIT', 'any', $member); |
|
222 | - } |
|
215 | + /** |
|
216 | + * @param null $member |
|
217 | + * @return bool|int |
|
218 | + */ |
|
219 | + public function canEdit($member = null) |
|
220 | + { |
|
221 | + return Permission::check('Location_EDIT', 'any', $member); |
|
222 | + } |
|
223 | 223 | |
224 | - /** |
|
225 | - * @param null $member |
|
226 | - * @return bool|int |
|
227 | - */ |
|
228 | - public function canDelete($member = null) |
|
229 | - { |
|
230 | - return Permission::check('Location_DELETE', 'any', $member); |
|
231 | - } |
|
224 | + /** |
|
225 | + * @param null $member |
|
226 | + * @return bool|int |
|
227 | + */ |
|
228 | + public function canDelete($member = null) |
|
229 | + { |
|
230 | + return Permission::check('Location_DELETE', 'any', $member); |
|
231 | + } |
|
232 | 232 | |
233 | - /** |
|
234 | - * @param null $member |
|
235 | - * @return bool|int |
|
236 | - */ |
|
237 | - public function canCreate($member = null) |
|
238 | - { |
|
239 | - return Permission::check('Location_CREATE', 'any', $member); |
|
240 | - } |
|
233 | + /** |
|
234 | + * @param null $member |
|
235 | + * @return bool|int |
|
236 | + */ |
|
237 | + public function canCreate($member = null) |
|
238 | + { |
|
239 | + return Permission::check('Location_CREATE', 'any', $member); |
|
240 | + } |
|
241 | 241 | |
242 | - /** |
|
243 | - * @return array |
|
244 | - */ |
|
245 | - public function providePermissions() |
|
246 | - { |
|
247 | - return array( |
|
248 | - 'Location_EDIT' => 'Edit a Location', |
|
249 | - 'Location_DELETE' => 'Delete a Location', |
|
250 | - 'Location_CREATE' => 'Create a Location', |
|
251 | - ); |
|
252 | - } |
|
242 | + /** |
|
243 | + * @return array |
|
244 | + */ |
|
245 | + public function providePermissions() |
|
246 | + { |
|
247 | + return array( |
|
248 | + 'Location_EDIT' => 'Edit a Location', |
|
249 | + 'Location_DELETE' => 'Delete a Location', |
|
250 | + 'Location_CREATE' => 'Create a Location', |
|
251 | + ); |
|
252 | + } |
|
253 | 253 | |
254 | - /** |
|
255 | - * |
|
256 | - */ |
|
257 | - public function onBeforeWrite() |
|
258 | - { |
|
259 | - parent::onBeforeWrite(); |
|
260 | - } |
|
254 | + /** |
|
255 | + * |
|
256 | + */ |
|
257 | + public function onBeforeWrite() |
|
258 | + { |
|
259 | + parent::onBeforeWrite(); |
|
260 | + } |
|
261 | 261 | } |
@@ -10,39 +10,39 @@ |
||
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 | } |
@@ -6,56 +6,56 @@ |
||
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 | } |
@@ -3,149 +3,149 @@ |
||
3 | 3 | class LocationTest extends SapphireTest |
4 | 4 | { |
5 | 5 | |
6 | - protected static $fixture_file = 'locator/tests/Locator_Test.yml'; |
|
7 | - |
|
8 | - public function testGetCoords() |
|
9 | - { |
|
10 | - $location = $this->objFromFixture('Location', 'dynamic'); |
|
11 | - $location->write(); |
|
12 | - |
|
13 | - $coords = ($location->Lat && $location->Lng) ? 'true' : 'false'; |
|
14 | - $geoCodable = Location::get()->byID($location->ID); |
|
15 | - |
|
16 | - $this->assertEquals($coords, $geoCodable->getCoords()); |
|
17 | - } |
|
18 | - |
|
19 | - public function testFieldLabels() |
|
20 | - { |
|
21 | - $location = $this->objFromFixture('Location', 'dynamic'); |
|
22 | - $labels = $location->FieldLabels(); |
|
23 | - $expected = array( |
|
24 | - 'Title' => 'Name', |
|
25 | - 'Featured' => 'Featured', |
|
26 | - 'Website' => 'Website', |
|
27 | - 'Phone' => 'Phone', |
|
28 | - 'Email' => 'Email', |
|
29 | - 'EmailAddress' => 'Email Address', |
|
30 | - 'ShowInLocator' => 'Show', |
|
31 | - 'Address' => 'Address', |
|
32 | - 'Suburb' => 'City', |
|
33 | - 'State' => 'State', |
|
34 | - 'Postcode' => 'Postal Code', |
|
35 | - 'Country' => 'Country', |
|
36 | - 'Lat' => 'Lat', |
|
37 | - 'Lng' => 'Lng', |
|
38 | - 'Category' => 'Category', |
|
39 | - 'ShowInLocator.NiceAsBoolean' => 'Show', |
|
40 | - 'Category.Name' => 'Category', |
|
41 | - 'Featured.NiceAsBoolean' => 'Featured', |
|
42 | - 'Coords' => 'Coords', |
|
43 | - 'LatLngOverride' => 'Lat Lng Override', |
|
44 | - ); |
|
45 | - $this->assertEquals($expected, $labels); |
|
46 | - } |
|
47 | - |
|
48 | - public function testGetCMSFields() |
|
49 | - { |
|
50 | - $object = new Location(); |
|
51 | - $fieldset = $object->getCMSFields(); |
|
52 | - $this->assertTrue(is_a($fieldset, 'FieldList')); |
|
53 | - } |
|
54 | - |
|
55 | - public function testValidate() |
|
56 | - { |
|
57 | - } |
|
58 | - |
|
59 | - public function testEmailAddress() |
|
60 | - { |
|
61 | - } |
|
62 | - |
|
63 | - public function testCanView() |
|
64 | - { |
|
65 | - $object = $this->objFromFixture('Location', 'dynamic'); |
|
66 | - $object->write(); |
|
67 | - |
|
68 | - $this->assertTrue($object->canView()); |
|
69 | - |
|
70 | - $nullMember = Member::create(); |
|
71 | - $nullMember->write(); |
|
72 | - |
|
73 | - $this->assertTrue($object->canView($nullMember)); |
|
74 | - |
|
75 | - $nullMember->delete(); |
|
76 | - } |
|
77 | - |
|
78 | - public function testCanEdit() |
|
79 | - { |
|
80 | - $object = $this->objFromFixture('Location', 'dynamic'); |
|
81 | - $object->write(); |
|
82 | - |
|
83 | - $objectID = $object->ID; |
|
84 | - |
|
85 | - //test permissions per permission setting |
|
86 | - $create = $this->objFromFixture('Member', 'locationcreate'); |
|
87 | - $edit = $this->objFromFixture('Member', 'locationedit'); |
|
88 | - $delete = $this->objFromFixture('Member', 'locationdelete'); |
|
89 | - |
|
90 | - $originalTitle = $object->Title; |
|
91 | - $this->assertEquals($originalTitle, 'Dynamic, Inc.'); |
|
92 | - |
|
93 | - $this->assertTrue($object->canEdit($edit)); |
|
94 | - $this->assertFalse($object->canEdit($create)); |
|
95 | - $this->assertFalse($object->canEdit($delete)); |
|
96 | - |
|
97 | - $object->Title = 'Changed Title'; |
|
98 | - $object->write(); |
|
99 | - |
|
100 | - $testEdit = Location::get()->byID($objectID); |
|
101 | - $this->assertEquals($testEdit->Title, 'Changed Title'); |
|
102 | - } |
|
103 | - |
|
104 | - public function testCanDelete() |
|
105 | - { |
|
106 | - $object = $this->objFromFixture('Location', 'dynamic'); |
|
107 | - $object->write(); |
|
108 | - |
|
109 | - //test permissions per permission setting |
|
110 | - $create = $this->objFromFixture('Member', 'locationcreate'); |
|
111 | - $edit = $this->objFromFixture('Member', 'locationedit'); |
|
112 | - $delete = $this->objFromFixture('Member', 'locationdelete'); |
|
113 | - |
|
114 | - $this->assertTrue($object->canDelete($delete)); |
|
115 | - $this->assertFalse($object->canDelete($create)); |
|
116 | - $this->assertFalse($object->canDelete($edit)); |
|
117 | - |
|
118 | - $checkObject = $object; |
|
119 | - $object->delete(); |
|
120 | - |
|
121 | - $this->assertEquals($checkObject->ID, 0); |
|
122 | - } |
|
123 | - |
|
124 | - public function testCanCreate() |
|
125 | - { |
|
126 | - $object = singleton('Location'); |
|
127 | - |
|
128 | - //test permissions per permission setting |
|
129 | - $create = $this->objFromFixture('Member', 'locationcreate'); |
|
130 | - $edit = $this->objFromFixture('Member', 'locationedit'); |
|
131 | - $delete = $this->objFromFixture('Member', 'locationdelete'); |
|
132 | - |
|
133 | - $this->assertTrue($object->canCreate($create)); |
|
134 | - $this->assertFalse($object->canCreate($edit)); |
|
135 | - $this->assertFalse($object->canCreate($delete)); |
|
136 | - |
|
137 | - $nullMember = Member::create(); |
|
138 | - $nullMember->write(); |
|
139 | - $this->assertFalse($object->canCreate($nullMember)); |
|
6 | + protected static $fixture_file = 'locator/tests/Locator_Test.yml'; |
|
7 | + |
|
8 | + public function testGetCoords() |
|
9 | + { |
|
10 | + $location = $this->objFromFixture('Location', 'dynamic'); |
|
11 | + $location->write(); |
|
12 | + |
|
13 | + $coords = ($location->Lat && $location->Lng) ? 'true' : 'false'; |
|
14 | + $geoCodable = Location::get()->byID($location->ID); |
|
15 | + |
|
16 | + $this->assertEquals($coords, $geoCodable->getCoords()); |
|
17 | + } |
|
18 | + |
|
19 | + public function testFieldLabels() |
|
20 | + { |
|
21 | + $location = $this->objFromFixture('Location', 'dynamic'); |
|
22 | + $labels = $location->FieldLabels(); |
|
23 | + $expected = array( |
|
24 | + 'Title' => 'Name', |
|
25 | + 'Featured' => 'Featured', |
|
26 | + 'Website' => 'Website', |
|
27 | + 'Phone' => 'Phone', |
|
28 | + 'Email' => 'Email', |
|
29 | + 'EmailAddress' => 'Email Address', |
|
30 | + 'ShowInLocator' => 'Show', |
|
31 | + 'Address' => 'Address', |
|
32 | + 'Suburb' => 'City', |
|
33 | + 'State' => 'State', |
|
34 | + 'Postcode' => 'Postal Code', |
|
35 | + 'Country' => 'Country', |
|
36 | + 'Lat' => 'Lat', |
|
37 | + 'Lng' => 'Lng', |
|
38 | + 'Category' => 'Category', |
|
39 | + 'ShowInLocator.NiceAsBoolean' => 'Show', |
|
40 | + 'Category.Name' => 'Category', |
|
41 | + 'Featured.NiceAsBoolean' => 'Featured', |
|
42 | + 'Coords' => 'Coords', |
|
43 | + 'LatLngOverride' => 'Lat Lng Override', |
|
44 | + ); |
|
45 | + $this->assertEquals($expected, $labels); |
|
46 | + } |
|
47 | + |
|
48 | + public function testGetCMSFields() |
|
49 | + { |
|
50 | + $object = new Location(); |
|
51 | + $fieldset = $object->getCMSFields(); |
|
52 | + $this->assertTrue(is_a($fieldset, 'FieldList')); |
|
53 | + } |
|
54 | + |
|
55 | + public function testValidate() |
|
56 | + { |
|
57 | + } |
|
58 | + |
|
59 | + public function testEmailAddress() |
|
60 | + { |
|
61 | + } |
|
62 | + |
|
63 | + public function testCanView() |
|
64 | + { |
|
65 | + $object = $this->objFromFixture('Location', 'dynamic'); |
|
66 | + $object->write(); |
|
67 | + |
|
68 | + $this->assertTrue($object->canView()); |
|
69 | + |
|
70 | + $nullMember = Member::create(); |
|
71 | + $nullMember->write(); |
|
72 | + |
|
73 | + $this->assertTrue($object->canView($nullMember)); |
|
74 | + |
|
75 | + $nullMember->delete(); |
|
76 | + } |
|
77 | + |
|
78 | + public function testCanEdit() |
|
79 | + { |
|
80 | + $object = $this->objFromFixture('Location', 'dynamic'); |
|
81 | + $object->write(); |
|
82 | + |
|
83 | + $objectID = $object->ID; |
|
84 | + |
|
85 | + //test permissions per permission setting |
|
86 | + $create = $this->objFromFixture('Member', 'locationcreate'); |
|
87 | + $edit = $this->objFromFixture('Member', 'locationedit'); |
|
88 | + $delete = $this->objFromFixture('Member', 'locationdelete'); |
|
89 | + |
|
90 | + $originalTitle = $object->Title; |
|
91 | + $this->assertEquals($originalTitle, 'Dynamic, Inc.'); |
|
92 | + |
|
93 | + $this->assertTrue($object->canEdit($edit)); |
|
94 | + $this->assertFalse($object->canEdit($create)); |
|
95 | + $this->assertFalse($object->canEdit($delete)); |
|
96 | + |
|
97 | + $object->Title = 'Changed Title'; |
|
98 | + $object->write(); |
|
99 | + |
|
100 | + $testEdit = Location::get()->byID($objectID); |
|
101 | + $this->assertEquals($testEdit->Title, 'Changed Title'); |
|
102 | + } |
|
103 | + |
|
104 | + public function testCanDelete() |
|
105 | + { |
|
106 | + $object = $this->objFromFixture('Location', 'dynamic'); |
|
107 | + $object->write(); |
|
108 | + |
|
109 | + //test permissions per permission setting |
|
110 | + $create = $this->objFromFixture('Member', 'locationcreate'); |
|
111 | + $edit = $this->objFromFixture('Member', 'locationedit'); |
|
112 | + $delete = $this->objFromFixture('Member', 'locationdelete'); |
|
113 | + |
|
114 | + $this->assertTrue($object->canDelete($delete)); |
|
115 | + $this->assertFalse($object->canDelete($create)); |
|
116 | + $this->assertFalse($object->canDelete($edit)); |
|
117 | + |
|
118 | + $checkObject = $object; |
|
119 | + $object->delete(); |
|
120 | + |
|
121 | + $this->assertEquals($checkObject->ID, 0); |
|
122 | + } |
|
123 | + |
|
124 | + public function testCanCreate() |
|
125 | + { |
|
126 | + $object = singleton('Location'); |
|
127 | + |
|
128 | + //test permissions per permission setting |
|
129 | + $create = $this->objFromFixture('Member', 'locationcreate'); |
|
130 | + $edit = $this->objFromFixture('Member', 'locationedit'); |
|
131 | + $delete = $this->objFromFixture('Member', 'locationdelete'); |
|
132 | + |
|
133 | + $this->assertTrue($object->canCreate($create)); |
|
134 | + $this->assertFalse($object->canCreate($edit)); |
|
135 | + $this->assertFalse($object->canCreate($delete)); |
|
136 | + |
|
137 | + $nullMember = Member::create(); |
|
138 | + $nullMember->write(); |
|
139 | + $this->assertFalse($object->canCreate($nullMember)); |
|
140 | 140 | |
141 | - $nullMember->delete(); |
|
142 | - } |
|
141 | + $nullMember->delete(); |
|
142 | + } |
|
143 | 143 | |
144 | - public function testProvidePermissions() |
|
145 | - { |
|
146 | - } |
|
144 | + public function testProvidePermissions() |
|
145 | + { |
|
146 | + } |
|
147 | 147 | |
148 | - public function testOnBeforeWrite() |
|
149 | - { |
|
150 | - } |
|
148 | + public function testOnBeforeWrite() |
|
149 | + { |
|
150 | + } |
|
151 | 151 | } |
@@ -6,42 +6,42 @@ |
||
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 |
|
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 |
|
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 | } |
@@ -11,127 +11,127 @@ discard block |
||
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.Settings', array( |
|
78 | - HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
79 | - $categoriesField, |
|
80 | - )); |
|
81 | - |
|
82 | - $this->extend('updateCMSFields', $fields); |
|
83 | - |
|
84 | - return $fields; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @param array $filter |
|
89 | - * @param array $exclude |
|
90 | - * @param array $filterAny |
|
91 | - * @return DataList |
|
92 | - */ |
|
93 | - public static function getLocations($filter = array(), $exclude = array(), $filterAny = array()) |
|
94 | - { |
|
95 | - $filter['ShowInLocator'] = true; |
|
96 | - $exclude['Lat'] = 0; |
|
97 | - |
|
98 | - $Locations = Location::get()->exclude($exclude)->filter($filter)->filterAny($filterAny); |
|
99 | - |
|
100 | - return $Locations; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @return DataList |
|
105 | - */ |
|
106 | - public function getAreLocations() |
|
107 | - { |
|
108 | - return self::getLocations(); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * @return DataList |
|
113 | - */ |
|
114 | - public function getAllCategories() |
|
115 | - { |
|
116 | - return LocationCategory::get(); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * @param null $id |
|
121 | - * @return bool |
|
122 | - */ |
|
123 | - public static function getPageCategories($id = null) |
|
124 | - { |
|
125 | - if ($id) { |
|
126 | - if ($locator = self::get()->byID($id)) { |
|
127 | - return $locator->Categories(); |
|
128 | - } |
|
129 | - |
|
130 | - return false; |
|
131 | - } |
|
132 | - |
|
133 | - return false; |
|
134 | - } |
|
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.Settings', array( |
|
78 | + HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
79 | + $categoriesField, |
|
80 | + )); |
|
81 | + |
|
82 | + $this->extend('updateCMSFields', $fields); |
|
83 | + |
|
84 | + return $fields; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @param array $filter |
|
89 | + * @param array $exclude |
|
90 | + * @param array $filterAny |
|
91 | + * @return DataList |
|
92 | + */ |
|
93 | + public static function getLocations($filter = array(), $exclude = array(), $filterAny = array()) |
|
94 | + { |
|
95 | + $filter['ShowInLocator'] = true; |
|
96 | + $exclude['Lat'] = 0; |
|
97 | + |
|
98 | + $Locations = Location::get()->exclude($exclude)->filter($filter)->filterAny($filterAny); |
|
99 | + |
|
100 | + return $Locations; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @return DataList |
|
105 | + */ |
|
106 | + public function getAreLocations() |
|
107 | + { |
|
108 | + return self::getLocations(); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * @return DataList |
|
113 | + */ |
|
114 | + public function getAllCategories() |
|
115 | + { |
|
116 | + return LocationCategory::get(); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * @param null $id |
|
121 | + * @return bool |
|
122 | + */ |
|
123 | + public static function getPageCategories($id = null) |
|
124 | + { |
|
125 | + if ($id) { |
|
126 | + if ($locator = self::get()->byID($id)) { |
|
127 | + return $locator->Categories(); |
|
128 | + } |
|
129 | + |
|
130 | + return false; |
|
131 | + } |
|
132 | + |
|
133 | + return false; |
|
134 | + } |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -140,64 +140,64 @@ discard block |
||
140 | 140 | class Locator_Controller extends Page_Controller |
141 | 141 | { |
142 | 142 | |
143 | - /** |
|
144 | - * allowed actions |
|
145 | - * |
|
146 | - * @var array |
|
147 | - */ |
|
148 | - private static $allowed_actions = array('xml'); |
|
143 | + /** |
|
144 | + * allowed actions |
|
145 | + * |
|
146 | + * @var array |
|
147 | + */ |
|
148 | + private static $allowed_actions = array('xml'); |
|
149 | 149 | |
150 | - /** |
|
151 | - * Set Requirements based on input from CMS |
|
152 | - */ |
|
153 | - public function init() |
|
154 | - { |
|
155 | - parent::init(); |
|
150 | + /** |
|
151 | + * Set Requirements based on input from CMS |
|
152 | + */ |
|
153 | + public function init() |
|
154 | + { |
|
155 | + parent::init(); |
|
156 | 156 | |
157 | - $themeDir = SSViewer::get_theme_folder(); |
|
157 | + $themeDir = SSViewer::get_theme_folder(); |
|
158 | 158 | |
159 | - // google maps api key |
|
160 | - $key = Config::inst()->get('GoogleGeocoding', 'google_api_key'); |
|
159 | + // google maps api key |
|
160 | + $key = Config::inst()->get('GoogleGeocoding', 'google_api_key'); |
|
161 | 161 | |
162 | - Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
|
163 | - if (Locator::getLocations()) { |
|
164 | - Requirements::javascript('//maps.google.com/maps/api/js?key=' . $key); |
|
165 | - Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); |
|
166 | - Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); |
|
167 | - } |
|
162 | + Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
|
163 | + if (Locator::getLocations()) { |
|
164 | + Requirements::javascript('//maps.google.com/maps/api/js?key=' . $key); |
|
165 | + Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); |
|
166 | + Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); |
|
167 | + } |
|
168 | 168 | |
169 | - Requirements::css('locator/css/map.css'); |
|
169 | + Requirements::css('locator/css/map.css'); |
|
170 | 170 | |
171 | - $featured = (Locator::getLocations(array('Featured' => 1))->count() > 0) ? |
|
172 | - 'featuredLocations: true' : |
|
173 | - 'featuredLocations: false'; |
|
171 | + $featured = (Locator::getLocations(array('Featured' => 1))->count() > 0) ? |
|
172 | + 'featuredLocations: true' : |
|
173 | + 'featuredLocations: false'; |
|
174 | 174 | |
175 | - // map config based on user input in Settings tab |
|
176 | - // AutoGeocode or Full Map |
|
177 | - $load = ($this->data()->AutoGeocode) ? |
|
178 | - 'autoGeocode: true, fullMapStart: false,' : |
|
179 | - 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
175 | + // map config based on user input in Settings tab |
|
176 | + // AutoGeocode or Full Map |
|
177 | + $load = ($this->data()->AutoGeocode) ? |
|
178 | + 'autoGeocode: true, fullMapStart: false,' : |
|
179 | + 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
180 | 180 | |
181 | - $base = Director::baseFolder(); |
|
182 | - $themePath = $base . '/' . $themeDir; |
|
181 | + $base = Director::baseFolder(); |
|
182 | + $themePath = $base . '/' . $themeDir; |
|
183 | 183 | |
184 | - $listTemplatePath = (file_exists($themePath . '/templates/location-list-description.html')) ? |
|
185 | - $themeDir . '/templates/location-list-description.html' : |
|
186 | - 'locator/templates/location-list-description.html'; |
|
187 | - $infowindowTemplatePath = (file_exists($themePath . '/templates/infowindow-description.html')) ? |
|
188 | - $themeDir . '/templates/infowindow-description.html' : |
|
189 | - 'locator/templates/infowindow-description.html'; |
|
184 | + $listTemplatePath = (file_exists($themePath . '/templates/location-list-description.html')) ? |
|
185 | + $themeDir . '/templates/location-list-description.html' : |
|
186 | + 'locator/templates/location-list-description.html'; |
|
187 | + $infowindowTemplatePath = (file_exists($themePath . '/templates/infowindow-description.html')) ? |
|
188 | + $themeDir . '/templates/infowindow-description.html' : |
|
189 | + 'locator/templates/infowindow-description.html'; |
|
190 | 190 | |
191 | - // in page or modal |
|
192 | - $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
|
191 | + // in page or modal |
|
192 | + $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
|
193 | 193 | |
194 | - $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; |
|
194 | + $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; |
|
195 | 195 | |
196 | - $link = $this->Link() . 'xml.xml'; |
|
196 | + $link = $this->Link() . 'xml.xml'; |
|
197 | 197 | |
198 | - // init map |
|
199 | - if (Locator::getLocations()) { |
|
200 | - Requirements::customScript(" |
|
198 | + // init map |
|
199 | + if (Locator::getLocations()) { |
|
200 | + Requirements::customScript(" |
|
201 | 201 | $(function($) { |
202 | 202 | $('#map-container').storeLocator({ |
203 | 203 | " . $load . " |
@@ -218,72 +218,72 @@ discard block |
||
218 | 218 | }); |
219 | 219 | }); |
220 | 220 | '); |
221 | - } |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * Find all locations for map. |
|
226 | - * |
|
227 | - * Will return a XML feed of all locations marked "show in locator". |
|
228 | - * |
|
229 | - * @param SS_HTTPRequest $request |
|
230 | - * @return HTMLText |
|
231 | - */ |
|
232 | - public function xml(SS_HTTPRequest $request) |
|
233 | - { |
|
234 | - $filter = array(); |
|
235 | - $exclude = array(); |
|
236 | - $filterAny = array(); |
|
237 | - |
|
238 | - //if a category filter selected |
|
239 | - if ($this->Categories()->exists()) { |
|
240 | - $categories = $this->Categories(); |
|
241 | - foreach ($categories as $category) { |
|
242 | - $filterAny['CategoryID'] = $category->ID; |
|
243 | - } |
|
244 | - } |
|
245 | - |
|
246 | - $Locations = Locator::getLocations($filter, $exclude, $filterAny); |
|
247 | - |
|
248 | - return $this->customise(array( |
|
249 | - 'Locations' => $Locations, |
|
250 | - ))->renderWith('LocationXML'); |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * LocationSearch form. |
|
255 | - * |
|
256 | - * Search form for locations, updates map and results list via AJAX |
|
257 | - * |
|
258 | - * @return Form |
|
259 | - */ |
|
260 | - public function LocationSearch() |
|
261 | - { |
|
262 | - $fields = FieldList::create( |
|
263 | - $address = TextField::create('address', '') |
|
264 | - ); |
|
265 | - $address->setAttribute('placeholder', 'address or zip code'); |
|
266 | - |
|
267 | - $locatorCategories = Locator::getPageCategories($this->ID); |
|
268 | - |
|
269 | - if (LocationCategory::get()->count() > 0 && $locatorCategories && $locatorCategories->count() != 1) { |
|
270 | - $categories = LocationCategory::get(); |
|
271 | - |
|
272 | - if ($categories->count() > 0) { |
|
273 | - $fields->push( |
|
274 | - DropdownField::create( |
|
275 | - 'category', |
|
276 | - '', |
|
277 | - $categories->map('Title', 'Title') |
|
278 | - )->setEmptyString('Select Category')); |
|
279 | - } |
|
280 | - } |
|
281 | - |
|
282 | - $actions = FieldList::create( |
|
283 | - FormAction::create('', 'Search') |
|
284 | - ); |
|
285 | - |
|
286 | - return Form::create($this, 'LocationSearch', $fields, $actions); |
|
287 | - } |
|
221 | + } |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * Find all locations for map. |
|
226 | + * |
|
227 | + * Will return a XML feed of all locations marked "show in locator". |
|
228 | + * |
|
229 | + * @param SS_HTTPRequest $request |
|
230 | + * @return HTMLText |
|
231 | + */ |
|
232 | + public function xml(SS_HTTPRequest $request) |
|
233 | + { |
|
234 | + $filter = array(); |
|
235 | + $exclude = array(); |
|
236 | + $filterAny = array(); |
|
237 | + |
|
238 | + //if a category filter selected |
|
239 | + if ($this->Categories()->exists()) { |
|
240 | + $categories = $this->Categories(); |
|
241 | + foreach ($categories as $category) { |
|
242 | + $filterAny['CategoryID'] = $category->ID; |
|
243 | + } |
|
244 | + } |
|
245 | + |
|
246 | + $Locations = Locator::getLocations($filter, $exclude, $filterAny); |
|
247 | + |
|
248 | + return $this->customise(array( |
|
249 | + 'Locations' => $Locations, |
|
250 | + ))->renderWith('LocationXML'); |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * LocationSearch form. |
|
255 | + * |
|
256 | + * Search form for locations, updates map and results list via AJAX |
|
257 | + * |
|
258 | + * @return Form |
|
259 | + */ |
|
260 | + public function LocationSearch() |
|
261 | + { |
|
262 | + $fields = FieldList::create( |
|
263 | + $address = TextField::create('address', '') |
|
264 | + ); |
|
265 | + $address->setAttribute('placeholder', 'address or zip code'); |
|
266 | + |
|
267 | + $locatorCategories = Locator::getPageCategories($this->ID); |
|
268 | + |
|
269 | + if (LocationCategory::get()->count() > 0 && $locatorCategories && $locatorCategories->count() != 1) { |
|
270 | + $categories = LocationCategory::get(); |
|
271 | + |
|
272 | + if ($categories->count() > 0) { |
|
273 | + $fields->push( |
|
274 | + DropdownField::create( |
|
275 | + 'category', |
|
276 | + '', |
|
277 | + $categories->map('Title', 'Title') |
|
278 | + )->setEmptyString('Select Category')); |
|
279 | + } |
|
280 | + } |
|
281 | + |
|
282 | + $actions = FieldList::create( |
|
283 | + FormAction::create('', 'Search') |
|
284 | + ); |
|
285 | + |
|
286 | + return Form::create($this, 'LocationSearch', $fields, $actions); |
|
287 | + } |
|
288 | 288 | |
289 | 289 | } |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | |
162 | 162 | Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
163 | 163 | if (Locator::getLocations()) { |
164 | - Requirements::javascript('//maps.google.com/maps/api/js?key=' . $key); |
|
164 | + Requirements::javascript('//maps.google.com/maps/api/js?key='.$key); |
|
165 | 165 | Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); |
166 | 166 | Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); |
167 | 167 | } |
@@ -169,44 +169,40 @@ discard block |
||
169 | 169 | Requirements::css('locator/css/map.css'); |
170 | 170 | |
171 | 171 | $featured = (Locator::getLocations(array('Featured' => 1))->count() > 0) ? |
172 | - 'featuredLocations: true' : |
|
173 | - 'featuredLocations: false'; |
|
172 | + 'featuredLocations: true' : 'featuredLocations: false'; |
|
174 | 173 | |
175 | 174 | // map config based on user input in Settings tab |
176 | 175 | // AutoGeocode or Full Map |
177 | 176 | $load = ($this->data()->AutoGeocode) ? |
178 | - 'autoGeocode: true, fullMapStart: false,' : |
|
179 | - 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
177 | + 'autoGeocode: true, fullMapStart: false,' : 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
180 | 178 | |
181 | 179 | $base = Director::baseFolder(); |
182 | - $themePath = $base . '/' . $themeDir; |
|
180 | + $themePath = $base.'/'.$themeDir; |
|
183 | 181 | |
184 | - $listTemplatePath = (file_exists($themePath . '/templates/location-list-description.html')) ? |
|
185 | - $themeDir . '/templates/location-list-description.html' : |
|
186 | - 'locator/templates/location-list-description.html'; |
|
187 | - $infowindowTemplatePath = (file_exists($themePath . '/templates/infowindow-description.html')) ? |
|
188 | - $themeDir . '/templates/infowindow-description.html' : |
|
189 | - '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'; |
|
190 | 186 | |
191 | 187 | // in page or modal |
192 | 188 | $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
193 | 189 | |
194 | 190 | $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; |
195 | 191 | |
196 | - $link = $this->Link() . 'xml.xml'; |
|
192 | + $link = $this->Link().'xml.xml'; |
|
197 | 193 | |
198 | 194 | // init map |
199 | 195 | if (Locator::getLocations()) { |
200 | 196 | Requirements::customScript(" |
201 | 197 | $(function($) { |
202 | 198 | $('#map-container').storeLocator({ |
203 | - " . $load . " |
|
204 | - dataLocation: '" . $link . "', |
|
205 | - listTemplatePath: '" . $listTemplatePath . "', |
|
206 | - infowindowTemplatePath: '" . $infowindowTemplatePath . "', |
|
199 | + " . $load." |
|
200 | + dataLocation: '" . $link."', |
|
201 | + listTemplatePath: '" . $listTemplatePath."', |
|
202 | + infowindowTemplatePath: '" . $infowindowTemplatePath."', |
|
207 | 203 | originMarker: true, |
208 | - " . $modal . ', |
|
209 | - ' . $featured . ", |
|
204 | + " . $modal.', |
|
205 | + ' . $featured.", |
|
210 | 206 | slideMap: false, |
211 | 207 | zoomLevel: 0, |
212 | 208 | distanceAlert: 120, |
@@ -214,7 +210,7 @@ discard block |
||
214 | 210 | inputID: 'Form_LocationSearch_address', |
215 | 211 | categoryID: 'Form_LocationSearch_category', |
216 | 212 | distanceAlert: -1, |
217 | - " . $kilometer . ' |
|
213 | + " . $kilometer.' |
|
218 | 214 | }); |
219 | 215 | }); |
220 | 216 | '); |