Umstrukturierung:
* CMS-Action-Methoden (also Seiten, die durch page-Eintrag repräsentiert werden) von DefaultController nach CmsController verschoben * Action-Methoden für Wiederverwendbare View-Komponenten (die Controller-Logik benötigen) von DefaultController nach ComponentController verschoben * CMS-Seiten-Templates in den Unterordner "cms" verschoben git-svn-id: http://78.47.251.156/svn/dev/sterntours-3@3302 f459cee4-fb09-11de-96c3-f9c5f16c3c76
This commit is contained in:
parent
4278e110fc
commit
bf69f20a50
12 changed files with 287 additions and 223 deletions
163
trunk/src/AppBundle/Controller/ComponentController.php
Normal file
163
trunk/src/AppBundle/Controller/ComponentController.php
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Controller;
|
||||
|
||||
use AppBundle\Entity\BreadcrumbEntry;
|
||||
use AppBundle\Entity\ContactRequest;
|
||||
use AppBundle\Entity\Page;
|
||||
use AppBundle\Entity\TravelCountry;
|
||||
use AppBundle\Form\ContactRequestType;
|
||||
use AppBundle\Form\SearchRequestType;
|
||||
use AppBundle\Form\TtSearchRequestType;
|
||||
use AppBundle\Util;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Gedmo\Tree\TreeListener;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
/**
|
||||
* @return EntityManager
|
||||
*/
|
||||
public function getEntityManager()
|
||||
{
|
||||
return $this->getDoctrine()->getManager();
|
||||
}
|
||||
|
||||
public function headerAction()
|
||||
{
|
||||
$navPages = $this->getEntityManager()->getRepository('AppBundle:Page')->findTopCountryNavPages();
|
||||
return $this->render('default/components/header.html.twig', [
|
||||
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
||||
'nav_pages' => $navPages,
|
||||
]);
|
||||
}
|
||||
|
||||
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 navSidebarWidgetAction(Page $page)
|
||||
{
|
||||
$pageRepo = $this->getEntityManager()->getRepository('AppBundle:Page');
|
||||
$view = [
|
||||
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
||||
'page' => $page,
|
||||
];
|
||||
|
||||
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/navSidebarWidget.html.twig', $view);
|
||||
}
|
||||
|
||||
public function searchSidebarWidgetAction(Page $page)
|
||||
{
|
||||
$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/searchSidebarWidget.html.twig', [
|
||||
'search_form' => $this->createForm(SearchRequestType::class, [
|
||||
'c' => $destination,
|
||||
'c2' => $combinedDestination,
|
||||
])->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
public function travelGuideSidebarWidgetAction(TravelCountry $country)
|
||||
{
|
||||
$repo = $this->getEntityManager()->getRepository('AppBundle:Page');
|
||||
$rootPage = $repo->find(13);
|
||||
$pages = $repo->getChildrenQueryBuilder($rootPage)
|
||||
->andWhere('IDENTITY(node.country) = '. $country->getId())
|
||||
->setMaxResults(3)
|
||||
->getQuery()
|
||||
->execute()
|
||||
;
|
||||
return $this->render('default/components/sidebar/textSliderSidebarWidget.html.twig', [
|
||||
'slider_title' => 'Reiseführer',
|
||||
'slides' => $pages
|
||||
]);
|
||||
}
|
||||
|
||||
public function travelMagazineSidebarWidgetAction(TravelCountry $country)
|
||||
{
|
||||
$repo = $this->getEntityManager()->getRepository('AppBundle:Page');
|
||||
$rootPage = $repo->find(2803);
|
||||
$pages = $repo->getChildrenQueryBuilder($rootPage)
|
||||
->andWhere('IDENTITY(node.country) = '. $country->getId())
|
||||
->setMaxResults(3)
|
||||
->getQuery()
|
||||
->execute()
|
||||
;
|
||||
return $this->render('default/components/sidebar/textSliderSidebarWidget.html.twig', [
|
||||
'slider_title' => 'Reisemagazin',
|
||||
'slides' => $pages
|
||||
]);
|
||||
}
|
||||
|
||||
public function offersSidebarWidgetAction(TravelCountry $country)
|
||||
{
|
||||
$pages = $this->getEntityManager()->getRepository('AppBundle:Page')->findWithTravelProgramsOfCountry($country);
|
||||
return $this->render('default/components/sidebar/pageSliderSidebarWidget.html.twig', [
|
||||
'slider_title' => 'Angebote',
|
||||
'pages' => $pages
|
||||
]);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue