/** * 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); }
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; } }
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); } }
/** * 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); }
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; }