@@ -220,7 +220,7 @@ |
||
220 | 220 | |
221 | 221 | /** |
222 | 222 | * @param array $searchCriteria |
223 | - * @return mixed |
|
223 | + * @return Locator_Controller |
|
224 | 224 | */ |
225 | 225 | public function Items($searchCriteria = array()) |
226 | 226 | { |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | |
136 | 136 | Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
137 | 137 | if (Locator::getLocations()) { |
138 | - Requirements::javascript('http://maps.google.com/maps/api/js?key='.$key); |
|
138 | + Requirements::javascript('http://maps.google.com/maps/api/js?key=' . $key); |
|
139 | 139 | Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); |
140 | 140 | Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); |
141 | 141 | } |
@@ -143,24 +143,20 @@ discard block |
||
143 | 143 | Requirements::css('locator/css/map.css'); |
144 | 144 | |
145 | 145 | $featured = (Locator::getLocations(array('Featured' => 1))->count() > 0) ? |
146 | - 'featuredLocations: true' : |
|
147 | - 'featuredLocations: false'; |
|
146 | + 'featuredLocations: true' : 'featuredLocations: false'; |
|
148 | 147 | |
149 | 148 | // map config based on user input in Settings tab |
150 | 149 | // AutoGeocode or Full Map |
151 | 150 | $load = ($this->data()->AutoGeocode) ? |
152 | - 'autoGeocode: true, fullMapStart: false,' : |
|
153 | - 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
151 | + 'autoGeocode: true, fullMapStart: false,' : 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
154 | 152 | |
155 | 153 | $base = Director::baseFolder(); |
156 | - $themePath = $base.'/'.$themeDir; |
|
154 | + $themePath = $base . '/' . $themeDir; |
|
157 | 155 | |
158 | - $listTemplatePath = (file_exists($themePath.'/templates/location-list-description.html')) ? |
|
159 | - $themeDir.'/templates/location-list-description.html' : |
|
160 | - 'locator/templates/location-list-description.html'; |
|
161 | - $infowindowTemplatePath = (file_exists($themePath.'/templates/infowindow-description.html')) ? |
|
162 | - $themeDir.'/templates/infowindow-description.html' : |
|
163 | - 'locator/templates/infowindow-description.html'; |
|
156 | + $listTemplatePath = (file_exists($themePath . '/templates/location-list-description.html')) ? |
|
157 | + $themeDir . '/templates/location-list-description.html' : 'locator/templates/location-list-description.html'; |
|
158 | + $infowindowTemplatePath = (file_exists($themePath . '/templates/infowindow-description.html')) ? |
|
159 | + $themeDir . '/templates/infowindow-description.html' : 'locator/templates/infowindow-description.html'; |
|
164 | 160 | |
165 | 161 | // in page or modal |
166 | 162 | $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
@@ -172,22 +168,22 @@ discard block |
||
172 | 168 | unset($vars['url']); |
173 | 169 | $url = ''; |
174 | 170 | if (count($vars)) { |
175 | - $url .= '?'.http_build_query($vars); |
|
171 | + $url .= '?' . http_build_query($vars); |
|
176 | 172 | } |
177 | - $link = $this->Link().'xml.xml'.$url; |
|
173 | + $link = $this->Link() . 'xml.xml' . $url; |
|
178 | 174 | |
179 | 175 | // init map |
180 | 176 | if (Locator::getLocations()) { |
181 | 177 | Requirements::customScript(" |
182 | 178 | $(function($) { |
183 | 179 | $('#map-container').storeLocator({ |
184 | - ".$load." |
|
185 | - dataLocation: '".$link."', |
|
186 | - listTemplatePath: '".$listTemplatePath."', |
|
187 | - infowindowTemplatePath: '".$infowindowTemplatePath."', |
|
180 | + ".$load . " |
|
181 | + dataLocation: '".$link . "', |
|
182 | + listTemplatePath: '".$listTemplatePath . "', |
|
183 | + infowindowTemplatePath: '".$infowindowTemplatePath . "', |
|
188 | 184 | originMarker: true, |
189 | - ".$modal.', |
|
190 | - '.$featured.", |
|
185 | + ".$modal . ', |
|
186 | + '.$featured . ", |
|
191 | 187 | slideMap: false, |
192 | 188 | zoomLevel: 0, |
193 | 189 | distanceAlert: 120, |
@@ -196,7 +192,7 @@ discard block |
||
196 | 192 | inputID: 'Form_LocationSearch_Address', |
197 | 193 | categoryID: 'Form_LocationSearch_CategoryID', |
198 | 194 | distanceAlert: -1, |
199 | - ".$kilometer.' |
|
195 | + ".$kilometer . ' |
|
200 | 196 | }); |
201 | 197 | }); |
202 | 198 | '); |
@@ -2,192 +2,192 @@ discard block |
||
2 | 2 | |
3 | 3 | class Locator extends Page |
4 | 4 | { |
5 | - private static $db = array( |
|
6 | - 'AutoGeocode' => 'Boolean', |
|
7 | - 'ModalWindow' => 'Boolean', |
|
8 | - 'Unit' => 'Enum("m,km","m")', |
|
9 | - ); |
|
10 | - |
|
11 | - private static $many_many = array( |
|
12 | - 'Categories' => 'LocationCategory', |
|
13 | - ); |
|
14 | - |
|
15 | - private static $defaults = array( |
|
16 | - 'AutoGeocode' => true, |
|
17 | - ); |
|
18 | - |
|
19 | - private static $singular_name = 'Locator'; |
|
20 | - private static $plural_name = 'Locators'; |
|
21 | - private static $description = 'Find locations on a map'; |
|
22 | - |
|
23 | - /** |
|
24 | - * @return FieldList |
|
25 | - */ |
|
26 | - public function getCMSFields() |
|
27 | - { |
|
28 | - $fields = parent::getCMSFields(); |
|
29 | - |
|
30 | - // Settings |
|
31 | - $fields->addFieldsToTab('Root.Settings', array( |
|
32 | - HeaderField::create('DisplayOptions', 'Display Options', 3), |
|
33 | - OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')), |
|
34 | - CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location') |
|
35 | - ->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'), |
|
36 | - CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'), |
|
37 | - )); |
|
38 | - |
|
39 | - // Filter categories |
|
40 | - $config = GridFieldConfig_RelationEditor::create(); |
|
41 | - if (class_exists('GridFieldAddExistingSearchButton')) { |
|
42 | - $config->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
|
43 | - $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
44 | - } |
|
45 | - $categories = $this->Categories(); |
|
46 | - $categoriesField = GridField::create('Categories', 'Categories', $categories, $config) |
|
47 | - ->setDescription('only show locations from the selected category'); |
|
48 | - |
|
49 | - // Filter |
|
50 | - $fields->addFieldsToTab('Root.Filter', array( |
|
51 | - HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
52 | - $categoriesField, |
|
53 | - )); |
|
54 | - |
|
55 | - $this->extend('updateCMSFields', $fields); |
|
56 | - |
|
57 | - return $fields; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * @param array $filter |
|
62 | - * @param array $filterAny |
|
63 | - * @param array $exclude |
|
64 | - * @param null $filterByCallback |
|
65 | - * @return ArrayList |
|
66 | - */ |
|
67 | - public static function locations( |
|
68 | - $filter = array(), |
|
69 | - $filterAny = array(), |
|
70 | - $exclude = array(), |
|
71 | - $filterByCallback = null |
|
72 | - ) { |
|
73 | - $locationsList = ArrayList::create(); |
|
74 | - |
|
75 | - // filter by ShowInLocator |
|
76 | - $filter['ShowInLocator'] = 1; |
|
77 | - |
|
78 | - $locations = Location::get()->filter($filter); |
|
79 | - |
|
80 | - if (!empty($filterAny)) { |
|
81 | - $locations = $locations->filterAny($filterAny); |
|
82 | - } |
|
83 | - if (!empty($exclude)) { |
|
84 | - $locations = $locations->exclude($exclude); |
|
85 | - } |
|
86 | - |
|
87 | - if ($filterByCallback !== null && is_callable($filterByCallback)) { |
|
88 | - $locations = $locations->filterByCallback($filterByCallback); |
|
89 | - } |
|
90 | - |
|
91 | - if ($locations->exists()) { |
|
92 | - $locationsList->merge($locations); |
|
93 | - } |
|
94 | - |
|
95 | - return $locationsList; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * @return DataList |
|
100 | - */ |
|
101 | - public static function getAllCategories() |
|
102 | - { |
|
103 | - return LocationCategory::get(); |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * @param null $id |
|
108 | - * @return bool |
|
109 | - */ |
|
110 | - public static function getPageCategories($id = null) |
|
111 | - { |
|
112 | - if ($id) { |
|
113 | - if ($locator = self::get()->byID($id)) { |
|
114 | - return $locator->Categories(); |
|
115 | - } |
|
116 | - |
|
117 | - return false; |
|
118 | - } |
|
119 | - |
|
120 | - return false; |
|
121 | - } |
|
5 | + private static $db = array( |
|
6 | + 'AutoGeocode' => 'Boolean', |
|
7 | + 'ModalWindow' => 'Boolean', |
|
8 | + 'Unit' => 'Enum("m,km","m")', |
|
9 | + ); |
|
10 | + |
|
11 | + private static $many_many = array( |
|
12 | + 'Categories' => 'LocationCategory', |
|
13 | + ); |
|
14 | + |
|
15 | + private static $defaults = array( |
|
16 | + 'AutoGeocode' => true, |
|
17 | + ); |
|
18 | + |
|
19 | + private static $singular_name = 'Locator'; |
|
20 | + private static $plural_name = 'Locators'; |
|
21 | + private static $description = 'Find locations on a map'; |
|
22 | + |
|
23 | + /** |
|
24 | + * @return FieldList |
|
25 | + */ |
|
26 | + public function getCMSFields() |
|
27 | + { |
|
28 | + $fields = parent::getCMSFields(); |
|
29 | + |
|
30 | + // Settings |
|
31 | + $fields->addFieldsToTab('Root.Settings', array( |
|
32 | + HeaderField::create('DisplayOptions', 'Display Options', 3), |
|
33 | + OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')), |
|
34 | + CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location') |
|
35 | + ->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'), |
|
36 | + CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'), |
|
37 | + )); |
|
38 | + |
|
39 | + // Filter categories |
|
40 | + $config = GridFieldConfig_RelationEditor::create(); |
|
41 | + if (class_exists('GridFieldAddExistingSearchButton')) { |
|
42 | + $config->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
|
43 | + $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
44 | + } |
|
45 | + $categories = $this->Categories(); |
|
46 | + $categoriesField = GridField::create('Categories', 'Categories', $categories, $config) |
|
47 | + ->setDescription('only show locations from the selected category'); |
|
48 | + |
|
49 | + // Filter |
|
50 | + $fields->addFieldsToTab('Root.Filter', array( |
|
51 | + HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
52 | + $categoriesField, |
|
53 | + )); |
|
54 | + |
|
55 | + $this->extend('updateCMSFields', $fields); |
|
56 | + |
|
57 | + return $fields; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * @param array $filter |
|
62 | + * @param array $filterAny |
|
63 | + * @param array $exclude |
|
64 | + * @param null $filterByCallback |
|
65 | + * @return ArrayList |
|
66 | + */ |
|
67 | + public static function locations( |
|
68 | + $filter = array(), |
|
69 | + $filterAny = array(), |
|
70 | + $exclude = array(), |
|
71 | + $filterByCallback = null |
|
72 | + ) { |
|
73 | + $locationsList = ArrayList::create(); |
|
74 | + |
|
75 | + // filter by ShowInLocator |
|
76 | + $filter['ShowInLocator'] = 1; |
|
77 | + |
|
78 | + $locations = Location::get()->filter($filter); |
|
79 | + |
|
80 | + if (!empty($filterAny)) { |
|
81 | + $locations = $locations->filterAny($filterAny); |
|
82 | + } |
|
83 | + if (!empty($exclude)) { |
|
84 | + $locations = $locations->exclude($exclude); |
|
85 | + } |
|
86 | + |
|
87 | + if ($filterByCallback !== null && is_callable($filterByCallback)) { |
|
88 | + $locations = $locations->filterByCallback($filterByCallback); |
|
89 | + } |
|
90 | + |
|
91 | + if ($locations->exists()) { |
|
92 | + $locationsList->merge($locations); |
|
93 | + } |
|
94 | + |
|
95 | + return $locationsList; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * @return DataList |
|
100 | + */ |
|
101 | + public static function getAllCategories() |
|
102 | + { |
|
103 | + return LocationCategory::get(); |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * @param null $id |
|
108 | + * @return bool |
|
109 | + */ |
|
110 | + public static function getPageCategories($id = null) |
|
111 | + { |
|
112 | + if ($id) { |
|
113 | + if ($locator = self::get()->byID($id)) { |
|
114 | + return $locator->Categories(); |
|
115 | + } |
|
116 | + |
|
117 | + return false; |
|
118 | + } |
|
119 | + |
|
120 | + return false; |
|
121 | + } |
|
122 | 122 | |
123 | 123 | |
124 | 124 | } |
125 | 125 | |
126 | 126 | class Locator_Controller extends Page_Controller |
127 | 127 | { |
128 | - // allowed actions |
|
129 | - private static $allowed_actions = array( |
|
130 | - 'xml', |
|
131 | - ); |
|
132 | - |
|
133 | - // Set Requirements based on input from CMS |
|
134 | - public function init() |
|
135 | - { |
|
136 | - parent::init(); |
|
137 | - |
|
138 | - $themeDir = SSViewer::get_theme_folder(); |
|
139 | - |
|
140 | - // google maps api key |
|
141 | - $key = Config::inst()->get('GoogleGeocoding', 'google_api_key'); |
|
142 | - |
|
143 | - $locations = $this->Items($this->request); |
|
144 | - |
|
145 | - Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
|
146 | - if ($locations) { |
|
147 | - Requirements::javascript('http://maps.google.com/maps/api/js?key='.$key); |
|
148 | - Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); |
|
149 | - Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); |
|
150 | - } |
|
151 | - |
|
152 | - Requirements::css('locator/css/map.css'); |
|
153 | - |
|
154 | - $featured = ($locations->filter(array('Featured' => 1))->count() > 0) ? |
|
155 | - 'featuredLocations: true' : |
|
156 | - 'featuredLocations: false'; |
|
157 | - |
|
158 | - // map config based on user input in Settings tab |
|
159 | - // AutoGeocode or Full Map |
|
160 | - $load = ($this->data()->AutoGeocode) ? |
|
161 | - 'autoGeocode: true, fullMapStart: false,' : |
|
162 | - 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
163 | - |
|
164 | - $base = Director::baseFolder(); |
|
165 | - $themePath = $base.'/'.$themeDir; |
|
166 | - |
|
167 | - $listTemplatePath = (file_exists($themePath.'/templates/location-list-description.html')) ? |
|
168 | - $themeDir.'/templates/location-list-description.html' : |
|
169 | - 'locator/templates/location-list-description.html'; |
|
170 | - $infowindowTemplatePath = (file_exists($themePath.'/templates/infowindow-description.html')) ? |
|
171 | - $themeDir.'/templates/infowindow-description.html' : |
|
172 | - 'locator/templates/infowindow-description.html'; |
|
173 | - |
|
174 | - // in page or modal |
|
175 | - $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
|
176 | - |
|
177 | - $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; |
|
178 | - |
|
179 | - // pass GET variables to xml action |
|
180 | - $vars = $this->request->getVars(); |
|
181 | - unset($vars['url']); |
|
182 | - $url = ''; |
|
183 | - if (count($vars)) { |
|
184 | - $url .= '?'.http_build_query($vars); |
|
185 | - } |
|
186 | - $link = $this->Link().'xml.xml'.$url; |
|
187 | - |
|
188 | - // init map |
|
189 | - if ($locations) { |
|
190 | - Requirements::customScript(" |
|
128 | + // allowed actions |
|
129 | + private static $allowed_actions = array( |
|
130 | + 'xml', |
|
131 | + ); |
|
132 | + |
|
133 | + // Set Requirements based on input from CMS |
|
134 | + public function init() |
|
135 | + { |
|
136 | + parent::init(); |
|
137 | + |
|
138 | + $themeDir = SSViewer::get_theme_folder(); |
|
139 | + |
|
140 | + // google maps api key |
|
141 | + $key = Config::inst()->get('GoogleGeocoding', 'google_api_key'); |
|
142 | + |
|
143 | + $locations = $this->Items($this->request); |
|
144 | + |
|
145 | + Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
|
146 | + if ($locations) { |
|
147 | + Requirements::javascript('http://maps.google.com/maps/api/js?key='.$key); |
|
148 | + Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); |
|
149 | + Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); |
|
150 | + } |
|
151 | + |
|
152 | + Requirements::css('locator/css/map.css'); |
|
153 | + |
|
154 | + $featured = ($locations->filter(array('Featured' => 1))->count() > 0) ? |
|
155 | + 'featuredLocations: true' : |
|
156 | + 'featuredLocations: false'; |
|
157 | + |
|
158 | + // map config based on user input in Settings tab |
|
159 | + // AutoGeocode or Full Map |
|
160 | + $load = ($this->data()->AutoGeocode) ? |
|
161 | + 'autoGeocode: true, fullMapStart: false,' : |
|
162 | + 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
163 | + |
|
164 | + $base = Director::baseFolder(); |
|
165 | + $themePath = $base.'/'.$themeDir; |
|
166 | + |
|
167 | + $listTemplatePath = (file_exists($themePath.'/templates/location-list-description.html')) ? |
|
168 | + $themeDir.'/templates/location-list-description.html' : |
|
169 | + 'locator/templates/location-list-description.html'; |
|
170 | + $infowindowTemplatePath = (file_exists($themePath.'/templates/infowindow-description.html')) ? |
|
171 | + $themeDir.'/templates/infowindow-description.html' : |
|
172 | + 'locator/templates/infowindow-description.html'; |
|
173 | + |
|
174 | + // in page or modal |
|
175 | + $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
|
176 | + |
|
177 | + $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; |
|
178 | + |
|
179 | + // pass GET variables to xml action |
|
180 | + $vars = $this->request->getVars(); |
|
181 | + unset($vars['url']); |
|
182 | + $url = ''; |
|
183 | + if (count($vars)) { |
|
184 | + $url .= '?'.http_build_query($vars); |
|
185 | + } |
|
186 | + $link = $this->Link().'xml.xml'.$url; |
|
187 | + |
|
188 | + // init map |
|
189 | + if ($locations) { |
|
190 | + Requirements::customScript(" |
|
191 | 191 | $(function($) { |
192 | 192 | $('#map-container').storeLocator({ |
193 | 193 | ".$load." |
@@ -208,129 +208,129 @@ discard block |
||
208 | 208 | }); |
209 | 209 | }); |
210 | 210 | '); |
211 | - } |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * @param SS_HTTPRequest $request |
|
216 | - * |
|
217 | - * @return ViewableData_Customised |
|
218 | - */ |
|
219 | - public function index(SS_HTTPRequest $request) |
|
220 | - { |
|
221 | - $locations = $this->Items($request); |
|
222 | - |
|
223 | - return $this->customise(array( |
|
224 | - 'Locations' => $locations, |
|
225 | - )); |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Return a XML feed of all locations marked "show in locator" |
|
230 | - * |
|
231 | - * @param SS_HTTPRequest $request |
|
232 | - * @return HTMLText |
|
233 | - */ |
|
234 | - public function xml(SS_HTTPRequest $request) |
|
235 | - { |
|
236 | - $locations = $this->Items($request); |
|
237 | - |
|
238 | - return $this->customise(array( |
|
239 | - 'Locations' => $locations, |
|
240 | - ))->renderWith('LocationXML'); |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * @param array $searchCriteria |
|
245 | - * |
|
246 | - * @return mixed |
|
247 | - */ |
|
248 | - public function Items($searchCriteria = array()) |
|
249 | - { |
|
250 | - $request = ($this->request) ? $this->request : $this->parentController->getRequest(); |
|
251 | - if (empty($searchCriteria)) { |
|
252 | - $searchCriteria = $request->requestVars(); |
|
253 | - } |
|
254 | - |
|
255 | - $filter = array(); |
|
256 | - $filterAny = array(); |
|
257 | - $exclude = array(); |
|
258 | - |
|
259 | - // only show locations marked as ShowInLocator |
|
260 | - $filter['ShowInLocator'] = 1; |
|
261 | - |
|
262 | - // search across all address related fields |
|
263 | - $address = ($request->getVar('Address')) ? $request->getVar('Address') : false; |
|
264 | - if ($address) { |
|
265 | - $filterAny['Address:PartialMatch'] = $address; |
|
266 | - $filterAny['Suburb:PartialMatch'] = $address; |
|
267 | - $filterAny['State:PartialMatch'] = $address; |
|
268 | - $filterAny['Postcode:PartialMatch'] = $address; |
|
269 | - $filterAny['Country:PartialMatch'] = $address; |
|
270 | - } |
|
271 | - |
|
272 | - $category = ($request->getVar('CategoryID')) ? $request->getVar('CategoryID') : false; |
|
273 | - if ($category) { |
|
274 | - $filter['CategoryID'] = $category; |
|
275 | - } |
|
276 | - |
|
277 | - $locations = Locator::locations($filter, $filterAny, $exclude); |
|
278 | - |
|
279 | - return $locations; |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * LocationSearch form. |
|
284 | - * |
|
285 | - * Search form for locations, updates map and results list via AJAX |
|
286 | - * |
|
287 | - * @return Form |
|
288 | - */ |
|
289 | - public function LocationSearch() |
|
290 | - { |
|
291 | - $fields = FieldList::create( |
|
292 | - $address = TextField::create('Address', '') |
|
293 | - ->setAttribute('placeholder', 'address or zip code') |
|
294 | - ); |
|
295 | - |
|
296 | - $filterCategories = Locator::getPageCategories($this->ID); |
|
297 | - $allCategories = Locator::getAllCategories(); |
|
298 | - |
|
299 | - if ($allCategories->Count() > 0) { |
|
300 | - $categories = ArrayList::create(); |
|
301 | - if ($filterCategories->Count() > 0) { |
|
302 | - if ($filterCategories->Count() != 1) { |
|
303 | - $categories = $filterCategories; |
|
304 | - } |
|
305 | - } else { |
|
306 | - $categories = $allCategories; |
|
307 | - } |
|
308 | - |
|
309 | - if ($categories->count() > 0) { |
|
310 | - $fields->push( |
|
311 | - DropdownField::create( |
|
312 | - 'CategoryID', |
|
313 | - '', |
|
314 | - $categories->map() |
|
315 | - )->setEmptyString('All Categories')); |
|
316 | - } |
|
317 | - } |
|
318 | - |
|
319 | - $actions = FieldList::create( |
|
320 | - FormAction::create('index', 'Search') |
|
321 | - ); |
|
322 | - |
|
323 | - if (class_exists('BootstrapForm')) { |
|
324 | - $form = BootstrapForm::create($this, 'LocationSearch', $fields, $actions); |
|
325 | - } else { |
|
326 | - $form = Form::create($this, 'LocationSearch', $fields, $actions); |
|
327 | - } |
|
328 | - |
|
329 | - return $form |
|
330 | - ->setFormMethod('GET') |
|
331 | - ->setFormAction($this->Link()) |
|
332 | - ->disableSecurityToken() |
|
333 | - ->loadDataFrom($this->request->getVars()) |
|
334 | - ; |
|
335 | - } |
|
211 | + } |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * @param SS_HTTPRequest $request |
|
216 | + * |
|
217 | + * @return ViewableData_Customised |
|
218 | + */ |
|
219 | + public function index(SS_HTTPRequest $request) |
|
220 | + { |
|
221 | + $locations = $this->Items($request); |
|
222 | + |
|
223 | + return $this->customise(array( |
|
224 | + 'Locations' => $locations, |
|
225 | + )); |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Return a XML feed of all locations marked "show in locator" |
|
230 | + * |
|
231 | + * @param SS_HTTPRequest $request |
|
232 | + * @return HTMLText |
|
233 | + */ |
|
234 | + public function xml(SS_HTTPRequest $request) |
|
235 | + { |
|
236 | + $locations = $this->Items($request); |
|
237 | + |
|
238 | + return $this->customise(array( |
|
239 | + 'Locations' => $locations, |
|
240 | + ))->renderWith('LocationXML'); |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * @param array $searchCriteria |
|
245 | + * |
|
246 | + * @return mixed |
|
247 | + */ |
|
248 | + public function Items($searchCriteria = array()) |
|
249 | + { |
|
250 | + $request = ($this->request) ? $this->request : $this->parentController->getRequest(); |
|
251 | + if (empty($searchCriteria)) { |
|
252 | + $searchCriteria = $request->requestVars(); |
|
253 | + } |
|
254 | + |
|
255 | + $filter = array(); |
|
256 | + $filterAny = array(); |
|
257 | + $exclude = array(); |
|
258 | + |
|
259 | + // only show locations marked as ShowInLocator |
|
260 | + $filter['ShowInLocator'] = 1; |
|
261 | + |
|
262 | + // search across all address related fields |
|
263 | + $address = ($request->getVar('Address')) ? $request->getVar('Address') : false; |
|
264 | + if ($address) { |
|
265 | + $filterAny['Address:PartialMatch'] = $address; |
|
266 | + $filterAny['Suburb:PartialMatch'] = $address; |
|
267 | + $filterAny['State:PartialMatch'] = $address; |
|
268 | + $filterAny['Postcode:PartialMatch'] = $address; |
|
269 | + $filterAny['Country:PartialMatch'] = $address; |
|
270 | + } |
|
271 | + |
|
272 | + $category = ($request->getVar('CategoryID')) ? $request->getVar('CategoryID') : false; |
|
273 | + if ($category) { |
|
274 | + $filter['CategoryID'] = $category; |
|
275 | + } |
|
276 | + |
|
277 | + $locations = Locator::locations($filter, $filterAny, $exclude); |
|
278 | + |
|
279 | + return $locations; |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * LocationSearch form. |
|
284 | + * |
|
285 | + * Search form for locations, updates map and results list via AJAX |
|
286 | + * |
|
287 | + * @return Form |
|
288 | + */ |
|
289 | + public function LocationSearch() |
|
290 | + { |
|
291 | + $fields = FieldList::create( |
|
292 | + $address = TextField::create('Address', '') |
|
293 | + ->setAttribute('placeholder', 'address or zip code') |
|
294 | + ); |
|
295 | + |
|
296 | + $filterCategories = Locator::getPageCategories($this->ID); |
|
297 | + $allCategories = Locator::getAllCategories(); |
|
298 | + |
|
299 | + if ($allCategories->Count() > 0) { |
|
300 | + $categories = ArrayList::create(); |
|
301 | + if ($filterCategories->Count() > 0) { |
|
302 | + if ($filterCategories->Count() != 1) { |
|
303 | + $categories = $filterCategories; |
|
304 | + } |
|
305 | + } else { |
|
306 | + $categories = $allCategories; |
|
307 | + } |
|
308 | + |
|
309 | + if ($categories->count() > 0) { |
|
310 | + $fields->push( |
|
311 | + DropdownField::create( |
|
312 | + 'CategoryID', |
|
313 | + '', |
|
314 | + $categories->map() |
|
315 | + )->setEmptyString('All Categories')); |
|
316 | + } |
|
317 | + } |
|
318 | + |
|
319 | + $actions = FieldList::create( |
|
320 | + FormAction::create('index', 'Search') |
|
321 | + ); |
|
322 | + |
|
323 | + if (class_exists('BootstrapForm')) { |
|
324 | + $form = BootstrapForm::create($this, 'LocationSearch', $fields, $actions); |
|
325 | + } else { |
|
326 | + $form = Form::create($this, 'LocationSearch', $fields, $actions); |
|
327 | + } |
|
328 | + |
|
329 | + return $form |
|
330 | + ->setFormMethod('GET') |
|
331 | + ->setFormAction($this->Link()) |
|
332 | + ->disableSecurityToken() |
|
333 | + ->loadDataFrom($this->request->getVars()) |
|
334 | + ; |
|
335 | + } |
|
336 | 336 | } |
@@ -2,118 +2,118 @@ |
||
2 | 2 | |
3 | 3 | class LocationTest extends Locator_Test |
4 | 4 | { |
5 | - public function testGetCoords() |
|
6 | - { |
|
7 | - $location = $this->objFromFixture('Location', 'dynamic'); |
|
8 | - $location->write(); |
|
5 | + public function testGetCoords() |
|
6 | + { |
|
7 | + $location = $this->objFromFixture('Location', 'dynamic'); |
|
8 | + $location->write(); |
|
9 | 9 | |
10 | - $coords = ($location->Lat && $location->Lng) ? 'true' : 'false'; |
|
11 | - $geoCodable = Location::get()->byID($location->ID); |
|
10 | + $coords = ($location->Lat && $location->Lng) ? 'true' : 'false'; |
|
11 | + $geoCodable = Location::get()->byID($location->ID); |
|
12 | 12 | |
13 | - $this->assertEquals($coords, $geoCodable->getCoords()); |
|
14 | - } |
|
13 | + $this->assertEquals($coords, $geoCodable->getCoords()); |
|
14 | + } |
|
15 | 15 | |
16 | - public function testFieldLabels() |
|
17 | - { |
|
18 | - $location = $this->objFromFixture('Location', 'dynamic'); |
|
19 | - $labels = $location->FieldLabels(); |
|
20 | - $expected = array( |
|
21 | - 'Title' => 'Name', |
|
22 | - 'Featured' => 'Featured', |
|
23 | - 'Website' => 'Website', |
|
24 | - 'Phone' => 'Phone', |
|
25 | - 'Email' => 'Email', |
|
26 | - 'EmailAddress' => 'Email Address', |
|
27 | - 'ShowInLocator' => 'Show', |
|
28 | - 'Address' => 'Address', |
|
29 | - 'Suburb' => 'City', |
|
30 | - 'State' => 'State', |
|
31 | - 'Postcode' => 'Postal Code', |
|
32 | - 'Country' => 'Country', |
|
33 | - 'Lat' => 'Lat', |
|
34 | - 'Lng' => 'Lng', |
|
35 | - 'Category' => 'Category', |
|
36 | - 'ShowInLocator.NiceAsBoolean' => 'Show', |
|
37 | - 'Category.Name' => 'Category', |
|
38 | - 'Category.ID' => 'Category', |
|
39 | - 'Featured.NiceAsBoolean' => 'Featured', |
|
40 | - 'Coords' => 'Coords', |
|
41 | - ); |
|
42 | - $this->assertEquals($expected, $labels); |
|
43 | - } |
|
16 | + public function testFieldLabels() |
|
17 | + { |
|
18 | + $location = $this->objFromFixture('Location', 'dynamic'); |
|
19 | + $labels = $location->FieldLabels(); |
|
20 | + $expected = array( |
|
21 | + 'Title' => 'Name', |
|
22 | + 'Featured' => 'Featured', |
|
23 | + 'Website' => 'Website', |
|
24 | + 'Phone' => 'Phone', |
|
25 | + 'Email' => 'Email', |
|
26 | + 'EmailAddress' => 'Email Address', |
|
27 | + 'ShowInLocator' => 'Show', |
|
28 | + 'Address' => 'Address', |
|
29 | + 'Suburb' => 'City', |
|
30 | + 'State' => 'State', |
|
31 | + 'Postcode' => 'Postal Code', |
|
32 | + 'Country' => 'Country', |
|
33 | + 'Lat' => 'Lat', |
|
34 | + 'Lng' => 'Lng', |
|
35 | + 'Category' => 'Category', |
|
36 | + 'ShowInLocator.NiceAsBoolean' => 'Show', |
|
37 | + 'Category.Name' => 'Category', |
|
38 | + 'Category.ID' => 'Category', |
|
39 | + 'Featured.NiceAsBoolean' => 'Featured', |
|
40 | + 'Coords' => 'Coords', |
|
41 | + ); |
|
42 | + $this->assertEquals($expected, $labels); |
|
43 | + } |
|
44 | 44 | |
45 | - public function testGetCMSFields() |
|
46 | - { |
|
47 | - $object = new Location(); |
|
48 | - $fieldset = $object->getCMSFields(); |
|
49 | - $this->assertTrue(is_a($fieldset, 'FieldList')); |
|
50 | - } |
|
45 | + public function testGetCMSFields() |
|
46 | + { |
|
47 | + $object = new Location(); |
|
48 | + $fieldset = $object->getCMSFields(); |
|
49 | + $this->assertTrue(is_a($fieldset, 'FieldList')); |
|
50 | + } |
|
51 | 51 | |
52 | - public function testValidate() |
|
53 | - { |
|
54 | - } |
|
52 | + public function testValidate() |
|
53 | + { |
|
54 | + } |
|
55 | 55 | |
56 | - public function testEmailAddress() |
|
57 | - { |
|
58 | - } |
|
56 | + public function testEmailAddress() |
|
57 | + { |
|
58 | + } |
|
59 | 59 | |
60 | - public function testCanView() |
|
61 | - { |
|
62 | - $object = $this->objFromFixture('Location', 'dynamic'); |
|
63 | - $object->write(); |
|
64 | - $this->logInWithPermission('ADMIN'); |
|
65 | - $this->assertTrue($object->canView()); |
|
66 | - $this->logOut(); |
|
67 | - $nullMember = Member::create(); |
|
68 | - $nullMember->write(); |
|
69 | - $this->assertTrue($object->canView($nullMember)); |
|
70 | - $nullMember->delete(); |
|
71 | - } |
|
60 | + public function testCanView() |
|
61 | + { |
|
62 | + $object = $this->objFromFixture('Location', 'dynamic'); |
|
63 | + $object->write(); |
|
64 | + $this->logInWithPermission('ADMIN'); |
|
65 | + $this->assertTrue($object->canView()); |
|
66 | + $this->logOut(); |
|
67 | + $nullMember = Member::create(); |
|
68 | + $nullMember->write(); |
|
69 | + $this->assertTrue($object->canView($nullMember)); |
|
70 | + $nullMember->delete(); |
|
71 | + } |
|
72 | 72 | |
73 | - public function testCanEdit() |
|
74 | - { |
|
75 | - $object = $this->objFromFixture('Location', 'dynamic'); |
|
76 | - $object->write(); |
|
77 | - $objectID = $object->ID; |
|
78 | - $this->logInWithPermission('Location_EDIT'); |
|
79 | - $originalTitle = $object->Title; |
|
80 | - $this->assertEquals($originalTitle, 'Dynamic, Inc.'); |
|
81 | - $this->assertTrue($object->canEdit()); |
|
82 | - $object->Title = 'Changed Title'; |
|
83 | - $object->write(); |
|
84 | - $testEdit = Location::get()->byID($objectID); |
|
85 | - $this->assertEquals($testEdit->Title, 'Changed Title'); |
|
86 | - $this->logOut(); |
|
87 | - } |
|
73 | + public function testCanEdit() |
|
74 | + { |
|
75 | + $object = $this->objFromFixture('Location', 'dynamic'); |
|
76 | + $object->write(); |
|
77 | + $objectID = $object->ID; |
|
78 | + $this->logInWithPermission('Location_EDIT'); |
|
79 | + $originalTitle = $object->Title; |
|
80 | + $this->assertEquals($originalTitle, 'Dynamic, Inc.'); |
|
81 | + $this->assertTrue($object->canEdit()); |
|
82 | + $object->Title = 'Changed Title'; |
|
83 | + $object->write(); |
|
84 | + $testEdit = Location::get()->byID($objectID); |
|
85 | + $this->assertEquals($testEdit->Title, 'Changed Title'); |
|
86 | + $this->logOut(); |
|
87 | + } |
|
88 | 88 | |
89 | - public function testCanDelete() |
|
90 | - { |
|
91 | - $object = $this->objFromFixture('Location', 'dynamic'); |
|
92 | - $object->write(); |
|
93 | - $this->logInWithPermission('Location_DELETE'); |
|
94 | - $this->assertTrue($object->canDelete()); |
|
95 | - $checkObject = $object; |
|
96 | - $object->delete(); |
|
97 | - $this->assertEquals($checkObject->ID, 0); |
|
98 | - } |
|
89 | + public function testCanDelete() |
|
90 | + { |
|
91 | + $object = $this->objFromFixture('Location', 'dynamic'); |
|
92 | + $object->write(); |
|
93 | + $this->logInWithPermission('Location_DELETE'); |
|
94 | + $this->assertTrue($object->canDelete()); |
|
95 | + $checkObject = $object; |
|
96 | + $object->delete(); |
|
97 | + $this->assertEquals($checkObject->ID, 0); |
|
98 | + } |
|
99 | 99 | |
100 | - public function testCanCreate() |
|
101 | - { |
|
102 | - $object = singleton('Location'); |
|
103 | - $this->logInWithPermission('Location_CREATE'); |
|
104 | - $this->assertTrue($object->canCreate()); |
|
105 | - $this->logOut(); |
|
106 | - $nullMember = Member::create(); |
|
107 | - $nullMember->write(); |
|
108 | - $this->assertFalse($object->canCreate($nullMember)); |
|
109 | - $nullMember->delete(); |
|
110 | - } |
|
100 | + public function testCanCreate() |
|
101 | + { |
|
102 | + $object = singleton('Location'); |
|
103 | + $this->logInWithPermission('Location_CREATE'); |
|
104 | + $this->assertTrue($object->canCreate()); |
|
105 | + $this->logOut(); |
|
106 | + $nullMember = Member::create(); |
|
107 | + $nullMember->write(); |
|
108 | + $this->assertFalse($object->canCreate($nullMember)); |
|
109 | + $nullMember->delete(); |
|
110 | + } |
|
111 | 111 | |
112 | - public function testProvidePermissions() |
|
113 | - { |
|
114 | - } |
|
112 | + public function testProvidePermissions() |
|
113 | + { |
|
114 | + } |
|
115 | 115 | |
116 | - public function testOnBeforeWrite() |
|
117 | - { |
|
118 | - } |
|
116 | + public function testOnBeforeWrite() |
|
117 | + { |
|
118 | + } |
|
119 | 119 | } |
@@ -2,200 +2,200 @@ |
||
2 | 2 | |
3 | 3 | class Location extends DataObject implements PermissionProvider |
4 | 4 | { |
5 | - private static $db = array( |
|
6 | - 'Title' => 'Varchar(255)', |
|
7 | - 'Featured' => 'Boolean', |
|
8 | - 'Website' => 'Varchar(255)', |
|
9 | - 'Phone' => 'Varchar(40)', |
|
10 | - 'Email' => 'Varchar(255)', |
|
11 | - 'EmailAddress' => 'Varchar(255)', |
|
12 | - 'ShowInLocator' => 'Boolean', |
|
13 | - ); |
|
14 | - |
|
15 | - private static $has_one = array( |
|
16 | - 'Category' => 'LocationCategory', |
|
17 | - ); |
|
18 | - |
|
19 | - private static $casting = array( |
|
20 | - 'distance' => 'Int', |
|
21 | - ); |
|
22 | - |
|
23 | - private static $default_sort = 'Title'; |
|
24 | - |
|
25 | - private static $defaults = array( |
|
26 | - 'ShowInLocator' => true, |
|
27 | - ); |
|
28 | - |
|
29 | - private static $singular_name = 'Location'; |
|
30 | - private static $plural_name = 'Locations'; |
|
31 | - |
|
32 | - // api access via Restful Server module |
|
33 | - private static $api_access = true; |
|
34 | - |
|
35 | - // search fields for Model Admin |
|
36 | - private static $searchable_fields = array( |
|
37 | - 'Title', |
|
38 | - 'Address', |
|
39 | - 'Suburb', |
|
40 | - 'State', |
|
41 | - 'Postcode', |
|
42 | - 'Country', |
|
43 | - 'Website', |
|
44 | - 'Phone', |
|
45 | - 'Email', |
|
46 | - 'Category.ID', |
|
47 | - 'ShowInLocator', |
|
48 | - 'Featured', |
|
49 | - ); |
|
50 | - |
|
51 | - // columns for grid field |
|
52 | - private static $summary_fields = array( |
|
53 | - 'Title', |
|
54 | - 'Address', |
|
55 | - 'Suburb', |
|
56 | - 'State', |
|
57 | - 'Postcode', |
|
58 | - 'Country', |
|
59 | - 'Category.Name', |
|
60 | - 'ShowInLocator.NiceAsBoolean', |
|
61 | - 'Featured.NiceAsBoolean', |
|
62 | - 'Coords', |
|
63 | - ); |
|
64 | - |
|
65 | - // Coords status for $summary_fields |
|
66 | - public function getCoords() |
|
67 | - { |
|
68 | - return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false'; |
|
69 | - } |
|
70 | - |
|
71 | - // custom labels for fields |
|
72 | - public function fieldLabels($includerelations = true) |
|
73 | - { |
|
74 | - $labels = parent::fieldLabels(); |
|
75 | - |
|
76 | - $labels['Title'] = 'Name'; |
|
77 | - $labels['Suburb'] = 'City'; |
|
78 | - $labels['Postcode'] = 'Postal Code'; |
|
79 | - $labels['ShowInLocator'] = 'Show'; |
|
80 | - $labels['ShowInLocator.NiceAsBoolean'] = 'Show'; |
|
81 | - $labels['Category.Name'] = 'Category'; |
|
82 | - $labels['Category.ID'] = 'Category'; |
|
83 | - $labels['Email'] = 'Email'; |
|
84 | - $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
85 | - $labels['Coords'] = 'Coords'; |
|
86 | - |
|
87 | - return $labels; |
|
88 | - } |
|
89 | - |
|
90 | - public function getCMSFields() |
|
91 | - { |
|
92 | - $fields = FieldList::create( |
|
93 | - new TabSet( |
|
94 | - $name = 'Root', |
|
95 | - new Tab( |
|
96 | - $title = 'Main', |
|
97 | - HeaderField::create('ContactHD', 'Contact Information'), |
|
98 | - TextField::create('Title', 'Name'), |
|
99 | - TextField::create('Phone'), |
|
100 | - EmailField::create('Email', 'Email'), |
|
101 | - TextField::create('Website') |
|
102 | - ->setAttribute('placeholder', 'http://'), |
|
103 | - DropDownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title')) |
|
104 | - ->setEmptyString('-- select --'), |
|
105 | - CheckboxField::create('ShowInLocator', 'Show in results') |
|
106 | - ->setDescription('Location will be included in results list'), |
|
107 | - CheckboxField::create('Featured') |
|
108 | - ->setDescription('Location will show at/near the top of the results list') |
|
109 | - ) |
|
110 | - ) |
|
111 | - ); |
|
112 | - |
|
113 | - // allow to be extended via DataExtension |
|
114 | - $this->extend('updateCMSFields', $fields); |
|
115 | - |
|
116 | - // override Suburb field name |
|
117 | - $fields->dataFieldByName('Suburb')->setTitle('City'); |
|
118 | - |
|
119 | - return $fields; |
|
120 | - } |
|
121 | - |
|
122 | - public function validate() |
|
123 | - { |
|
124 | - $result = parent::validate(); |
|
125 | - |
|
126 | - return $result; |
|
127 | - } |
|
128 | - |
|
129 | - public function EmailAddress() |
|
130 | - { |
|
131 | - Deprecation::notice('3.0', 'Use "$Email" instead.'); |
|
132 | - if ($this->Email) { |
|
133 | - return $this->Email; |
|
134 | - } elseif ($this->EmailAddress) { |
|
135 | - return $this->EmailAddress; |
|
136 | - } |
|
137 | - |
|
138 | - return false; |
|
139 | - } |
|
140 | - |
|
141 | - public function getCustomSearchContext() |
|
142 | - { |
|
143 | - $fields = $this->scaffoldSearchFields(array( |
|
144 | - 'restrictFields' => array('Address', 'Category.ID'), |
|
145 | - )); |
|
146 | - |
|
147 | - $filters = array( |
|
148 | - 'Address' => new PartialMatchFilter('Address'), |
|
149 | - 'Suburb' => new PartialMatchFilter('Suburb'), |
|
150 | - 'State' => new PartialMatchFilter('State'), |
|
151 | - 'Postcode' => new PartialMatchFilter('Postcode'), |
|
152 | - 'Country' => new PartialMatchFilter('Postcode'), |
|
153 | - 'CategoryID' => new ExactMatchFilter('CategoryID'), |
|
154 | - ); |
|
155 | - |
|
156 | - return new SearchContext( |
|
157 | - $this->class, |
|
158 | - $fields, |
|
159 | - $filters |
|
160 | - ); |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * @param Member $member |
|
165 | - * |
|
166 | - * @return bool |
|
167 | - */ |
|
168 | - public function canView($member = false) |
|
169 | - { |
|
170 | - return true; |
|
171 | - } |
|
172 | - |
|
173 | - public function canEdit($member = false) |
|
174 | - { |
|
175 | - return Permission::check('Location_EDIT'); |
|
176 | - } |
|
177 | - |
|
178 | - public function canDelete($member = false) |
|
179 | - { |
|
180 | - return Permission::check('Location_DELETE'); |
|
181 | - } |
|
182 | - |
|
183 | - public function canCreate($member = false) |
|
184 | - { |
|
185 | - return Permission::check('Location_CREATE'); |
|
186 | - } |
|
187 | - |
|
188 | - public function providePermissions() |
|
189 | - { |
|
190 | - return array( |
|
191 | - 'Location_EDIT' => 'Edit a Location', |
|
192 | - 'Location_DELETE' => 'Delete a Location', |
|
193 | - 'Location_CREATE' => 'Create a Location', |
|
194 | - ); |
|
195 | - } |
|
196 | - |
|
197 | - public function onBeforeWrite() |
|
198 | - { |
|
199 | - parent::onBeforeWrite(); |
|
200 | - } |
|
5 | + private static $db = array( |
|
6 | + 'Title' => 'Varchar(255)', |
|
7 | + 'Featured' => 'Boolean', |
|
8 | + 'Website' => 'Varchar(255)', |
|
9 | + 'Phone' => 'Varchar(40)', |
|
10 | + 'Email' => 'Varchar(255)', |
|
11 | + 'EmailAddress' => 'Varchar(255)', |
|
12 | + 'ShowInLocator' => 'Boolean', |
|
13 | + ); |
|
14 | + |
|
15 | + private static $has_one = array( |
|
16 | + 'Category' => 'LocationCategory', |
|
17 | + ); |
|
18 | + |
|
19 | + private static $casting = array( |
|
20 | + 'distance' => 'Int', |
|
21 | + ); |
|
22 | + |
|
23 | + private static $default_sort = 'Title'; |
|
24 | + |
|
25 | + private static $defaults = array( |
|
26 | + 'ShowInLocator' => true, |
|
27 | + ); |
|
28 | + |
|
29 | + private static $singular_name = 'Location'; |
|
30 | + private static $plural_name = 'Locations'; |
|
31 | + |
|
32 | + // api access via Restful Server module |
|
33 | + private static $api_access = true; |
|
34 | + |
|
35 | + // search fields for Model Admin |
|
36 | + private static $searchable_fields = array( |
|
37 | + 'Title', |
|
38 | + 'Address', |
|
39 | + 'Suburb', |
|
40 | + 'State', |
|
41 | + 'Postcode', |
|
42 | + 'Country', |
|
43 | + 'Website', |
|
44 | + 'Phone', |
|
45 | + 'Email', |
|
46 | + 'Category.ID', |
|
47 | + 'ShowInLocator', |
|
48 | + 'Featured', |
|
49 | + ); |
|
50 | + |
|
51 | + // columns for grid field |
|
52 | + private static $summary_fields = array( |
|
53 | + 'Title', |
|
54 | + 'Address', |
|
55 | + 'Suburb', |
|
56 | + 'State', |
|
57 | + 'Postcode', |
|
58 | + 'Country', |
|
59 | + 'Category.Name', |
|
60 | + 'ShowInLocator.NiceAsBoolean', |
|
61 | + 'Featured.NiceAsBoolean', |
|
62 | + 'Coords', |
|
63 | + ); |
|
64 | + |
|
65 | + // Coords status for $summary_fields |
|
66 | + public function getCoords() |
|
67 | + { |
|
68 | + return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false'; |
|
69 | + } |
|
70 | + |
|
71 | + // custom labels for fields |
|
72 | + public function fieldLabels($includerelations = true) |
|
73 | + { |
|
74 | + $labels = parent::fieldLabels(); |
|
75 | + |
|
76 | + $labels['Title'] = 'Name'; |
|
77 | + $labels['Suburb'] = 'City'; |
|
78 | + $labels['Postcode'] = 'Postal Code'; |
|
79 | + $labels['ShowInLocator'] = 'Show'; |
|
80 | + $labels['ShowInLocator.NiceAsBoolean'] = 'Show'; |
|
81 | + $labels['Category.Name'] = 'Category'; |
|
82 | + $labels['Category.ID'] = 'Category'; |
|
83 | + $labels['Email'] = 'Email'; |
|
84 | + $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
85 | + $labels['Coords'] = 'Coords'; |
|
86 | + |
|
87 | + return $labels; |
|
88 | + } |
|
89 | + |
|
90 | + public function getCMSFields() |
|
91 | + { |
|
92 | + $fields = FieldList::create( |
|
93 | + new TabSet( |
|
94 | + $name = 'Root', |
|
95 | + new Tab( |
|
96 | + $title = 'Main', |
|
97 | + HeaderField::create('ContactHD', 'Contact Information'), |
|
98 | + TextField::create('Title', 'Name'), |
|
99 | + TextField::create('Phone'), |
|
100 | + EmailField::create('Email', 'Email'), |
|
101 | + TextField::create('Website') |
|
102 | + ->setAttribute('placeholder', 'http://'), |
|
103 | + DropDownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title')) |
|
104 | + ->setEmptyString('-- select --'), |
|
105 | + CheckboxField::create('ShowInLocator', 'Show in results') |
|
106 | + ->setDescription('Location will be included in results list'), |
|
107 | + CheckboxField::create('Featured') |
|
108 | + ->setDescription('Location will show at/near the top of the results list') |
|
109 | + ) |
|
110 | + ) |
|
111 | + ); |
|
112 | + |
|
113 | + // allow to be extended via DataExtension |
|
114 | + $this->extend('updateCMSFields', $fields); |
|
115 | + |
|
116 | + // override Suburb field name |
|
117 | + $fields->dataFieldByName('Suburb')->setTitle('City'); |
|
118 | + |
|
119 | + return $fields; |
|
120 | + } |
|
121 | + |
|
122 | + public function validate() |
|
123 | + { |
|
124 | + $result = parent::validate(); |
|
125 | + |
|
126 | + return $result; |
|
127 | + } |
|
128 | + |
|
129 | + public function EmailAddress() |
|
130 | + { |
|
131 | + Deprecation::notice('3.0', 'Use "$Email" instead.'); |
|
132 | + if ($this->Email) { |
|
133 | + return $this->Email; |
|
134 | + } elseif ($this->EmailAddress) { |
|
135 | + return $this->EmailAddress; |
|
136 | + } |
|
137 | + |
|
138 | + return false; |
|
139 | + } |
|
140 | + |
|
141 | + public function getCustomSearchContext() |
|
142 | + { |
|
143 | + $fields = $this->scaffoldSearchFields(array( |
|
144 | + 'restrictFields' => array('Address', 'Category.ID'), |
|
145 | + )); |
|
146 | + |
|
147 | + $filters = array( |
|
148 | + 'Address' => new PartialMatchFilter('Address'), |
|
149 | + 'Suburb' => new PartialMatchFilter('Suburb'), |
|
150 | + 'State' => new PartialMatchFilter('State'), |
|
151 | + 'Postcode' => new PartialMatchFilter('Postcode'), |
|
152 | + 'Country' => new PartialMatchFilter('Postcode'), |
|
153 | + 'CategoryID' => new ExactMatchFilter('CategoryID'), |
|
154 | + ); |
|
155 | + |
|
156 | + return new SearchContext( |
|
157 | + $this->class, |
|
158 | + $fields, |
|
159 | + $filters |
|
160 | + ); |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * @param Member $member |
|
165 | + * |
|
166 | + * @return bool |
|
167 | + */ |
|
168 | + public function canView($member = false) |
|
169 | + { |
|
170 | + return true; |
|
171 | + } |
|
172 | + |
|
173 | + public function canEdit($member = false) |
|
174 | + { |
|
175 | + return Permission::check('Location_EDIT'); |
|
176 | + } |
|
177 | + |
|
178 | + public function canDelete($member = false) |
|
179 | + { |
|
180 | + return Permission::check('Location_DELETE'); |
|
181 | + } |
|
182 | + |
|
183 | + public function canCreate($member = false) |
|
184 | + { |
|
185 | + return Permission::check('Location_CREATE'); |
|
186 | + } |
|
187 | + |
|
188 | + public function providePermissions() |
|
189 | + { |
|
190 | + return array( |
|
191 | + 'Location_EDIT' => 'Edit a Location', |
|
192 | + 'Location_DELETE' => 'Delete a Location', |
|
193 | + 'Location_CREATE' => 'Create a Location', |
|
194 | + ); |
|
195 | + } |
|
196 | + |
|
197 | + public function onBeforeWrite() |
|
198 | + { |
|
199 | + parent::onBeforeWrite(); |
|
200 | + } |
|
201 | 201 | } |
@@ -2,72 +2,72 @@ |
||
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 testLocations() |
|
13 | - { |
|
14 | - $locations = Locator::locations(); |
|
15 | - $locations2 = Location::get()->filter('ShowInLocator', 1); |
|
16 | - $this->assertEquals($locations->Count(), $locations2->Count()); |
|
17 | - } |
|
12 | + public function testLocations() |
|
13 | + { |
|
14 | + $locations = Locator::locations(); |
|
15 | + $locations2 = Location::get()->filter('ShowInLocator', 1); |
|
16 | + $this->assertEquals($locations->Count(), $locations2->Count()); |
|
17 | + } |
|
18 | 18 | |
19 | - public function testGetAllCategories() |
|
20 | - { |
|
21 | - $locator = singleton('Locator'); |
|
22 | - $count = LocationCategory::get(); |
|
23 | - $this->assertEquals($locator->getAllCategories(), $count); |
|
24 | - } |
|
19 | + public function testGetAllCategories() |
|
20 | + { |
|
21 | + $locator = singleton('Locator'); |
|
22 | + $count = LocationCategory::get(); |
|
23 | + $this->assertEquals($locator->getAllCategories(), $count); |
|
24 | + } |
|
25 | 25 | |
26 | - public function testGetPageCategories() |
|
27 | - { |
|
28 | - $locator = Locator::create(); |
|
29 | - $this->assertFalse($locator->getPageCategories()); |
|
26 | + public function testGetPageCategories() |
|
27 | + { |
|
28 | + $locator = Locator::create(); |
|
29 | + $this->assertFalse($locator->getPageCategories()); |
|
30 | 30 | |
31 | - $this->assertFalse($locator->getPageCategories(500)); |
|
31 | + $this->assertFalse($locator->getPageCategories(500)); |
|
32 | 32 | |
33 | - $locator->write(); |
|
34 | - $category = $this->objFromFixture('LocationCategory', 'service'); |
|
35 | - $locator->Categories()->add($category); |
|
36 | - $this->assertEquals($locator->getPageCategories($locator->ID), $locator->Categories()); |
|
37 | - } |
|
33 | + $locator->write(); |
|
34 | + $category = $this->objFromFixture('LocationCategory', 'service'); |
|
35 | + $locator->Categories()->add($category); |
|
36 | + $this->assertEquals($locator->getPageCategories($locator->ID), $locator->Categories()); |
|
37 | + } |
|
38 | 38 | |
39 | - public function testInit() |
|
40 | - { |
|
41 | - } |
|
39 | + public function testInit() |
|
40 | + { |
|
41 | + } |
|
42 | 42 | |
43 | - public function testIndex() |
|
44 | - { |
|
43 | + public function testIndex() |
|
44 | + { |
|
45 | 45 | |
46 | - } |
|
46 | + } |
|
47 | 47 | |
48 | - public function testXml() |
|
49 | - { |
|
50 | - } |
|
48 | + public function testXml() |
|
49 | + { |
|
50 | + } |
|
51 | 51 | |
52 | - public function testItems() |
|
53 | - { |
|
52 | + public function testItems() |
|
53 | + { |
|
54 | 54 | |
55 | - } |
|
55 | + } |
|
56 | 56 | |
57 | - public function testLocationSearch() |
|
58 | - { |
|
59 | - $locator = $this->objFromFixture('Locator', 'locator1'); |
|
60 | - $object = Locator_Controller::create($locator); |
|
61 | - $form = $object->LocationSearch(); |
|
62 | - $this->assertTrue(is_a($form, 'Form')); |
|
57 | + public function testLocationSearch() |
|
58 | + { |
|
59 | + $locator = $this->objFromFixture('Locator', 'locator1'); |
|
60 | + $object = Locator_Controller::create($locator); |
|
61 | + $form = $object->LocationSearch(); |
|
62 | + $this->assertTrue(is_a($form, 'Form')); |
|
63 | 63 | |
64 | - $category = $this->objFromFixture('LocationCategory', 'service'); |
|
65 | - $category2 = $this->objFromFixture('LocationCategory', 'manufacturing'); |
|
66 | - $locator->Categories()->add($category); |
|
67 | - $locator->Categories()->add($category2); |
|
64 | + $category = $this->objFromFixture('LocationCategory', 'service'); |
|
65 | + $category2 = $this->objFromFixture('LocationCategory', 'manufacturing'); |
|
66 | + $locator->Categories()->add($category); |
|
67 | + $locator->Categories()->add($category2); |
|
68 | 68 | |
69 | - $form = $object->LocationSearch(); |
|
70 | - $fields = $form->Fields(); |
|
71 | - $this->assertNotNull($fields->fieldByName('CategoryID')); |
|
72 | - } |
|
69 | + $form = $object->LocationSearch(); |
|
70 | + $fields = $form->Fields(); |
|
71 | + $this->assertNotNull($fields->fieldByName('CategoryID')); |
|
72 | + } |
|
73 | 73 | } |