/**
  * Generate module
  */
 protected function compile()
 {
     // Get ID
     $strAlias = \Input::get('auto_item') ? \Input::get('auto_item') : \Input::get('store');
     // Find published store from ID
     if (($objStore = AnyStoresModel::findPublishedByIdOrAlias($strAlias)) !== null) {
         // load all details
         $objStore->loadDetails();
         // generate description
         $objDescription = \ContentModel::findPublishedByPidAndTable($objStore->id, $objStore->getTable());
         if ($objDescription !== null) {
             while ($objDescription->next()) {
                 $objStore->description .= \Controller::getContentElement($objDescription->current());
             }
         }
         // Get referer for back button
         $objStore->referer = $this->getReferer();
         // generate google map if template and geodata is set
         if ($this->anystores_mapTpl != '' && is_numeric($objStore->latitude) && is_numeric($objStore->longitude)) {
             $objMapTemplate = new \FrontendTemplate($this->anystores_mapTpl);
             $objMapTemplate->setData($objStore->row());
             $objStore->gMap = $objMapTemplate->parse();
         }
         // Template
         $objDetailTemplate = new \FrontendTemplate($this->anystores_detailTpl);
         $objDetailTemplate->setData($objStore->row());
         $this->Template->store = $objDetailTemplate->parse();
     } else {
         $this->_redirect404();
     }
 }
Esempio n. 2
0
 /**
  * Set the opening times to null if nothing was set
  * @param DataContainer $dc
  */
 public function clearOpeningTimes(DataContainer $dc)
 {
     $arrOpeningTimes = deserialize($dc->activeRecord->opening_times);
     if (empty($arrOpeningTimes[0]['from']) && empty($arrOpeningTimes[0]['isClosed'])) {
         $objStore = AnyStoresModel::findByPk($dc->id);
         $objStore->opening_times = null;
         $objStore->save();
     }
 }
Esempio n. 3
0
 /**
  * Generate module
  */
 protected function compile()
 {
     // hide list when details shown
     //@todo make optinonal in module
     if (strlen(\Input::get('auto_item')) || strlen(\Input::get('store'))) {
         return;
     }
     // localized url parameter
     //@todo use $GLOBALS['TL_URL_PARAMS']...
     $this->strSearchKey = $GLOBALS['TL_LANG']['anystores']['url_params']['search'];
     $this->strSearchValue = \Input::get($this->strSearchKey);
     $this->strCountryKey = $GLOBALS['TL_LANG']['anystores']['url_params']['country'];
     $this->strCountryValue = \Input::get($this->strCountryKey) ?: $this->anystores_defaultCountry;
     // if no empty search is allowed
     if (!$this->anystores_allowEmptySearch && !$this->strSearchValue && $this->strCountryValue) {
         $this->Template->error = $GLOBALS['TL_LANG']['anystores']['noResults'];
         return;
     }
     if (!$this->strSearchValue) {
         // order
         $arrOptions = array();
         if (strlen($this->anystores_sortingOrder)) {
             $arrOptions['order'] = $this->anystores_sortingOrder;
         }
         $objStore = AnyStoresModel::findPublishedByCategoryAndCountry(deserialize($this->anystores_categories), $this->strCountryValue, $arrOptions);
     } else {
         $objStore = AnyStoresModel::findPublishedByAdressAndCountryAndCategory($this->strSearchValue, $this->strCountryValue, deserialize($this->anystores_categories), $this->anystores_listLimit, $this->anystores_limitDistance ? $this->anystores_maxDistance : null);
     }
     if (!$objStore) {
         $this->Template->error = $GLOBALS['TL_LANG']['anystores']['noResults'];
         return;
     }
     while ($objStore->next()) {
         $objTemplate = new \Contao\FrontendTemplate($this->anystores_detailTpl);
         // generate jump to
         if ($this->jumpTo) {
             if (($objLocation = \PageModel::findByPk($this->jumpTo)) !== null) {
                 //@todo language parameter
                 $strStoreKey = !$GLOBALS['TL_CONFIG']['useAutoItem'] ? '/store/' : '/';
                 $strStoreValue = $objStore->alias;
                 $objStore->href = \Controller::generateFrontendUrl($objLocation->row(), $strStoreKey . $strStoreValue);
             }
         }
         $arrStore = $objStore->current()->loadDetails()->row();
         $objTemplate->setData($arrStore);
         $arrStores[] = $objTemplate->parse();
         $arrRawStores[] = $arrStore;
     }
     $this->Template->stores = $arrStores;
     $this->Template->rawstores = $arrRawStores;
     // set licence hint
     $this->Template->licence = $GLOBALS['ANYSTORES_GEODATA_LICENCE_HINT'];
 }
