src/AppBundle.php line 126

Open in your IDE?
  1. <?php
  2. namespace App;
  3. use Pimcore\Model\DataObject;
  4. use SaintElmos\BaseBundle\Interfaces\IncludeInterface;
  5. use Symfony\Component\HttpKernel\Bundle\Bundle;
  6. use SaintElmos\BaseBundle\Templating\Helper\FrontendHelper;
  7. use Pimcore\Model\Asset;
  8. class AppBundle extends Bundle implements IncludeInterface
  9. {
  10.     /**
  11.      * Returns method value as string or empty string if method non existent
  12.      * @param object $object
  13.      * @param string $method Method name
  14.      * @param string $default Default value if method not exists
  15.      * @return string
  16.      */
  17.     public static function getValue($object$method$default '')
  18.     {
  19.         if ($object instanceof('\\Pimcore\\Model\\DataObject')){
  20.             return (method_exists($object$method))? $object->{$method}() : $default;
  21.         }
  22.         return "";        
  23.     }
  24.     /**
  25.      * Returns Bugfix Image Url
  26.      */
  27.     public static function getBugfiximageurl()
  28.     {
  29.         $string $_SERVER['HTTP_HOST'];
  30.         $find 'project.';
  31.         $pos strpos($string$find);
  32.         if ($pos === false) {
  33.             $url '';
  34.         } else {
  35.             $server_protocol 'http' . ($_SERVER['REQUEST_SCHEME'] == 'https' 's' '');
  36.             $url $server_protocol '://' str_replace($find"dev.",  $string);
  37.         }
  38.         return $url;
  39.     }
  40.     /**
  41.      * Returns Theme (from Property)
  42.      */
  43.     public static function getTheme($doc,$propertyname)
  44.     {
  45.         if($doc->getProperty($propertyname))
  46.         {
  47.             $theme $doc->getProperty($propertyname);
  48.         }
  49.         else
  50.         {
  51.             $theme 'neutral';
  52.         }
  53.         return $theme;
  54.     }
  55.     /**
  56.      * Returns list of template files to include in header
  57.      * @return array
  58.      */
  59.     public static function getHeaderIncludes()
  60.     {
  61.         return array(
  62.             'AppBundle::Includes/frontend-incl-kopf.html.php',
  63.             'AppBundle::Tracking/incl-tracking-vor-ende-head.html.php',
  64.         );
  65.     }
  66.     /**
  67.      * Returns list of template files to include at the beginning of the body
  68.      * @return array
  69.      */
  70.     public static function getBodyIncludes()
  71.     {
  72.         return array(
  73.             'AppBundle::Tracking/incl-tracking-nach-anfang-body.html.php',
  74.         );
  75.     }
  76.     /**
  77.      * Returns list of template files to include in footer
  78.      * @return array
  79.      */
  80.     public static function getFooterIncludes()
  81.     {
  82.         return array(
  83.             'AppBundle::Includes/frontend-incl-fuss.html.php',
  84.             'AppBundle::Tracking/incl-tracking-vor-ende-body.html.php',
  85.             'AppBundle::Cookiebar/incl-cookiebar-fuss.html.php',
  86.         );
  87.     }
  88.     /**
  89.      * Sort objects by index
  90.      * @param DataObject[]
  91.      * @param string $order 'asc' default for ascending, 'desc' for descending
  92.      * @return
  93.      */
  94.     public static function sortByIndex($array$order 'asc'){
  95.         usort($array, function($a$b) use($order){
  96.             /**
  97.              * @var $a DataObject
  98.              * @var $b DataObject
  99.              */
  100.             $aIndex $a->getIndex();
  101.             $bIndex $b->getIndex();
  102.             $result $aIndex >= $bIndex;
  103.             if($order == 'desc'){
  104.                 $result $aIndex $bIndex;
  105.             }
  106.             return $result;
  107.         });
  108.         return $array;
  109.     }
  110.     /**
  111.      * Ezeugt Thambnails
  112.      * @param
  113.      * @param
  114.      * @return
  115.      */
  116.     public function CreateThumbnail($src$thumbnailname$language$ausgabe){
  117.         if (is_file($_SERVER["DOCUMENT_ROOT"] . '/var/assets' $src) != '')
  118.         {
  119.             try
  120.             {
  121.                 $imgObj \Pimcore\Model\Asset::getByPath($src);
  122.                 $imgSrcThumb $imgObj->getThumbnail($thumbnailname);
  123.                 $alt $imgObj->getMetadata("alt"$language);
  124.             } catch (Exception $e)
  125.             {
  126.                 $result false;
  127.             }
  128.             if($ausgabe == 'alt')
  129.             {
  130.                 $result$alt;
  131.             }
  132.             else
  133.             {
  134.                 $result $imgSrcThumb;
  135.             }
  136.         }
  137.         return $result;
  138.     }
  139.     /**
  140.      * Map-Array das mit json_encode die infos für das Google-Map-Javascript liefert
  141.      * @param $this->document
  142.      * @param $theme (rent,homes,shops)
  143.      * @param $category (sports,fashion,ski-u-snowboard,bike)
  144.      * @return array
  145.      */
  146.     public static function mapArray($pim_this$category_specification){
  147.         $container self::getContainer();
  148.         $translator $container->get('translator');
  149.         $doc $pim_this->document;
  150.         $frontendhelper = new FrontendHelper();
  151.         $pageId $doc->getParent()->getId();
  152.         $list \Pimcore\Model\DataObject\Geolocation::getList();
  153.         $list->getOrder("desc");
  154.         $list->setOrderKey("o_index");
  155.         $sort_by_theme $doc->getProperty('sort_by_theme');
  156.         $doc_theme $doc->getProperty('theme_doc');
  157.         $page $doc->getProperty('region_homes_doc');
  158.         $doc_category $doc->getProperty('category_doc');
  159.         $cat = ($category_specification != '')? $category_specification $doc_category;
  160.         $language $doc->getProperty('language');
  161.         $oeffnungszeiten $translator->trans("map_oeffnungszeiten", array(), null$language);
  162.         $linktext $translator->trans("map_linktext", array(), null$language);
  163.         $mapArray = [];
  164.         foreach ($list as $key => $element)
  165.         {
  166.             $self_element $element;
  167.             $theme $element->getProperty('theme_obj');
  168.             $obj_category $element->getProperty('category');
  169.             $alias  '';
  170.             $go  true;
  171.             if($cat != '')
  172.             {
  173.                 if($obj_category == $cat)
  174.                 {
  175.                     $go true;
  176.                 }
  177.                 else
  178.                 {
  179.                     $go false;
  180.                 }
  181.             }
  182.             if($sort_by_theme && $go)
  183.             {
  184.                 if($theme == $doc_theme)
  185.                 {
  186.                     $go true;
  187.                 }
  188.                 else
  189.                 {
  190.                     $go false;
  191.                 }
  192.             }
  193.             if($go)
  194.             {
  195.                 $ObjId $element->getId();
  196.                 $alias = (string)AppBundle::getValue($element'getAlias');
  197.                 if($alias != '')
  198.                 {
  199.                     $element \Pimcore\Model\DataObject::getByPath($alias);
  200.                 }
  201.                 /* ********************************************************************************************************************* */
  202.                 $name           $frontendhelper->changeTextarea(AppBundle::getValue($element'getName'));
  203.                 $name           $frontendhelper->compress($name);
  204.                 $openinghours   $frontendhelper->changeTextarea(AppBundle::getValue($element'getOeffnungszeiten'));
  205.                 $street   AppBundle::getValue($element'getStrasse');
  206.                 $city     AppBundle::getValue($element'getOrt');
  207.                 $phone    AppBundle::getValue($element'getPhone');
  208.                 $mail     AppBundle::getValue($element'getMail');
  209.                 $landingpage_obj AppBundle::getValue($self_element'getUrl_zielseite');
  210.                 $landingpage_url = (string)$landingpage_obj;
  211.                 $landingpage_id = ($landingpage_url != '')? $landingpage_obj->getId() : '';
  212.                 $heighlight_location = ($landingpage_id == $pageId )? 0;
  213.                 $brandlogogroup_objpath = (string)AppBundle::getValue($element'getMarkenlogogruppe');
  214.                 $brandlogogroup_objid = ($brandlogogroup_objpath != '')? (string)AppBundle::getValue($element'getMarkenlogogruppe')->getId() : '';
  215.                 $latitude trim(AppBundle::getValue($element'getLatitude'));
  216.                 $longitude trim(AppBundle::getValue($element'getLongitude'));
  217.                 /* ********************************************************************************************************************* */
  218.                 if(!empty($latitude) && !empty($longitude))
  219.                 {
  220.                     $mapArray[$ObjId] = array(
  221.                         "sort_by_theme"         => $sort_by_theme,
  222.                         "theme"                 => $theme,
  223.                         "page"                    => $page,
  224.                         "language"              => $language,
  225.                         "category"              => $obj_category,
  226.                         "name"                  => $name,
  227.                         "openinghours"          => $openinghours,
  228.                         "brandlogogroup_objid"  => $brandlogogroup_objid,
  229.                         "highlight_location"    => $heighlight_location,
  230.                         "address"     => array(
  231.                             "street"  => $street,
  232.                             "city"    => $city,
  233.                             "phone"   => $phone,
  234.                             "mail"    => $mail
  235.                         ),
  236.                         "translation" => array(
  237.                             "oeffnungszeiten"  => $oeffnungszeiten,
  238.                             "linktext"    => $linktext
  239.                         ),
  240.                         "location"     => array(
  241.                             "latitude" => $latitude,
  242.                             "longitude"=> $longitude
  243.                         )   ,
  244.                         "landingpage"  => array(
  245.                             "url" => $landingpage_url,
  246.                             "id"  => $landingpage_id
  247.                         )
  248.                     );
  249.                 };
  250.             }
  251.         }
  252.         return $mapArray;
  253.     }
  254.     /**
  255.      * Returns global container
  256.      * @return \Symfony\Component\DependencyInjection\ContainerInterface
  257.      */
  258.     public static function getContainer(){
  259.         global $kernel;
  260.         $container $kernel->getContainer();
  261.         return $container;
  262.     }
  263. }