<?php
namespace App\Controller;
use App\Service\CanonicalRedirectHelper;
use App\Twig\LinkGenerator;
use Carbon\Carbon;
use Elements\Bundle\CmsToolsBundle\Tool\Helper\FunctionsHelper;
use Knp\Component\Pager\PaginatorInterface;
use Pimcore\Model\DataObject\ConventionIncentive;
use Pimcore\Model\DataObject\ConventionPartner;
use Pimcore\Model\DataObject\ConventionPartnerCategory;
use Pimcore\Model\DataObject\DemiInfrastructure;
use Pimcore\Model\DataObject\DemiInfrastructureTopic;
use Pimcore\Model\DataObject\Region;
use Pimcore\Model\DataObject\SiteConfig;
use Pimcore\Model\WebsiteSetting;
use Pimcore\Translation\Translator;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
class ConventionController extends AbstractController
{
/**
* @var LinkGenerator
*/
private $linkGenerator;
/**
* @var array
*/
private array $mapIds = [];
private Translator $translator;
public function __construct( LinkGenerator $linkGenerator, Translator $translator)
{
$this->linkGenerator = $linkGenerator;
$this->translator = $translator;
}
public function portalAction(): ?\Symfony\Component\HttpFoundation\Response
{
return $this->render("Convention/portal.html.twig");
}
public function conventionIncentiveDetailAction(Request $request, LinkGenerator $linkGenerator, CanonicalRedirectHelper $redirectHelper) {
$incentive = ConventionIncentive::getById($request->get('id', 0));
if (!$incentive || !$incentive->isPublished()){
throw new NotFoundHttpException("the requested object doesn't exist anymore");
}
if (CanonicalRedirectHelper::ENABLE_CANONICAL_REDIRECT && $redirect = $redirectHelper->canonicalRedirect($incentive)) {
return $redirect;
}
$formSendData = [];
if ($request->get('isSend', 0) && $request->getMethod() == 'POST' ) {
$formSendData = $this->sendContactRequest($request, [$incentive]);
if($formSendData && $formSendData['redirect']) {
return $formSendData['redirect'];
}
}
$partnerTeaser = $this->getRandomPartnerForTeaser($incentive, $linkGenerator);
return $this->renderTemplate('Convention/conventionIncentiveDetail.html.twig', [
'incentive' => $incentive,
'partnerTeaser' => $partnerTeaser,
'formSendData' => $formSendData
]);
}
public function conventionPartnerDetailAction(Request $request, LinkGenerator $linkGenerator, CanonicalRedirectHelper $redirectHelper) {
$convention = ConventionPartner::getById($request->get('id', 0));
if (!$convention || !$convention->isPublished()){
throw new NotFoundHttpException("the requested object doesn't exist anymore");
}
if (CanonicalRedirectHelper::ENABLE_CANONICAL_REDIRECT && $redirect = $redirectHelper->canonicalRedirect($convention)) {
return $redirect;
}
$formSendData = [];
if ($request->get('isSend', 0) && $request->getMethod() == 'POST' ) {
$formSendData = $this->sendContactRequest($request, [$convention]);
if($formSendData && $formSendData['redirect']) {
return $formSendData['redirect'];
}
}
$info = $this->prepareInfoblocks($convention);
$incentiveTeaser = $this->getRandomIncentivesForTeaser($convention, $linkGenerator);
$demiInfrastructure = $this->getDemiInfrastructureTeasers($convention, $linkGenerator);
return $this->renderTemplate('Convention/conventionPartnerDetail.html.twig', [
'convention' => $convention,
'info' => $info,
'incentiveTeaser' => $incentiveTeaser,
'demiInfrastructure' => $demiInfrastructure,
'formSendData' => $formSendData
]);
}
public function eventplannerAction(Request $request, PaginatorInterface $paginator): JsonResponse|\Symfony\Component\HttpFoundation\Response
{
$conventionCategories = new ConventionPartnerCategory\Listing();
$conventionCategories->addConditionParam("notShowInEventplannerFilter is null or notShowInEventplannerFilter = 0");
$excludedIds = $this->getExcludedConventionCategoryIds();
$conventionPartners = new ConventionPartner\Listing();
//if locations use category => default every category
$partnerId = null;
if(($partnerId = $request->get('convention-partner')) && $request->get('convention-partner') != 'locations') {
$conventionPartners->addConditionParam('partnerType__id = :partnerId', ['partnerId' => (int)$partnerId]);
}
if(!empty($excludedIds)) {
$conventionPartners->addConditionParam("partnerType__id NOT IN (" . implode(",", $excludedIds) . ")");
}
$location = null;
if($partnerId == 'locations') {
// if($location = $request->get('location')) {
// $conventionPartners->addConditionParam('', ['locations' => $location]);
// }
if($category = $request->get('category')) {
$conventionPartners->addConditionParam('partnerType__id = :category', ['category' => (int)$category]);
}
if($q = $request->get('keyword')) {
$conventionPartners->addConditionParam('name like :q or contactName like :q or city like :q or street like :q or zip like :q or firstname like :q or lastname like :q', ['q' => '%' . $q . '%']);
}
$partnerIds = $this->checkCapacityAndSaalStyle($conventionPartners, $request);
if(!empty($partnerIds)) {
$conventionPartners->addConditionParam('o_id IN (' . implode(',', $partnerIds) . ')');
}
if($seminarrooms = $request->get('seminarrooms')) {
$conventionPartners->addConditionParam("length(saele) - length(replace(saele, ',', '')) > :seminarrooms", ['seminarrooms' => $seminarrooms]);
}
if($rooms = $request->get('rooms')) {
$conventionPartners->addConditionParam("roomCount >= :rooms", ['rooms' => (int)$rooms]);
}
if($request->get('pkw-checkbox')) {
$conventionPartners->addConditionParam("pkwReachable = 1");
}
}
$preparedCategories = $this->getConventionCategoriesSelect($conventionCategories, $partnerId);
if ($request->isXmlHttpRequest() && $request->get('pois', false)) {
return $this->getMapdata($conventionPartners);
}
$numTeaser = (int)$this->getDocumentEditable('numeric', 'teaserPerPage')->getData();
if($numTeaser < 4) {
$numTeaser = 8;
}
$pagination = $paginator->paginate($conventionPartners, $request->get('page', 1), $numTeaser);
// $pagination->setPageRange(5); is default
if($request->get('ajax') && $request->isXmlHttpRequest() && !$request->get('pois')) {
$response =[
"success" => true,
"content" => [
'result-main' => $this->render('Convention/Includes/eventplanner-list.html.twig', [
'items' => $pagination,
])->getContent(),
'result-paging' => $this->renderView('Navigation/paging.html.twig', [
'styleModifier' => 'justify-content-center',
'ajaxClass' => 'js-ajax-form-map__link',
'ajaxPaging' => true,
'paginator' => $pagination
]),
'result-paging2' => $this->renderView('Navigation/paging.html.twig', [
'styleModifier' => 'justify-content-center',
'ajaxClass' => 'js-ajax-form-map__link',
'ajaxPaging' => true,
'paginator' => $pagination
]),
],
];
return new JsonResponse($response);
}
$activeWishlistIds = array_values(array_map('intval', $request->getSession()->get('wishlistIds', [])));
return $this->renderTemplate('Convention/eventplanner.html.twig', [
'partners' => $conventionPartners,
'conventionCategories' => $conventionCategories,
'conventionCategoriesSelect' => $preparedCategories['select'],
'conventionAllCategoriesSelect' => $preparedCategories['selectAll'],
'locationCategories' => $preparedCategories['locations'],
'paginator' => $pagination,
'regionSelect' => [], //$this->getRegionSelectData($location),
'partnerId' => $partnerId,
'activeWishlistIds' => $activeWishlistIds
]);
}
public function conventionFormAction(Request $request) {
$partnerId = $request->get('convention-partner', null);
$location = $request->get('location', null);
if ($request->getMethod() == 'POST') {
$formSendData = $this->processContactForm($request);
if($formSendData && $formSendData['redirect']) {
return $formSendData['redirect'];
}
}
$conventionCategories = new ConventionPartnerCategory\Listing();
$preparedCategories = $this->getConventionCategoriesSelect($conventionCategories, $partnerId);
return $this->renderTemplate('Convention/conventionForm.html.twig', [
'conventionCategoriesSelect' => $preparedCategories['select'],
'regionSelect' => $this->getRegionSelectData($location),
'conventionAllCategoriesSelect' => $preparedCategories['selectAll'],
'params' => $request->request->all() ?? [],
]);
}
public function wishlistEnquiryAction(Request $request) {
if($request->get('removeAllFromWishlist') !== null) {
$request->getSession()->set('wishlistIds', []);
}
$sessionIds = $request->getSession()->get('wishlistIds', []);
$partners = [];
if(!empty($sessionIds)) {
foreach ($sessionIds as $id) {
if($partner = ConventionPartner::getById($id)) {
$partners[] = $partner;
}
}
}
if ($request->get('isSend', 0) && $request->getMethod() == 'POST' ) {
$conventions = [];
foreach($request->get('pool-enquiries') as $enquiry) {
if($convention = ConventionPartner::getById($enquiry)) {
$conventions[] = $convention;
}
}
$formSendData = $this->sendContactRequest($request, $conventions);
if($formSendData && $formSendData['redirect']) {
return $formSendData['redirect'];
}
}
return $this->renderTemplate('Convention/wishlistEnquiry.html.twig', [
'partners' => $partners,
]);
}
public function incentivesOverviewAction(Request $request, PaginatorInterface $paginator): JsonResponse|\Symfony\Component\HttpFoundation\Response
{
$locationId = $request->get('location');
$incentivesListing = new ConventionIncentive\Listing();
if($locationId) {
$incentivesListing->addConditionParam('region__id = :locationId', ['locationId' => $locationId]);
}
if($this->getDocumentEditable('checkbox', 'randomize') && $this->getDocumentEditable('checkbox', 'randomize')->getData()) {
$incentivesListing->setOrderKey('RAND(CURDATE())', false);
}
$numTeaser = (int)$this->getDocumentEditable('numeric', 'teaserPerPage')->getData();
if($numTeaser < 4) {
$numTeaser = 8;
}
$pagination = $paginator->paginate($incentivesListing, $request->get('page', 1), $numTeaser);
if( $request->isXmlHttpRequest()) {
$response =[
"success" => true,
"content" => [
'result-main' => $this->render('Convention/Includes/incentives-list.html.twig', [
'items' => $pagination,
])->getContent(),
'result-paging' => $this->renderView('Navigation/paging.html.twig', [
'styleModifier' => 'justify-content-center',
'ajaxClass' => 'js-ajax-form-map__link',
'ajaxPaging' => true,
'paginator' => $pagination
]),
],
];
return new JsonResponse($response);
}
return $this->renderTemplate('Convention/incentivesOverview.html.twig', [
'paginator' => $pagination,
'regionSelect' => $this->getRegionSelectData($locationId),
]);
}
private function getConventionCategoriesSelect(ConventionPartnerCategory\Listing $conventionCategories, $partnerId = null) : array{
$conventionCategoriesSelect = $conventionAllCategoriesSelect = [[
"label" => "",
"value" => "",
"disabled" => true,
"selected" => !$partnerId,
"class" => "sr-only"
]];
$locationNames = [];
$locations = [];
foreach ($conventionCategories as $category) {
if($category->getIsLocation()) {
$locationNames[] = $category->getName();
$locations[] = $category;
$conventionAllCategoriesSelect[] = [
"label" => $category->getName(),
"value" => $category->getId(),
"selected" => false,
"class" => ""
];
} else {
$conventionCategoriesSelect[] = $conventionAllCategoriesSelect[] = [
"label" => $category->getName(),
"value" => $category->getId(),
"selected" => ($partnerId && $partnerId == $category->getId()),
"class" => ""
];
}
}
$conventionCategoriesSelect[] = [
"label" => implode(', ', $locationNames),
"value" => 'locations',
"class" => "",
"selected" => $partnerId && $partnerId === 'locations',
];
return [
'select' => $conventionCategoriesSelect,
'selectAll' => $conventionAllCategoriesSelect,
'locations' => $locations,
];
}
private function getRandomIncentivesForTeaser(ConventionPartner $partner, LinkGenerator $linkGenerator, $numOfTeaser = 3) : array {
$incentives = $partner->getDetailRelatedincentives();
if(empty($incentives)) {
$incentives = new ConventionIncentive\Listing();
if($partner->getDetailRadius()) {
$functionsHelper = new FunctionsHelper();
$distance = $functionsHelper->getGeoDistanceQuery($partner->getGeoposition(), 'geoposition');
$incentives->addConditionParam('(:distance) <= :detailRadius', ['distance' => $distance, 'detailRadius' => $partner->getDetailRadius()]);
}
$incentives->setOrderKey(['name']);
$incentives->setOrder(['ASC']);
}
$count = 0;
$teaserdata = [];
foreach ($incentives as $inc) {
$text = '';
foreach($inc->getTeaserBullets() as $bullet) {
$text .= '<li>' . $bullet['item']->getData() . '</li>';
}
$teaserdata[] = [
'title' => $inc->getName(),
'badgeText' => $inc->getCity(),
'image' => $inc->getTeaserimage(),
'wysiwyg' => '<ul>' . $text . '</ul>',
'link' => $linkGenerator->generate($inc),
'linktext' => $this->translator->trans('convention-detail.Mehr anzeigen'),
];
$count++;
if($count >= $numOfTeaser) break;
}
return $teaserdata;
}
private function getDemiInfrastructureTeasers(ConventionPartner $partner, LinkGenerator $linkGenerator, $numOfTeaser = 3) : array {
if($partner->getDetailRelated() && !empty($partner->getDetailRelated())) {
$demiInfrastructures = $partner->getDetailRelated();
} else {
$demiInfrastructures = DemiInfrastructure::getList();
$demiInfrastructures->addConditionParam('name is not null and name != ""');
if($partner->getDetailRadius()) {
$functionsHelper = new FunctionsHelper();
$distance = $functionsHelper->getGeoDistanceQuery($partner->getGeoposition(), 'position');
$demiInfrastructures->addConditionParam('(' . $distance . ') <= :detailRadius', [ 'detailRadius' => $partner->getDetailRadius()]);
}
$topics = [];
if(($infraTypes = $partner->getDetailRadiusTypes()) && !empty($infraTypes)) {
foreach($infraTypes as $type) {
foreach($type->getChildren() as $child) {
if($child instanceof DemiInfrastructureTopic) {
$topics[] = $child->getId();
}
}
}
}
if(($infraTopics = $partner->getDetailRadiusTopics()) && !empty($infraTopics)) {
foreach ($infraTopics as $topic) {
$topics[] = $topic->getId();
}
}
if(!empty($topics)) {
$topics = array_unique($topics);
$subcondition = [];
foreach ($topics as $topic) {
$subcondition[] = 'topics LIKE "%,' . $topic . ',%"';
$subcondition[] = 'subTopics LIKE "%,' . $topic . ',%"';
}
$demiInfrastructures->addConditionParam('(' . implode(' OR ', $subcondition) . ')');
}
$demiInfrastructures->setOrderKey("RAND()", false);
$demiInfrastructures->setLimit(3);
}
//prepare img-teasers
$count = 0;
$teaserdata = [];
foreach ($demiInfrastructures as $infra) {
$teaserdata[] = [
"title" => $infra->getName(),
"href" => $this->linkGenerator->generate($infra),
"image" => $infra->getFirstImage(),
// "badgeText" => $infra->get(),
"isInNav" => false,
"isSearchTeaser" => false,
"ratio" => null
];
$count++;
if($count >= $numOfTeaser) break;
}
return $teaserdata;
}
private function getRegionSelectData($location = null): array
{
$regions = new Region\Listing();
$regions->setOrderKey('sorting');
$regionsSelect = [[
"label" => "",
"value" => "",
"disabled" => true,
"selected" => !$location,
"class"=> "sr-only"
]];
foreach ($regions as $region) {
$regionsSelect[] = [
"label" => $region->getName(),
"value" => $region->getId(),
"class" => "",
"selected" => $location && $location == $region->getId(),
];
}
return $regionsSelect;
}
private function prepareInfoblocks(ConventionPartner $convention) : array {
$infos = ['hotel' => [], 'convention' => []];
if(!empty($convention->getRoomInfo())) {
$infos['hotel']['roominfo'] = [
"icon" => "bed",
"title" => $this->translator->trans("convention-detail.Zimmer"),
'data' => [],
];
foreach($convention->getRoomInfo() as $item) {
$infos['hotel']['roominfo']['data'][] = $item['item']->getData();
}
}
if(!empty($convention->getHotelInfo())) {
$infos['hotel']['hotelinfo'] = [
"icon" => "house",
"title" => $this->translator->trans("convention-detail.Hoteleinrichtungen"),
'data' => [],
];
foreach($convention->getHotelInfo() as $item) {
$infos['hotel']['hotelinfo']['data'][] = $item['item']->getData();
}
}
if(!empty($convention->getDayroomInfo())) {
$infos['hotel']['dayrooms'] = [
"icon" => "calendar",
"title" => $this->translator->trans("convention-detail.Tagungsräume"),
'data' => [],
];
foreach($convention->getDayroomInfo() as $item) {
$infos['hotel']['dayrooms']['data'][] = $item['item']->getData();
}
}
if(!empty($convention->getGastronomyInfo())) {
$infos['hotel']['gastronomy'] = [
"icon" => "cutlery",
"title" => $this->translator->trans("convention-detail.Gastronomie"),
'data' => [],
];
foreach($convention->getGastronomyInfo() as $item) {
$infos['hotel']['gastronomy']['data'][] = $item['item']->getData();
}
}
if(!empty($convention->getFreetimeInfo())) {
$infos['hotel']['freetime'] = [
"icon" => "shoe",
"title" => $this->translator->trans("convention-detail.Freizeiteinrichtungen"),
'data' => [],
];
foreach($convention->getFreetimeInfo() as $item) {
$infos['hotel']['freetime']['data'][] = $item['item']->getData();
}
}
if(!empty($convention->getSpecialInfo())) {
$infos['hotel']['special'] = [
"icon" => "star",
"title" => $this->translator->trans("convention-detail.Besonderheiten"),
'data' => [],
];
foreach($convention->getSpecialInfo() as $item) {
$infos['hotel']['special']['data'][] = $item['item']->getData();
}
}
if(!empty($convention->getSaele())) {
foreach ($convention->getSaele() as $saal) {
$infos['convention'][$saal->getName()] = [
"title" => $saal->getName(),
'data' => [],
'bestuhlung' => [],
];
$infos['convention'][$saal->getName()]['data'][] = $this->translator->trans('convention-detail.saal.Personen(maximal)') . ': ' . max($saal->getCapacityBankett(), $saal->getCapacityTheater(), $saal->getCapacityParlament(), $saal->getCapacityUStyle(), $saal->getCapacityReception());
$infos['convention'][$saal->getName()]['data'][] = $this->translator->trans('convention-detail.saal.Größe') . ': ' . $saal->getSize();
$infos['convention'][$saal->getName()]['data'][]= $this->translator->trans('convention-detail.saal.Tageslicht') . ': ' . ($saal->getDaylight() ? $this->translator->trans('generic.yes') : $this->translator->trans('generic.no'));
if($saal->getSpecials()) {
$infos['convention'][$saal->getName()]['data'][] = $this->translator->trans('convention-detail.saal.Bodenbelag') . ': ' . $saal->getFloorType();
$infos['convention'][$saal->getName()]['data'][] = $this->translator->trans('convention-detail.saal.Besonderheiten') . ': ' . $saal->getSpecials();
}
if($saal->getCapacityBankett() > 0) {
$infos['convention'][$saal->getName()]['bestuhlung'][] = [
'icon' => 'bankett',
'text' => $this->translator->trans('convention-detail.saal.Bankett') . ': ' . $saal->getCapacityBankett()
];
}
if($saal->getCapacityTheater() > 0) {
$infos['convention'][$saal->getName()]['bestuhlung'][] = [
'icon' => 'theater',
'text' => $this->translator->trans('convention-detail.saal.Theater') . ': ' . $saal->getCapacityTheater()
];
}
if($saal->getCapacityParlament() > 0) {
$infos['convention'][$saal->getName()]['bestuhlung'][] = [
'icon' => 'parliament',
'text' => $this->translator->trans('convention-detail.saal.Parlament') . ': ' . $saal->getCapacityParlament()
];
}
if($saal->getCapacityUStyle() > 0) {
$infos['convention'][$saal->getName()]['bestuhlung'][] = [
'icon' => 'u-style',
'text' => $this->translator->trans('convention-detail.saal.U-Style') . ': ' . $saal->getCapacityUStyle()
];
}
if($saal->getCapacityReception() > 0) {
$infos['convention'][$saal->getName()]['bestuhlung'][] = [
'icon' => 'cocktail',
'text' => $this->translator->trans('convention-detail.saal.Empfang') . ': ' . $saal->getCapacityReception()
];
}
}
}
return $infos;
}
private function sendContactRequest(Request $request, array $partners) {
if ($request->get('isSend', 0) && !empty($partners) ) {
$requiredParams = [
'arrival' => Carbon::createFromFormat('Y-m-d H:i:s', str_replace('T', '', $request->get('arrival')))->format('d.m.Y') ?? null,
'departure' => Carbon::createFromFormat('Y-m-d H:i:s', str_replace('T', '', $request->get('departure')))->format('d.m.Y') ?? null,
'company' => $request->get('company'),
'participants' => $request->get('participants'),
'salutation' => $request->get('salutation'),
'firstname' => $request->get('firstname'),
'lastname' => $request->get('lastname'),
'street' => $request->get('street'),
'zip' => $request->get('zip'),
'city' => $request->get('city'),
'country' => $request->get('country'),
'phone' => $request->get('phone'),
'email' => $request->get('email'),
];
$optionalParams = [
'contactType phone' => $request->get('contactType') && $request->get('contactType') == '1' ? 'checked' : 'not checked',
'contactType mail' => $request->get('contactType') && $request->get('contactType') == '2'? 'checked' : 'not checked',
'message' => $request->get('message'),
'title' => $request->get('title'),
];
$errors = [];
foreach ($requiredParams as $key => $param) {
if(empty($param)) {
$errors[] = $key;
}
}
foreach ($optionalParams as $key => $param) {
if(empty($param)) {
unset($optionalParams[$key]);
}
}
if(!$requiredParams['email'] || !filter_var($requiredParams['email'], FILTER_VALIDATE_EMAIL) ) {
$errors[] = 'no valid email';
}
$websiteSetting = WebsiteSetting::getByName('DefaultSiteConfig');
if ($websiteSetting instanceof WebsiteSetting) {
$config = $websiteSetting->getData();
}
$success = false;
if(empty($errors) && $config && $config instanceof SiteConfig) {
foreach ($partners as $partner) {
//build param
$params = array_merge($requiredParams, $optionalParams);
$params['items'] = [];
if ($partner instanceof ConventionPartner) {
$params = array_merge($params, ['hotels' => $partner->getName()]); //is overridden later
$params['items'] = array_merge($params['items'], ['hotels']);
} elseif($partner instanceof ConventionIncentive) {
$params = array_merge($params, ['incentives' => $partner->getName()]);
$params['items'] = array_merge($params['items'], ['incentives']);
}
$params['items'] = array_merge($params['items'], [
'arrival', 'departure', 'company', 'participants', 'salutation', 'title',
'firstname', 'lastname',
'street', 'zip', 'city', 'country', 'phone', 'email',
'contactType phone', 'contactType mail', 'message'
]);
$docs = $this->getEmailDocuments($partner, $config, $request->getLocale());
$adminMailDoc = $docs['adminMail'];
$userMailDoc = $docs['userMail'];
$successPage = $docs['successPage'];
if($adminMailDoc) {
$adminmail = new \Pimcore\Mail();
$adminmail->setDocument($adminMailDoc);
if($partner instanceof ConventionPartner && !empty($partner->getEmail())) {
$adminmail->addTo($partner->getEmail());
} elseif($partner instanceof ConventionIncentive && $partner->getEmail()) {
$adminmail->addTo($partner->getEmail());
}
$adminmail->addReplyTo($requiredParams['email']);
$adminmail->setParams($params);
$adminmail->send();
}
if($userMailDoc) {
$usermail = new \Pimcore\Mail();
$usermail->setDocument($userMailDoc);
$usermail->addTo( $requiredParams['email']);
$usermail->setParams($params);
$usermail->send();
$success = true;
}
if($successPage) {
$redirect = new RedirectResponse($successPage->getFullPath());
}
}
}
}
return [
'errors' => $errors ?? [],
'success' => $success ?? false,
'redirect' => $redirect ?? null,
];
}
private function checkCapacityAndSaalStyle(ConventionPartner\Listing $conventionPartners, Request $request): array
{
$idList = [];
$participant = $request->get('participant'); // is a required field
$any = !($request->get('bankett') | $request->get('theater') | $request->get('parliament') | $request->get('u-style') | $request->get('cocktail'));
foreach($conventionPartners as $partner) {
$capacities = [];
$roomcount = $maxAmount = 0;
$bankett = $theater = $parliament = $u_style = $cocktail = false;
if (!empty($partner->getSaele())) {
foreach ($partner->getSaele() as $saal) {
if ($request->get('daylight') && !$saal->getDaylight()) {
continue;
}
$saalmax = 0;
if($request->get('bankett') || $any) {
$saalmax = $saal->getCapacityBankett();
}
if($request->get('theater') || $any) {
$saalmax = max($saal->getCapacityTheater(), $saalmax);
}
if($request->get('parliament') || $any) {
$saalmax = max($saal->getCapacityParlament(), $saalmax);
}
if($request->get('u_style') || $any) {
$saalmax = max($saal->getCapacityUStyle(), $saalmax);
}
if($request->get('cocktail') || $any) {
$saalmax = max($saal->getCapacityReception(), $saalmax);
}
$capacities[] = $saalmax;
$roomcount++;
}
}
rsort($capacities);
for ($i = 0; $i < count($capacities); $i++) {
$maxAmount += intval($capacities[$i]);
}
if($maxAmount >= $participant ) {
$idList[] = $partner->getId();
}
}
return $idList;
}
private function processContactForm(Request $request): array
{
$requiredParams = [
"participant" => $request->get('participant'),
"seminarrooms" => $request->get('seminarrooms'),
"rooms" => $request->get('rooms'),
"company" => $request->get('company'),
"salutation" => $request->get('salutation'),
"firstname" => $request->get('firstname'),
"lastname" => $request->get('lastname'),
"street" => $request->get('street'),
"zip" => $request->get('zip'),
"city" => $request->get('city'),
"country" => $request->get('country'),
"email" => $request->get('email'),
];
if($request->get('location')) {
$region = Region::getById( $request->get('location'));
}
if($request->get('category')) {
$partnerCategory = ConventionPartnerCategory::getById($request->get('category'));
}
$optionalParams = [
"convention-partner" => $request->get('convention-partner'),
"region" => $region ? $region->getName() : null,
"keyword" => $request->get('keyword'),
"category" => $partnerCategory ? $partnerCategory->getName() : null,
"bankett" => $request->get('bankett') ? 'Checked' : 'Not Checked',
"theater" => $request->get('theater') ? 'Checked' : 'Not Checked',
"parliament" => $request->get('parliament') ? 'Checked' : 'Not Checked',
"u-style" => $request->get('u-style') ? 'Checked' : 'Not Checked',
"cocktail" => $request->get('cocktail') ? 'Checked' : 'Not Checked',
"daylight" => $request->get( "daylight-checkbox") ? 'Checked' : 'Not Checked',
"pkw-available" => $request->get('pkw-checkbox') ? 'Checked' : 'Not Checked',
'arrival' => $request->get('arrival') ? Carbon::createFromFormat('Y-m-d H:i:s', str_replace('T', ' ', $request->get('arrival')))->format('d.m.Y') : null,
'departure' => $request->get('departure') ? Carbon::createFromFormat('Y-m-d H:i:s', str_replace('T', ' ', $request->get('departure')))->format('d.m.Y') : null,
'title' => $request->get('title'),
'phone' => $request->get('phone'),
'contactType phone' => $request->get('contactType') && $request->get('contactType') == '1' ? 'Checked' : 'Not Checked',
'contactType mail' => $request->get('contactType') && $request->get('contactType') == '2' ? 'Checked' : 'Not Checked',
'message' => $request->get('message'),
];
$errors = [];
foreach ($requiredParams as $key => $param) {
if(empty($param)) {
$errors[] = $key;
}
}
if(!$requiredParams['email'] || !filter_var($requiredParams['email'], FILTER_VALIDATE_EMAIL) ) {
$errors[] = 'no valid email';
}
$success = false;
$config = $this->document->getProperty('siteConfig');
if(empty($errors) && $config && $config instanceof SiteConfig) {
$adminMailDoc = $this->getDocumentEditable('relation', 'adminmail')->getElement();
$userMailDoc = $this->getDocumentEditable('relation', 'usermail')->getElement();
$successPage = $this->getDocumentEditable('relation', 'successpage')->getElement();
$params = array_merge($requiredParams, $optionalParams);
$params['items'] = ['salutation', 'firstname', 'lastname', 'category', 'participant', 'seminarrooms', 'bankett', 'theater', 'parliament', 'u-style', 'cocktail', 'daylight', 'pkw-available', 'rooms', 'region', 'keyword', 'company', 'street', 'zip', 'city', 'country', 'phone', 'email', 'contactType phone', 'contactType mail', 'arrival', 'departure', 'message'];
if($adminMailDoc) {
$adminmail = new \Pimcore\Mail();
$adminmail->setDocument($adminMailDoc);
$adminmail->setReplyTo($requiredParams['email']);
$adminmail->setParams($params);
$adminmail->send();
}
if($userMailDoc) {
$usermail = new \Pimcore\Mail();
$usermail->setDocument($userMailDoc);
$usermail->addTo( $requiredParams['email']);
$usermail->setParams($params);
$usermail->send();
}
if($successPage) {
$redirect = new RedirectResponse($successPage->getFullPath());
}
$success = true;
}
return [
'errors' => $errors ?? [],
'success' => $success ?? false,
'redirect' => $redirect ?? null,
];
}
private function getRandomPartnerForTeaser(ConventionIncentive $incentive, LinkGenerator $linkGenerator, $numOfTeaser = 3) : array {
//see if manual incentive
//if not take radom
//if detailradius
//if detailradiusCategories
//if detailradiusClassifications
$partners = [];
if($incentive->getDetailRelated() && !empty($incentive->getDetailRelated())) {
$partners = $incentive->getDetailRelated();
} else {
$partners = new ConventionPartner\Listing();
$partners->addConditionParam('name is not null and name != ""');
if($incentive->getDetailRadius()) {
$functionsHelper = new FunctionsHelper();
$distance = $functionsHelper->getGeoDistanceQuery($incentive->getGeoposition(), 'geoposition');
$partners->addConditionParam('(:distance) <= :detailRadius', ['distance' => $distance, 'detailRadius' => $incentive->getDetailRadius()]);
}
$partners = $partners->getObjects();
shuffle($partners);
}
//prepare img-teasers
$count = 0;
$teaserdata = [];
foreach ($partners as $partner) {
$teaserdata[] = [
"title" => $partner->getName(),
"href" => $linkGenerator->generate($partner),
"image" => $partner->getTeaserimage(),
"badgeText" => $partner->getCity(),
"isInNav" => false,
"isSearchTeaser" => false,
"ratio" => null
];
$count++;
if($count >= $numOfTeaser) break;
}
return $teaserdata;
}
private function getMailFromDemi(ConventionPartner $partner)
{
if (!empty($mails) && method_exists($partner, 'getDemiAccommodation') && $partner->getDemiAccommodation()) {
$addressPriorities = ['Venue', 'Object', 'ExternalAddress', 'Organizer', 'Owner'];
$addresses = $partner->getDemiAccommodation() ? $partner->getDemiAccommodation()->getAddresses() : [];
foreach ($addresses as $address) {
$addressType = $address->getAddressType();
if (in_array($addressType, $addressPriorities)) {
$mainAddress = $address;
break;
}
}
if ($mainAddress && $mainAddress->getEmail()) {
return $mainAddress->getEmail();
}
}
return null;
}
/**
* @Route("/{_locale}/interactive-map-info-box", name="interactive-map-info-box")
*/
public function getMapInfoBox(Request $request, LinkGenerator $linkGenerator) {
$partner = ConventionPartner::getById($request->get('id', null));
$document = $this->document;
$locale = $document->getProperty('language') ?? $request->getLocale();
if($partner) {
$wysiwyg = '<ul>';
foreach($partner->getTeaserBullets($locale) as $bulletpoint) {
$wysiwyg .= '<li>' . $bulletpoint['item']->getData() . '</li>';
}
$wysiwyg .= '</ul>';
return $this->json([
'success' => true,
'html' => $this->renderView('Convention/Includes/interactive-map-info-box.html.twig', [
'image' => $partner->getTeaserimage(),
'subtitle' => $partner->getShortdescription($locale),
'title' => $partner->getName($locale),
'wysiwyg' => $wysiwyg,
'link' => $linkGenerator->generate($partner, ['document' => $document]),
'id' => $request->get('id')
])
]);
}
}
public function getMapdata($items): JsonResponse
{
$geoData = [];
foreach ($items as $partner) {
if($partner) {
$geo = $partner->getGeoposition();
if($geo) {
$geoData[] = [
"id" => $partner->getId(),
"lat" => $geo->getLatitude(),
"lng" => $geo->getLongitude(),
"detailInfoBoxUrl" => $this->generateUrl('interactive-map-info-box',[
'id' => $partner->getId(),
])
];
}
}
}
return new JsonResponse([
"success" => true,
"pois" => $geoData
]);
}
/**
* @Route("/{_locale}/add-to-wishlist", name="add-to-wishlist")
*/
public function addToWishlist(Request $request): JsonResponse
{
$id = $request->get('id');
$wishlistId = $request->get('wishlistId');
$sessionIds = $request->getSession()->get('wishlistIds', []);
$sessionIds[] = $id;
$request->getSession()->set('wishlistIds', $sessionIds);
$returnArr['ids'] = $sessionIds;
$url = $this->document->getProperty('siteConfig') ? ($this->document->getProperty('siteConfig')->getWatchlistOverview() ?: '#') : '#';
return new JsonResponse([
"success" => true,
"activeIds" => array_values(array_map('intval',$sessionIds)),
"__alertNotification" => [
"type" => "notification-default",
"content" => $this->renderView('Convention/Includes/add-wishlist-notification-content.html.twig', [
'url' => $url
])
]
]);
}
/**
* @Route("/{_locale}/remove-from-wishlist", name="remove-from-wishlist")
*/
public function removeFromWishlist(Request $request): JsonResponse
{
$id = $request->get('id');
$wishlistId = $request->get('wishlistId');
$sessionIds = $request->getSession()->get('wishlistIds', []);
if (($key = array_search($id, $sessionIds)) !== false) {
unset($sessionIds[$key]);
}
$request->getSession()->set('wishlistIds', $sessionIds);
$returnArr['ids'] = $sessionIds;
$url = $this->document->getProperty('siteConfig') ? ($this->document->getProperty('siteConfig')->getWatchlistOverview() ?: '#') : '#';
return new JsonResponse([
"success" => true,
"activeIds" => array_values(array_map('intval',$sessionIds)),
"__alertNotification" => [
"type" => "notification-default",
"content" => $this->renderView('Convention/Includes/remove-wishlist-notification-content.html.twig', [
'url' => $url,
])
]
]);
}
private function getExcludedConventionCategoryIds()
{
$excludedCategories = new ConventionPartnerCategory\Listing();
$excludedCategories->addConditionParam("notShowInEventplannerFilter is not null and notShowInEventplannerFilter = 1");
$ids = [];
if($excludedCategories->getCount() > 0) {
$ids = array_map(function ($cat) {
return $cat->getId();
}, $excludedCategories->getObjects());
}
return $ids;
}
/**
* @param mixed $partner
* @param SiteConfig $fallbackConfig
* @param string $locale
* @return array
*/
private function getEmailDocuments(mixed $partner, SiteConfig $fallbackConfig, string $locale)
{
//initalize with fallback values
$adminmail = $fallbackConfig->getConventionPartnerDetailContactFormAdminMail($locale);
$usermail = $fallbackConfig->getConventionPartnerDetailContactFormUserMail($locale);
$successPage = $fallbackConfig->getConventionPartnerDetailContactFormSuccessPage($locale);
$regionconfig = null;
if($partner instanceof ConventionPartner && count($partner->getRegions()) > 0 && ($region = $partner->getRegions()[0]) && $region->getSiteConfig() && $region->getSiteConfig()->getId() !== $fallbackConfig->getId()) {
$regionconfig = $region->getSiteConfig();
} elseif( $partner instanceof ConventionIncentive && ($region = $partner->getRegion()) && $region->getSiteConfig() && $region->getSiteConfig()->getId() !== $fallbackConfig->getId()) {
$regionconfig = $region->getSiteConfig();
}
if($regionconfig) {
if($regionconfig->getConventionPartnerDetailContactFormAdminMail($locale)) {
$adminmail = $regionconfig->getConventionPartnerDetailContactFormAdminMail($locale);
}
if($regionconfig->getConventionPartnerDetailContactFormUserMail($locale)) {
$usermail = $regionconfig->getConventionPartnerDetailContactFormUserMail($locale);
}
if($regionconfig->getConventionPartnerDetailContactFormSuccessPage($locale)) {
$successPage = $regionconfig->getConventionPartnerDetailContactFormSuccessPage($locale);
}
}
return [
'adminMail' => $adminmail,
'userMail' => $usermail,
'successPage' => $successPage,
];
}
}