Esempio n. 4
0
 /**
  * Generate module
  */
 protected function compile()
 {
     $GLOBALS['TL_JAVASCRIPT']['googleapis-maps'] = 'https://maps.googleapis.com/maps/api/js?sensor=false&language=' . $GLOBALS['TL_LANGUAGE'];
     $GLOBALS['TL_JAVASCRIPT']['markerclusterer'] = 'system/modules/anyStores/assets/js/markerclusterer.js';
     // get published stores from categories
     $objStores = AnyStoresModel::findPublishedByCategory(deserialize($this->anystores_categories));
     // return if no stores found
     if (!$objStores) {
         return;
     }
     // generate entries
     while ($objStores->next()) {
         // generate jump to
         //@todo copy do AnyStoresModule and extends from it
         if ($this->jumpTo) {
             if (($objLocation = \PageModel::findByPk($this->jumpTo)) !== null) {
                 //@todo language parameter
                 $strStoreKey = !$GLOBALS['TL_CONFIG']['useAutoItem'] ? '/store/' : '/';
                 $strStoreValue = $objStores->alias;
                 $objStores->href = \Controller::generateFrontendUrl($objLocation->row(), $strStoreKey . $strStoreValue);
             }
         }
         // unset logo because json_encode drops error:
         // Malformed UTF-8 characters, possibly incorrectly encoded
         //@todo maybe ->loadDetails() fix it
         $objStores->logo = null;
         // encode email
         $objStores->email = \String::encodeEmail($objStores->email);
     }
     // get all stores
     $arrStores = $objStores->fetchAll();
     $this->Template->entries = $arrStores;
     if (!($strJson = json_encode($arrStores))) {
         $this->log(json_last_error_msg(), __METHOD__, TL_ERROR);
         //@todo stop display the broken module
         return;
     }
     // Temporär
     $this->Template->json = $strJson;
     //@todo cleanup
     $path = 'system/modules/anyStores/html/' . $this->id . '-locations.json';
     $this->Template->path = $path;
     //JSON schreiben
     //@todo: Muss noch in tl_storelocator_map zum save_callback verschoben werden!!!
     #$file   =   new \File($path);
     #$file->write($strJson);
     //@todo language
     #$this->log('Neue JSON-Datei erstellt', __METHOD__, TL_FILES);
 }
