/**
  * Get all anyStores categories
  * 
  * @return array
  * @deprecated 1.8.1 use 'foreignKey' instead
  */
 public static function getCategories()
 {
     $objCategories = AnyStoresCategoryModel::findAll(array('order' => 'title'));
     if (!$objCategories) {
         return array();
     }
     return $objCategories->fetchEach('title');
 }
Exemple #2
0
// with ♥ and Contao
/**
 * anyStores for Contao Open Source CMS
 *
 * @copyright   (c) 2015 Tastaturberuf <*****@*****.**>
 * @author      Daniel Jahnsmüller <*****@*****.**>
 * @license     http://opensource.org/licenses/lgpl-3.0.html
 * @package     anyStores
 */
/**
 * Palettes
 */
$GLOBALS['TL_DCA']['tl_form_field']['palettes']['stores'] = '
    {type_legend},type,name,label;
    {fconfig_legend},mandatory,multiple;
    {options_legend},anystores_categories;
    {expert_legend:hide},class,accesskey,tabindex;
    {template_legend:hide},customTpl;
    {submit_legend},addSubmit
';
/**
 * Fields
 */
$GLOBALS['TL_DCA']['tl_form_field']['fields']['anystores_categories'] = array('label' => &$GLOBALS['TL_LANG']['tl_form_field']['anystores_categories'], 'exclude' => true, 'inputType' => 'checkbox', 'options_callback' => function () {
    $objCategories = AnyStoresCategoryModel::findAll(array('order' => 'title'));
    if ($objCategories === null) {
        return;
    }
    return $objCategories->fetchEach('title');
}, 'eval' => array('mandatory' => true, 'multiple' => true), 'sql' => "text NULL");
 /**
  * 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);
 }