/** * Generate the module */ protected function compile() { $offset = intval($this->skipFirst); $limit = null; $this->Template->libraries = array(); // Maximum number of items if ($this->numberOfItems > 0) { $limit = $this->numberOfItems; } $session = $this->Session->get('bmfilter') ?: array(); if (strlen($session['geo_lat']) > 0 && strlen($session['geo_lon']) > 0) { $geodata = array('lat' => $session['geo_lat'], 'lon' => $session['geo_lon']); } else { $geodata = $this->getGeoDataFromCurrentPosition(); } // Get the total number of items $intTotal = \BmStoresModel::countStoreEntries($geodata, $session['distance']); // Filter anwenden um die Gesamtanzahl zuermitteln if ($intTotal > 0) { $filterStoresObj = \BmStoresModel::findStores($intTotal, 0, $geodata, $session['distance']); $counter = 0; $idArr = array(); while ($filterStoresObj->next()) { // aktuell offen if ($session['only_open'] && $this->getCurrentOpenStatus($filterStoresObj) != 'open') { continue; } // gehoert einer bestimmten Kategorie an if (strlen($session['category']) > 0 && !$this->hasCategory($filterStoresObj)) { continue; } //wenn alle Filter stimmen -> Werte setzen $idArr[] = $filterStoresObj->id; $counter++; } if ((int) $intTotal > $counter) { $intTotal = $counter; } } if ((int) $intTotal < 1) { $this->Template = new \FrontendTemplate('mod_bm_entries_empty'); $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyBmList']; return; } $total = $intTotal - $offset; // Split the results if ($this->perPage > 0 && (!isset($limit) || $this->numberOfItems > $this->perPage)) { // Adjust the overall limit if (isset($limit)) { $total = min($limit, $total); } // Get the current page $id = 'page_n' . $this->id; $page = \Input::get($id) ?: 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) { global $objPage; $objPage->noSearch = 1; $objPage->cache = 0; $objTarget = \PageModel::findByPk($objPage->id); if ($objTarget !== null) { $reloadUrl = ampersand($this->generateFrontendUrl($objTarget->row())); } $this->redirect($reloadUrl); } // Set limit and offset $limit = $this->perPage; $offset += (max($page, 1) - 1) * $this->perPage; $skip = intval($this->skipFirst); // Overall limit if ($offset + $limit > $total + $skip) { $limit = $total + $skip - $offset; } // Add the pagination menu $objPagination = new \Pagination($total, $this->perPage, $GLOBALS['TL_CONFIG']['maxPaginationLinks'], $id); $this->Template->pagination = $objPagination->generate("\n "); } // Get the items if (isset($limit)) { $storesObj = \BmStoresModel::findStores($limit, $offset, $geodata, $session['distance'], $idArr); } else { $storesObj = \BmStoresModel::findStores(0, $offset, $geodata, $session['distance'], $idArr); } // No items found if ($storesObj === null) { $this->Template = new \FrontendTemplate('mod_bm_entries_empty'); $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyBmList']; } else { $this->Template->stores = $this->parseStores($storesObj); } $GLOBALS['TL_JAVASCRIPT'][] = '.' . BM_PATH . '/assets/js/bm_fe.js'; $this->Template->isDistance = count($session) > 0 && strlen($session['plzcity']) > 0 ? true : false; $this->Template->filterActive = \Input::get('s') ? true : false; $this->Template->totalItems = $intTotal; }
/** * Generate the module */ protected function compile() { $this->import('FrontendUser', 'User'); $this->Template->session = false; $session = $this->Session->get('bmfilter') ?: array(); //Formular verarbeiten wenn es gesendet wurde if ($this->Input->post('FORM_SUBMIT') == 'tl_bm_search_form') { if ($this->Input->post('filter_reset') == 1) { $session = array(); } else { $geodata = $this->getGeoDataFromCurrentPosition(urlencode(\Input::post('plzcity'))); $session = array('plzcity' => $geodata['plzcity'], 'distance' => $this->Input->post('distance'), 'only_open' => $this->Input->post('only_open'), 'category' => $this->Input->post('category'), 'geo_lat' => $geodata['lat'], 'geo_lon' => $geodata['lon']); } $this->Session->set('bmfilter', $session); $this->Input->setPost('FORM_SUBMIT', ''); if ($this->jumpTo) { $objDetailPage = \PageModel::findByPk($this->jumpTo); $listUrl = ampersand($this->generateFrontendUrl($objDetailPage->row())); $this->redirect($listUrl); } $this->reload(); } if (strlen($session['geo_lat']) > 0 && strlen($session['geo_lon']) > 0) { $geodata = array('lat' => $session['geo_lat'], 'lon' => $session['geo_lon']); } else { $geodata = $this->getGeoDataFromCurrentPosition(); } // Get the total number of items $intTotal = \BmStoresModel::countStoreEntries($geodata, $session['distance']); // Filter anwenden um die Gesamtanzahl zuermitteln if ($intTotal > 0) { $filterStoresObj = \BmStoresModel::findStores($intTotal, 0, $geodata, $session['distance']); $counter = 0; $idArr = array(); while ($filterStoresObj->next()) { // aktuell offen if ($session['only_open'] && $this->getCurrentOpenStatus($filterStoresObj) != 'open') { continue; } // gehoert einer bestimmten Kategorie an if (strlen($session['category']) > 0 && !$this->hasCategory($filterStoresObj)) { continue; } //wenn alle Filter stimmen -> Werte setzen $idArr[] = $filterStoresObj->id; $counter++; } if ((int) $intTotal > $counter) { $intTotal = $counter; } } $this->Template->total = (int) $intTotal; if (count($session) > 0) { $this->Template->session = true; $this->Template->plzcity = $session['plzcity']; $this->Template->distance = $session['distance']; $this->Template->only_open = $session['only_open']; $this->Template->cid = $session['category']; } else { //default-Werte setzen $this->Template->distance = 15; } $GLOBALS['TL_CSS'][] = '.' . BM_PATH . '/assets/css/jquery-ui-autocomplete.min.css'; $GLOBALS['TL_CSS'][] = '.' . BM_PATH . '/assets/css/bm_autocomplete.css'; $GLOBALS['TL_JAVASCRIPT'][] = '.' . BM_PATH . '/assets/js/jquery-ui-autocomplete.min.js'; $GLOBALS['TL_BODY'][] = '<script> (function($){ $(document).ready(function(){ $("#plzcity").autocomplete({ source: document.URL+"?action=ajax&id=' . $this->id . '", minLength: 2, response: function( event, ui ) { console.log(ui.content); } }); }); })(jQuery); </script>'; //Kategorien-Optionen $categoriesArr = array(); $cObj = $this->Database->prepare('SELECT `id`,`title` FROM `tl_bm_stores_categories` ORDER BY `sorting` ASC')->execute(); if ($cObj->numRows > 0) { while ($cObj->next()) { $categoriesArr[$cObj->id] = $cObj->title; } } $this->Template->categories = $categoriesArr; }