* Update auf Twig 2 (notwendig, da block() bei Twig 1 '' statt null zurückgibt. Somit kann nicht unterschieden werden, ob ein Block nicht definiert wurde oder leer ist; das ist wiederum notwendig, damit Templates die Blöcke in sidebar.html.twig auch mit leerem Inhalt überschreiben können)

* Symfony-Update
* Behoben: Reisemagazin/-führer Slider zeigt deaktivierte Seiten an; Begrenzung auf 3 Einträge entfernt
* Behoben: Angebote werden nicht überall angezeigt
* Land einer Seite von übergeordneten Seiten erben (getEffectiveCountry())
* Seitentemplate "offers": Diese Seiten haben unten im Body ein Angebots-Karusell
* Templates ohne Controller action werden jetzt unterstützt. Falls keine Action existiert, wird einfach ein gleichnamiges twig-Template gerendert

git-svn-id: http://78.47.251.156/svn/dev/sterntours-3@3303 f459cee4-fb09-11de-96c3-f9c5f16c3c76
This commit is contained in:
uli 2017-02-22 12:03:49 +00:00
parent bf69f20a50
commit ce292748fb
14 changed files with 662 additions and 288 deletions

View file

@ -17,6 +17,8 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
* 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.
*
@ -34,9 +36,9 @@ class CmsController extends Controller
return $this->getDoctrine()->getManager();
}
public function defaultAction(Page $page)
public function defaultAction(Page $page, $template = 'default')
{
return $this->render('default/pages/cms/default.html.twig', [
return $this->render('default/pages/cms/'. $template .'.html.twig', [
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
'page' => $page,
]);

View file

@ -126,7 +126,7 @@ class ComponentController extends Controller
$rootPage = $repo->find(13);
$pages = $repo->getChildrenQueryBuilder($rootPage)
->andWhere('IDENTITY(node.country) = '. $country->getId())
->setMaxResults(3)
->andWhere('node.status > 0')
->getQuery()
->execute()
;
@ -142,7 +142,7 @@ class ComponentController extends Controller
$rootPage = $repo->find(2803);
$pages = $repo->getChildrenQueryBuilder($rootPage)
->andWhere('IDENTITY(node.country) = '. $country->getId())
->setMaxResults(3)
->andWhere('node.status > 0')
->getQuery()
->execute()
;
@ -152,12 +152,27 @@ class ComponentController extends Controller
]);
}
public function offersSidebarWidgetAction(TravelCountry $country)
public function offersSidebarWidgetAction(TravelCountry $country = null)
{
$pages = $this->getEntityManager()->getRepository('AppBundle:Page')->findWithTravelProgramsOfCountry($country);
return $this->render('default/components/sidebar/pageSliderSidebarWidget.html.twig', [
'slider_title' => 'Angebote',
'pages' => $pages
'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)
;
}
}

View file

@ -40,9 +40,9 @@ class DefaultController extends Controller
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
'canonical_url' => Util::getBaseUrl() .'/',
'show_search_sidebar_widget' => false,
'show_offers_sidebar_widget' => false,
'search_form' => $this->createForm(SearchRequestType::class)->createView(),
'tt_search_form' => $this->createForm(TtSearchRequestType::class)->createView(),
'offers' => $this->getEntityManager()->getRepository('AppBundle:Page')->findOffers(),
'country_pages' => $this->getEntityManager()->getRepository('AppBundle:Page')->findCountryPages(),
]);
}
@ -202,6 +202,27 @@ class DefaultController extends Controller
]);
}
/**
* @Route("/sitemap")
*/
public function sitemapAction()
{
$repo = $this->getDoctrine()->getRepository('AppBundle:Page');
$rootNodes = $repo->getRootNodesQueryBuilder()
->andWhere('node.status = 1')
->andWhere('node.lvl = 0')
->getQuery()
->execute()
;
//$rootNodes[0]->
/** @var Page $node */
foreach ($rootNodes as $rootNode)
{
// #TODO
$repo->childrenHierarchy($rootNode);
}
}
/*
Suche Kindknoten
Für jeden Kindknoten

View file

@ -1199,4 +1199,20 @@ class Page
{
return $this->lft != null && $this->rgt != null && $this->rgt - $this->lft > 1;
}
/**
* @return TravelCountry|null The country. If no country is set, trace the ancestor page nodes for a country.
*/
public function getEffectiveCountry()
{
$node = $this;
do
{
if ($node->getCountry())
{
return $node->getCountry();
}
} while ($node = $node->getParent());
return null;
}
}

View file

@ -135,13 +135,26 @@ class KernelControllerListener
{
$handler = $node->getTemplate() ? ucfirst($node->getTemplate()) : 'Default';
$request->attributes->set('_controller', 'AppBundle:Cms:'. $handler);
if ($node->getTemplate())
{
try
{
$controller = $this->controllerResolver->getController($request);
}
catch (\LogicException $e)
{
// If there is no controller action, call the default action and pass the template name
$request->attributes->set('_controller', 'AppBundle:Cms:Default');
$request->attributes->set('template', $node->getTemplate());
}
}
}
}
else
{
return;
}
$event->setController($this->controllerResolver->getController($request));
$event->setController($controller ?? $this->controllerResolver->getController($request));
}
}
}