<?php
namespace AppBundle\Controller;
use AppBundle\Entity\Message;
use AppBundle\Entity\Subscribe;
use AppBundle\Services\Date;
use AppBundle\Services\SoapService;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Routing\Annotation\Route;
class DefaultController extends Controller
{
/**
* @Route("/{_locale}", name="homepage",
* defaults={"_locale":"en"
* },
* requirements={"_locale":"en|ru|am"
* }
* )
*/
public function indexAction(Request $request, $_locale)
{
$sliders = $this->getDoctrine()->getRepository('AppBundle:Slider')->findBy([], ['orderSlider' => 'ASC']);
// page
$page = $this->getDoctrine()->getRepository('AppBundle:Page')->find(7);
$aboutPage = $this->getDoctrine()->getRepository('AppBundle:Page')->find(1);
$roomPage = $this->getDoctrine()->getRepository('AppBundle:Page')->find(2);
$eventsPage = $this->getDoctrine()->getRepository('AppBundle:Page')->find(3);
$diningPage = $this->getDoctrine()->getRepository('AppBundle:Page')->find(4);
$fitnessPage = $this->getDoctrine()->getRepository('AppBundle:Page')->find(5);
$galleryCategory = $this->getDoctrine()->getRepository('AppBundle:GalleryCategory')->findBy([],['orderCategory'=>'ASC']);
$gallery = $this->getDoctrine()->getRepository('AppBundle:Gallery')->findAll();
$galleryPage = $this->getDoctrine()->getRepository('AppBundle:Page')->find(6);
return $this->render('page/index.html.twig', [
'page' => $page,
'sliders' => $sliders,
'aboutPage' => $aboutPage,
'roomPage' => $roomPage,
'eventsPage' => $eventsPage,
'diningPage' => $diningPage,
'fitnessPage' => $fitnessPage,
'galleryPage' => $galleryPage,
'galleryCateg' => $galleryCategory,
'gallery' => $gallery,
]);
}
/**
* @Route("/{_locale}/about", name="about_page",
* defaults={"_locale":"en"
* },
* requirements={"_locale":"en|ru|am"
* }
* )
*/
public function aboutAction(Request $request, $_locale)
{
$page = $this->getDoctrine()->getRepository('AppBundle:Page')->find(1);
$wyndhamPage = $this->getDoctrine()->getRepository('AppBundle:Page')->find(8);
return $this->render('page/about.html.twig', [
'page' => $page,
'wyndham' => $wyndhamPage,
]);
}
/**
* @Route("/{_locale}/contact", name="contact_page",
* defaults={"_locale":"en"
* },
* requirements={"_locale":"en|ru|am"
* }
* )
*/
public function contactAction(Request $request, $_locale)
{
$page = $this->getDoctrine()->getRepository('AppBundle:Page')->find(10);
$contact = $this->getDoctrine()->getRepository('AppBundle:Contact')->findAll();
return $this->render('page/contact.html.twig', [
'page' => $page,
'contact' => $contact
]);
}
/**
* @Route("/{_locale}/dining", name="dining_page",
* defaults={"_locale":"en"
* },
* requirements={"_locale":"en|ru|am"
* }
* )
*/
public function diningAction(Request $request, $_locale)
{
$page = $this->getDoctrine()->getRepository('AppBundle:Page')->find(4);
$dining = $this->getDoctrine()->getRepository('AppBundle:Dining')->findBy([], ['orderDining' => 'ASC']);
return $this->render('page/dining.html.twig', [
'dining' => $dining,
'page' => $page,
]);
}
/**
* @Route("/{_locale}/dining_view/{slug}", name="dining_view_page",
* defaults={"_locale":"en"
* },
* requirements={"_locale":"en|ru|am"
* }
* )
*/
public function diningViewAction(Request $request, $_locale, $slug)
{
$dining = $this->getDoctrine()->getRepository('AppBundle:Dining')->find($slug);
$page = $this->getDoctrine()->getRepository('AppBundle:Page')->find(4);
return $this->render('page/dining-view.html.twig', [
'dining' => $dining,
'page' => $page,
]);
}
/**
* @Route("/{_locale}/events_list", name="events_list_page",
* defaults={"_locale":"en"
* },
* requirements={"_locale":"en|ru|am"
* }
* )
*/
public function eventsListAction(Request $request, $_locale)
{
$page = $this->getDoctrine()->getRepository('AppBundle:Page')->find(3);
$events = $this->getDoctrine()->getRepository('AppBundle:EventsCategory')->findBy([], ['orderEvents' => 'ASC']);
$aboutPage = $this->getDoctrine()->getRepository('AppBundle:page')->find(1);
return $this->render('page/events-list.html.twig', [
'page' => $page,
'events' => $events,
'about' => $aboutPage,
]);
}
/**
* @Route("/{_locale}/events_view/{slug}", name="events_view_page",
* defaults={"_locale":"en"
* },
* requirements={"_locale":"en|ru|am"
* }
* )
*/
public function eventsViewAction(Request $request, $_locale, $slug)
{
$events = $this->getDoctrine()->getRepository('AppBundle:Events')->findBy(['category' => $slug], ['orderEvents' => 'ASC']);
$category = $this->getDoctrine()->getRepository('AppBundle:EventsCategory')->find($slug);
$page = $this->getDoctrine()->getRepository('AppBundle:Page')->find(3);
$aboutPage = $this->getDoctrine()->getRepository('AppBundle:page')->find(1);
if (empty($events)) {
return $this->redirectToRoute('events_list_page');
}
return $this->render('page/events_view.html.twig', [
'event' => $events,
'page' => $page,
'about' => $aboutPage,
'category' => $category,
]);
}
/**
* @Route("/{_locale}/fitness_page", name="fitness_page",
* defaults={"_locale":"en"
* },
* requirements={"_locale":"en|ru|am"
* }
* )
*/
public function fitnessAction(Request $request, $_locale)
{
$page = $this->getDoctrine()->getRepository('AppBundle:Page')->find(5);
$fitness = $this->getDoctrine()->getRepository('AppBundle:Fitness')->findBy([], ['orderFitness' => 'asc']);
return $this->render('page/fitness.html.twig', [
'page' => $page,
'fitness' => $fitness
]);
}
/**
* @Route("/{_locale}/gallery_page", name="gallery_page",
* defaults={"_locale":"en"
* },
* requirements={"_locale":"en|ru|am"
* }
* )
*/
public function galleryAction(Request $request, $_locale)
{
$page = $this->getDoctrine()->getRepository('AppBundle:Page')->find(6);
$galleryCategory = $this->getDoctrine()->getRepository('AppBundle:GalleryCategory')->findAll();
$gallery = $this->getDoctrine()->getRepository('AppBundle:Gallery')->findAll();
// $paginator = $this->get('knp_paginator');
// $pagination = $paginator->paginate(
// $gallery,
// $request->query->getInt('page',1),
// 2
// );
return $this->render('page/gallery.html.twig', [
'page' => $page,
'gallery' => $gallery,
'galleryCategory' => $galleryCategory,
]);
}
/**
* @Route("/{_locale}/rooms_list", name="rooms_list_page",
* defaults={"_locale":"en"
* },
* requirements={"_locale":"en|ru|am"
* }
* )
*/
public function roomsListAction(Request $request, Date $date, $_locale)
{
$currenc = $request->getSession()->get('cba');
if ($currenc !== 'AMD' && $currenc !== null) {
$rates = $date->getCbaRatesCurrent()['rates'][$currenc];
} else {
$rates = ['rate' => '1', 'iso' => 'AMD'];
}
$page = $this->getDoctrine()->getRepository('AppBundle:Page')->find(2);
$rooms = $this->getDoctrine()->getRepository('AppBundle:Room')->findBy([], ['orderRoom' => 'ASC']);
return $this->render('page/rooms_list.html.twig', [
'page' => $page,
'rooms' => $rooms,
'rates' => (int)$rates['rate'],
'iso' => $rates['iso'],
]);
}
/**
* @Route("/{_locale}/rooms_view/{slug}", name="rooms_view_page",
* defaults={"_locale":"en"
* },
* requirements={"_locale":"en|ru|am"
* }
* )
*/
public function roomsViewAction(Request $request, Date $date, $_locale, $slug)
{
$currenc = $request->getSession()->get('cba');
if ($currenc !== 'AMD' && $currenc !== null) {
$rates = $date->getCbaRatesCurrent()['rates'][$currenc];
} else {
$rates = ['rate' => '1', 'iso' => 'AMD'];
}
$arr = [];
$room = $this->getDoctrine()->getRepository('AppBundle:Room')->find($slug);
$allRooms = $this->getDoctrine()->getRepository('AppBundle:Room')->findBy([], [], 3,4);
$index = 0;
foreach ($allRooms as $item) {
if ($item->getId() != $slug) {
$arr[$index] = $item;
$index++;
}
}
return $this->render('page/rooms_view.html.twig', [
'room' => $room,
'other' => $arr,
'rates' => (int)$rates['rate'],
'iso' => $rates['iso'],
]);
}
/**
* @Route("/{_locale}/message", name="message",
* defaults={"_locale":"en"
* },
* requirements={"_locale":"en|ru|am"
* }
* )
*/
public function messageAction(Request $request, $_locale)
{
$em = $this->getDoctrine()->getManager();
$name = $request->get('name');
$mail = $request->get('mail');
$subject = $request->get('subject');
$message = $request->get('message');
$emMessage = new Message();
if
(!empty($name) && !empty($mail) &&
!empty($subject) && !empty($message)) {
$emMessage->setName($name);
$emMessage->setEmail($mail);
$emMessage->setSubject($subject);
$emMessage->setMessage($message);
$em->persist($emMessage);
$em->flush();
$this->addFlash('success', 'Your Message Successful Send');
} else {
$this->addFlash('error', 'Your Message Not Send');
}
return $this->redirectToRoute('contact_page');
}
/**
* @Route("/{_locale}/subscribe", name="subscribe",
* defaults={"_locale":"en"
* },
* requirements={"_locale":"en|ru|am"
* }
* )
*/
public function subscribeAction(Request $request, $_locale)
{
$url = $request->server->get('HTTP_REFERER');
$mail = $request->get('mailSubs');
$em = $this->getDoctrine()->getManager();
if (!empty($mail) && filter_var($mail, FILTER_VALIDATE_EMAIL)) {
$subscribe = new Subscribe();
$subscribe->setEmail($mail);
$em->persist($subscribe);
$em->flush();
$this->addFlash('subSuccess', 'Your Mail Successful Subscribe');
} else {
$this->addFlash('subError', 'Your Mail Not Subscribe');
}
return $this->redirect($url);
}
/**
* @Route("/{_locale}/booking/", name="reservation_room",
* defaults={"_locale":"en"
* },
* requirements={"_locale":"en|ru|am"
* }
* )
*/
public function reservationAction(Request $request, $_locale)
{
return $this->render('page/register.html.twig');
}
/**
* @Route("/{_locale}/cba/{cba}", name="cba",
* defaults={"_locale":"en"
* },
* requirements={"_locale":"en|ru|am"
* }
* )
*/
public function sessionAction(Request $request, $cba, $_locale)
{
$url = $request->server->get('HTTP_REFERER');
$session = new Session();
$session->set('cba', $cba);
return $this->redirect($url);
}
/**
* @Route("/{_locale}/test", name="test",
* defaults={"_locale":"en"
* },
* requirements={"_locale":"en|ru|am"
* }
* )
*/
public function testAction(Request $request, $_locale)
{
return $this->render('default/index.html.twig');
}
}