1 | <?php |
||
126 | class Locator_Controller extends Page_Controller |
||
127 | { |
||
128 | /** |
||
129 | * @var array |
||
130 | */ |
||
131 | private static $allowed_actions = array( |
||
1 ignored issue
–
show
|
|||
132 | 'xml', |
||
133 | ); |
||
134 | |||
135 | /** |
||
136 | * Set Requirements based on input from CMS |
||
137 | */ |
||
138 | public function init() |
||
139 | { |
||
140 | parent::init(); |
||
141 | |||
142 | $themeDir = SSViewer::get_theme_folder(); |
||
143 | |||
144 | // google maps api key |
||
145 | $key = Config::inst()->get('GoogleGeocoding', 'google_api_key'); |
||
146 | |||
147 | $locations = $this->Items($this->request); |
||
148 | |||
149 | Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
||
150 | if ($locations) { |
||
151 | Requirements::javascript('http://maps.google.com/maps/api/js?key='.$key); |
||
152 | Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); |
||
153 | Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); |
||
154 | } |
||
155 | |||
156 | Requirements::css('locator/css/map.css'); |
||
157 | |||
158 | $featured = ($locations->filter(array('Featured' => 1))->count() > 0) ? |
||
159 | 'featuredLocations: true' : |
||
160 | 'featuredLocations: false'; |
||
161 | |||
162 | // map config based on user input in Settings tab |
||
163 | // AutoGeocode or Full Map |
||
164 | $load = ($this->data()->AutoGeocode) ? |
||
165 | 'autoGeocode: true, fullMapStart: false,' : |
||
166 | 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
||
167 | |||
168 | 1 | $base = Director::baseFolder(); |
|
169 | $themePath = $base.'/'.$themeDir; |
||
170 | 1 | ||
171 | 1 | $listTemplatePath = (file_exists($themePath.'/templates/location-list-description.html')) ? |
|
172 | 1 | $themeDir.'/templates/location-list-description.html' : |
|
173 | 1 | 'locator/templates/location-list-description.html'; |
|
174 | $infowindowTemplatePath = (file_exists($themePath.'/templates/infowindow-description.html')) ? |
||
175 | 1 | $themeDir.'/templates/infowindow-description.html' : |
|
176 | 1 | 'locator/templates/infowindow-description.html'; |
|
177 | 1 | ||
178 | 1 | // in page or modal |
|
179 | $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
||
180 | 1 | ||
181 | $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; |
||
182 | 1 | ||
183 | // pass GET variables to xml action |
||
184 | 1 | $vars = $this->request->getVars(); |
|
185 | unset($vars['url']); |
||
186 | $url = ''; |
||
187 | if (count($vars)) { |
||
188 | $url .= '?'.http_build_query($vars); |
||
189 | } |
||
190 | $link = $this->Link().'xml.xml'.$url; |
||
191 | |||
192 | 1 | // init map |
|
193 | if ($locations) { |
||
194 | 1 | Requirements::customScript(" |
|
195 | 1 | $(function($) { |
|
196 | 1 | $('#map-container').storeLocator({ |
|
197 | ".$load." |
||
198 | 1 | dataLocation: '".$link."', |
|
199 | listTemplatePath: '".$listTemplatePath."', |
||
200 | infowindowTemplatePath: '".$infowindowTemplatePath."', |
||
201 | 1 | originMarker: true, |
|
202 | ".$modal.', |
||
203 | '.$featured.", |
||
204 | slideMap: false, |
||
205 | zoomLevel: 0, |
||
206 | noForm: true, |
||
207 | formID: 'Form_LocationSearch', |
||
208 | inputID: 'Form_LocationSearch_Address', |
||
209 | categoryID: 'Form_LocationSearch_CategoryID', |
||
210 | distanceAlert: -1, |
||
211 | ".$kilometer.' |
||
212 | }); |
||
213 | }); |
||
214 | '); |
||
215 | } |
||
216 | } |
||
217 | |||
218 | /** |
||
219 | * @param SS_HTTPRequest $request |
||
220 | * |
||
221 | * @return ViewableData_Customised |
||
222 | */ |
||
223 | public function index(SS_HTTPRequest $request) |
||
231 | |||
232 | /** |
||
233 | * Return a XML feed of all locations marked "show in locator" |
||
234 | * |
||
235 | * @param SS_HTTPRequest $request |
||
236 | * @return HTMLText |
||
237 | */ |
||
238 | public function xml(SS_HTTPRequest $request) |
||
246 | |||
247 | /** |
||
248 | * @param array $searchCriteria |
||
249 | * |
||
250 | * @return ArrayList |
||
251 | */ |
||
252 | public function Items(SS_HTTPRequest $request) |
||
253 | { |
||
254 | $request = ($request) ? $request : $this->request; |
||
255 | |||
256 | $filter = array(); |
||
257 | $filterAny = array(); |
||
258 | $exclude = array(); |
||
259 | |||
260 | // only show locations marked as ShowInLocator |
||
261 | $filter['ShowInLocator'] = 1; |
||
262 | |||
263 | // search across all address related fields |
||
264 | $address = ($request->getVar('Address')) ? $request->getVar('Address') : false; |
||
265 | if ($address) { |
||
266 | $filterAny['Address:PartialMatch'] = $address; |
||
267 | $filterAny['Suburb:PartialMatch'] = $address; |
||
268 | $filterAny['State:PartialMatch'] = $address; |
||
269 | $filterAny['Postcode:PartialMatch'] = $address; |
||
270 | $filterAny['Country:PartialMatch'] = $address; |
||
271 | } |
||
272 | |||
273 | $category = ($request->getVar('CategoryID')) ? $request->getVar('CategoryID') : false; |
||
274 | if ($category) { |
||
275 | $filter['CategoryID'] = $category; |
||
276 | } |
||
277 | |||
278 | $locations = Locator::locations($filter, $filterAny, $exclude); |
||
279 | |||
280 | return $locations; |
||
281 | } |
||
282 | |||
283 | /** |
||
284 | * LocationSearch form. |
||
285 | * |
||
286 | * Search form for locations, updates map and results list via AJAX |
||
287 | * |
||
288 | * @return Form |
||
289 | */ |
||
290 | public function LocationSearch() |
||
337 | } |
||
338 |
This check marks private properties in classes that are never used. Those properties can be removed.