Esempio n. 5
0
 public function __construct($arrAttributes = null)
 {
     parent::__construct($arrAttributes);
     if ($this->anystores_categories === null) {
         return;
     }
     $arrCategories = deserialize($this->anystores_categories);
     $arrOptions = array('order' => 'postal');
     $objLocations = AnyStoresModel::findPublishedByCategory($arrCategories, $arrOptions);
     if ($objLocations) {
         while ($objLocations->next()) {
             $arrLocations[] = array('type' => 'option', 'value' => $objLocations->id, 'label' => $objLocations->postal . ' ' . $objLocations->name);
         }
         $this->arrOptions = $arrLocations;
     }
 }
 /**
  * Generate module
  */
 protected function compile()
 {
     // unique form id
     $strFormId = 'anystores_search_' . $this->id;
     // localize url parameter keys
     $strSearchKey = $GLOBALS['TL_LANG']['anystores']['url_params']['search'] ?: 'search';
     $strSearchValue = \Input::post($strSearchKey);
     $strCountryKey = $GLOBALS['TL_LANG']['anystores']['url_params']['country'] ?: 'country';
     $strCountryValue = \Input::post($strCountryKey);
     // redirect if form was send
     if (\Input::post('FORM_SUBMIT') == $strFormId && ($this->anystores_allowEmptySearch || !empty($strSearchValue))) {
         $intPageId = $this->jumpTo ?: $GLOBALS['objPage']->id;
         $objPage = \PageModel::findByPk($intPageId);
         if ($objPage) {
             /**
              * Build url
              * @example /search/_term_/country/_de_
              */
             $strPageUrl = $this->generateFrontendUrl($objPage->row(), "/{$strSearchKey}/" . $this->encodeSearchValue($strSearchValue) . "/{$strCountryKey}/" . $strCountryValue);
             $this->redirect($strPageUrl, 302);
         }
         $this->log("Can't find redirect page in module ID {$this->id}", __METHOD__, TL_ERROR);
     }
     // render countries for the dropdown
     if (($objCountries = AnyStoresModel::findAllPublished()) !== null) {
         $arrCountries = array_unique($objCountries->fetchEach('country'));
         $arrCountryNames = \System::getCountries();
         foreach ($arrCountries as $country) {
             $arrCountryOptions[$country] = $arrCountryNames[$country];
         }
         asort($arrCountryOptions);
         $this->Template->countryOptions = $arrCountryOptions;
     }
     $this->Template->formId = $strFormId;
     $this->Template->formAction = \Environment::get('indexFreeRequest');
     $this->Template->searchName = $strSearchKey;
     $this->Template->searchId = 'ctrl_search_' . $this->id;
     $this->Template->searchValue = \Input::get($strSearchKey);
     $this->Template->countryName = $strCountryKey;
     $this->Template->countryId = 'ctrl_country_' . $this->id;
     $this->Template->countryValue = \Input::get($strCountryKey) ?: $GLOBALS['TL_LANGUAGE'];
 }
