* Kontaktformular git-svn-id: http://78.47.251.156/svn/dev/sterntours-3@3300 f459cee4-fb09-11de-96c3-f9c5f16c3c76
482 lines
17 KiB
PHP
482 lines
17 KiB
PHP
<?php
|
|
|
|
namespace AppBundle\Controller;
|
|
|
|
use AppBundle\Entity\BreadcrumbEntry;
|
|
use AppBundle\Entity\ContactRequest;
|
|
use AppBundle\Entity\Page;
|
|
use AppBundle\Entity\TravelProgram;
|
|
use AppBundle\Form\ContactRequestType;
|
|
use AppBundle\Form\SearchRequestType;
|
|
use AppBundle\Form\TtSearchRequestType;
|
|
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)
|
|
{
|
|
throw new $this->createNotFoundException();
|
|
}
|
|
|
|
/**
|
|
* @Route("/")
|
|
*/
|
|
public function homeAction()
|
|
{
|
|
return $this->render('default/pages/home.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'canonical_url' => Util::getBaseUrl() .'/',
|
|
'show_search_sidebar_widget' => false,
|
|
'search_form' => $this->createForm(SearchRequestType::class)->createView(),
|
|
'tt_search_form' => $this->createForm(TtSearchRequestType::class)->createView(),
|
|
]);
|
|
}
|
|
|
|
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);
|
|
|
|
$nonMediated = [];
|
|
$mediated = [];
|
|
foreach ($childPages as $childPage)
|
|
{
|
|
if ($childPage->getStatus() == 1 && $childPage->getTravelProgram() &&
|
|
$childPage->getTravelProgram()->getIsMediated())
|
|
{
|
|
$mediated[] = $childPage;
|
|
}
|
|
else
|
|
{
|
|
$nonMediated[] = $childPage;
|
|
}
|
|
}
|
|
// We only need a separation if there are mediated AND non mediated travel programs
|
|
if (empty($nonMediated) && !empty($mediated))
|
|
{
|
|
$childPages = $mediated;
|
|
}
|
|
else
|
|
{
|
|
$childPages = $nonMediated;
|
|
}
|
|
|
|
return $this->render('default/pages/travelProgramOverview.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'page' => $page,
|
|
'child_pages' => $childPages,
|
|
'mediated_child_pages' => $mediated,
|
|
]);
|
|
}
|
|
|
|
public function cmsTraveltainmentAction(Page $page)
|
|
{
|
|
$form = $this->createForm(TtSearchRequestType::class);
|
|
|
|
return $this->render('default/pages/traveltainment.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'page' => $page,
|
|
'tt_search_form' => $form->createView(),
|
|
]);
|
|
}
|
|
|
|
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)
|
|
{
|
|
$em = $this->getEntityManager();
|
|
|
|
$form = $this->createForm(SearchRequestType::class);
|
|
$form->handleRequest($request);
|
|
|
|
if ($form->isValid())
|
|
{
|
|
$data = $form->getData();
|
|
|
|
$destinationIds = [];
|
|
if (!empty($data['c']))
|
|
{
|
|
$destinationIds = [$data['c']->getId()];
|
|
}
|
|
if (!empty($destinationIds) && !empty($data['c2']))
|
|
{
|
|
$destinationIds[] = $data['c2']->getId();
|
|
}
|
|
|
|
$r = $this->getDoctrine()->getRepository('AppBundle:TravelPeriod')->getTravelProgramsWithTravelDatesForTimePeriod(
|
|
$data['b'], $data['e'], $destinationIds, count($destinationIds) > 1);
|
|
}
|
|
else
|
|
{
|
|
$r = [];
|
|
}
|
|
|
|
return $this->render('default/pages/search.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'breadcrumb_entries' => [new BreadcrumbEntry('Suchen')],
|
|
'search_form' => $form->createView(),
|
|
'travel_programs' => $r,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @Route("/tt-suche")
|
|
*/
|
|
public function ttSearchAction(Request $request)
|
|
{
|
|
$form = $this->createForm(TtSearchRequestType::class);
|
|
$form->handleRequest($request);
|
|
|
|
if ($form->isValid())
|
|
{
|
|
$data = $form->getData();
|
|
|
|
$ttUrl = 'http://www.vidado.com/booking/ibe_bp2/index.php?CID=8ce65750ce5af9d9a6b22c9b04772ea7&formular=4&engine=pauschal&showresult=1';
|
|
$ttUrl .= '&termin=' . $data['termin']->format('d.m.Y');
|
|
$ttUrl .= '&ruecktermin=' . $data['ruecktermin']->format('d.m.Y');
|
|
if (!empty($data['dauer'])) $ttUrl .= '&dauer='. $data['dauer'];
|
|
if (!empty($data['t']))
|
|
{
|
|
$ttUrl .= '&personen=25'. str_repeat(';25', $data['t']);
|
|
for ($i = 0; $i < 3; ++$i)
|
|
{
|
|
if (!empty($data['child'.$i]))
|
|
{
|
|
$ttUrl .= ';'. $data['child'. $i];
|
|
}
|
|
}
|
|
}
|
|
$ttUrl .= '&detail=';
|
|
if (!empty($data['topRegion']) && isset(TtSearchRequestType::$DESTINATION_CHOICES[$data['topRegion']]))
|
|
{
|
|
$ttUrl .= 'hotel&topRegion='. TtSearchRequestType::$DESTINATION_CHOICES[$data['topRegion']];
|
|
}
|
|
else
|
|
{
|
|
$ttUrl .= 'zielgebiet';
|
|
}
|
|
if (!empty($data['abflughafen'])) $ttUrl .= '&abflughafen='. $data['abflughafen'];
|
|
if (!empty($data['shotel'])) $ttUrl .= '&shotel='. urlencode($data['shotel']);
|
|
if (!empty($data['kategorie'])) $ttUrl .= '&kategorie='. $data['kategorie'];
|
|
if (!empty($data['zimmer'])) $ttUrl .= '&zimmer='. $data['zimmer'];
|
|
if (!empty($data['verpflegung'])) $ttUrl .= '&verpflegung='. $data['verpflegung'];
|
|
if (!empty($data['hbfges'])) $ttUrl .= '&hbfges='. $data['hbfges'];
|
|
if (!empty($data['hbfanz'])) $ttUrl .= '&hbfanz='. $data['hbfanz'];
|
|
if (!empty($data['hbfempf'])) $ttUrl .= '&hbfempf='. $data['hbfempf'];
|
|
if ($data['familie_kinder'] ?? false) $ttUrl .= '&familie_kinder=0';
|
|
if ($data['strand'] ?? false) $ttUrl .= '&strand=0';
|
|
if ($data['wellness'] ?? false) $ttUrl .= '&wellness=0';
|
|
if ($data['typ'] ?? false) $ttUrl .= '&typ=0';
|
|
if (!empty($data['sportangebot'])) $ttUrl .= '&sportangebot='. $data['sportangebot'];
|
|
|
|
//die($ttUrl);
|
|
//http://www.vidado.com/booking/ibe_bp2/index.php?CID=8ce65750ce5af9d9a6b22c9b04772ea7&formular=4&engine=pauschal&detail=hotel&showresult=1&termin=26.02.2017&ruecktermin=12.03.2017&dauer=6_14&personen=25;25&abflughafen=-1&topRegion=727
|
|
//http://www.vidado.com/booking/ibe_bp2/index.php?CID=8ce65750ce5af9d9a6b22c9b04772ea7&formular=4&engine=pauschal&detail=zielgebiet&showresult=1&termin=26.02.2017&ruecktermin=12.03.2017&dauer=6_14&personen=25;25&abflughafen=-1&topRegion=
|
|
}
|
|
|
|
return $this->render('default/pages/ttSearch.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'breadcrumb_entries' => [new BreadcrumbEntry('Suchen')],
|
|
'tt_search_form' => $form->createView(),
|
|
'tt_url' => $ttUrl ?? null,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @Route("/kontakt")
|
|
*/
|
|
public function contactAction(Request $request)
|
|
{
|
|
$form = $this->createForm(ContactRequestType::class);
|
|
$breadcrumbEntries = [new BreadcrumbEntry('Kontaktformular')];
|
|
|
|
if ($request->getMethod() == 'POST')
|
|
{
|
|
$form->handleRequest($request);
|
|
|
|
if ($form->isValid())
|
|
{
|
|
/** @var ContactRequest $contactRequest */
|
|
$contactRequest = $form->getData();
|
|
|
|
$crmLeadUrl = $this->get('app.contact_exporter')->process($contactRequest);
|
|
if ($crmLeadUrl)
|
|
{
|
|
$crmLeadUrl = preg_replace('/\\/api\\/lead/', '/leads', $crmLeadUrl) .'/edit';
|
|
}
|
|
else
|
|
{
|
|
$crmLeadUrl = '[Übertragung zum CRM fehlgeschlagung]';
|
|
}
|
|
|
|
$this->get('mailer')->send(\Swift_Message::newInstance()
|
|
->setSubject('Kontaktformular (stern-tours.de)')
|
|
->setFrom('stern@stern-tours.de', 'STERN TOURS')
|
|
->setTo('ulrich.hecht@hecht-software.de')
|
|
->setBody(
|
|
$this->renderView('default/email/contactServiceEmail.txt.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'crm_url' => $crmLeadUrl,
|
|
'contact_request' => $contactRequest,
|
|
]),
|
|
'text/plain', 'utf-8'
|
|
)
|
|
);
|
|
|
|
// #TODO This will lead to multiple submissions. Redirect instead!
|
|
return $this->render('default/pages/contactConfirmation.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'breadcrumb_entries' => $breadcrumbEntries,
|
|
]);
|
|
}
|
|
}
|
|
|
|
return $this->render('default/pages/contact.html.twig', [
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
|
'breadcrumb_entries' => $breadcrumbEntries,
|
|
'contact_form' => $form->createView(),
|
|
]);
|
|
}
|
|
|
|
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.lft,page.title,childPage.lft,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),
|
|
]);
|
|
}
|
|
|
|
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()
|
|
]);
|
|
}
|
|
|
|
/*
|
|
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();
|
|
|
|
// 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');
|
|
// Add missing owner relation
|
|
$em->getConnection()->executeUpdate('UPDATE page SET owner = 13 WHERE id in (1314,1426,1472,1548)');
|
|
|
|
$lft = 0;
|
|
$this->createTree(0, $lft, 0);
|
|
$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->getConnection()->executeUpdate('UPDATE page SET owner = 0 WHERE id in (1314,1426,1472,1548)');
|
|
|
|
$em->commit();
|
|
|
|
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.order');
|
|
$qb->addOrderBy('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);
|
|
}
|
|
}
|
|
}
|