git-svn-id: http://78.47.251.156/svn/dev/sterntours-3@3286 f459cee4-fb09-11de-96c3-f9c5f16c3c76
227 lines
7 KiB
PHP
227 lines
7 KiB
PHP
<?php
|
|
|
|
namespace AppBundle\Controller;
|
|
|
|
use AppBundle\Entity\Page;
|
|
use AppBundle\Entity\TravelProgram;
|
|
use AppBundle\Util;
|
|
use Doctrine\ORM\EntityManager;
|
|
use Doctrine\ORM\Query\Expr;
|
|
use Gedmo\Tree\TreeListener;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
use Symfony\Component\Stopwatch\Stopwatch;
|
|
|
|
class DefaultController extends Controller
|
|
{
|
|
/**
|
|
* @return EntityManager
|
|
*/
|
|
public function getEntityManager()
|
|
{
|
|
return $this->getDoctrine()->getManager();
|
|
}
|
|
|
|
public function defaultAction(Request $request)
|
|
{
|
|
// #TODO 404
|
|
die ("caught");
|
|
}
|
|
|
|
/**
|
|
* @Route("/")
|
|
*/
|
|
public function homeAction()
|
|
{
|
|
//$departures = $this->getEntityManager()->getRepository('AppBundle:TravelDeparturePoint')->findAll();
|
|
$destinations = $this->getEntityManager()->getRepository('AppBundle:TravelCountry')->findAll();
|
|
|
|
return $this->render('default/pages/home.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'destinations' => $destinations,
|
|
'startDate' => new \DateTime('+5 day'),
|
|
'endDate' => new \DateTime('+19 day')
|
|
]);
|
|
}
|
|
|
|
public function cmsDefaultAction(Page $page)
|
|
{
|
|
return $this->render('default/pages/default.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'page' => $page
|
|
]);
|
|
}
|
|
|
|
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
|
|
]);
|
|
}
|
|
|
|
public function cmsTravelProgramOverviewAction(Page $page)
|
|
{
|
|
$childPages =
|
|
$this->getEntityManager()->getRepository('AppBundle:Page')->getChildrenWithTravelProgramsAndDates($page);
|
|
|
|
return $this->render('default/pages/travelProgramOverview.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'page' => $page,
|
|
'child_pages' => $childPages
|
|
]);
|
|
}
|
|
|
|
public function cmsTravelProgramAction(Page $page)
|
|
{
|
|
$this->getDoctrine()->getRepository('AppBundle:TravelPeriod')->getTrueTravelPeriods($page->getTravelProgram());
|
|
|
|
// replace this example code with whatever you need
|
|
return $this->render('default/pages/travelProgram.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'page' => $page,
|
|
'travel_program' => $page->getTravelProgram()
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @Route("/suche")
|
|
*/
|
|
public function searchAction(Request $request)
|
|
{
|
|
$stopwatch = $this->get('debug.stopwatch');
|
|
$em = $this->getEntityManager();
|
|
|
|
$destinationIds = null;
|
|
$destination = $em->getRepository('AppBundle:TravelCountry')->find($request->query->get('c'));
|
|
if ($destination)
|
|
{
|
|
$destinationsIds = [$destination->getId()];
|
|
}
|
|
$startDate = $request->query->has('b')
|
|
? \DateTime::createFromFormat('d.m.Y', $request->query->get('b'))
|
|
: new \DateTime();
|
|
$endDate = \DateTime::createFromFormat('d.m.Y', $request->query->get('e'));
|
|
|
|
$stopwatch->start('search');
|
|
$r = $this->getDoctrine()->getRepository('AppBundle:TravelPeriod')->getTravelProgramsWithTravelDatesForTimePeriod(
|
|
$startDate, $endDate, $destinationIds, true);
|
|
$stopwatch->stop('search');
|
|
|
|
return $this->render('default/pages/search.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'travel_programs' => $r
|
|
]);
|
|
}
|
|
|
|
public function headerAction()
|
|
{
|
|
$qb = $this->getEntityManager()->createQueryBuilder();
|
|
$navPages = $qb
|
|
->from('AppBundle:Page', 'page')
|
|
->select('page')
|
|
->leftJoin('page.children', 'childPage', Expr\Join::WITH, 'childPage.status > 0')
|
|
->addSelect('childPage')
|
|
->where('page.status > 0')
|
|
->andWhere('page.template = \'overview\'')
|
|
->andWhere('page.lvl = 0')
|
|
->orderBy('page.title,childPage.title')
|
|
->getQuery()
|
|
->execute()
|
|
;
|
|
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)
|
|
]);
|
|
}
|
|
|
|
/*
|
|
Suche Kindknoten
|
|
Für jeden Kindknoten
|
|
++LFT
|
|
Setze LFT
|
|
f()
|
|
++LFT
|
|
RGT = LFT
|
|
Setze RGT
|
|
*/
|
|
|
|
/**
|
|
* @Route("/create-tree")
|
|
*/
|
|
public function createTreeAction()
|
|
{
|
|
set_time_limit(0);
|
|
ini_set('memory_limit', '2048M');
|
|
|
|
$em = $this->getEntityManager();
|
|
|
|
$em->getConnection()->executeUpdate(
|
|
'UPDATE page SET lvl = NULL, lft = NULL, rgt = NULL, parent_id = NULL, tree_root = NULL');
|
|
|
|
foreach ($em->getEventManager()->getListeners() as $event => $listeners) {
|
|
foreach ($listeners as $hash => $listener) {
|
|
if ($listener instanceof TreeListener)
|
|
{
|
|
$em->getEventManager()->removeEventListener($event, $listener);
|
|
}
|
|
}
|
|
}
|
|
|
|
$em->beginTransaction();
|
|
$lft = 0;
|
|
$this->createTree(0, $lft, 0);
|
|
$em->commit();
|
|
$em->flush();
|
|
|
|
die("DONE.");
|
|
}
|
|
|
|
private function createTree($owner, &$lft, $lvl, $root = null)
|
|
{
|
|
$em = $this->getEntityManager();
|
|
|
|
$qb = $em->createQueryBuilder()->from('AppBundle:Page', 'p')->select('p');
|
|
$qb->where($qb->expr()->eq('p.owner', $owner));
|
|
if ($owner == 0)
|
|
{
|
|
$qb->orWhere('p.owner IS NULL');
|
|
}
|
|
$qb->orderBy('p.title');
|
|
$pages = $qb->getQuery()->execute();
|
|
foreach ($pages as $page)
|
|
{
|
|
/** @var Page $page */
|
|
|
|
if ($owner == 0)
|
|
{
|
|
$root = $page->getId();
|
|
}
|
|
|
|
++$lft;
|
|
$page->setLft($lft);
|
|
$page->setLvl($lvl);
|
|
$page->setRoot($em->getReference('AppBundle:Page', $root));
|
|
if ($owner != 0)
|
|
{
|
|
$page->setParent($em->getReference('AppBundle:Page', $owner));
|
|
}
|
|
|
|
$this->createTree($page->getId(), $lft, $lvl + 1, $root);
|
|
|
|
++$lft;
|
|
$page->setRgt($lft);
|
|
|
|
$em->persist($page);
|
|
}
|
|
}
|
|
}
|