<?php
/***************************************************************
*
* Copyright notice
*
* (c) 14.12.21 Paul Bönisch <p.boenisch@saint-elmos.com>, Saint Elmo's
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
namespace App\Controller\Traits;
use App\AppBundle;
use SaintElmos\BaseBundle\Templating\Helper\FrontendHelper;
use \Pimcore\Model\WebsiteSetting;
use Pimcore\Model\Asset\Document;
use Pimcore\Model\Asset\Image;
trait IconTrait
{
public function getFooterObject()
{
$theme = AppBundle::getTheme($this->document, 'theme_doc');
switch ($theme) {
case 'rent':
$footer_obj = WebsiteSetting::getByName('footer_rent')->getData();
break;
case 'homes':
$footer_obj = WebsiteSetting::getByName('footer_homes')->getData();
break;
case 'shops':
$footer_obj = WebsiteSetting::getByName('footer_shops')->getData();
break;
default:
//neutral
$footer_obj = WebsiteSetting::getByName('footer_neutral')->getData();
}
return $footer_obj;
}
public function getContactLinks()
{
$frontendhelper = new FrontendHelper();
$bugfiximageurl = AppBundle::getBugfiximageurl();
$footer_obj = $this->getFooterObject();
if(is_object($footer_obj))
{
$tel_icon_path = AppBundle::getValue($footer_obj, 'getTelefonicon');
if (is_file($_SERVER["DOCUMENT_ROOT"] . '/var/assets' . $tel_icon_path))
{
if (is_object(\Pimcore\Model\Asset::getByPath($tel_icon_path)))
{
$tel_icon_obj = \Pimcore\Model\Asset::getByPath($tel_icon_path);
$tel_icon_alttag = $tel_icon_obj->getMetadata("alt");
}
$tel_icon_img = (trim($tel_icon_path != ''))? '<img width="25" height="25" src="'.$bugfiximageurl.$tel_icon_path.'" alt="'.$tel_icon_alttag.'"/>':'';
}
else
{
$tel_icon_img = '';
}
$tel = AppBundle::getValue($footer_obj, 'getTelefonnummer');
$tel_num = $frontendhelper->clearTelnumber($tel);
$telefonnummer = '<a href="tel:'.$tel_num.'">' . $tel_icon_img . '<label>' .$tel . '</label></a>';
}
if(is_object($footer_obj))
{
$email_icon_path = AppBundle::getValue($footer_obj, 'getEmailicon');
if (is_file($_SERVER["DOCUMENT_ROOT"] . '/var/assets' . $email_icon_path))
{
if (is_object(\Pimcore\Model\Asset::getByPath($email_icon_path)))
{
$email_icon_obj = \Pimcore\Model\Asset::getByPath($email_icon_path);
$email_icon_alttag = $email_icon_obj->getMetadata("alt");
}
$email_icon_img = (trim($email_icon_path != ''))? '<img width="25" height="25" src="'.$bugfiximageurl.$email_icon_path.'" alt="'.$email_icon_alttag.'"/>':'';
}
else
{
$email_icon_img = '';
}
$email_adresse = AppBundle::getValue($footer_obj, 'getEmail');
$email = '<a href="mailto:'.$email_adresse.'">' . $email_icon_img . '<label>' . $email_adresse . '</label></a>';
}
return array(
'email' => $email,
'telefonnummer' => $telefonnummer
);
}
public function getWetter($language) {
$bugfiximageurl = AppBundle::getBugfiximageurl();
$lg = $this->document->getProperty('language');
$lg_trimmed = trim($lg);
$footer_obj = $this->getFooterObject($this->document);
$wetter_icon = AppBundle::getValue($footer_obj, 'getWettericon');
$wetter_link = AppBundle::getValue($footer_obj, 'getWetterlink');
$wetterFullImage = Image::getById($wetter_icon->getId());
$wetterFullLink = null;
if ($wetter_link) {
$wetterFullLink = $wetter_link->getHref();
}
if ($language === 'en')
{
$baseLink = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]".'/en'.$wetterFullLink;
} else {
$baseLink = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]".$wetterFullLink;
}
$wetterFullLink = $baseLink;
return [
"link" => $wetterFullLink,
"icon" => $wetterFullImage->getFrontendPath()
];
}
}