Esempio n. 7
0
     echo json_encode(array('status' => 'NO_VALID_MODULE'));
     exit;
 }
 // Hook to manipulate the module
 if (isset($GLOBALS['TL_HOOKS']['anystores_getAjaxModule']) && is_array($GLOBALS['TL_HOOKS']['anystores_getAjaxModule'])) {
     foreach ($GLOBALS['TL_HOOKS']['anystores_getAjaxModule'] as $callback) {
         \System::importStatic($callback[0])->{$callback[1]}($objModule);
     }
 }
 if (\Validator::isBinaryUuid($objModule->anystores_defaultMarker)) {
     if (($objFile = \FilesModel::findByPk($objModule->anystores_defaultMarker)) !== null) {
         $objModule->anystores_defaultMarker = $objFile->path;
     }
 }
 // Find stores
 $objStores = AnyStoresModel::findPublishedByCategory(deserialize($objModule->anystores_categories));
 if (!$objStores) {
     header('Content-Type: application/json');
     echo json_encode(array('status' => 'NO_STORES'));
     exit;
 }
 while ($objStores->next()) {
     // generate jump to
     if ($objModule->jumpTo) {
         if (($objLocation = \PageModel::findByPk($objModule->jumpTo)) !== null) {
             //@todo language parameter
             $strStoreKey = !$GLOBALS['TL_CONFIG']['useAutoItem'] ? '/store/' : '/';
             $strStoreValue = $objStores->alias;
             $objStores->href = \Controller::generateFrontendUrl($objLocation->row(), $strStoreKey . $strStoreValue);
         }
     }
Esempio n. 8
0
 /**
  * FrontendAjax constructor.
  *
  * @param int $intModuleId
  */
 public static function run($intModuleId, $strToken)
 {
     if (!static::validateRequestToken($intModuleId, $strToken)) {
         static::respond(array('status' => 'error', 'message' => 'Invalid request token'));
     }
     $objModule = \ModuleModel::findByPk($intModuleId);
     if (!$objModule || $objModule->type !== 'anystores_map') {
         static::respond(array('status' => 'error', 'message' => 'Invalid module'));
     }
     // Hook to manipulate the module
     if (isset($GLOBALS['TL_HOOKS']['anystores_getAjaxModule']) && is_array($GLOBALS['TL_HOOKS']['anystores_getAjaxModule'])) {
         foreach ($GLOBALS['TL_HOOKS']['anystores_getAjaxModule'] as $callback) {
             \System::importStatic($callback[0])->{$callback[1]}($objModule);
         }
     }
     if (\Validator::isBinaryUuid($objModule->anystores_defaultMarker)) {
         $objFile = \FilesModel::findByPk($objModule->anystores_defaultMarker);
         $objModule->anystores_defaultMarker = $objFile ? $objFile->path : null;
     }
     // Find stores
     $objStores = AnyStoresModel::findPublishedByCategory(deserialize($objModule->anystores_categories));
     if (!$objStores) {
         static::respond(array('status' => 'error', 'message' => 'No stores found'));
     }
     while ($objStores->next()) {
         // generate jump to
         if ($objModule->jumpTo) {
             if (($objLocation = \PageModel::findByPk($objModule->jumpTo)) !== null) {
                 //@todo language parameter
                 $strStoreKey = !$GLOBALS['TL_CONFIG']['useAutoItem'] ? '/store/' : '/';
                 $strStoreValue = $objStores->alias;
                 $objStores->href = \Controller::generateFrontendUrl($objLocation->row(), $strStoreKey . $strStoreValue);
             }
         }
         // Encode email
         $objStores->email = \String::encodeEmail($objStores->email);
         // Encode opening times
         $objStores->opening_times = deserialize($objStores->opening_times);
         // decode logo
         if (\Validator::isBinaryUuid($objStores->logo)) {
             $objFile = \FilesModel::findByPk($objStores->logo);
             $objStores->logo = $objFile ? $objFile->path : null;
         }
         // decode marker
         if (\Validator::isBinaryUuid($objStores->marker)) {
             $objFile = \FilesModel::findByPk($objStores->marker);
             $objStores->marker = $objFile ? $objFile->path : null;
         }
         // add category marker
         $objStores->categoryMarker = null;
         if (($objCategory = AnyStoresCategoryModel::findByPk($objStores->pid)) !== null) {
             if (\Validator::isBinaryUuid($objCategory->defaultMarker)) {
                 $objFile = \FilesModel::findByPk($objCategory->defaultMarker);
                 if ($objFile) {
                     $objStores->categoryMarker = $objFile->path;
                 }
             }
         }
         // render html
         $strTemplate = $objModule->anystores_detailTpl ?: 'anystores_details';
         $objTemplate = new \FrontendTemplate($strTemplate);
         $objTemplate->setData($objStores->current()->row());
         $objStores->tiphtml = static::replaceInsertTags($objTemplate->parse());
     }
     $arrRespond = array('status' => 'success', 'count' => (int) $objStores->count(), 'module' => array('latitude' => (double) $objModule->anystores_latitude, 'longitude' => (double) $objModule->anystores_longitude, 'zoom' => (int) $objModule->anystores_zoom, 'streetview' => (bool) $objModule->anystores_streetview, 'maptype' => (string) $objModule->anystores_maptype, 'defaultMarker' => (string) $objModule->anystores_defaultMarker), 'stores' => $objStores->fetchAll());
     // decode global default marker
     $arrRespond['global']['defaultMarker'] = null;
     if (\Validator::isUuid(\Config::get('anystores_defaultMarker'))) {
         if (($objFile = \FilesModel::findByPk(\Config::get('anystores_defaultMarker'))) !== null) {
             $arrRespond['global']['defaultMarker'] = $objFile->path;
         }
     }
     static::respond($arrRespond);
 }
Esempio n. 9
0
 /**
  * Return the store model if available
  *
  * @since 1.7.2
  * @return object AnyStoresModel | null
  */
 public static function getStoreFromUrl()
 {
     $strAlias = \Input::get('auto_item') ? \Input::get('auto_item') : \Input::get('store');
     return AnyStoresModel::findByAlias($strAlias);
 }
Esempio n. 10
0
 public function getSearchablePages($arrPages, $intRootId, $bln = true, $strLanguage = null)
 {
     // get the root page object
     $objRoot = \PageModel::findByPk($intRootId);
     if (!$objRoot) {
         \System::log('Can\'t get the root page', __METHOD__, TL_ERROR);
         return $arrPages;
     }
     // check for sitemap enabled
     if (!$objRoot->anystores_sitemap) {
         return $arrPages;
     }
     // get the domain
     $strDomain = ($objRoot->useSSL ? 'https://' : 'http://') . ($objRoot->dns ?: \Environment::get('host')) . TL_PATH . '/';
     // get the details page
     $objPage = \PageModel::findByPk($objRoot->anystores_detailPage);
     if (!$objPage) {
         \System::log('Can\'t find the details page for anyStores', __METHOD__, TL_ERROR);
         return $arrPages;
     }
     // get the locations
     $objLocations = AnyStoresModel::findPublishedByCategory(deserialize($objRoot->anystores_categories));
     if (!$objLocations) {
         \System::log('Can\'t get the published locations', __METHOD__, TL_ERROR);
         return $arrPages;
     }
     while ($objLocations->next()) {
         $strAlias = \Controller::generateFrontendUrl($objLocations->row(), null, $strLanguage);
         $arrPages[] = $strDomain . $objPage->alias . '/' . $strAlias;
     }
     return $arrPages;
 }
Esempio n. 11
0
 public static function findPublishedByAdressAndCountryAndCategory($strSearch, $strCountry = null, array $arrCategories, $intLimit = null, $intMaxDistance = null)
 {
     $t = static::$strTable;
     $arrCoordinates = AnyStores::getLonLat($strSearch, $strCountry);
     if (!$arrCoordinates) {
         \System::log("Can't find coordinates for '{$strSearch}'", __METHOD__, TL_ERROR);
         return;
     }
     $arrOptions = array('fields' => array("{$t}.id", "( 6371 * acos( cos( radians(?) ) * cos( radians( {$t}.latitude ) ) * cos( radians( {$t}.longitude ) - radians(?) ) + sin( radians(?) ) * sin( radians( {$t}.latitude ) ) ) ) AS distance"), 'table' => $t, 'column' => array("{$t}.pid IN(" . implode(',', array_map('intval', $arrCategories)) . ")", "({$t}.start='' OR {$t}.start<UNIX_TIMESTAMP()) AND ({$t}.stop='' OR {$t}.stop>UNIX_TIMESTAMP()) AND {$t}.published=1"), 'order' => "distance");
     // Country
     if ($strCountry) {
         $arrOptions['column'][] = "{$t}.country=?";
     }
     // Maximun distance
     if (is_numeric($intMaxDistance)) {
         $arrOptions['having'] = "distance < " . $intMaxDistance;
     }
     // Get query
     $strQuery = \Model\QueryBuilder::find($arrOptions);
     // replace * with additional fields
     $strQuery = preg_replace('/\\*/', implode(',', $arrOptions['fields']), $strQuery, 1);
     $objResult = \Database::getInstance()->prepare($strQuery)->limit($intLimit)->execute($arrCoordinates['latitude'], $arrCoordinates['longitude'], $arrCoordinates['latitude'], $strCountry ?: null);
     if (!$objResult->numRows) {
         \System::log("No results for '{$objResult->query}'", __METHOD__, TL_ERROR);
         return;
     }
     // Create store models from database result
     while ($objResult->next()) {
         $objModel = AnyStoresModel::findByPk($objResult->id);
         $objModel->distance = $objResult->distance;
         $objModel->preventSaving();
         $arrModels[] = $objModel;
     }
     // Return model collection
     return new \Model\Collection($arrModels, 'tl_anystores');
 }