Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.00 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Created by e-spin Berlin.
  5.  *
  6.  * (c) 2019
  7.  *
  8.  * @author     Ingolf Steinhardt <info@e-spin.de>
  9.  * @copyright  2019 Ingolf Steinhardt <info@e-spin.de>
  10.  * @license    Commercial
  11.  * @filesource
  12.  */
  13.  
  14. namespace AppBundle\Helper;
  15.  
  16. use MetaModels\Filter\Rules\SimpleQuery;
  17. use MetaModels\FilterPerimetersearchBundle\FilterRules\Perimetersearch;
  18.  
  19. class MmTemplateHelper
  20. {
  21.     /**
  22.      * @param $id
  23.      *
  24.      * @return mixed
  25.      */
  26.     public function getEventDataById($id)
  27.     {
  28.         // Get MetaModel and retrieve item.
  29.         $modelName = 'mm_events';
  30.         $container = $GLOBALS['container']['metamodels-service-container'];
  31.         $factory   = $container->getFactory();
  32.         $model     = $factory->getMetaModel($modelName);
  33.         $filter    = $model->getEmptyFilter();
  34.         $query     = sprintf('SELECT id FROM %s WHERE id = %s', $modelName, $id);
  35.         $filter->addFilterRule(new SimpleQuery($query));
  36.         $items     = $model->findByFilter($filter);
  37.  
  38.         return $items->parseAll('text')[0];
  39.     }
  40.  
  41.     /**
  42.      * @param $arrCategories
  43.      *
  44.      * @return string
  45.      */
  46.     function getCategoryIcons($arrCategories)
  47.     {
  48.         $icons = [];
  49.         foreach ($arrCategories as $arrCategory) {
  50.             if ($arrCategory['__TAGS_RAW__']['symbol_image']['path']) {
  51.                 $icons[] = $arrCategory['__TAGS_RAW__']['symbol_image']['path'];
  52.             }
  53.         }
  54.  
  55.         return implode(', ', $icons);
  56.     }
  57.  
  58.     /**
  59.      * @param $address
  60.      *
  61.      * @return array
  62.      */
  63.     function getPoisByAddress($address) {
  64.         if (!$address) {
  65.             return [];
  66.         }
  67.         // Get MetaModel and retrieve item.
  68.         $modelName = 'mm_pois';
  69.         $filterId  = 5;
  70.         $filterUrl = ['adresse' => $address];
  71.         $container = $GLOBALS['container']['metamodels-service-container'];
  72.         $factory   = $container->getFactory();
  73.         $model     = $factory->getMetaModel($modelName);
  74.         $filter    = $model->prepareFilter($filterId, $filterUrl);
  75.         $items     = $model->findByFilter($filter,'geodistance');
  76.  
  77.         return $items->parseAll('text');
  78.     }
  79.  
  80.     function getPoisByGeoCoordinates($geoLat, $geoLong, $distance) {
  81.         if (!$geoLat || !$geoLong) {
  82.             return [];
  83.         }
  84.         // Get MetaModel and retrieve item.
  85.         $modelName = 'mm_pois';
  86.         $latName   = 'geo_lat';
  87.         $longName  = 'geo_long';
  88.         $container = $GLOBALS['container']['metamodels-service-container'];
  89.         $factory   = $container->getFactory();
  90.         $model     = $factory->getMetaModel($modelName);
  91.         $attrLat   = $model->getAttribute($latName);
  92.         $attrLong  = $model->getAttribute($longName);
  93.         $filter    = $model->getEmptyFilter();
  94.         $filter->addFilterRule(new Perimetersearch($attrLat, $attrLong, null, $geoLat, $geoLong, $distance));
  95.         $items     = $model->findByFilter($filter,'geodistance');
  96.  
  97.         return $items->parseAll('text');
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement