* Navigation in Sidebar

* Seitenbaum: Jugendreisen und Reisemagazin mit einbeziehen; Ursprüngliche Sortierung berücksichtigen
* Neue Datenbank-Spalten für automatisch generierte Seitenübersichtsboxen und Datenbank
* Unterstützung statisch festgelegter URLs (page.real_url_path) - wird aus SEO-technischen Gründen benötigt, um vorerst die alten URLs zu behalten
* Redirect-Tabelle: Hier können alte URLs mit page-Einträge verknüpft werden. Bei Aufruf so einer URL wird auf die URL der verknüpften page umgeleitet

SQL:

UPDATE page SET template = 'overview' WHERE slug IN ('iran-reisen', 'marokko-urlaub');
UPDATE page SET `order` = 0 WHERE slug = 'aegypten-reisen';
UPDATE page SET `order` = 1 WHERE slug = 'israel-reisen';
UPDATE page SET `order` = 2 WHERE slug = 'jordanien-reisen';
UPDATE page SET `order` = 3 WHERE slug = 'iran-reisen';
UPDATE page SET `order` = 4 WHERE slug = 'marokko-urlaub';
UPDATE page SET `order` = 5 WHERE slug = 'oman-reisen';
UPDATE page SET `order` = 6 WHERE slug = 'tuerkei-urlaub';

UPDATE page SET template = 'overview' WHERE
  (slug IN ('jugendreisen', 'reisemagazin') AND lvl = 0) OR
  (catalog_id IN (6, 14) AND owner = 0);

-- Request URL /create-tree in browser to re-create the page tree

ALTER TABLE page ADD COLUMN real_url_path VARCHAR(200) DEFAULT NULL;
CREATE UNIQUE INDEX UNIQ_140AB620E2652A2A ON page (real_url_path);
UPDATE page p INNER JOIN catalog c ON c.id = p.catalog_id SET p.real_url_path = CONCAT('/', c.slug, '/', p.slug, '.html');

ALTER TABLE page ADD COLUMN box_body TEXT DEFAULT NULL;
ALTER TABLE page ADD COLUMN box_image_url VARCHAR(200) DEFAULT NULL;
ALTER TABLE page ADD COLUMN box_star VARCHAR(255) DEFAULT NULL;
ALTER TABLE page ADD COLUMN box_discount VARCHAR(255) DEFAULT NULL;
ALTER TABLE page ADD COLUMN content_new TEXT DEFAULT NULL AFTER content;

ALTER TABLE page DROP COLUMN preview_image_url;

