src/Controller/Module/TeaserController.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Module;
  3. use App\AppBundle;
  4. use Pimcore\Model\DataObject;
  5. use Pimcore\Model\Asset;
  6. use Pimcore\Model\Document;
  7. use SaintElmos\BaseBundle\Services\ImageResponsive;
  8. use SaintElmos\BaseBundle\Templating\Helper\FrontendHelper;
  9. use SaintElmos\BaseBundle\Utils\SETConf;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Pimcore\Controller\FrontendController;
  12. #use SaintElmos\BaseBundle\Controller\BaseController;
  13. class TeaserController extends FrontendController
  14. {
  15.     public function infoteaserAction(Request $request,\Pimcore\Config\Config $websiteConfig)
  16.     {
  17.         return $this->render('module/Teaser/__infoteaser-3x.html.twig');
  18.     }
  19.     public function teaserAction(Request $request,\Pimcore\Config\Config $websiteConfig)
  20.     {
  21.         //die("Hello");
  22.         /* Teaser  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
  23.        // echo "<pre>"; print_r($this->document->getTemplate()); die;
  24.         $template $this->document->getTemplate() ? $this->document->getTemplate() : 'module/Teaser/__teaser-quer.html.twig';
  25.         $konfiguration_projekt_obj =  $websiteConfig->get('konfiguration_projekt');
  26.         $saison = (string)AppBundle::getValue($konfiguration_projekt_obj'getSaison');
  27.         $frontendhelper = new FrontendHelper();
  28.         //$bugfiximageurl = AppBundle::getBugfiximageurl();
  29.         $teaserobjects =  $this->document->getEditable('teaserobjects');
  30.         $thumb_name_quadrat_normal '';
  31.         $thumb_name_quadrat_retina '';
  32.         $teaser_text '';
  33.         $teaser_bild_normal '';
  34.         $teaser_bild_retina '';
  35.         $teaser_bild_default '';
  36.         $teaser_bild__alttag '';
  37.         $teaser_headline_small '';
  38.         $teaser = [];
  39.         
  40.         if(!empty($teaserobjects))
  41.         {
  42.             $count_teaserobjects count($teaserobjects->getElements());
  43.         }
  44.         else
  45.         {
  46.             $count_teaserobjects 0;
  47.         }
  48.         if($count_teaserobjects === 0) {
  49.             $teaserfolder =  $this->document->getEditable('teaserfolder');
  50.             $teaser_folder_Obj "";
  51.             if (!empty($teaserfolder) && !$teaserfolder instanceof("Pimcore\Model\Document\Editable\Link")) {
  52.                 $teaser_folder_id $teaserfolder->getId();
  53.                 $teaser_folder_Obj DataObject::getById($teaser_folder_id);
  54.             } else {
  55.                 $teaserfolder $this->document->getProperty('teaserfolder');
  56.                 if (!empty($teaserfolder) && !$teaserfolder instanceof("Pimcore\Model\Document\Editable\Link")) {
  57.                     $teaser_folder_id $teaserfolder->getId();
  58.                     $teaser_folder_Obj DataObject::getById($teaser_folder_id);
  59.                 }
  60.             }
  61.             
  62.             if(is_object($teaser_folder_Obj))
  63.             {
  64.                 /**
  65.                  * @var $items DataObject\Folder
  66.                  */
  67.                 $itemsArray $teaser_folder_Obj->getChildren();
  68.                 $items AppBundle::sortByIndex($itemsArray);
  69.                 foreach ($items as $key => $element){
  70.                     
  71.                     $linkElement =  AppBundle::getValue($element'getLink');
  72.                     $href_link ""//($linkElement->getLinktype() == 'direct') ? $linkElement->getDirect() : $linkElement->getInternal();
  73.                     if(!empty($linkElement)){
  74.                         if($linkElement->getLinktype() == 'direct')
  75.                         {
  76.                             $href_link $linkElement->getDirect();
  77.                         }
  78.                         else
  79.                         {
  80.                             $linkID $linkElement->getInternal();
  81.                             if (is_object(\Pimcore\Model\Document::getById($linkID)))
  82.                             {
  83.                                 $href_link \Pimcore\Model\Document::getById($linkID)->getFullPath();
  84.                             }
  85.                         }
  86.                     }
  87.                     $href_teaser_target = (!empty($linkElement) && trim($linkElement->getTarget()) != '')? trim($linkElement->getTarget()) : '_self';
  88.                     $href_teaser_text = (!empty($linkElement)) ? trim($linkElement->getText()) : "";
  89.                     $href_teaser_link trim($href_link);
  90.                     $show_button = ($href_teaser_link != '')? true false;
  91.                     $teaser_headline  = (string)$frontendhelper->changeTextarea(AppBundle::getValue($element'getTitle'));
  92.                     $teaser_button_text  = (string)$frontendhelper->changeTextarea(AppBundle::getValue($element'getButton_text'));
  93.             
  94.             
  95.                     if($element->geto_className() == 'teaserhochformat')
  96.                     {
  97.                         $thumb_name_normal 'teaser-hochformat-normal';
  98.                         $thumb_name_retina 'teaser-hochformat-retina';
  99.                         $thumb_name_default 'teaser-default';
  100.                         $teaser_text  = (string)$frontendhelper->changeTextarea(AppBundle::getValue($element'getText'));                    
  101.                     }
  102.                     elseif($element->geto_className() == 'teaserquerformat')
  103.                     {
  104.                         $thumb_name_normal 'teaser-querformat-normal';
  105.                         $thumb_name_retina 'teaser-querformat-retina';
  106.                         $thumb_name_default 'teaser-default';
  107.                         $thumb_name_quadrat_normal 'teaser-querformat-mobilquadrat-normal';
  108.                         $thumb_name_quadrat_retina 'teaser-querformat-mobilquadrat-retina';
  109.                         $teaser_headline_small = (string)$frontendhelper->changeTextarea(AppBundle::getValue($element'getHeadline_small'));
  110.                         $teaser_button_text = (string)$frontendhelper->changeTextarea(AppBundle::getValue($element'getButton_text'));
  111.                     }
  112.                     $teaser_bild_normalQadrat $teaser_bild_retinaQuadrat "";   
  113.                     if($saison == 'sommer')
  114.                     {
  115.                         $bild_path =  (string)AppBundle::getValue($element'getBild'); //Default Bild
  116.                     }
  117.                     elseif($saison == 'winter')
  118.                     {
  119.                         $bild_path =  (string)AppBundle::getValue($element'getBild_saison_winter');
  120.                         if($bild_path == '')
  121.                         {
  122.                             $bild_path = (string) AppBundle::getValue($element'getBild'); //Default Bild
  123.                         }
  124.                     }
  125.                     else
  126.                     {
  127.                         $bild_path =  (string)AppBundle::getValue($element'getBild'); //Default Bild
  128.                     }
  129.     if (is_file($_SERVER["DOCUMENT_ROOT"] . '/var/assets/' $bild_path) && $bild_path != '') {
  130.                         $teaser_bild_obj \Pimcore\Model\Asset::getByPath($bild_path);
  131.                         $teaser_bild__alttag $teaser_bild_obj->getMetadata("alt");
  132.                         if (is_object($teaser_bild_obj)) {
  133.                             $teaser_bild_normal $teaser_bild_obj->getThumbnail($thumb_name_normal);
  134.                             $teaser_bild_retina $teaser_bild_obj->getThumbnail($thumb_name_retina);
  135.                             $teaser_bild_default $teaser_bild_obj->getThumbnail($thumb_name_default);
  136.                             $teaser_bild_normalQadrat $teaser_bild_obj->getThumbnail($thumb_name_quadrat_normal);
  137.                             $teaser_bild_retinaQuadrat $teaser_bild_obj->getThumbnail($thumb_name_quadrat_retina);
  138.                             if ($teaser_bild_normal instanceof Image) {
  139.                                 $teaser_bild_normal $teaser_bild_normal->getPath();
  140.                             }
  141.                             if ($teaser_bild_retina instanceof Image) {
  142.                                 $teaser_bild_retina $teaser_bild_retina->getPath();
  143.                             }
  144.                             if ($teaser_bild_default instanceof Image) {
  145.                                 $teaser_bild_default $teaser_bild_default->getPath();
  146.                             }
  147.                             if ($teaser_bild_normalQadrat instanceof Image) {
  148.                                 $teaser_bild_normalQadrat $teaser_bild_normalQadrat->getPath();
  149.                             }
  150.                             if ($teaser_bild_retinaQuadrat instanceof Image) {
  151.                                 $teaser_bild_retinaQuadrat $teaser_bild_retinaQuadrat->getPath();
  152.                             }
  153.                         }
  154.                     }
  155.                     if ($element->geto_className() == 'teaserhochformat') {
  156.                         $teaser[] = array(
  157.                             'show_button_and_ancor' => $show_button,
  158.                             'href_teaser_text' => $href_teaser_text,
  159.                             'href_teaser_link' => $href_teaser_link,
  160.                             'href_teaser_target' => $href_teaser_target,
  161.                             'teaser_headline' => $teaser_headline,
  162.                             'teaser_button_text' => $teaser_button_text,
  163.                             'teaser_text' => $teaser_text,
  164.                             'teaser_bild_normal' => $teaser_bild_normal,
  165.                             'teaser_bild_retina' => $teaser_bild_retina,
  166.                             'teaser_bild_default' => $teaser_bild_default,
  167.                             'teaser_bild__alttag' => $teaser_bild__alttag,
  168.                             'teaser_bild_normalQadrat' => $teaser_bild_normalQadrat,
  169.                             'teaser_bild_retinaQuadrat' => $teaser_bild_retinaQuadrat
  170.                         );
  171.                     } elseif ($element->geto_className() == 'teaserquerformat') {
  172.                         $teaser[] = array(
  173.                             'show_button_and_ancor' => $show_button,
  174.                             'href_teaser_text' => $href_teaser_text,
  175.                             'href_teaser_link' => $href_teaser_link,
  176.                             'href_teaser_target' => $href_teaser_target,
  177.                             'teaser_headline' => $teaser_headline,
  178.                             'teaser_button_text' => $teaser_button_text,
  179.                             'teaser_headline_small' => $teaser_headline_small,
  180.                             'teaser_bild_normal' => $teaser_bild_normal,
  181.                             'teaser_bild_retina' => $teaser_bild_retina,
  182.                             'teaser_bild_default' => $teaser_bild_default,
  183.                             'teaser_bild__alttag' => $teaser_bild__alttag,
  184.                             'teaser_bild_normalQadrat' => $teaser_bild_normalQadrat,
  185.                             'teaser_bild_retinaQuadrat' => $teaser_bild_retinaQuadrat
  186.                         );
  187.                     }
  188.                     else
  189.                     {
  190.                         $teaser = [];
  191.                     }
  192.                 }
  193.             }
  194.         } else {
  195.             foreach($teaserobjects as $obj) {
  196.                 $linkElement =  AppBundle::getValue($obj'getLink');
  197.                 $href_link "";
  198.                 if(!empty($linkElement)){
  199.                     if($linkElement->getLinktype() == 'direct')
  200.                     {
  201.                         $href_link $linkElement->getDirect();
  202.                     }
  203.                     else
  204.                     {
  205.                         $linkID $linkElement->getInternal();
  206.                         if (is_object(\Pimcore\Model\Document::getById($linkID)))
  207.                         {
  208.                             $href_link \Pimcore\Model\Document::getById($linkID)->getFullPath();
  209.                         }
  210.                     }
  211.                 }
  212.                 $href_teaser_link trim($href_link);
  213.                 $show_button = ($href_teaser_link != '')? true false;
  214.                 $href_teaser_text = (!empty($linkElement)) ? trim($linkElement->getText()) : "";
  215.                 $href_teaser_target = (!empty($linkElement) && trim($linkElement->getTarget()) != '')? trim($linkElement->getTarget()) : '_self';
  216.                 $teaser_headline  = (string)$frontendhelper->changeTextarea(AppBundle::getValue($obj'getTitle'));
  217.                 $teaser_button_text  = (string)$frontendhelper->changeTextarea(AppBundle::getValue($obj'getButton_text'));
  218.                 if($obj->geto_className() == 'teaserhochformat')
  219.                 {
  220.                     $thumb_name_normal 'teaser-hochformat-normal';
  221.                     $thumb_name_retina 'teaser-hochformat-retina';
  222.                     $thumb_name_default 'teaser-default';
  223.                     $teaser_text  = (string)$frontendhelper->changeTextarea(AppBundle::getValue($obj'getText'));                    
  224.                 }   elseif($obj->geto_className() == 'teaserquerformat')
  225.                 {
  226.                     $thumb_name_normal 'teaser-querformat-normal';
  227.                     $thumb_name_retina 'teaser-querformat-retina';
  228.                     $thumb_name_default 'teaser-default';
  229.                     $thumb_name_quadrat_normal 'teaser-querformat-mobilquadrat-normal';
  230.                     $thumb_name_quadrat_retina 'teaser-querformat-mobilquadrat-retina';
  231.                     $teaser_headline_small = (string)$frontendhelper->changeTextarea(AppBundle::getValue($obj'getHeadline_small'));
  232.                     $teaser_button_text = (string)$frontendhelper->changeTextarea(AppBundle::getValue($obj'getButton_text'));
  233.                 }
  234.                 $teaser_bild_normalQadrat $teaser_bild_retinaQuadrat "";   
  235.                 if($saison == 'sommer')
  236.                 {
  237.                     $bild_path =  (string)AppBundle::getValue($obj'getBild'); //Default Bild
  238.                 }
  239.                 elseif($saison == 'winter')
  240.                 {
  241.                     $bild_path =  (string)AppBundle::getValue($obj'getBild_saison_winter');
  242.                     if($bild_path == '')
  243.                     {
  244.                         $bild_path = (string) AppBundle::getValue($obj'getBild'); //Default Bild
  245.                     }
  246.                 }
  247.                 else
  248.                 {
  249.                     $bild_path =  (string)AppBundle::getValue($obj'getBild'); //Default Bild
  250.                 }
  251.                 if (is_file($_SERVER["DOCUMENT_ROOT"] . '/var/assets/' $bild_path) && $bild_path != '') {
  252.                     $teaser_bild_obj \Pimcore\Model\Asset::getByPath($bild_path);
  253.                     $teaser_bild__alttag $teaser_bild_obj->getMetadata("alt");
  254.                     if (is_object($teaser_bild_obj)) {
  255.                         $teaser_bild_normal $teaser_bild_obj->getThumbnail($thumb_name_normal);
  256.                         $teaser_bild_retina $teaser_bild_obj->getThumbnail($thumb_name_retina);
  257.                         $teaser_bild_default $teaser_bild_obj->getThumbnail($thumb_name_default);
  258.                         $teaser_bild_normalQadrat $teaser_bild_obj->getThumbnail($thumb_name_quadrat_normal);
  259.                         $teaser_bild_retinaQuadrat $teaser_bild_obj->getThumbnail($thumb_name_quadrat_retina);
  260.                         if ($teaser_bild_normal instanceof Image) {
  261.                             $teaser_bild_normal $teaser_bild_normal->getPath();
  262.                         }
  263.                         if ($teaser_bild_retina instanceof Image) {
  264.                             $teaser_bild_retina $teaser_bild_retina->getPath();
  265.                         }
  266.                         if ($teaser_bild_default instanceof Image) {
  267.                             $teaser_bild_default $teaser_bild_default->getPath();
  268.                         }
  269.                         if ($teaser_bild_normalQadrat instanceof Image) {
  270.                             $teaser_bild_normalQadrat $teaser_bild_normalQadrat->getPath();
  271.                         }
  272.                         if ($teaser_bild_retinaQuadrat instanceof Image) {
  273.                             $teaser_bild_retinaQuadrat $teaser_bild_retinaQuadrat->getPath();
  274.                         }
  275.                     }
  276.                 }
  277.                 if ($obj->geto_className() == 'teaserhochformat') {
  278.                     $teaser[] = array(
  279.                         'show_button_and_ancor' => $show_button,
  280.                         'href_teaser_text' => $href_teaser_text,
  281.                         'href_teaser_link' => $href_teaser_link,
  282.                         'href_teaser_target' => $href_teaser_target,
  283.                         'teaser_headline' => $teaser_headline,
  284.                         'teaser_button_text' => $teaser_button_text,
  285.                         'teaser_text' => $teaser_text,
  286.                         'teaser_bild_normal' => $teaser_bild_normal,
  287.                         'teaser_bild_retina' => $teaser_bild_retina,
  288.                         'teaser_bild_default' => $teaser_bild_default,
  289.                         'teaser_bild__alttag' => $teaser_bild__alttag,
  290.                         'teaser_bild_normalQadrat' => $teaser_bild_normalQadrat,
  291.                         'teaser_bild_retinaQuadrat' => $teaser_bild_retinaQuadrat
  292.                     );
  293.                 } elseif ($obj->geto_className() == 'teaserquerformat') {
  294.                     $teaser[] = array(
  295.                         'show_button_and_ancor' => $show_button,
  296.                         'href_teaser_text' => $href_teaser_text,
  297.                         'href_teaser_link' => $href_teaser_link,
  298.                         'href_teaser_target' => $href_teaser_target,
  299.                         'teaser_headline' => $teaser_headline,
  300.                         'teaser_button_text' => $teaser_button_text,
  301.                         'teaser_headline_small' => $teaser_headline_small,
  302.                         'teaser_bild_normal' => $teaser_bild_normal,
  303.                         'teaser_bild_retina' => $teaser_bild_retina,
  304.                         'teaser_bild_default' => $teaser_bild_default,
  305.                         'teaser_bild__alttag' => $teaser_bild__alttag,
  306.                         'teaser_bild_normalQadrat' => $teaser_bild_normalQadrat,
  307.                         'teaser_bild_retinaQuadrat' => $teaser_bild_retinaQuadrat
  308.                     );
  309.                 }
  310.             }
  311.         }
  312.        // return ['teaser' => $teaser];
  313.         return $this->render($template, ['teaser' => $teaser]);
  314.     }
  315. }