@@ -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,240 +16,240 @@ |
||
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(); |
|
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(); |
|
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 | } |
@@ -6,45 +6,45 @@ |
||
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 | } |
@@ -6,116 +6,116 @@ |
||
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->assertTrue(is_a($fieldset, 'FieldList')); |
|
17 | - } |
|
18 | - |
|
19 | - /** |
|
20 | - * |
|
21 | - */ |
|
22 | - public function testLocations() |
|
23 | - { |
|
24 | - $filter = array('ShowInLocator' => 1); |
|
25 | - $filterAny = array('Suburb' => 'Sheboygan'); |
|
26 | - $exclude = array('Suburb' => 'Milwaukee'); |
|
27 | - $locations = Locator::locations($filter, $filterAny, $exclude); |
|
28 | - $locations2 = Location::get()->filter($filter)->filterAny($filterAny)->exclude($exclude); |
|
29 | - $this->assertEquals($locations->Count(), $locations2->Count()); |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * |
|
34 | - */ |
|
35 | - public function testGetAllCategories() |
|
36 | - { |
|
37 | - $locator = singleton('Locator'); |
|
38 | - $count = LocationCategory::get(); |
|
39 | - $this->assertEquals($locator->getAllCategories(), $count); |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * |
|
44 | - */ |
|
45 | - public function testGetPageCategories() |
|
46 | - { |
|
47 | - $locator = Locator::create(); |
|
48 | - $this->assertFalse($locator->getPageCategories()); |
|
49 | - |
|
50 | - $this->assertFalse($locator->getPageCategories(500)); |
|
51 | - |
|
52 | - $locator->write(); |
|
53 | - $category = $this->objFromFixture('LocationCategory', 'service'); |
|
54 | - $locator->Categories()->add($category); |
|
55 | - $this->assertEquals($locator->getPageCategories($locator->ID), $locator->Categories()); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * |
|
60 | - */ |
|
61 | - public function testInit() |
|
62 | - { |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * |
|
67 | - */ |
|
68 | - public function testIndex() |
|
69 | - { |
|
70 | - $locator = $this->objFromFixture('Locator', 'locator1'); |
|
71 | - $controller = Locator_Controller::create($locator); |
|
72 | - $this->assertInstanceOf('ViewableData', $controller->index($controller->request)); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * |
|
77 | - */ |
|
78 | - public function testXml() |
|
79 | - { |
|
80 | - $locator = $this->objFromFixture('Locator', 'locator1'); |
|
81 | - $controller = Locator_Controller::create($locator); |
|
82 | - $this->assertInstanceOf('HTMLText', $controller->xml($controller->request)); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * |
|
87 | - */ |
|
88 | - public function testItems() |
|
89 | - { |
|
90 | - $locator = $this->objFromFixture('Locator', 'locator1'); |
|
91 | - $controller = Locator_Controller::create($locator); |
|
92 | - |
|
93 | - $filter = array('ShowInLocator' => 1); |
|
94 | - $exclude = ['Lat' => 0.00000, 'Lng' => 0.00000]; |
|
95 | - |
|
96 | - $locations = $controller->Items($controller->request); |
|
97 | - $locations2 = Location::get()->filter($filter)->exclude($exclude); |
|
98 | - $this->assertEquals($locations->count(), $locations2->count()); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * |
|
103 | - */ |
|
104 | - public function testLocationSearch() |
|
105 | - { |
|
106 | - $locator = $this->objFromFixture('Locator', 'locator1'); |
|
107 | - $object = Locator_Controller::create($locator); |
|
108 | - $form = $object->LocationSearch(); |
|
109 | - $this->assertTrue(is_a($form, 'Form')); |
|
110 | - |
|
111 | - $category = $this->objFromFixture('LocationCategory', 'service'); |
|
112 | - $category2 = $this->objFromFixture('LocationCategory', 'manufacturing'); |
|
113 | - $locator->Categories()->add($category); |
|
114 | - $locator->Categories()->add($category2); |
|
115 | - |
|
116 | - $form = $object->LocationSearch(); |
|
117 | - $fields = $form->Fields(); |
|
118 | - $this->assertNotNull($fields->fieldByName('CategoryID')); |
|
119 | - } |
|
9 | + /** |
|
10 | + * |
|
11 | + */ |
|
12 | + public function testGetCMSFields() |
|
13 | + { |
|
14 | + $object = new Locator(); |
|
15 | + $fieldset = $object->getCMSFields(); |
|
16 | + $this->assertTrue(is_a($fieldset, 'FieldList')); |
|
17 | + } |
|
18 | + |
|
19 | + /** |
|
20 | + * |
|
21 | + */ |
|
22 | + public function testLocations() |
|
23 | + { |
|
24 | + $filter = array('ShowInLocator' => 1); |
|
25 | + $filterAny = array('Suburb' => 'Sheboygan'); |
|
26 | + $exclude = array('Suburb' => 'Milwaukee'); |
|
27 | + $locations = Locator::locations($filter, $filterAny, $exclude); |
|
28 | + $locations2 = Location::get()->filter($filter)->filterAny($filterAny)->exclude($exclude); |
|
29 | + $this->assertEquals($locations->Count(), $locations2->Count()); |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * |
|
34 | + */ |
|
35 | + public function testGetAllCategories() |
|
36 | + { |
|
37 | + $locator = singleton('Locator'); |
|
38 | + $count = LocationCategory::get(); |
|
39 | + $this->assertEquals($locator->getAllCategories(), $count); |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * |
|
44 | + */ |
|
45 | + public function testGetPageCategories() |
|
46 | + { |
|
47 | + $locator = Locator::create(); |
|
48 | + $this->assertFalse($locator->getPageCategories()); |
|
49 | + |
|
50 | + $this->assertFalse($locator->getPageCategories(500)); |
|
51 | + |
|
52 | + $locator->write(); |
|
53 | + $category = $this->objFromFixture('LocationCategory', 'service'); |
|
54 | + $locator->Categories()->add($category); |
|
55 | + $this->assertEquals($locator->getPageCategories($locator->ID), $locator->Categories()); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * |
|
60 | + */ |
|
61 | + public function testInit() |
|
62 | + { |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * |
|
67 | + */ |
|
68 | + public function testIndex() |
|
69 | + { |
|
70 | + $locator = $this->objFromFixture('Locator', 'locator1'); |
|
71 | + $controller = Locator_Controller::create($locator); |
|
72 | + $this->assertInstanceOf('ViewableData', $controller->index($controller->request)); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * |
|
77 | + */ |
|
78 | + public function testXml() |
|
79 | + { |
|
80 | + $locator = $this->objFromFixture('Locator', 'locator1'); |
|
81 | + $controller = Locator_Controller::create($locator); |
|
82 | + $this->assertInstanceOf('HTMLText', $controller->xml($controller->request)); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * |
|
87 | + */ |
|
88 | + public function testItems() |
|
89 | + { |
|
90 | + $locator = $this->objFromFixture('Locator', 'locator1'); |
|
91 | + $controller = Locator_Controller::create($locator); |
|
92 | + |
|
93 | + $filter = array('ShowInLocator' => 1); |
|
94 | + $exclude = ['Lat' => 0.00000, 'Lng' => 0.00000]; |
|
95 | + |
|
96 | + $locations = $controller->Items($controller->request); |
|
97 | + $locations2 = Location::get()->filter($filter)->exclude($exclude); |
|
98 | + $this->assertEquals($locations->count(), $locations2->count()); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * |
|
103 | + */ |
|
104 | + public function testLocationSearch() |
|
105 | + { |
|
106 | + $locator = $this->objFromFixture('Locator', 'locator1'); |
|
107 | + $object = Locator_Controller::create($locator); |
|
108 | + $form = $object->LocationSearch(); |
|
109 | + $this->assertTrue(is_a($form, 'Form')); |
|
110 | + |
|
111 | + $category = $this->objFromFixture('LocationCategory', 'service'); |
|
112 | + $category2 = $this->objFromFixture('LocationCategory', 'manufacturing'); |
|
113 | + $locator->Categories()->add($category); |
|
114 | + $locator->Categories()->add($category2); |
|
115 | + |
|
116 | + $form = $object->LocationSearch(); |
|
117 | + $fields = $form->Fields(); |
|
118 | + $this->assertNotNull($fields->fieldByName('CategoryID')); |
|
119 | + } |
|
120 | 120 | |
121 | 121 | } |
@@ -6,183 +6,183 @@ |
||
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 | } |
@@ -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,43 +6,43 @@ |
||
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 | } |
@@ -11,142 +11,142 @@ 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.Filter', array( |
|
78 | - HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
79 | - $categoriesField, |
|
80 | - )); |
|
81 | - |
|
82 | - $this->extend('updateCMSFields', $fields); |
|
83 | - |
|
84 | - return $fields; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @param array $filter |
|
89 | - * @param array $filterAny |
|
90 | - * @param array $exclude |
|
91 | - * @param null $filterByCallback |
|
92 | - * @return ArrayList |
|
93 | - */ |
|
94 | - public static function locations( |
|
95 | - $filter = array(), |
|
96 | - $filterAny = array(), |
|
97 | - $exclude = array(), |
|
98 | - $filterByCallback = null |
|
99 | - ) |
|
100 | - { |
|
101 | - $locationsList = ArrayList::create(); |
|
102 | - |
|
103 | - // filter by ShowInLocator |
|
104 | - $filter['ShowInLocator'] = 1; |
|
105 | - |
|
106 | - $locations = Location::get()->filter($filter); |
|
107 | - |
|
108 | - if (!empty($filterAny)) { |
|
109 | - $locations = $locations->filterAny($filterAny); |
|
110 | - } |
|
111 | - if (!empty($exclude)) { |
|
112 | - $locations = $locations->exclude($exclude); |
|
113 | - } |
|
114 | - |
|
115 | - if ($filterByCallback !== null && is_callable($filterByCallback)) { |
|
116 | - $locations = $locations->filterByCallback($filterByCallback); |
|
117 | - } |
|
118 | - |
|
119 | - if ($locations->exists()) { |
|
120 | - $locationsList->merge($locations); |
|
121 | - } |
|
122 | - |
|
123 | - return $locationsList; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @return DataList |
|
128 | - */ |
|
129 | - public static function getAllCategories() |
|
130 | - { |
|
131 | - return LocationCategory::get(); |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * @param null $id |
|
136 | - * @return bool |
|
137 | - */ |
|
138 | - public static function getPageCategories($id = null) |
|
139 | - { |
|
140 | - if ($id) { |
|
141 | - if ($locator = self::get()->byID($id)) { |
|
142 | - return $locator->Categories(); |
|
143 | - } |
|
144 | - |
|
145 | - return false; |
|
146 | - } |
|
147 | - |
|
148 | - return false; |
|
149 | - } |
|
14 | + /** |
|
15 | + * @var array |
|
16 | + */ |
|
17 | + private static $db = array( |
|
18 | + 'AutoGeocode' => 'Boolean', |
|
19 | + 'ModalWindow' => 'Boolean', |
|
20 | + 'Unit' => 'Enum("m,km","m")', |
|
21 | + ); |
|
22 | + |
|
23 | + /** |
|
24 | + * @var array |
|
25 | + */ |
|
26 | + private static $many_many = array( |
|
27 | + 'Categories' => 'LocationCategory', |
|
28 | + ); |
|
29 | + |
|
30 | + /** |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + private static $defaults = array( |
|
34 | + 'AutoGeocode' => true, |
|
35 | + ); |
|
36 | + |
|
37 | + /** |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + private static $singular_name = 'Locator'; |
|
41 | + /** |
|
42 | + * @var string |
|
43 | + */ |
|
44 | + private static $plural_name = 'Locators'; |
|
45 | + /** |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + private static $description = 'Find locations on a map'; |
|
49 | + |
|
50 | + /** |
|
51 | + * @return FieldList |
|
52 | + */ |
|
53 | + public function getCMSFields() |
|
54 | + { |
|
55 | + $fields = parent::getCMSFields(); |
|
56 | + |
|
57 | + // Settings |
|
58 | + $fields->addFieldsToTab('Root.Settings', array( |
|
59 | + HeaderField::create('DisplayOptions', 'Display Options', 3), |
|
60 | + OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')), |
|
61 | + CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location') |
|
62 | + ->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'), |
|
63 | + CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'), |
|
64 | + )); |
|
65 | + |
|
66 | + // Filter categories |
|
67 | + $config = GridFieldConfig_RelationEditor::create(); |
|
68 | + if (class_exists('GridFieldAddExistingSearchButton')) { |
|
69 | + $config->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
|
70 | + $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
71 | + } |
|
72 | + $categories = $this->Categories(); |
|
73 | + $categoriesField = GridField::create('Categories', 'Categories', $categories, $config) |
|
74 | + ->setDescription('only show locations from the selected category'); |
|
75 | + |
|
76 | + // Filter |
|
77 | + $fields->addFieldsToTab('Root.Filter', array( |
|
78 | + HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
79 | + $categoriesField, |
|
80 | + )); |
|
81 | + |
|
82 | + $this->extend('updateCMSFields', $fields); |
|
83 | + |
|
84 | + return $fields; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @param array $filter |
|
89 | + * @param array $filterAny |
|
90 | + * @param array $exclude |
|
91 | + * @param null $filterByCallback |
|
92 | + * @return ArrayList |
|
93 | + */ |
|
94 | + public static function locations( |
|
95 | + $filter = array(), |
|
96 | + $filterAny = array(), |
|
97 | + $exclude = array(), |
|
98 | + $filterByCallback = null |
|
99 | + ) |
|
100 | + { |
|
101 | + $locationsList = ArrayList::create(); |
|
102 | + |
|
103 | + // filter by ShowInLocator |
|
104 | + $filter['ShowInLocator'] = 1; |
|
105 | + |
|
106 | + $locations = Location::get()->filter($filter); |
|
107 | + |
|
108 | + if (!empty($filterAny)) { |
|
109 | + $locations = $locations->filterAny($filterAny); |
|
110 | + } |
|
111 | + if (!empty($exclude)) { |
|
112 | + $locations = $locations->exclude($exclude); |
|
113 | + } |
|
114 | + |
|
115 | + if ($filterByCallback !== null && is_callable($filterByCallback)) { |
|
116 | + $locations = $locations->filterByCallback($filterByCallback); |
|
117 | + } |
|
118 | + |
|
119 | + if ($locations->exists()) { |
|
120 | + $locationsList->merge($locations); |
|
121 | + } |
|
122 | + |
|
123 | + return $locationsList; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @return DataList |
|
128 | + */ |
|
129 | + public static function getAllCategories() |
|
130 | + { |
|
131 | + return LocationCategory::get(); |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * @param null $id |
|
136 | + * @return bool |
|
137 | + */ |
|
138 | + public static function getPageCategories($id = null) |
|
139 | + { |
|
140 | + if ($id) { |
|
141 | + if ($locator = self::get()->byID($id)) { |
|
142 | + return $locator->Categories(); |
|
143 | + } |
|
144 | + |
|
145 | + return false; |
|
146 | + } |
|
147 | + |
|
148 | + return false; |
|
149 | + } |
|
150 | 150 | |
151 | 151 | |
152 | 152 | } |
@@ -156,84 +156,84 @@ discard block |
||
156 | 156 | */ |
157 | 157 | class Locator_Controller extends Page_Controller |
158 | 158 | { |
159 | - /** |
|
160 | - * @var array |
|
161 | - */ |
|
162 | - private static $allowed_actions = array( |
|
163 | - 'xml', |
|
164 | - ); |
|
165 | - |
|
166 | - /** |
|
167 | - * Set Requirements based on input from CMS |
|
168 | - */ |
|
169 | - public function init() |
|
170 | - { |
|
171 | - parent::init(); |
|
172 | - |
|
173 | - $themeDir = SSViewer::get_theme_folder(); |
|
174 | - |
|
175 | - // google maps api key |
|
176 | - $key = Config::inst()->get('GoogleGeocoding', 'google_api_key'); |
|
177 | - |
|
178 | - $locations = $this->Items($this->request); |
|
179 | - |
|
180 | - Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
|
181 | - if ($locations) { |
|
182 | - Requirements::javascript('http://maps.google.com/maps/api/js?key=' . $key); |
|
183 | - Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); |
|
184 | - Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); |
|
185 | - } |
|
186 | - |
|
187 | - Requirements::css('locator/css/map.css'); |
|
188 | - |
|
189 | - $featuredInList = ($locations->filter('Featured', true)->count() > 0); |
|
190 | - |
|
191 | - $featured = $featuredInList |
|
192 | - ? 'featuredLocations: true' |
|
193 | - : 'featuredLocations: false'; |
|
194 | - |
|
195 | - // map config based on user input in Settings tab |
|
196 | - // AutoGeocode or Full Map |
|
197 | - if ($this->data()->AutoGeocode) { |
|
198 | - $load = $featuredInList |
|
199 | - ? 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,' |
|
200 | - : 'autoGeocode: true, fullMapStart: false,'; |
|
201 | - } else { |
|
202 | - $load = 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
203 | - } |
|
204 | - |
|
205 | - /*$load = ($this->data()->AutoGeocode) ? |
|
159 | + /** |
|
160 | + * @var array |
|
161 | + */ |
|
162 | + private static $allowed_actions = array( |
|
163 | + 'xml', |
|
164 | + ); |
|
165 | + |
|
166 | + /** |
|
167 | + * Set Requirements based on input from CMS |
|
168 | + */ |
|
169 | + public function init() |
|
170 | + { |
|
171 | + parent::init(); |
|
172 | + |
|
173 | + $themeDir = SSViewer::get_theme_folder(); |
|
174 | + |
|
175 | + // google maps api key |
|
176 | + $key = Config::inst()->get('GoogleGeocoding', 'google_api_key'); |
|
177 | + |
|
178 | + $locations = $this->Items($this->request); |
|
179 | + |
|
180 | + Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
|
181 | + if ($locations) { |
|
182 | + Requirements::javascript('http://maps.google.com/maps/api/js?key=' . $key); |
|
183 | + Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); |
|
184 | + Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); |
|
185 | + } |
|
186 | + |
|
187 | + Requirements::css('locator/css/map.css'); |
|
188 | + |
|
189 | + $featuredInList = ($locations->filter('Featured', true)->count() > 0); |
|
190 | + |
|
191 | + $featured = $featuredInList |
|
192 | + ? 'featuredLocations: true' |
|
193 | + : 'featuredLocations: false'; |
|
194 | + |
|
195 | + // map config based on user input in Settings tab |
|
196 | + // AutoGeocode or Full Map |
|
197 | + if ($this->data()->AutoGeocode) { |
|
198 | + $load = $featuredInList |
|
199 | + ? 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,' |
|
200 | + : 'autoGeocode: true, fullMapStart: false,'; |
|
201 | + } else { |
|
202 | + $load = 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
203 | + } |
|
204 | + |
|
205 | + /*$load = ($this->data()->AutoGeocode) ? |
|
206 | 206 | 'autoGeocode: true, fullMapStart: false,' : |
207 | 207 | 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';*/ |
208 | 208 | |
209 | - $base = Director::baseFolder(); |
|
210 | - $themePath = $base . '/' . $themeDir; |
|
211 | - |
|
212 | - $listTemplatePath = (file_exists($themePath . '/templates/location-list-description.html')) ? |
|
213 | - $themeDir . '/templates/location-list-description.html' : |
|
214 | - 'locator/templates/location-list-description.html'; |
|
215 | - $infowindowTemplatePath = (file_exists($themePath . '/templates/infowindow-description.html')) ? |
|
216 | - $themeDir . '/templates/infowindow-description.html' : |
|
217 | - 'locator/templates/infowindow-description.html'; |
|
218 | - |
|
219 | - // in page or modal |
|
220 | - $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
|
221 | - |
|
222 | - $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; |
|
223 | - |
|
224 | - // pass GET variables to xml action |
|
225 | - $vars = $this->request->getVars(); |
|
226 | - unset($vars['url']); |
|
227 | - unset($vars['action_index']); |
|
228 | - $url = ''; |
|
229 | - if (count($vars)) { |
|
230 | - $url .= '?' . http_build_query($vars); |
|
231 | - } |
|
232 | - $link = $this->Link() . 'xml.xml' . $url; |
|
233 | - |
|
234 | - // init map |
|
235 | - if ($locations) { |
|
236 | - Requirements::customScript(" |
|
209 | + $base = Director::baseFolder(); |
|
210 | + $themePath = $base . '/' . $themeDir; |
|
211 | + |
|
212 | + $listTemplatePath = (file_exists($themePath . '/templates/location-list-description.html')) ? |
|
213 | + $themeDir . '/templates/location-list-description.html' : |
|
214 | + 'locator/templates/location-list-description.html'; |
|
215 | + $infowindowTemplatePath = (file_exists($themePath . '/templates/infowindow-description.html')) ? |
|
216 | + $themeDir . '/templates/infowindow-description.html' : |
|
217 | + 'locator/templates/infowindow-description.html'; |
|
218 | + |
|
219 | + // in page or modal |
|
220 | + $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
|
221 | + |
|
222 | + $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; |
|
223 | + |
|
224 | + // pass GET variables to xml action |
|
225 | + $vars = $this->request->getVars(); |
|
226 | + unset($vars['url']); |
|
227 | + unset($vars['action_index']); |
|
228 | + $url = ''; |
|
229 | + if (count($vars)) { |
|
230 | + $url .= '?' . http_build_query($vars); |
|
231 | + } |
|
232 | + $link = $this->Link() . 'xml.xml' . $url; |
|
233 | + |
|
234 | + // init map |
|
235 | + if ($locations) { |
|
236 | + Requirements::customScript(" |
|
237 | 237 | $(function($) { |
238 | 238 | $('#map-container').storeLocator({ |
239 | 239 | " . $load . " |
@@ -254,136 +254,136 @@ discard block |
||
254 | 254 | }); |
255 | 255 | }); |
256 | 256 | '); |
257 | - } |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * @param SS_HTTPRequest $request |
|
262 | - * |
|
263 | - * @return ViewableData_Customised |
|
264 | - */ |
|
265 | - public function index(SS_HTTPRequest $request) |
|
266 | - { |
|
267 | - $locations = $this->Items($request); |
|
268 | - |
|
269 | - return $this->customise(array( |
|
270 | - 'Locations' => $locations, |
|
271 | - )); |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Return a XML feed of all locations marked "show in locator" |
|
276 | - * |
|
277 | - * @param SS_HTTPRequest $request |
|
278 | - * @return HTMLText |
|
279 | - */ |
|
280 | - public function xml(SS_HTTPRequest $request) |
|
281 | - { |
|
282 | - $locations = $this->Items($request); |
|
283 | - |
|
284 | - return $this->customise(array( |
|
285 | - 'Locations' => $locations, |
|
286 | - ))->renderWith('LocationXML'); |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * @param SS_HTTPRequest $request |
|
291 | - * |
|
292 | - * @return ArrayList |
|
293 | - */ |
|
294 | - public function Items(SS_HTTPRequest $request) |
|
295 | - { |
|
296 | - $request = ($request) ? $request : $this->request; |
|
297 | - |
|
298 | - $filter = array(); |
|
299 | - $filterAny = array(); |
|
300 | - $exclude = ['Lat' => 0.00000, 'Lng' => 0.00000]; |
|
301 | - |
|
302 | - // only show locations marked as ShowInLocator |
|
303 | - $filter['ShowInLocator'] = 1; |
|
304 | - |
|
305 | - // search across all address related fields |
|
306 | - $address = ($request->getVar('Address')) ? $request->getVar('Address') : false; |
|
307 | - if ($address && $this->data()->AutoGeocode == 0) { |
|
308 | - $filterAny['Address:PartialMatch'] = $address; |
|
309 | - $filterAny['Suburb:PartialMatch'] = $address; |
|
310 | - $filterAny['State:PartialMatch'] = $address; |
|
311 | - $filterAny['Postcode:PartialMatch'] = $address; |
|
312 | - $filterAny['Country:PartialMatch'] = $address; |
|
313 | - } else { |
|
314 | - unset($filter['Address']); |
|
315 | - } |
|
316 | - |
|
317 | - // search for category from form, else categories from Locator |
|
318 | - $category = ($request->getVar('CategoryID')) ? $request->getVar('CategoryID') : false; |
|
319 | - if ($category) { |
|
320 | - $filter['CategoryID:ExactMatch'] = $category; |
|
321 | - } elseif ($this->Categories()->exists()) { |
|
322 | - $categories = $this->Categories(); |
|
323 | - $categoryArray = array(); |
|
324 | - foreach ($categories as $category) { |
|
325 | - array_push($categoryArray, $category->ID); |
|
326 | - } |
|
327 | - $filter['CategoryID'] = $categoryArray; |
|
328 | - } |
|
329 | - |
|
330 | - $locations = Locator::locations($filter, $filterAny, $exclude); |
|
331 | - |
|
332 | - return $locations; |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * LocationSearch form. |
|
337 | - * |
|
338 | - * Search form for locations, updates map and results list via AJAX |
|
339 | - * |
|
340 | - * @return Form |
|
341 | - */ |
|
342 | - public function LocationSearch() |
|
343 | - { |
|
344 | - $fields = FieldList::create( |
|
345 | - $address = TextField::create('Address', '') |
|
346 | - ->setAttribute('placeholder', 'address or zip code') |
|
347 | - ); |
|
348 | - |
|
349 | - $filterCategories = Locator::getPageCategories($this->ID); |
|
350 | - $allCategories = Locator::getAllCategories(); |
|
351 | - |
|
352 | - if ($allCategories->Count() > 0) { |
|
353 | - $categories = ArrayList::create(); |
|
354 | - if ($filterCategories->Count() > 0) { |
|
355 | - if ($filterCategories->Count() != 1) { |
|
356 | - $categories = $filterCategories; |
|
357 | - } |
|
358 | - } else { |
|
359 | - $categories = $allCategories; |
|
360 | - } |
|
361 | - |
|
362 | - if ($categories->count() > 0) { |
|
363 | - $fields->push( |
|
364 | - DropdownField::create( |
|
365 | - 'CategoryID', |
|
366 | - '', |
|
367 | - $categories->map() |
|
368 | - )->setEmptyString('All Categories')); |
|
369 | - } |
|
370 | - } |
|
371 | - |
|
372 | - $actions = FieldList::create( |
|
373 | - FormAction::create('index', 'Search') |
|
374 | - ); |
|
375 | - |
|
376 | - if (class_exists('BootstrapForm')) { |
|
377 | - $form = BootstrapForm::create($this, 'LocationSearch', $fields, $actions); |
|
378 | - } else { |
|
379 | - $form = Form::create($this, 'LocationSearch', $fields, $actions); |
|
380 | - } |
|
381 | - |
|
382 | - return $form |
|
383 | - ->setFormMethod('GET') |
|
384 | - ->setFormAction($this->Link()) |
|
385 | - ->disableSecurityToken() |
|
386 | - ->loadDataFrom($this->request->getVars()); |
|
387 | - } |
|
257 | + } |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * @param SS_HTTPRequest $request |
|
262 | + * |
|
263 | + * @return ViewableData_Customised |
|
264 | + */ |
|
265 | + public function index(SS_HTTPRequest $request) |
|
266 | + { |
|
267 | + $locations = $this->Items($request); |
|
268 | + |
|
269 | + return $this->customise(array( |
|
270 | + 'Locations' => $locations, |
|
271 | + )); |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Return a XML feed of all locations marked "show in locator" |
|
276 | + * |
|
277 | + * @param SS_HTTPRequest $request |
|
278 | + * @return HTMLText |
|
279 | + */ |
|
280 | + public function xml(SS_HTTPRequest $request) |
|
281 | + { |
|
282 | + $locations = $this->Items($request); |
|
283 | + |
|
284 | + return $this->customise(array( |
|
285 | + 'Locations' => $locations, |
|
286 | + ))->renderWith('LocationXML'); |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * @param SS_HTTPRequest $request |
|
291 | + * |
|
292 | + * @return ArrayList |
|
293 | + */ |
|
294 | + public function Items(SS_HTTPRequest $request) |
|
295 | + { |
|
296 | + $request = ($request) ? $request : $this->request; |
|
297 | + |
|
298 | + $filter = array(); |
|
299 | + $filterAny = array(); |
|
300 | + $exclude = ['Lat' => 0.00000, 'Lng' => 0.00000]; |
|
301 | + |
|
302 | + // only show locations marked as ShowInLocator |
|
303 | + $filter['ShowInLocator'] = 1; |
|
304 | + |
|
305 | + // search across all address related fields |
|
306 | + $address = ($request->getVar('Address')) ? $request->getVar('Address') : false; |
|
307 | + if ($address && $this->data()->AutoGeocode == 0) { |
|
308 | + $filterAny['Address:PartialMatch'] = $address; |
|
309 | + $filterAny['Suburb:PartialMatch'] = $address; |
|
310 | + $filterAny['State:PartialMatch'] = $address; |
|
311 | + $filterAny['Postcode:PartialMatch'] = $address; |
|
312 | + $filterAny['Country:PartialMatch'] = $address; |
|
313 | + } else { |
|
314 | + unset($filter['Address']); |
|
315 | + } |
|
316 | + |
|
317 | + // search for category from form, else categories from Locator |
|
318 | + $category = ($request->getVar('CategoryID')) ? $request->getVar('CategoryID') : false; |
|
319 | + if ($category) { |
|
320 | + $filter['CategoryID:ExactMatch'] = $category; |
|
321 | + } elseif ($this->Categories()->exists()) { |
|
322 | + $categories = $this->Categories(); |
|
323 | + $categoryArray = array(); |
|
324 | + foreach ($categories as $category) { |
|
325 | + array_push($categoryArray, $category->ID); |
|
326 | + } |
|
327 | + $filter['CategoryID'] = $categoryArray; |
|
328 | + } |
|
329 | + |
|
330 | + $locations = Locator::locations($filter, $filterAny, $exclude); |
|
331 | + |
|
332 | + return $locations; |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * LocationSearch form. |
|
337 | + * |
|
338 | + * Search form for locations, updates map and results list via AJAX |
|
339 | + * |
|
340 | + * @return Form |
|
341 | + */ |
|
342 | + public function LocationSearch() |
|
343 | + { |
|
344 | + $fields = FieldList::create( |
|
345 | + $address = TextField::create('Address', '') |
|
346 | + ->setAttribute('placeholder', 'address or zip code') |
|
347 | + ); |
|
348 | + |
|
349 | + $filterCategories = Locator::getPageCategories($this->ID); |
|
350 | + $allCategories = Locator::getAllCategories(); |
|
351 | + |
|
352 | + if ($allCategories->Count() > 0) { |
|
353 | + $categories = ArrayList::create(); |
|
354 | + if ($filterCategories->Count() > 0) { |
|
355 | + if ($filterCategories->Count() != 1) { |
|
356 | + $categories = $filterCategories; |
|
357 | + } |
|
358 | + } else { |
|
359 | + $categories = $allCategories; |
|
360 | + } |
|
361 | + |
|
362 | + if ($categories->count() > 0) { |
|
363 | + $fields->push( |
|
364 | + DropdownField::create( |
|
365 | + 'CategoryID', |
|
366 | + '', |
|
367 | + $categories->map() |
|
368 | + )->setEmptyString('All Categories')); |
|
369 | + } |
|
370 | + } |
|
371 | + |
|
372 | + $actions = FieldList::create( |
|
373 | + FormAction::create('index', 'Search') |
|
374 | + ); |
|
375 | + |
|
376 | + if (class_exists('BootstrapForm')) { |
|
377 | + $form = BootstrapForm::create($this, 'LocationSearch', $fields, $actions); |
|
378 | + } else { |
|
379 | + $form = Form::create($this, 'LocationSearch', $fields, $actions); |
|
380 | + } |
|
381 | + |
|
382 | + return $form |
|
383 | + ->setFormMethod('GET') |
|
384 | + ->setFormAction($this->Link()) |
|
385 | + ->disableSecurityToken() |
|
386 | + ->loadDataFrom($this->request->getVars()); |
|
387 | + } |
|
388 | 388 | |
389 | 389 | } |
@@ -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 | } |