<?php
namespace App\Controller\Module;
use App\AppBundle;
use Pimcore\Model\DataObject;
use Pimcore\Model\Asset;
use Pimcore\Model\Document;
use SaintElmos\BaseBundle\Services\ImageResponsive;
use SaintElmos\BaseBundle\Templating\Helper\FrontendHelper;
use SaintElmos\BaseBundle\Utils\SETConf;
use Symfony\Component\HttpFoundation\Request;
use Pimcore\Controller\FrontendController;
#use SaintElmos\BaseBundle\Controller\BaseController;
class TeaserController extends FrontendController
{
public function infoteaserAction(Request $request,\Pimcore\Config\Config $websiteConfig)
{
return $this->render('module/Teaser/__infoteaser-3x.html.twig');
}
public function teaserAction(Request $request,\Pimcore\Config\Config $websiteConfig)
{
//die("Hello");
/* Teaser +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
// echo "<pre>"; print_r($this->document->getTemplate()); die;
$template = $this->document->getTemplate() ? $this->document->getTemplate() : 'module/Teaser/__teaser-quer.html.twig';
$konfiguration_projekt_obj = $websiteConfig->get('konfiguration_projekt');
$saison = (string)AppBundle::getValue($konfiguration_projekt_obj, 'getSaison');
$frontendhelper = new FrontendHelper();
//$bugfiximageurl = AppBundle::getBugfiximageurl();
$teaserobjects = $this->document->getEditable('teaserobjects');
$thumb_name_quadrat_normal = '';
$thumb_name_quadrat_retina = '';
$teaser_text = '';
$teaser_bild_normal = '';
$teaser_bild_retina = '';
$teaser_bild_default = '';
$teaser_bild__alttag = '';
$teaser_headline_small = '';
$teaser = [];
if(!empty($teaserobjects))
{
$count_teaserobjects = count($teaserobjects->getElements());
}
else
{
$count_teaserobjects = 0;
}
if($count_teaserobjects === 0) {
$teaserfolder = $this->document->getEditable('teaserfolder');
$teaser_folder_Obj = "";
if (!empty($teaserfolder) && !$teaserfolder instanceof("Pimcore\Model\Document\Editable\Link")) {
$teaser_folder_id = $teaserfolder->getId();
$teaser_folder_Obj = DataObject::getById($teaser_folder_id);
} else {
$teaserfolder = $this->document->getProperty('teaserfolder');
if (!empty($teaserfolder) && !$teaserfolder instanceof("Pimcore\Model\Document\Editable\Link")) {
$teaser_folder_id = $teaserfolder->getId();
$teaser_folder_Obj = DataObject::getById($teaser_folder_id);
}
}
if(is_object($teaser_folder_Obj))
{
/**
* @var $items DataObject\Folder
*/
$itemsArray = $teaser_folder_Obj->getChildren();
$items = AppBundle::sortByIndex($itemsArray);
foreach ($items as $key => $element){
$linkElement = AppBundle::getValue($element, 'getLink');
$href_link = ""; //($linkElement->getLinktype() == 'direct') ? $linkElement->getDirect() : $linkElement->getInternal();
if(!empty($linkElement)){
if($linkElement->getLinktype() == 'direct')
{
$href_link = $linkElement->getDirect();
}
else
{
$linkID = $linkElement->getInternal();
if (is_object(\Pimcore\Model\Document::getById($linkID)))
{
$href_link = \Pimcore\Model\Document::getById($linkID)->getFullPath();
}
}
}
$href_teaser_target = (!empty($linkElement) && trim($linkElement->getTarget()) != '')? trim($linkElement->getTarget()) : '_self';
$href_teaser_text = (!empty($linkElement)) ? trim($linkElement->getText()) : "";
$href_teaser_link = trim($href_link);
$show_button = ($href_teaser_link != '')? true : false;
$teaser_headline = (string)$frontendhelper->changeTextarea(AppBundle::getValue($element, 'getTitle'));
$teaser_button_text = (string)$frontendhelper->changeTextarea(AppBundle::getValue($element, 'getButton_text'));
if($element->geto_className() == 'teaserhochformat')
{
$thumb_name_normal = 'teaser-hochformat-normal';
$thumb_name_retina = 'teaser-hochformat-retina';
$thumb_name_default = 'teaser-default';
$teaser_text = (string)$frontendhelper->changeTextarea(AppBundle::getValue($element, 'getText'));
}
elseif($element->geto_className() == 'teaserquerformat')
{
$thumb_name_normal = 'teaser-querformat-normal';
$thumb_name_retina = 'teaser-querformat-retina';
$thumb_name_default = 'teaser-default';
$thumb_name_quadrat_normal = 'teaser-querformat-mobilquadrat-normal';
$thumb_name_quadrat_retina = 'teaser-querformat-mobilquadrat-retina';
$teaser_headline_small = (string)$frontendhelper->changeTextarea(AppBundle::getValue($element, 'getHeadline_small'));
$teaser_button_text = (string)$frontendhelper->changeTextarea(AppBundle::getValue($element, 'getButton_text'));
}
$teaser_bild_normalQadrat = $teaser_bild_retinaQuadrat = "";
if($saison == 'sommer')
{
$bild_path = (string)AppBundle::getValue($element, 'getBild'); //Default Bild
}
elseif($saison == 'winter')
{
$bild_path = (string)AppBundle::getValue($element, 'getBild_saison_winter');
if($bild_path == '')
{
$bild_path = (string) AppBundle::getValue($element, 'getBild'); //Default Bild
}
}
else
{
$bild_path = (string)AppBundle::getValue($element, 'getBild'); //Default Bild
}
if (is_file($_SERVER["DOCUMENT_ROOT"] . '/var/assets/' . $bild_path) && $bild_path != '') {
$teaser_bild_obj = \Pimcore\Model\Asset::getByPath($bild_path);
$teaser_bild__alttag = $teaser_bild_obj->getMetadata("alt");
if (is_object($teaser_bild_obj)) {
$teaser_bild_normal = $teaser_bild_obj->getThumbnail($thumb_name_normal);
$teaser_bild_retina = $teaser_bild_obj->getThumbnail($thumb_name_retina);
$teaser_bild_default = $teaser_bild_obj->getThumbnail($thumb_name_default);
$teaser_bild_normalQadrat = $teaser_bild_obj->getThumbnail($thumb_name_quadrat_normal);
$teaser_bild_retinaQuadrat = $teaser_bild_obj->getThumbnail($thumb_name_quadrat_retina);
if ($teaser_bild_normal instanceof Image) {
$teaser_bild_normal = $teaser_bild_normal->getPath();
}
if ($teaser_bild_retina instanceof Image) {
$teaser_bild_retina = $teaser_bild_retina->getPath();
}
if ($teaser_bild_default instanceof Image) {
$teaser_bild_default = $teaser_bild_default->getPath();
}
if ($teaser_bild_normalQadrat instanceof Image) {
$teaser_bild_normalQadrat = $teaser_bild_normalQadrat->getPath();
}
if ($teaser_bild_retinaQuadrat instanceof Image) {
$teaser_bild_retinaQuadrat = $teaser_bild_retinaQuadrat->getPath();
}
}
}
if ($element->geto_className() == 'teaserhochformat') {
$teaser[] = array(
'show_button_and_ancor' => $show_button,
'href_teaser_text' => $href_teaser_text,
'href_teaser_link' => $href_teaser_link,
'href_teaser_target' => $href_teaser_target,
'teaser_headline' => $teaser_headline,
'teaser_button_text' => $teaser_button_text,
'teaser_text' => $teaser_text,
'teaser_bild_normal' => $teaser_bild_normal,
'teaser_bild_retina' => $teaser_bild_retina,
'teaser_bild_default' => $teaser_bild_default,
'teaser_bild__alttag' => $teaser_bild__alttag,
'teaser_bild_normalQadrat' => $teaser_bild_normalQadrat,
'teaser_bild_retinaQuadrat' => $teaser_bild_retinaQuadrat
);
} elseif ($element->geto_className() == 'teaserquerformat') {
$teaser[] = array(
'show_button_and_ancor' => $show_button,
'href_teaser_text' => $href_teaser_text,
'href_teaser_link' => $href_teaser_link,
'href_teaser_target' => $href_teaser_target,
'teaser_headline' => $teaser_headline,
'teaser_button_text' => $teaser_button_text,
'teaser_headline_small' => $teaser_headline_small,
'teaser_bild_normal' => $teaser_bild_normal,
'teaser_bild_retina' => $teaser_bild_retina,
'teaser_bild_default' => $teaser_bild_default,
'teaser_bild__alttag' => $teaser_bild__alttag,
'teaser_bild_normalQadrat' => $teaser_bild_normalQadrat,
'teaser_bild_retinaQuadrat' => $teaser_bild_retinaQuadrat
);
}
else
{
$teaser = [];
}
}
}
} else {
foreach($teaserobjects as $obj) {
$linkElement = AppBundle::getValue($obj, 'getLink');
$href_link = "";
if(!empty($linkElement)){
if($linkElement->getLinktype() == 'direct')
{
$href_link = $linkElement->getDirect();
}
else
{
$linkID = $linkElement->getInternal();
if (is_object(\Pimcore\Model\Document::getById($linkID)))
{
$href_link = \Pimcore\Model\Document::getById($linkID)->getFullPath();
}
}
}
$href_teaser_link = trim($href_link);
$show_button = ($href_teaser_link != '')? true : false;
$href_teaser_text = (!empty($linkElement)) ? trim($linkElement->getText()) : "";
$href_teaser_target = (!empty($linkElement) && trim($linkElement->getTarget()) != '')? trim($linkElement->getTarget()) : '_self';
$teaser_headline = (string)$frontendhelper->changeTextarea(AppBundle::getValue($obj, 'getTitle'));
$teaser_button_text = (string)$frontendhelper->changeTextarea(AppBundle::getValue($obj, 'getButton_text'));
if($obj->geto_className() == 'teaserhochformat')
{
$thumb_name_normal = 'teaser-hochformat-normal';
$thumb_name_retina = 'teaser-hochformat-retina';
$thumb_name_default = 'teaser-default';
$teaser_text = (string)$frontendhelper->changeTextarea(AppBundle::getValue($obj, 'getText'));
} elseif($obj->geto_className() == 'teaserquerformat')
{
$thumb_name_normal = 'teaser-querformat-normal';
$thumb_name_retina = 'teaser-querformat-retina';
$thumb_name_default = 'teaser-default';
$thumb_name_quadrat_normal = 'teaser-querformat-mobilquadrat-normal';
$thumb_name_quadrat_retina = 'teaser-querformat-mobilquadrat-retina';
$teaser_headline_small = (string)$frontendhelper->changeTextarea(AppBundle::getValue($obj, 'getHeadline_small'));
$teaser_button_text = (string)$frontendhelper->changeTextarea(AppBundle::getValue($obj, 'getButton_text'));
}
$teaser_bild_normalQadrat = $teaser_bild_retinaQuadrat = "";
if($saison == 'sommer')
{
$bild_path = (string)AppBundle::getValue($obj, 'getBild'); //Default Bild
}
elseif($saison == 'winter')
{
$bild_path = (string)AppBundle::getValue($obj, 'getBild_saison_winter');
if($bild_path == '')
{
$bild_path = (string) AppBundle::getValue($obj, 'getBild'); //Default Bild
}
}
else
{
$bild_path = (string)AppBundle::getValue($obj, 'getBild'); //Default Bild
}
if (is_file($_SERVER["DOCUMENT_ROOT"] . '/var/assets/' . $bild_path) && $bild_path != '') {
$teaser_bild_obj = \Pimcore\Model\Asset::getByPath($bild_path);
$teaser_bild__alttag = $teaser_bild_obj->getMetadata("alt");
if (is_object($teaser_bild_obj)) {
$teaser_bild_normal = $teaser_bild_obj->getThumbnail($thumb_name_normal);
$teaser_bild_retina = $teaser_bild_obj->getThumbnail($thumb_name_retina);
$teaser_bild_default = $teaser_bild_obj->getThumbnail($thumb_name_default);
$teaser_bild_normalQadrat = $teaser_bild_obj->getThumbnail($thumb_name_quadrat_normal);
$teaser_bild_retinaQuadrat = $teaser_bild_obj->getThumbnail($thumb_name_quadrat_retina);
if ($teaser_bild_normal instanceof Image) {
$teaser_bild_normal = $teaser_bild_normal->getPath();
}
if ($teaser_bild_retina instanceof Image) {
$teaser_bild_retina = $teaser_bild_retina->getPath();
}
if ($teaser_bild_default instanceof Image) {
$teaser_bild_default = $teaser_bild_default->getPath();
}
if ($teaser_bild_normalQadrat instanceof Image) {
$teaser_bild_normalQadrat = $teaser_bild_normalQadrat->getPath();
}
if ($teaser_bild_retinaQuadrat instanceof Image) {
$teaser_bild_retinaQuadrat = $teaser_bild_retinaQuadrat->getPath();
}
}
}
if ($obj->geto_className() == 'teaserhochformat') {
$teaser[] = array(
'show_button_and_ancor' => $show_button,
'href_teaser_text' => $href_teaser_text,
'href_teaser_link' => $href_teaser_link,
'href_teaser_target' => $href_teaser_target,
'teaser_headline' => $teaser_headline,
'teaser_button_text' => $teaser_button_text,
'teaser_text' => $teaser_text,
'teaser_bild_normal' => $teaser_bild_normal,
'teaser_bild_retina' => $teaser_bild_retina,
'teaser_bild_default' => $teaser_bild_default,
'teaser_bild__alttag' => $teaser_bild__alttag,
'teaser_bild_normalQadrat' => $teaser_bild_normalQadrat,
'teaser_bild_retinaQuadrat' => $teaser_bild_retinaQuadrat
);
} elseif ($obj->geto_className() == 'teaserquerformat') {
$teaser[] = array(
'show_button_and_ancor' => $show_button,
'href_teaser_text' => $href_teaser_text,
'href_teaser_link' => $href_teaser_link,
'href_teaser_target' => $href_teaser_target,
'teaser_headline' => $teaser_headline,
'teaser_button_text' => $teaser_button_text,
'teaser_headline_small' => $teaser_headline_small,
'teaser_bild_normal' => $teaser_bild_normal,
'teaser_bild_retina' => $teaser_bild_retina,
'teaser_bild_default' => $teaser_bild_default,
'teaser_bild__alttag' => $teaser_bild__alttag,
'teaser_bild_normalQadrat' => $teaser_bild_normalQadrat,
'teaser_bild_retinaQuadrat' => $teaser_bild_retinaQuadrat
);
}
}
}
// return ['teaser' => $teaser];
return $this->render($template, ['teaser' => $teaser]);
}
}