312 lines
10 KiB
PHP
312 lines
10 KiB
PHP
<?php
|
|
|
|
namespace AppBundle\Controller;
|
|
|
|
use AppBundle\Entity\Page;
|
|
use AppBundle\Entity\TravelCountry;
|
|
use AppBundle\Form\SearchRequestType;
|
|
use AppBundle\Util;
|
|
use Doctrine\ORM\EntityManager;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
|
|
/**
|
|
* Controller for re-usable view components. They are normally included by a render twig-expression. Example:
|
|
*
|
|
* <code>{{ render(controller('AppBundle:Component:travelGuideSidebarWidget', {country: page.country})) }}</code>
|
|
*/
|
|
class ComponentController extends Controller
|
|
{
|
|
|
|
private $headerContent;
|
|
/**
|
|
* @return EntityManager
|
|
*/
|
|
public function getEntityManager()
|
|
{
|
|
return $this->getDoctrine()->getManager();
|
|
}
|
|
|
|
|
|
public function getHeaderContent(){
|
|
|
|
if(!$this->headerContent){
|
|
$this->headerContent = Util::loadFromApi('cms/header/info', ['url'=>""]);
|
|
}
|
|
return $this->headerContent;
|
|
|
|
}
|
|
|
|
public function headerAction()
|
|
{
|
|
$navPages = $this->getEntityManager()->getRepository('AppBundle:Page')->findTopCountryNavPages();
|
|
|
|
$content = $this->getHeaderContent();
|
|
|
|
$local = [];
|
|
foreach ($content->local as $key=>$value){
|
|
$local[$key] = $value;
|
|
}
|
|
|
|
$phone = [];
|
|
foreach ($content->phone as $key=>$value){
|
|
$phone[$key] = $value;
|
|
}
|
|
|
|
|
|
return $this->render('default/components/header.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'nav_pages' => $navPages,
|
|
'content' => $content,
|
|
'local' => $local,
|
|
'phone' => $phone,
|
|
]);
|
|
}
|
|
|
|
public function footerAction()
|
|
{
|
|
$content = $this->getHeaderContent();
|
|
return $this->render('default/components/footer.html.twig', [
|
|
'content' => $content,
|
|
]);
|
|
}
|
|
|
|
|
|
|
|
public function breadcrumbAction(Page $page)
|
|
{
|
|
return $this->render('default/components/breadcrumb.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'breadcrumb_entries' => Util::createBreadcrumb($page),
|
|
]);
|
|
}
|
|
|
|
|
|
public function navSidebarApiWidgetAction($api, $title = 'Reiseführer')
|
|
{
|
|
|
|
return $this->render('default/components/sidebar/navSidebarApiWidgetInner.html.twig', [
|
|
'api'=>$api,
|
|
'title' => "Reiseführer",
|
|
]);
|
|
}
|
|
|
|
public function navSidebarWidgetAction(Page $page, $title = 'Reiseprogramme')
|
|
{
|
|
if(!empty($page->getTitle())){
|
|
$title = $page->getTitle();
|
|
}
|
|
$pageRepo = $this->getEntityManager()->getRepository('AppBundle:Page');
|
|
$view = [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'page' => $page,
|
|
'slider_title' => $title,
|
|
|
|
];
|
|
|
|
if ($page->getHasChildren())
|
|
{
|
|
if ($page->getLvl() == 0)
|
|
{
|
|
$view['nav_pages'] = $page->getChildren();
|
|
|
|
$view['nav_child_pages'] = [];
|
|
}
|
|
else
|
|
{
|
|
$view['nav_pages'] = $pageRepo->getSiblings($page);
|
|
$view['nav_child_pages'] = $page->getChildren();
|
|
}
|
|
$view['nav_open_node'] = $page;
|
|
}
|
|
else
|
|
{
|
|
$parent = $page->getParent();
|
|
if ($parent)
|
|
{
|
|
$view['nav_pages'] = $pageRepo->getSiblings($parent);
|
|
if (empty($view['nav_pages']))
|
|
{
|
|
$view['nav_pages'] = $pageRepo->getSiblings($page);
|
|
}
|
|
else
|
|
{
|
|
$view['nav_child_pages'] = $pageRepo->getSiblings($page);
|
|
}
|
|
$view['nav_open_node'] = $parent;
|
|
}
|
|
else
|
|
{
|
|
$view['nav_pages'] = $pageRepo->getSiblings($page);
|
|
$view['nav_child_pages'] = [];
|
|
$view['nav_open_node'] = null;
|
|
}
|
|
}
|
|
return $this->render('default/components/sidebar/navSidebarWidgetInner.html.twig', $view);
|
|
}
|
|
|
|
public function searchSidebarApiWidgetAction($api, $title = 'Suche')
|
|
{
|
|
$combinedDestination = null;
|
|
$destination = null;
|
|
//todo need Country by name
|
|
if(isset($api->sites[0]->country_id)){
|
|
$repo = $this->getEntityManager()->getRepository('AppBundle:TravelCountry');
|
|
$destination = $repo->find($api->sites[0]->country_id);
|
|
}
|
|
return $this->render('default/components/sidebar/searchSidebarWidgetInner.html.twig', [
|
|
'slider_title' => "suche",
|
|
'search_form' => $this->createForm(SearchRequestType::class, [
|
|
'c' =>$destination,
|
|
'c2' => $combinedDestination,
|
|
])->createView()
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
public function searchSidebarWidgetAction(Page $page, $title = 'Suche')
|
|
{
|
|
$combinedDestination = null;
|
|
if ($page->getTravelProgram())
|
|
{
|
|
$countries = $page->getTravelProgram()->getCountries();
|
|
$destination = $countries->first();
|
|
if (count($countries) > 1)
|
|
{
|
|
$combinedDestination = $countries[1];
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$destination = $page->getCountry();
|
|
}
|
|
|
|
return $this->render('default/components/sidebar/searchSidebarWidgetInner.html.twig', [
|
|
'slider_title' => "suche",
|
|
'search_form' => $this->createForm(SearchRequestType::class, [
|
|
'c' => $destination,
|
|
'c2' => $combinedDestination,
|
|
])->createView()
|
|
]);
|
|
}
|
|
|
|
public function travelGuideSidebarWidgetAction(TravelCountry $country, $title = 'Reiseführer')
|
|
{
|
|
$repo = $this->getEntityManager()->getRepository('AppBundle:Page');
|
|
$rootPage = $repo->find(13);
|
|
$pages = $repo->getChildrenQueryBuilder($rootPage)
|
|
->andWhere('IDENTITY(node.country) = '. $country->getId())
|
|
->andWhere('node.status > 0')
|
|
->getQuery()
|
|
->execute()
|
|
;
|
|
return $this->render('default/components/sidebar/pageSliderSidebarWidget.html.twig', [
|
|
'slider_title' => $title,
|
|
'target_widget' => 'travel-leader-widget',
|
|
'pages' => $pages
|
|
]);
|
|
}
|
|
|
|
public function travelMagazineSidebarWidgetAction(TravelCountry $country, $title = 'Reisemagazin')
|
|
{
|
|
$repo = $this->getEntityManager()->getRepository('AppBundle:Page');
|
|
$rootPage = $repo->find(2803);
|
|
$pages = $repo->getChildrenQueryBuilder($rootPage)
|
|
->andWhere('IDENTITY(node.country) = '. $country->getId())
|
|
->andWhere('node.status > 0')
|
|
->getQuery()
|
|
->execute()
|
|
;
|
|
return $this->render('default/components/sidebar/pageSliderSidebarWidget.html.twig', [
|
|
'slider_title' => $title,
|
|
'target_widget' => 'travel-magazine-widget',
|
|
'pages' => $pages
|
|
]);
|
|
}
|
|
|
|
public function offersSidebarWidgetAction(TravelCountry $country = null, $title = 'Angebote')
|
|
{
|
|
return $this->render('default/components/sidebar/pageSliderSidebarWidget.html.twig', [
|
|
'slider_title' => $title,
|
|
'target_widget' => 'offer-widget',
|
|
'pages' => $this->getOffersByCountry($country),
|
|
]);
|
|
}
|
|
|
|
public function offersCarouselAction(TravelCountry $country = null)
|
|
{
|
|
return $this->render('default/components/multiPageBoxCarousel.html.twig', [
|
|
'pages' => $this->getOffersByCountry($country),
|
|
]);
|
|
}
|
|
|
|
private function getOffersByCountry(TravelCountry $country = null)
|
|
{
|
|
$repo = $this->getDoctrine()->getRepository('AppBundle:Page');
|
|
return $country === null
|
|
? $repo->findOffers()
|
|
: $repo->findWithTravelProgramsOfCountry($country)
|
|
;
|
|
}
|
|
|
|
public function feedbacksSidebarWidgetAction(TravelCountry $country, $title = 'Kundenfeedback')
|
|
{
|
|
return $this->render(':default/components/sidebar:textSliderSidebarWidget.html.twig', [
|
|
'slider_title' => $title,
|
|
'target_widget' => 'feedback-widget',
|
|
'slides' => $this->getDoctrine()->getRepository('AppBundle:Page')->findFeedbacks(
|
|
$country->getFeedbackPage()->getId()),
|
|
'theme' => 'gray-box',
|
|
]);
|
|
}
|
|
|
|
public function makeSidebarWidgetAction($site_loading = 'default', Page $page = null, $api=null, $search_form = null){
|
|
|
|
$show_seal_of_approval = false;
|
|
//default
|
|
switch ($site_loading){
|
|
case 'home' :
|
|
$site = 'home';
|
|
break;
|
|
case 'search' :
|
|
$site = 'search';
|
|
break;
|
|
case 'default' :
|
|
$site = 'default';
|
|
break;
|
|
case 'overview' :
|
|
$site = 'overview';
|
|
break;
|
|
case 'program' :
|
|
$site = 'program';
|
|
break;
|
|
case 'booking' :
|
|
$site = 'booking';
|
|
$show_seal_of_approval = true;
|
|
break;
|
|
case 'bookingconfirm' :
|
|
$site = 'bookingconfirm';
|
|
$show_seal_of_approval = true;
|
|
break;
|
|
default :
|
|
$site = 'default';
|
|
break;
|
|
}
|
|
$sidebarRepo = $this->getEntityManager()->getRepository('AppBundle:SidebarWidget');
|
|
$widgets = $sidebarRepo->findWidgetsBy($site);
|
|
|
|
$vars = [ 'page' => $page,
|
|
'api' => $api,
|
|
'site_loading' => $site_loading,
|
|
'widgets' => $widgets,
|
|
'show_seal_of_approval' => $show_seal_of_approval,
|
|
'loop_half' => ceil(count($widgets) / 2)
|
|
];
|
|
if($search_form != null){
|
|
$vars['search_form'] = $search_form;
|
|
}
|
|
return $this->render(':default/components/sidebar:sidebar.html.twig', $vars);
|
|
|
|
|
|
}
|
|
}
|