CREATE TABLE redirect (id INT AUTO_INCREMENT NOT NULL, page_id INT DEFAULT NULL, source_url_path VARCHAR(200) NOT NULL, UNIQUE INDEX UNIQ_C30C9E2B56207465 (source_url_path), INDEX IDX_C30C9E2BC4663E4 (page_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
ALTER TABLE redirect ADD CONSTRAINT FK_C30C9E2BC4663E4 FOREIGN KEY (page_id) REFERENCES page (id);
ALTER TABLE redirect MODIFY COLUMN page_id INT NOT NULL;



git-svn-id: http://78.47.251.156/svn/dev/sterntours-3@3293 f459cee4-fb09-11de-96c3-f9c5f16c3c76
This commit is contained in:
uli 2017-02-15 15:36:15 +00:00
parent 03f50fc03c
commit 6bb5c271c6
15 changed files with 596 additions and 125 deletions

View file

@ -78,7 +78,9 @@
<!-- START CONTENT -->
<div class="row">
{% include 'default/components/sidebar.html.twig' %}
{% include 'default/components/sidebar.html.twig' with {
nav_sidebar_widget_block: block('nav_sidebar_widget')
} %}
<div id="content" class="col-md-9 col-sm-8 col-xs-12">
{% block body %}{% endblock %}

View file

@ -19,23 +19,60 @@
<div class="navbar-inner">
<div id="navbar-collapse" class="navbar-left navbar-collapse collapse clearfix">
<ul class="nav navbar-nav">
<li itemprop="name"><a href="#" title="" itemprop="url">Kulturreisen</a></li>
<li itemprop="name"><a href="#" title="" itemprop="url">Usedom Ferienwohnungen</a></li>
<li itemprop="name"><a href="#" title="" itemprop="">Kulturreisen</a></li>
<li itemprop="name">
<a href="https://www.stern-usedom.de" title="Usedom Ferienwohnungen" itemprop="url"
target="_blank"
>
Usedom Ferienwohnungen
</a>
</li>
<li class="dropdown openClick" itemprop="name"><a itemprop="url" href="#" title="" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-menu27"></i></a>
<ul class="dropdown-menu" role="menu">
<li itemprop="name"><a itemprop="url" href="#" title="">Ägypten Rundreisen</a></li>
<li itemprop="name"><a itemprop="url" href="#" title="">Nilkreuzfahrten</a></li>
<li itemprop="name"><a itemprop="url" href="#" title="">Ägypten Badeurlaub</a></li>
<li itemprop="name"><a itemprop="url" href="#" title="">Individuelle Ägyptenreisen</a></li>
<li itemprop="name"><a itemprop="url" href="#" title="">Ägypten Gruppenreisen</a></li>
<li itemprop="name"><a itemprop="url" href="#" title="">Ägypten Lastminute</a></li>
<li itemprop="name"><a itemprop="url" href="#" title="">Nasserseekreuzfahrt</a></li>
<li itemprop="name"><a itemprop="url" href="#" title="">Ägypten Klassenfahrt</a></li>
<li itemprop="name"><a itemprop="url" href="#" title="">Info Ägypten Spezialis</a></li>
<li itemprop="name"><a itemprop="url" href="#" title="">Ägypten Landesinformationen</a></li>
<li itemprop="name"><a itemprop="url" href="#" title="">Ägypten Erfahrungen</a></li>
<li itemprop="name"><a itemprop="url" href="#" title="">Ägypten Reiseführer</a></li>
<li itemprop="name"><a itemprop="url" href="#" title="">Ägypten Reisemagazin</a></li>
{#
{% for nav_page in nav_pages if nav_page.country is empty %}
<li itemprop="name">
<a itemprop="url" href="{{ nav_page.urlPath }}"
title="{{ nav_page.title }}"
>
{{ nav_page.title }}
</a>
</li>
{% endfor %}
#}
<li itemprop="name">
<a itemprop="url" href="/docs/gruppenreisen.html" title="Gruppenreisen">
Gruppenreisen
</a>
</li>
<li itemprop="name">
<a itemprop="url" href="/docs/jugendreisen.html" title="Jugendreisen">
Jugendreisen
</a>
</li>
<li itemprop="name">
<a itemprop="url" href="/docs/reiseversicherung.html" title="Reiseversicherung">
Reiseversicherung
</a>
</li>
<li itemprop="name">
<a itemprop="url" href="/docs/urlaubsinfos.html" title="Reiseführer">
Reiseführer
</a>
</li>
<li itemprop="name">
<a itemprop="url" href="/docs/urlaubsinfos.html" title="Reiseführer">
Reiseführer
</a>
</li>
<li itemprop="name">
<a itemprop="url" href="/docs/reisemagazin.html" title="Reisemagazin">
Reisemagazin
</a>
</li>
</ul>
</li>
</ul><!-- end navbar-left -->
@ -67,7 +104,7 @@
<div class="navbar-subnavi">
<div id="navbar-collapse" class="navbar-left navbar-collapse collapse clearfix subnavi">
<ul class="nav navbar-nav">
{% for nav_page in nav_pages %}
{% for nav_page in nav_pages if nav_page.country is not empty %}
{# @var nav_page \AppBundle\Entity\Page #}
<li class="dropdown" itemprop="name">
<a href="{{ nav_page.urlPath }}" title="{{ nav_page.title }}"

View file

@ -0,0 +1,36 @@
{# @var child_page \AppBundle\Entity\Page #}
<div class="col-md-4 col-sm-4">
<div class="travel-wrapper get-box-link">
<div class="item text-left">
<div class="item-img">
<div class="lb">
{% if child_page.boxStar is not empty %}
<div class="cstar_left">{{ child_page.boxStar|raw }}</div>
{% endif %}
{% if child_page.travelProgram is not empty %}
<div class="cprice">ab {{ child_page.travelProgram.lowestPrice|number_format }} € p.P.</div>
{% endif %}
{% if child_page.boxDiscount is not empty %}
<div class="cdiscount">{{ child_page.boxDiscount|raw }}</div>
{% endif %}
</div>
{% if child_page.travelProgram is not empty and child_page.travelProgram.previewImage is not empty %}
<img src="https://www.sterntours.de/uploads/travel_program/{{ child_page.travelProgram.previewImage.fileNameWithExtension }}"
alt="{{ child_page.title }}"
>
{% else %}
<img src="{{ child_page.boxImageUrl ~ '/bundles/app/images/page1_img1.jpg' }}"
alt="{{ child_page.title }}"
>
{% endif %}
</div>
<div class="box_mid">
<div class="hl5">{{ child_page.title }}</div>
<p>{{ child_page.description }}</p>
</div>
<a class="item-button is-box-link dobble_line" href="{{ child_page.urlPath }}" title="{{ child_page.title }}">
{{ child_page.title }}
</a>
</div>
</div>
</div>

View file

@ -1,5 +1,13 @@
<div id="sidebar" class="col-md-3 col-sm-4 col-xs-12 hidden-xs">
{% if show_nav_sidebar_widget ?? true and page is defined %} {# TODO #}
{% if nav_sidebar_widget_block is empty %}
{{ render(controller('AppBundle:Default:navSidebarWidget', {page: page})) }}
{% else %}
{{ nav_sidebar_widget_block|raw }}
{% endif %}
{% endif %}
<div class="widget clearfix">
<div class="widget-title">
TOP bewertet

View file

@ -0,0 +1,36 @@
<div class="widget clearfix">
<div class="widget-title visible-xs">
<a class="collapse-widget" href="#side-navigation" data-toggle="collapse">Reiseziele</a>
</div><!-- end title -->
<nav id="side-navigation" class="navbar collapse in" role="navigation" itemscope
itemtype="https://schema.org/SiteNavigationElement"
>
<ul class="side-menu" role="menu">
{% for nav_page in nav_pages if nav_page.status == 1 and nav_page.showInNavi == 1 %}
<li {% if nav_page == nav_open_node or nav_page == page %}class ="active"{% endif %} itemprop="name">
<a itemprop="url" href="{{ nav_page.urlPath }}" title="{{ nav_page.title }}">
{{ nav_page.title }}
</a>
</li>
{% if nav_page == nav_open_node %}
{% for nav_child_page in nav_child_pages if nav_child_page.status == 1 and nav_child_page.showInNavi == 1 %}
<li class="sub-menu-item{% if nav_child_page == page %} active{% endif %}" itemprop="name">
<i class="fa fa-star"></i>
<a itemprop="url" href="{{ nav_child_page.urlPath }}" title="{{ nav_child_page.title }}">
{{ nav_child_page.title }}
</a>
</li>
{% endfor %}
{% endif %}
{% endfor %}
</ul>
</nav>
</div>

View file

@ -1,5 +1,9 @@
{% extends 'base.html.twig' %}
{% block nav_sidebar_widget %}
{% include 'default/components/sidebar/navSidebarWidget.html.twig' %}
{% endblock %}
{% block body %}
<section class="clearfix">
<div class="hl2">{{ page.pagetitle ?? page.title }}</div>
@ -7,22 +11,9 @@
{#{% for i in 0..page.children|length//3 %}#}
<div class="row">
{% for child_page in page.children if child_page.status == 1 %}
<div class="col-md-4 col-sm-4">
<div class="travel-wrapper get-box-link">
<div class="item text-left">
<div class="item-img">
<img src="{{ child_page.previewImageUrl ?? '/bundles/app/images/page1_img'~ (random(3)+1) ~'.jpg' }}" alt="{{ child_page.title }}">
</div>
<div class="box_mid">
<div class="hl5">{{ child_page.title }}</div>
<p>{{ child_page.description }}</p>
</div>
<a class="item-button is-box-link" href="{{ child_page.urlPath }}" title="{{ child_page.title }}">
{{ child_page.title }}
</a>
</div>
</div>
</div>
{% include 'default/components/pageBox.html.twig' %}
{% endfor %}
</div>
</section>

View file

@ -7,34 +7,9 @@
{#{% for i in 0..page.children|length//3 %}#}
<div class="row">
{% for child_page in child_pages if child_page.status == 1 and child_page.travelProgram is defined %}
{# @var child_page \AppBundle\Entity\Page #}
<div class="col-md-4 col-sm-4">
<div class="travel-wrapper get-box-link">
<div class="item text-left">
<div class="item-img">
<div class="lb">
{% if child_page.travelProgram.id > 0 and child_page.travelProgram.id <= 10 %}
<div class="cstar_left">{{ child_page.travelProgram.id }}</div>
{% endif %}
<div class="cprice">ab {{ child_page.travelProgram.lowestPrice|number_format }} € p.P.</div>
<div class="cdiscount">Frühbucherrabatt</div>
</div>
{% if child_page.travelProgram.previewImage is defined %}
<img src="https://www.sterntours.de/uploads/travel_program/{{ child_page.travelProgram.previewImage.fileNameWithExtension }}"
alt="{{ child_page.title }}"
>
{% endif %}
</div>
<div class="box_mid">
<div class="hl5">{{ child_page.title }}</div>
<p>{{ child_page.description }}</p>
</div>
<a class="item-button is-box-link" href="{{ child_page.urlPath }}" title="{{ child_page.title }}">
{{ child_page.title }}
</a>
</div>
</div>
</div>
{% include 'default/components/pageBox.html.twig' %}
{% endfor %}
</div>
</section>

View file

@ -80,7 +80,7 @@ class BookingController extends Controller
$bookingPriceInfo = [];
$totalPrice = $this->calculatePrice($travelDate, $bookingRequest, $htmlSummary, $bookingPriceInfo);
if ($action == 'buchen')
if ($action == '/buchen')
{
$breadcrumbEntries = Util::createBreadcrumb($travelProgramPage);
$breadcrumbEntries[] = new BreadcrumbEntry('Buchen', $travelProgramPage->getUrlPath() .'/buchen');
@ -119,8 +119,7 @@ class BookingController extends Controller
$this->renderView('default/email/bookingServiceEmail.txt.twig', [
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
'crm_url' => $crmBookingUrl .'/edit',
'travel_program_url' => 'http' . (($_SERVER['SERVER_PORT'] == 443) ? 's://' : '://') .
$_SERVER['HTTP_HOST'] . $travelProgramPage->getUrlPath(),
'travel_program_url' => Util::getBaseUrl() . $travelProgramPage->getUrlPath(),
'booking_request' => $bookingRequest,
'booking_price_info' => $bookingPriceInfo,
'travel_date' => $travelDate,
@ -150,7 +149,7 @@ class BookingController extends Controller
'total_price' => $totalPrice
]);
}
elseif ($action == 'berechne-gesamtpreis')
elseif ($action == '/berechne-gesamtpreis')
{
return $this->render('default/components/booking/summary.html.twig', [
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,

View file

@ -56,8 +56,14 @@ class DefaultController extends Controller
public function cmsOverviewAction(Page $page)
{
return $this->render('default/pages/overview.html.twig', [
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
'page' => $page
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
'page' => $page,
// #WORKAROUND Special navigation logic here adapted from the old website: Don't show child entries
// #TODO Only applies at level 0
'nav_pages' => $page->getChildren(),
'nav_child_pages' => [],
'nav_open_node' => null
]);
}
@ -126,7 +132,7 @@ class DefaultController extends Controller
->where('page.status > 0')
->andWhere('page.template = \'overview\'')
->andWhere('page.lvl = 0')
->orderBy('page.title,childPage.title')
->orderBy('page.lft,page.title,childPage.lft,childPage.title')
->getQuery()
->execute()
;
@ -144,6 +150,39 @@ class DefaultController extends Controller
]);
}
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())
{
$view['nav_pages'] = $pageRepo->getSiblings($page);
$view['nav_child_pages'] = $pageRepo->getChildren($page);
$view['nav_open_node'] = $page;
}
else
{
$parent = $page->getParent();
if ($parent)
{
$view['nav_pages'] = $pageRepo->getSiblings($parent);
$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);
}
/*
Suche Kindknoten
Für jeden Kindknoten
@ -178,11 +217,23 @@ class DefaultController extends Controller
}
$em->beginTransaction();
// Add missing owner relation for catalog root pages (e.g. children of 'aegypten-reisen')
$em->getConnection()->executeUpdate('UPDATE page SET owner = 47 WHERE catalog_id = 3 AND owner = 0');
$em->getConnection()->executeUpdate('UPDATE page SET owner = 66 WHERE catalog_id = 6 AND owner = 0');
$em->getConnection()->executeUpdate('UPDATE page SET owner = 2803 WHERE catalog_id = 14 AND owner = 0');
$lft = 0;
$this->createTree(0, $lft, 0);
$em->commit();
$em->flush();
// Reset the owner field to avoid problems in the old website
$em->getConnection()->executeUpdate('UPDATE page SET owner = 0 WHERE parent_id = 47 AND catalog_id = 3');
$em->getConnection()->executeUpdate('UPDATE page SET owner = 0 WHERE parent_id = 66 AND catalog_id = 6');
$em->getConnection()->executeUpdate('UPDATE page SET owner = 0 WHERE parent_id = 2803 AND catalog_id = 14');
$em->commit();
die("DONE.");
}
@ -196,7 +247,8 @@ class DefaultController extends Controller
{
$qb->orWhere('p.owner IS NULL');
}
$qb->orderBy('p.title');
$qb->orderBy('p.order');
$qb->addOrderBy('p.title');
$pages = $qb->getQuery()->execute();
foreach ($pages as $page)
{

View file

@ -160,6 +160,13 @@ class Page
*/
private $content;
/**
* @ORM\Column(type="text", length=65535, nullable=true)
*
* @todo Remove this field as soon as the new page is launched and instead use "content" again
*/
protected $contentNew;
/**
* @var string
*
@ -238,10 +245,30 @@ class Page
*/
protected $template;
/**
* @ORM\Column(type="string", length=200, nullable=true, unique=true)
*/
protected $realUrlPath;
/**
* @ORM\Column(type="string", length=65535, nullable=true)
*/
protected $boxBody;
/**
* @ORM\Column(type="string", length=200, nullable=true)
*/
protected $boxImageUrl;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $previewImageUrl;
protected $boxStar;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $boxDiscount;
/**
@ -553,7 +580,31 @@ class Page
*/
public function getContent()
{
return $this->content;
return $this->contentNew ?? $this->content;
}
/**
* Set contentNew
*
* @param string $contentNew
*
* @return Page
*/
public function setContentNew($contentNew)
{
$this->contentNew = $contentNew;
return $this;
}
/**
* Get contentNew
*
* @return string
*/
public function getContentNew()
{
return $this->contentNew;
}
/**
@ -991,30 +1042,6 @@ class Page
return $this->template;
}
/**
* Set previewImageUrl
*
* @param string $previewImageUrl
*
* @return Page
*/
public function setPreviewImageUrl($previewImageUrl)
{
$this->previewImageUrl = $previewImageUrl;
return $this;
}
/**
* Get previewImageUrl
*
* @return string
*/
public function getPreviewImageUrl()
{
return $this->previewImageUrl;
}
/**
* Set travelProgram
*
@ -1039,8 +1066,29 @@ class Page
return $this->travelProgram;
}
/**
* @param string|null $realUrlPath
*
* @return Page
*/
public function setRealUrlPath($realUrlPath)
{
$this->realUrlPath = $realUrlPath;
return $this;
}
public function getRealUrlPath()
{
return $this->realUrlPath;
}
public function getUrlPath()
{
if ($this->realUrlPath !== null)
{
return $this->realUrlPath;
}
$urlParts = [];
$page = $this;
do
@ -1050,4 +1098,105 @@ class Page
} while ($page !== null);
return '/'. implode('/', array_reverse($urlParts));
}
/**
* Set boxBody
*
* @param string $boxBody
*
* @return Page
*/
public function setBoxBody($boxBody)
{
$this->boxBody = $boxBody;
return $this;
}
/**
* Get boxBody
*
* @return string
*/
public function getBoxBody()
{
return $this->boxBody;
}
/**
* Set boxImageUrl
*
* @param string $boxImageUrl
*
* @return Page
*/
public function setBoxImageUrl($boxImageUrl)
{
$this->boxImageUrl = $boxImageUrl;
return $this;
}
/**
* Get boxImageUrl
*
* @return string
*/
public function getBoxImageUrl()
{
return $this->boxImageUrl;
}
/**
* Set boxStar
*
* @param string $boxStar
*
* @return Page
*/
public function setBoxStar($boxStar)
{
$this->boxStar = $boxStar;
return $this;
}
/**
* Get boxStar
*
* @return string
*/
public function getBoxStar()
{
return $this->boxStar;
}
/**
* Set boxDiscount
*
* @param string $boxDiscount
*
* @return Page
*/
public function setBoxDiscount($boxDiscount)
{
$this->boxDiscount = $boxDiscount;
return $this;
}
/**
* Get boxDiscount
*
* @return string
*/
public function getBoxDiscount()
{
return $this->boxDiscount;
}
public function getHasChildren()
{
return $this->lft != null && $this->rgt != null && $this->rgt - $this->lft > 1;
}
}

View file

@ -40,4 +40,25 @@ class PageRepository extends NestedTreeRepository
}
return $pages;
}
/**
* @param Page $page
*
* @return Page[]|\Doctrine\Common\Collections\Collection
*/
public function getSiblings(Page $page)
{
$parent = $page->getParent();
if (!$parent)
{
// #TODO Return all root pages
return [];
}
$siblings = $parent->getChildren();
foreach ($siblings as &$sibling)
{
$sibling->setParent($parent);
}
return $siblings;
}
}

View file

@ -0,0 +1,96 @@
<?php
/**
* @author Ulrich Hecht <ulrich.hecht@hecht-software.de>
* @date 02/15/2017
*/
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Redirect
*
* @ORM\Table(name="redirect")
* @ORM\Entity(repositoryClass="AppBundle\Entity\RedirectRepository")
*/
class Redirect
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\Column(type="string", length=200, nullable=false, unique=true)
*/
private $sourceUrlPath;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Page")
* @ORM\JoinColumn(name="page_id", referencedColumnName="id", nullable=false)
*/
protected $page;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set sourceUrlPath
*
* @param string $sourceUrlPath
*
* @return Redirect
*/
public function setSourceUrlPath($sourceUrlPath)
{
$this->sourceUrlPath = $sourceUrlPath;
return $this;
}
/**
* Get sourceUrlPath
*
* @return string
*/
public function getSourceUrlPath()
{
return $this->sourceUrlPath;
}
/**
* Set page
*
* @param \AppBundle\Entity\Page $page
*
* @return Redirect
*/
public function setPage(\AppBundle\Entity\Page $page = null)
{
$this->page = $page;
return $this;
}
/**
* Get page
*
* @return \AppBundle\Entity\Page
*/
public function getPage()
{
return $this->page;
}
}

View file

@ -0,0 +1,13 @@
<?php
namespace AppBundle\Entity;
/**
* RedirectRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class RedirectRepository extends \Doctrine\ORM\EntityRepository
{
}

View file

@ -11,6 +11,9 @@ use AppBundle\AppBundle;
use AppBundle\Controller\DefaultController;
use AppBundle\Entity\Page;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\PersistentCollection;
use Symfony\Bundle\FrameworkBundle\Routing\Router;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
@ -18,11 +21,14 @@ class KernelControllerListener
{
private $em;
private $controllerResolver;
private $router;
public function __construct(EntityManager $entityManager, ControllerResolverInterface $controllerResolver)
public function __construct(EntityManager $entityManager, ControllerResolverInterface $controllerResolver,
Router $router)
{
$this->em = $entityManager;
$this->controllerResolver = $controllerResolver;
$this->router = $router;
}
public function onKernelController(FilterControllerEvent $event)
@ -32,36 +38,89 @@ class KernelControllerListener
{
$repo = $this->em->getRepository('AppBundle:Page');
$path = preg_replace('/^\/?(.*?)\/?$/', '$1', $request->getPathInfo());
$pathArray = explode('/', $path);
/** @var Page $node */
$node = null;
for ($i = 0; $i < count($pathArray); ++$i)
// Try to find by url path. It's possible that the path consists of two parts:
// - the beginning part represents a node
// - the ending part represents a handler
// e.g. /path/to/travel/program/buchen ("buchen" is the handler part)
$pathArray = explode('/', $path);
$restOfPath = '';
$curPath = $path;
while (!empty($pathArray))
{
$qb = $repo->createQueryBuilder('p');
$qb->where($qb->expr()->eq('p.lvl', $i));
$qb->andWhere($qb->expr()->eq('p.slug', ':slug'));
$qb->setParameter('slug', $pathArray[$i]);
if ($node != null)
{
$qb->andWhere($qb->expr()->between('p.lft', $node->getLft(), $node->getRgt()));
}
$qb->setMaxResults(1);
$node = $qb->getQuery()->getOneOrNullResult();
if (!$node)
$node = $repo->findOneBy(['realUrlPath' => '/'. $curPath]);
if ($node)
{
break;
}
if (isset($parentNode))
{
// Avoid database calls to parent later
$node->setParent($parentNode);
}
$parentNode = $node;
$restOfPath = '/'. array_pop($pathArray) . $restOfPath;
$curPath = implode('/', $pathArray);
}
if (!$node)
{
// Now try to find a page by tracing a page node path using the page nodes' slugs
$pathArray = explode('/', $path);
$i = 0;
while (!empty($pathArray))
{
$slug = array_shift($pathArray);
$restOfPath = '/'. implode('/', $pathArray);
$qb = $repo->createQueryBuilder('p');
$qb->where($qb->expr()->eq('p.lvl', $i));
$qb->andWhere($qb->expr()->eq('p.slug', ':slug'));
$qb->setParameter('slug', $slug);
if ($node != null)
{
$qb->andWhere($qb->expr()->between('p.lft', $node->getLft(), $node->getRgt()));
}
$qb->setMaxResults(1);
$childNode = $qb->getQuery()->getOneOrNullResult();
if (!$childNode)
{
break;
}
if ($node)
{
// Avoid database calls to parent later
$childNode->setParent($node);
}
$node = $childNode;
++$i;
}
}
if (!$node)
{
// Search for a redirect entry
$redirect = $this->em->getRepository('AppBundle:Redirect')->findOneBy(['sourceUrlPath' => '/'. $path]);
if ($redirect)
{
$redirectUrl = $redirect->getPage()->getUrlPath();
$event->setController(function() use ($redirectUrl) {
return new RedirectResponse($redirectUrl, 301);
});
return;
}
}
if ($node)
{
$request->attributes->set('page', $node);
if ($node->getTravelProgram() != null)
if ($restOfPath && $node->getTravelProgram() != null && (
$restOfPath == '/buchen' || $restOfPath == '/berechne-gesamtpreis'))
{
// Special case: Booking actions
$request->attributes->set('travelProgramPage', $node);
$request->attributes->set('action', $restOfPath);
$request->attributes->set('_controller', 'AppBundle:Booking:index');
}
elseif ($node->getTravelProgram() != null)
{
$request->attributes->set('_controller', 'AppBundle:Default:cmsTravelProgram');
}
@ -71,13 +130,6 @@ class KernelControllerListener
$request->attributes->set('_controller', 'AppBundle:Default:'. $handler);
}
}
elseif (isset($parentNode) && $parentNode->getTravelProgram() != null && (
$pathArray[$i] == 'buchen' || $pathArray[$i] == 'berechne-gesamtpreis'))
{
$request->attributes->set('travelProgramPage', $parentNode);
$request->attributes->set('action', $pathArray[$i]);
$request->attributes->set('_controller', 'AppBundle:Booking:index');
}
else
{
return;

View file

@ -35,6 +35,11 @@ class Util
$prop->setValue($entity, $collection);
}
public static function getBaseUrl()
{
return 'http' . (($_SERVER['SERVER_PORT'] == 443) ? 's://' : '://') .$_SERVER['HTTP_HOST'];
}
public static function formatPrice($value)
{
return number_format($value, 2, ',', '.') .' €';
@ -46,7 +51,6 @@ class Util
global $kernel;
$ch = curl_init();
$headerList = array();
//self::buildHttpQueryForCurl($headers, $headerList); //?
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url);