<?php
namespace App;
use Pimcore\Model\DataObject;
use SaintElmos\BaseBundle\Interfaces\IncludeInterface;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use SaintElmos\BaseBundle\Templating\Helper\FrontendHelper;
use Pimcore\Model\Asset;
class AppBundle extends Bundle implements IncludeInterface
{
/**
* Returns method value as string or empty string if method non existent
* @param object $object
* @param string $method Method name
* @param string $default Default value if method not exists
* @return string
*/
public static function getValue($object, $method, $default = '')
{
if ($object instanceof('\\Pimcore\\Model\\DataObject')){
return (method_exists($object, $method))? $object->{$method}() : $default;
}
return "";
}
/**
* Returns Bugfix Image Url
*/
public static function getBugfiximageurl()
{
$string = $_SERVER['HTTP_HOST'];
$find = 'project.';
$pos = strpos($string, $find);
if ($pos === false) {
$url = '';
} else {
$server_protocol = 'http' . ($_SERVER['REQUEST_SCHEME'] == 'https' ? 's' : '');
$url = $server_protocol . '://' . str_replace($find, "dev.", $string);
}
return $url;
}
/**
* Returns Theme (from Property)
*/
public static function getTheme($doc,$propertyname)
{
if($doc->getProperty($propertyname))
{
$theme = $doc->getProperty($propertyname);
}
else
{
$theme = 'neutral';
}
return $theme;
}
/**
* Returns list of template files to include in header
* @return array
*/
public static function getHeaderIncludes()
{
return array(
'AppBundle::Includes/frontend-incl-kopf.html.php',
'AppBundle::Tracking/incl-tracking-vor-ende-head.html.php',
);
}
/**
* Returns list of template files to include at the beginning of the body
* @return array
*/
public static function getBodyIncludes()
{
return array(
'AppBundle::Tracking/incl-tracking-nach-anfang-body.html.php',
);
}
/**
* Returns list of template files to include in footer
* @return array
*/
public static function getFooterIncludes()
{
return array(
'AppBundle::Includes/frontend-incl-fuss.html.php',
'AppBundle::Tracking/incl-tracking-vor-ende-body.html.php',
'AppBundle::Cookiebar/incl-cookiebar-fuss.html.php',
);
}
/**
* Sort objects by index
* @param DataObject[]
* @param string $order 'asc' default for ascending, 'desc' for descending
* @return
*/
public static function sortByIndex($array, $order = 'asc'){
usort($array, function($a, $b) use($order){
/**
* @var $a DataObject
* @var $b DataObject
*/
$aIndex = $a->getIndex();
$bIndex = $b->getIndex();
$result = $aIndex >= $bIndex;
if($order == 'desc'){
$result = $aIndex < $bIndex;
}
return $result;
});
return $array;
}
/**
* Ezeugt Thambnails
* @param
* @param
* @return
*/
public function CreateThumbnail($src, $thumbnailname, $language, $ausgabe){
if (is_file($_SERVER["DOCUMENT_ROOT"] . '/var/assets' . $src) != '')
{
try
{
$imgObj = \Pimcore\Model\Asset::getByPath($src);
$imgSrcThumb = $imgObj->getThumbnail($thumbnailname);
$alt = $imgObj->getMetadata("alt", $language);
} catch (Exception $e)
{
$result = false;
}
if($ausgabe == 'alt')
{
$result= $alt;
}
else
{
$result = $imgSrcThumb;
}
}
return $result;
}
/**
* Map-Array das mit json_encode die infos für das Google-Map-Javascript liefert
* @param $this->document
* @param $theme (rent,homes,shops)
* @param $category (sports,fashion,ski-u-snowboard,bike)
* @return array
*/
public static function mapArray($pim_this, $category_specification){
$container = self::getContainer();
$translator = $container->get('translator');
$doc = $pim_this->document;
$frontendhelper = new FrontendHelper();
$pageId = $doc->getParent()->getId();
$list = \Pimcore\Model\DataObject\Geolocation::getList();
$list->getOrder("desc");
$list->setOrderKey("o_index");
$sort_by_theme = $doc->getProperty('sort_by_theme');
$doc_theme = $doc->getProperty('theme_doc');
$page = $doc->getProperty('region_homes_doc');
$doc_category = $doc->getProperty('category_doc');
$cat = ($category_specification != '')? $category_specification : $doc_category;
$language = $doc->getProperty('language');
$oeffnungszeiten = $translator->trans("map_oeffnungszeiten", array(), null, $language);
$linktext = $translator->trans("map_linktext", array(), null, $language);
$mapArray = [];
foreach ($list as $key => $element)
{
$self_element = $element;
$theme = $element->getProperty('theme_obj');
$obj_category = $element->getProperty('category');
$alias = '';
$go = true;
if($cat != '')
{
if($obj_category == $cat)
{
$go = true;
}
else
{
$go = false;
}
}
if($sort_by_theme && $go)
{
if($theme == $doc_theme)
{
$go = true;
}
else
{
$go = false;
}
}
if($go)
{
$ObjId = $element->getId();
$alias = (string)AppBundle::getValue($element, 'getAlias');
if($alias != '')
{
$element = \Pimcore\Model\DataObject::getByPath($alias);
}
/* ********************************************************************************************************************* */
$name = $frontendhelper->changeTextarea(AppBundle::getValue($element, 'getName'));
$name = $frontendhelper->compress($name);
$openinghours = $frontendhelper->changeTextarea(AppBundle::getValue($element, 'getOeffnungszeiten'));
$street = AppBundle::getValue($element, 'getStrasse');
$city = AppBundle::getValue($element, 'getOrt');
$phone = AppBundle::getValue($element, 'getPhone');
$mail = AppBundle::getValue($element, 'getMail');
$landingpage_obj = AppBundle::getValue($self_element, 'getUrl_zielseite');
$landingpage_url = (string)$landingpage_obj;
$landingpage_id = ($landingpage_url != '')? $landingpage_obj->getId() : '';
$heighlight_location = ($landingpage_id == $pageId )? 1 : 0;
$brandlogogroup_objpath = (string)AppBundle::getValue($element, 'getMarkenlogogruppe');
$brandlogogroup_objid = ($brandlogogroup_objpath != '')? (string)AppBundle::getValue($element, 'getMarkenlogogruppe')->getId() : '';
$latitude = trim(AppBundle::getValue($element, 'getLatitude'));
$longitude = trim(AppBundle::getValue($element, 'getLongitude'));
/* ********************************************************************************************************************* */
if(!empty($latitude) && !empty($longitude))
{
$mapArray[$ObjId] = array(
"sort_by_theme" => $sort_by_theme,
"theme" => $theme,
"page" => $page,
"language" => $language,
"category" => $obj_category,
"name" => $name,
"openinghours" => $openinghours,
"brandlogogroup_objid" => $brandlogogroup_objid,
"highlight_location" => $heighlight_location,
"address" => array(
"street" => $street,
"city" => $city,
"phone" => $phone,
"mail" => $mail
),
"translation" => array(
"oeffnungszeiten" => $oeffnungszeiten,
"linktext" => $linktext
),
"location" => array(
"latitude" => $latitude,
"longitude"=> $longitude
) ,
"landingpage" => array(
"url" => $landingpage_url,
"id" => $landingpage_id
)
);
};
}
}
return $mapArray;
}
/**
* Returns global container
* @return \Symfony\Component\DependencyInjection\ContainerInterface
*/
public static function getContainer(){
global $kernel;
$container = $kernel->getContainer();
return $container;
}
}