401 lines
No EOL
15 KiB
PHP
401 lines
No EOL
15 KiB
PHP
<?php
|
|
/**
|
|
* @author Ulrich Hecht <ulrich.hecht@hecht-software.de>
|
|
* @date 02/22/2017
|
|
*/
|
|
|
|
namespace AppBundle\Controller;
|
|
|
|
|
|
use AppBundle\Entity\FewoPrice;
|
|
use AppBundle\Entity\Page;
|
|
use AppBundle\Entity\SunstarTravelProgram;
|
|
use AppBundle\Entity\FewoLodgingGroup;
|
|
use AppBundle\Form\TtSearchRequestType;
|
|
use AppBundle\Listener\KernelControllerListener;
|
|
use Doctrine\ORM\EntityManager;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
use AppBundle\Util;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
/**
|
|
* Controller for CMS pages. CMS pages are represented by Page instances (i.e. entries of the page database table).
|
|
* The template property of a Page object defines the action method below. If a travel program is assigned then the
|
|
* travelProgramAction is used. If no template is specified, then the defaultAction is used.
|
|
* If there is no action method, the defaultAction is called and the template name is passed as an argument. A twig
|
|
* file with this template will be rendered in this case.
|
|
*
|
|
* The view templates can be found pages/cms.
|
|
*
|
|
* Also see {@link KernelControllerListener}, which handles routing.
|
|
*
|
|
* @package AppBundle\Controller
|
|
*/
|
|
class CmsController extends Controller
|
|
{
|
|
/**
|
|
* @return EntityManager
|
|
*/
|
|
private function getEntityManager()
|
|
{
|
|
return $this->getDoctrine()->getManager();
|
|
}
|
|
|
|
public function defaultAction(Page $page, $template = 'default')
|
|
{
|
|
return $this->render('default/pages/cms/'. $template .'.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'site_loading' => 'default',
|
|
'page' => $page,
|
|
]);
|
|
}
|
|
|
|
|
|
public function travelGuideAction(Page $page, $template = 'default')
|
|
{
|
|
if(!empty($page->getTemplate())){
|
|
$template = $page->getTemplate();
|
|
}
|
|
|
|
return $this->render('default/pages/cms/'. $template .'.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'site_loading' => 'default',
|
|
'page' => $page,
|
|
]);
|
|
}
|
|
|
|
public function ssSudanTourAction(Page $page, $template = 'default')
|
|
{
|
|
|
|
|
|
$slugs = array(
|
|
'nilschiff-ss-sudan' => [0, 1],
|
|
'bruecke-nilschiff-ss-sudan' => [31, 1],
|
|
'sonnendeck-nilschiff-ss-sudan' => [32, 1],
|
|
'agatha-christie-suite-nilschiff-ss-sudan' => [1, 2],
|
|
'lady-duff-gordon-suite-nilschiff-ss-sudan' => [2, 2],
|
|
'hercule-poirot-kabine-nilschiff-ss-sudan' => [3, 2],
|
|
'gustave-flaubert-kabine-nilschiff-ss-sudan' => [4, 2],
|
|
'herodote-kabine-nilschiff-ss-sudan' => [5, 2],
|
|
'vivant-denon-kabine-nilschiff-ss-sudan' => [6, 2],
|
|
'yacoubian-kabine-nilschiff-ss-sudan' => [7, 2],
|
|
'le-roi-farouk-kabine-nilschiff-ss-sudan' => [8, 2],
|
|
'mariette-auguste-pacha-kabine-nilschiff-ss-sudan' => [9, 2],
|
|
'gerard-de-nerval-kabine-nilschiff-ss-sudan' => [10, 2],
|
|
'ferdinand-de-lesseps-kabine-nilschiff-ss-sudan' => [11, 2],
|
|
'david-roberts-kabine-nilschiff-ss-sudan' => [12, 2],
|
|
'alexandre-le-grand-kabine-nilschiff-ss-sudan' => [14, 2],
|
|
'john-mason-cook-kabine-nilschiff-ss-sudan' => [15, 2],
|
|
'howard-carter-kabine-nilschiff-ss-sudan' => [16, 2],
|
|
'le-venitien-inconnu-kabine-nilschiff-ss-sudan' => [17, 2],
|
|
'suite-18-nilschiff-ss-sudan' => [18, 2],
|
|
'reine-victoria-suite-nilschiff-ss-sudan' => [19, 3],
|
|
'oum-kalsoum-suite-nilschiff-ss-sudan' => [20, 3],
|
|
'naguib-mahfouz-kabine-nilschiff-ss-sudan' => [21, 3],
|
|
'geoffroy-st-hilaire-kabine-nilschiff-ss-sudan' => [22, 3],
|
|
'jean-francois-champollion-kabine-nilschiff-ss-sudan' => [23, 3],
|
|
'samuel-shepheard-kabine-nilschiff-ss-sudan' => [24, 3],
|
|
'bar-nilschiff-ss-sudan' => [33, 3],
|
|
'restaurant-nilschiff-ss-sudan' => [34, 3],
|
|
'maschinenraum-nilschiff-ss-sudan' => [35, 4],
|
|
'kueche-ss-sudan' => [36, 4],
|
|
|
|
);
|
|
$tour_id = 0;
|
|
$tour_tap = 1;
|
|
if(isset($slugs[$page->getSlug()])){
|
|
$tour_id = $slugs[$page->getSlug()][0];
|
|
$tour_tap = $slugs[$page->getSlug()][1];
|
|
}
|
|
|
|
return $this->render('default/pages/cms/'. $page->getTemplate() .'.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'site_loading' => 'default',
|
|
'page' => $page,
|
|
'tour_id' => $tour_id,
|
|
'tour_tap' => $tour_tap,
|
|
]);
|
|
}
|
|
|
|
public function ssSudanAction(Page $page, $template = 'default')
|
|
{
|
|
$repo = $this->getEntityManager()->getRepository('AppBundle:Page');
|
|
|
|
$box_childs = $repo->findParentsWithShowNav(437);
|
|
return $this->render('default/pages/cms/'. $page->getTemplate() .'.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'site_loading' => 'default',
|
|
'page' => $page,
|
|
'box_childs' => $box_childs,
|
|
'tour_id' => 0,
|
|
'tour_tap' => 1,
|
|
]);
|
|
}
|
|
|
|
|
|
public function nilecruiseAction(Page $page, $template = 'nilecruise')
|
|
{
|
|
//read stern 1 + 6
|
|
//read vermittelte
|
|
$repo = $this->getEntityManager()->getRepository('AppBundle:Page');
|
|
$slug_page = $repo->findOneBy(['slug' => 'aegypten-rundreisen']);
|
|
|
|
$childPages = $this->getEntityManager()->getRepository('AppBundle:Page')->getChildrenWithTravelProgramsAndDates($slug_page);
|
|
|
|
$nonMediated = [];
|
|
$mediated = [];
|
|
foreach ($childPages as $childPage)
|
|
{
|
|
if ($childPage->getStatus() == 1 && $childPage->getTravelProgram() &&
|
|
$childPage->getTravelProgram()->getIsMediated())
|
|
{
|
|
$mediated[] = $childPage;
|
|
}
|
|
else
|
|
{
|
|
if(in_array($childPage->getSlug(), ['stern1', 'stern2', 'stern3', 'stern4', 'stern5', 'stern6'])){
|
|
$nonMediated[] = $childPage;
|
|
}
|
|
}
|
|
}
|
|
// We only need a separation if there are mediated AND non mediated travel programs
|
|
if (empty($nonMediated) && !empty($mediated))
|
|
{
|
|
$childPages = $mediated;
|
|
$mediated = null;
|
|
}
|
|
else
|
|
{
|
|
$childPages = $nonMediated;
|
|
}
|
|
|
|
return $this->render('default/pages/cms/'. $page->getTemplate() .'.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'site_loading' => 'default',
|
|
'page' => $page,
|
|
'child_pages' => $childPages,
|
|
'mediated_child_pages' => $mediated,
|
|
]);
|
|
}
|
|
|
|
public function overviewAction(Page $page)
|
|
{
|
|
|
|
$settings = $page->getCmsSettings();
|
|
if (!is_array($settings))
|
|
{
|
|
$settings = [];
|
|
}
|
|
|
|
$fewoLodgingGroupRepo = $this->getEntityManager()->getRepository('AppBundle:FewoLodgingGroup');
|
|
$lodgingGroups = $fewoLodgingGroupRepo->findAll();
|
|
|
|
|
|
return $this->render('default/pages/cms/overview.html.twig', array_merge($settings, [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'site_loading' => 'overview',
|
|
'page' => $page,
|
|
'lodgingGroups' => $lodgingGroups,
|
|
]));
|
|
}
|
|
|
|
public function travelProgramOverviewAction(Page $page)
|
|
{
|
|
$childPages =
|
|
$this->getEntityManager()->getRepository('AppBundle:Page')->getChildrenWithTravelProgramsAndDates($page);
|
|
|
|
$nonMediated = [];
|
|
$mediated = [];
|
|
foreach ($childPages as $childPage)
|
|
{
|
|
if ($childPage->getStatus() == 1 && $childPage->getTravelProgram() &&
|
|
$childPage->getTravelProgram()->getIsMediated())
|
|
{
|
|
$mediated[] = $childPage;
|
|
}
|
|
else
|
|
{
|
|
$nonMediated[] = $childPage;
|
|
}
|
|
}
|
|
// We only need a separation if there are mediated AND non mediated travel programs
|
|
if (empty($nonMediated) && !empty($mediated))
|
|
{
|
|
$childPages = $mediated;
|
|
$mediated = null;
|
|
}
|
|
else
|
|
{
|
|
$childPages = $nonMediated;
|
|
}
|
|
|
|
return $this->render('default/pages/cms/travelProgramOverview.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'site_loading' => 'program',
|
|
'page' => $page,
|
|
'child_pages' => $childPages,
|
|
'mediated_child_pages' => $mediated,
|
|
]);
|
|
}
|
|
|
|
public function traveltainmentAction(Page $page)
|
|
{
|
|
$destination = array_search($page->getBumaDestination(), TtSearchRequestType::$DESTINATION_CHOICES);
|
|
$form = $this->createForm(TtSearchRequestType::class, [
|
|
'topRegion' => $destination ? $destination : null,
|
|
], [
|
|
'country' => $page->getCountry(),
|
|
]);
|
|
|
|
return $this->render('default/pages/cms/traveltainment.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'site_loading' => 'default',
|
|
'page' => $page,
|
|
'show_search_sidebar_widget' => false,
|
|
'tt_search_form' => $form->createView(),
|
|
]);
|
|
}
|
|
|
|
public function travelProgramAction(Page $page)
|
|
{
|
|
$this->getDoctrine()->getRepository('AppBundle:TravelPeriod')->getTrueTravelPeriods($page->getTravelProgram());
|
|
|
|
// replace this example code with whatever you need
|
|
return $this->render('default/pages/cms/travelProgram.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'site_loading' => 'program',
|
|
'page' => $page,
|
|
'show_offers_sidebar_widget' => false,
|
|
'travel_program' => $page->getTravelProgram(),
|
|
]);
|
|
}
|
|
|
|
public function fewoLodgingAction(Page $page)
|
|
{
|
|
$calendarService = $this->container->get('app.lodging_calendar_util');
|
|
$lodging = $page->getFewoLodging();
|
|
|
|
$prices = $lodging->getPricesFilterNow();
|
|
$lodging->setPrices($prices);
|
|
$paddedCalendar = $calendarService->getCalendarWithPadding($calendarService->getMinCalendarEntriesByLodging($lodging));
|
|
if (count($lodging->getPrices()->toArray()) != 0)
|
|
{
|
|
$calendar = $calendarService->calendarAndFillDayStates($paddedCalendar, $lodging);
|
|
// $calendar = $calendarService->mergeWithPaddedCalendar($calendar, $paddedCalendar);
|
|
} else {
|
|
$calendar = $paddedCalendar;
|
|
}
|
|
$imgs = array();
|
|
$imgs_pre = array();
|
|
$imgs_post = array();
|
|
|
|
$lodgingGroup = $lodging->getGroup();
|
|
foreach ($lodgingGroup->getImages() as $image) {
|
|
if($image->getComp() == 'pre'){
|
|
$imgs_pre[] = $image;
|
|
}
|
|
if($image->getComp() == 'post'){
|
|
$imgs_post[] = $image;
|
|
}
|
|
}
|
|
foreach ($lodging->getImages() as $image) {
|
|
$imgs[] = $image;
|
|
}
|
|
|
|
|
|
return $this->render('default/pages/cms/fewoTravelProgram.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'site_loading' => 'program',
|
|
'page' => $page,
|
|
'fewo_lodging' => $lodging,
|
|
'slider_imgs' => array_merge ($imgs_pre, $imgs, $imgs_post),
|
|
//'lodging' => $lodging, //so wurde es im AdminController aufgerufen
|
|
'calendar' => $calendar,
|
|
'show_search_sidebar_widget' => false,
|
|
|
|
]);
|
|
}
|
|
|
|
public function pdfAction(Page $page)
|
|
{
|
|
$travelProgram = $page->getTravelProgram();
|
|
$program_id = $travelProgram->getId();
|
|
|
|
if($program_id != NULL)
|
|
{
|
|
|
|
$url = Util::getBaseUrl().$page->getUrlPath();
|
|
|
|
// Initialisierung
|
|
$pdfObj = $this->container->get('app.pdf');
|
|
$pdfObj->SetMargins(PDF_MARGIN_LEFT, 40, PDF_MARGIN_RIGHT);
|
|
$pdfObj->SetAutoPageBreak(true, 65);
|
|
$pdfObj->AddPage();
|
|
|
|
// Erzeugen des HTML über das Twig-Template
|
|
$pageHTML = $this->render('default/pages/cms/travelProgramPDF.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'page' => $page,
|
|
'show_offers_sidebar_widget' => false,
|
|
'travel_program' => $page->getTravelProgram()
|
|
]);
|
|
|
|
|
|
// Filtern von Hyper-Links
|
|
$filteredContent = preg_replace('#<p><a(.*)>(.*)</a></p>#Uis', '', $pageHTML->getContent());
|
|
$filteredContent = preg_replace('#<a(.*)>#Uis', '', $filteredContent);
|
|
$filteredContent = preg_replace('#</a>#Uis', '', $filteredContent);
|
|
//$filteredContent = str_replace('*', '<img src="https://www.stern-tours.de/images/icons/star-mini.png" />', $filteredContent);
|
|
|
|
|
|
// $filteredContent = str_replace('*', '<img src="/assetic/sun.jpg" height="6" width="6" />', $filteredContent);
|
|
|
|
// Schreiben des HTML
|
|
$pdfObj->writeHTML('<strong>Reiseangebot zu finden unter:</strong><br /><a href="'.$url.'"style="text-decoration: none!; font-size: 10px; color: black;">'.$url.'</a><br />');
|
|
$pdfObj->writeHTML($filteredContent);
|
|
|
|
// Ersetzen der Umlaute
|
|
$germanLetters = array("/ä/","/ö/","/ü/","/Ä/","/Ö/","/Ü/","/ß/");
|
|
$replace = array("ae","oe","ue","Ae","Oe","Ue","ss");
|
|
$filename = preg_replace($germanLetters, $replace, $travelProgram->getTitle());
|
|
|
|
header('Link: <'.$travelProgram->getUrl().'>; rel="canonical"');
|
|
|
|
$pdfObj->Output($filename.'.pdf', 'D');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @param Page $page
|
|
*
|
|
* @return \Symfony\Component\HttpFoundation\Response
|
|
*
|
|
* @todo This is actually the same as overview, but with different sidebar. Utilize cmsSettings field of page entity for such requirements
|
|
*/
|
|
public function jugendreisenAction(Page $page)
|
|
{
|
|
return $this->render('default/pages/cms/overview.html.twig', [
|
|
'page' => $page,
|
|
'site_loading' => 'default',
|
|
'show_search_sidebar_widget' => false,
|
|
'show_offers_sidebar_widget' => false,
|
|
]);
|
|
}
|
|
|
|
public function sunstarAction(Page $page)
|
|
{
|
|
/** @var SunstarTravelProgram[] $sunstarTravelPrograms */
|
|
$sunstarTravelPrograms = $this->getDoctrine()->getRepository('AppBundle:SunstarTravelProgram')
|
|
->findBy(['destination' => $page->getCmsSettings()]);
|
|
|
|
return $this->render('default/pages/cms/sunstar.html.twig', [
|
|
'page' => $page,
|
|
'site_loading' => 'default',
|
|
'show_search_sidebar_widget' => false,
|
|
'show_offers_sidebar_widget' => false,
|
|
'sunstar_travel_programs' => $sunstarTravelPrograms,
|
|
]);
|
|
}
|
|
} |