DB-Skript:
CREATE TABLE fewo_lodging (id INT AUTO_INCREMENT NOT NULL, type_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, description LONGTEXT NOT NULL, equipment LONGTEXT NOT NULL, adress1 VARCHAR(255) NOT NULL, adress2 VARCHAR(255) DEFAULT NULL, zip_code VARCHAR(255) NOT NULL, city VARCHAR(255) NOT NULL, maximum_persons INT NOT NULL, deposit DOUBLE PRECISION NOT NULL, only_weekday INT NOT NULL, calendar_visible TINYINT(1) NOT NULL, INDEX IDX_9629C357C54C8C93 (type_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE fewo_lodging_image (id INT AUTO_INCREMENT NOT NULL, lodging_id INT DEFAULT NULL, full_file_name VARCHAR(255) NOT NULL, file_name VARCHAR(255) NOT NULL, description VARCHAR(255) DEFAULT NULL, INDEX IDX_D49F667187335AF1 (lodging_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE fewo_lodging_type (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE fewo_price (id INT AUTO_INCREMENT NOT NULL, lodging_id INT DEFAULT NULL, season_id INT DEFAULT NULL, per_night DOUBLE PRECISION NOT NULL, flat_price DOUBLE PRECISION NOT NULL, INDEX IDX_3DE13C987335AF1 (lodging_id), INDEX IDX_3DE13C94EC001D1 (season_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE fewo_reservation (id INT AUTO_INCREMENT NOT NULL, lodging_id INT DEFAULT NULL, from_date DATE NOT NULL, to_date DATE NOT NULL, status INT NOT NULL, type INT NOT NULL, INDEX IDX_36537F7487335AF1 (lodging_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE fewo_season (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, from_date DATE NOT NULL, to_date DATE NOT NULL, minimum_stay INT NOT NULL, description LONGTEXT DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
ALTER TABLE fewo_lodging ADD CONSTRAINT FK_9629C357C54C8C93 FOREIGN KEY (type_id) REFERENCES fewo_lodging_type (id);
ALTER TABLE fewo_lodging_image ADD CONSTRAINT FK_D49F667187335AF1 FOREIGN KEY (lodging_id) REFERENCES fewo_lodging (id) ON DELETE SET NULL;
ALTER TABLE fewo_price ADD CONSTRAINT FK_3DE13C987335AF1 FOREIGN KEY (lodging_id) REFERENCES fewo_lodging (id);
ALTER TABLE fewo_price ADD CONSTRAINT FK_3DE13C94EC001D1 FOREIGN KEY (season_id) REFERENCES fewo_season (id) ON DELETE SET NULL;
ALTER TABLE fewo_reservation ADD CONSTRAINT FK_36537F7487335AF1 FOREIGN KEY (lodging_id) REFERENCES fewo_lodging (id) ON DELETE SET NULL;
ALTER TABLE page ADD fewo_lodging INT DEFAULT NULL;
ALTER TABLE page ADD CONSTRAINT FK_140AB6209629C357 FOREIGN KEY (fewo_lodging) REFERENCES fewo_lodging (id) ON DELETE SET NULL;
CREATE UNIQUE INDEX UNIQ_140AB6209629C357 ON page (fewo_lodging);
INSERT INTO `fewo_lodging_type` (`name`) VALUES ('Apartment');
INSERT INTO `fewo_lodging_type` (`name`) VALUES ('Bauernhof');
INSERT INTO `fewo_lodging_type` (`name`) VALUES ('Bungalow');
INSERT INTO `fewo_lodging_type` (`name`) VALUES ('Campingplatz');
INSERT INTO `fewo_lodging_type` (`name`) VALUES ('Chalet');
INSERT INTO `fewo_lodging_type` (`name`) VALUES ('Ferienanlage');
INSERT INTO `fewo_lodging_type` (`name`) VALUES ('Ferienhaus');
INSERT INTO `fewo_lodging_type` (`name`) VALUES ('Ferienwohnung');
INSERT INTO `fewo_lodging_type` (`name`) VALUES ('Finca');
INSERT INTO `fewo_lodging_type` (`name`) VALUES ('Hotel');
INSERT INTO `fewo_lodging_type` (`name`) VALUES ('Hütte');
INSERT INTO `fewo_lodging_type` (`name`) VALUES ('Pension');
INSERT INTO `fewo_lodging_type` (`name`) VALUES ('Schloss');
INSERT INTO `fewo_lodging_type` (`name`) VALUES ('Villa');
git-svn-id: http://78.47.251.156/svn/dev/sterntours-3@3348 f459cee4-fb09-11de-96c3-f9c5f16c3c76
This commit is contained in:
parent
2ebd38d3d7
commit
ab026b752f
57 changed files with 6507 additions and 25 deletions
830
trunk/src/AppBundle/Controller/AdminController.php
Normal file
830
trunk/src/AppBundle/Controller/AdminController.php
Normal file
|
|
@ -0,0 +1,830 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Valentin Wacker
|
||||
* Date: 18.08.2017
|
||||
* Time: 15:03
|
||||
*/
|
||||
namespace AppBundle\Controller;
|
||||
|
||||
use AppBundle\AppBundle;
|
||||
use AppBundle\Entity\FewoBookingRequest;
|
||||
use AppBundle\Entity\FewoLodging;
|
||||
use AppBundle\Entity\FewoPrice;
|
||||
use AppBundle\Entity\FewoReservation;
|
||||
use AppBundle\Entity\FewoSeason;
|
||||
use AppBundle\Entity\FewoLodgingImage;
|
||||
use AppBundle\Form\FewoBookingRequestType;
|
||||
use AppBundle\Form\FewoLodgingType;
|
||||
use AppBundle\Form\FewoPriceType;
|
||||
use AppBundle\Form\FewoReservationType;
|
||||
use AppBundle\Form\FewoSeasonType;
|
||||
use AppBundle\Form\FewoLodgingImageType;
|
||||
use AppBundle\Service\FileManager;
|
||||
use AppBundle\Util;
|
||||
use Doctrine\Bundle\DoctrineCacheBundle\Tests\Functional\FileSystemCacheTest;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpFoundation\File;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
|
||||
class AdminController extends Controller
|
||||
{
|
||||
public function getEntityManager()
|
||||
{
|
||||
return $this->getDoctrine()->getManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/login", name="login")
|
||||
*/
|
||||
public function adminAction(Request $request)
|
||||
{
|
||||
$authUtils = $this->get('security.authentication_utils');
|
||||
$error = $authUtils->getLastAuthenticationError();
|
||||
$lastUsername = $authUtils->getLastUsername();
|
||||
|
||||
return $this->render('default/admin/loginAdmin.html.twig', [
|
||||
'last_username' => $lastUsername,
|
||||
'error' => $error,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/admin/fewo")
|
||||
*/
|
||||
public function adminFewoAction()
|
||||
{
|
||||
return $this->render('admin.html.twig', [
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/admin/fewo/lodgings", name="after_login")
|
||||
*/
|
||||
public function adminFewoLodgingsAction(Request $request)
|
||||
{
|
||||
$fewoLodgingRepo = $this->getEntityManager()->getRepository('AppBundle:FewoLodging');
|
||||
|
||||
$lodgings = $fewoLodgingRepo->findAll();
|
||||
|
||||
return $this->render('default/admin/lodgings.html.twig', [
|
||||
'lodgings' => $lodgings,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/admin/fewo/lodgings/new")
|
||||
*/
|
||||
public function adminFewoNewLodgingAction(Request $request)
|
||||
{
|
||||
$lodging = null;
|
||||
|
||||
if ($request->getMethod() != 'POST')
|
||||
{
|
||||
$lodging = new FewoLodging();
|
||||
}
|
||||
|
||||
$form = $this->createForm(FewoLodgingType::class, $lodging, [
|
||||
|
||||
]);
|
||||
|
||||
// todo if(form == null)...
|
||||
|
||||
if ($request->getMethod() == 'POST')
|
||||
{
|
||||
$form->handleRequest($request);
|
||||
$lodging = $form->getData();
|
||||
}
|
||||
|
||||
|
||||
if ($request->getMethod() == 'POST' && $form->isValid())
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$em->persist($lodging);
|
||||
$em->flush();
|
||||
|
||||
return $this->redirect('/admin/fewo/lodgings');
|
||||
}
|
||||
return $this->render('default/admin/lodgingsNew.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function getSeasons(FewoLodging $lodging)
|
||||
{
|
||||
$seasons = [];
|
||||
$lodgingPrices = $lodging->getPrices();
|
||||
foreach($lodgingPrices as $price)
|
||||
{
|
||||
$seasons[] = $price->getSeason();
|
||||
}
|
||||
|
||||
return $seasons;
|
||||
}
|
||||
|
||||
private function setChoosableSeasons(FewoLodging $lodging)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$fewoSeasonRepo = $em->getRepository('AppBundle:FewoSeason');
|
||||
$allSeasons = $fewoSeasonRepo->findAll();
|
||||
$lodgingSeasons = [];
|
||||
$lodgingSeasons = $this->getSeasons($lodging);
|
||||
$seasons = null;
|
||||
|
||||
for($i = 0; $i < count($allSeasons); $i++)
|
||||
{
|
||||
if(!in_array($allSeasons[$i], $lodgingSeasons))
|
||||
{
|
||||
$seasons[] = $allSeasons[$i];
|
||||
}
|
||||
}
|
||||
|
||||
$lodging->setChoosableSeasons($seasons);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/admin/fewo/lodgings/{lodgingId}", requirements={"lodgingId": "\d+"})
|
||||
*/
|
||||
public function adminFewoEditLodgingAction(Request $request, $lodgingId)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$fewoLodgingRepo = $em->getRepository('AppBundle:FewoLodging');
|
||||
|
||||
$lodging = null;
|
||||
|
||||
$calendarUtil = $this->container->get('app.lodging_calendar_util');
|
||||
|
||||
$lodging = $fewoLodgingRepo->find($lodgingId);
|
||||
$reservations = $calendarUtil->getReservations($lodging);
|
||||
|
||||
|
||||
|
||||
$paddedCalendar = $calendarUtil->getCalendarWithPadding();
|
||||
$calendar = $calendarUtil->getCalendar();
|
||||
$calendar = $calendarUtil->markCalendarDaysWithReservations($lodging, $calendar);
|
||||
$calendar = $calendarUtil->mergeWithPaddedCalendar($calendar, $paddedCalendar);
|
||||
|
||||
$form = $this->createForm(FewoLodgingType::class, $lodging, [
|
||||
//options
|
||||
]);
|
||||
|
||||
if($request->getMethod() == 'POST')
|
||||
{
|
||||
$form->handleRequest($request);
|
||||
}
|
||||
|
||||
|
||||
if ($request->getMethod() == 'POST' && $form->isValid())
|
||||
{
|
||||
$em->flush();
|
||||
|
||||
return $this->redirect('/admin/fewo/lodgings');
|
||||
}
|
||||
|
||||
|
||||
return $this->render('default/admin/lodgingsEdit.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'lodging' => $lodging,
|
||||
'calendar'=> $calendar,
|
||||
'reservations' => $reservations
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/admin/fewo/lodgings/{lodgingId}/delete", requirements={"lodgingId": "\d+"})
|
||||
*/
|
||||
public function adminFewoDeleteLodgingAction(Request $request, $lodgingId)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$fewoLodgingRepo = $em->getRepository('AppBundle:FewoLodging');
|
||||
|
||||
$lodging = $fewoLodgingRepo->find($lodgingId);
|
||||
|
||||
if($lodging != null)
|
||||
{
|
||||
$em->remove($lodging);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
return $this->redirect('/admin/fewo/lodgings');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/admin/fewo/lodgings/{lodgingId}/program", requirements={"lodgingId": "\d+"})
|
||||
*/
|
||||
public function adminFewoLodgingProgramAction(Request $request, $lodgingId)
|
||||
{
|
||||
$fewoLodgingRepo = $this->getEntityManager()->getRepository('AppBundle:FewoLodging');
|
||||
|
||||
$lodging = $fewoLodgingRepo->find($lodgingId);
|
||||
|
||||
$calendarUtil = $this->container->get('app.lodging_calendar_util');
|
||||
|
||||
$reservations = $calendarUtil->getReservations($lodging);
|
||||
|
||||
$paddedCalendar = $calendarUtil->getCalendarWithPadding();
|
||||
$calendar = $calendarUtil->getCalendar();
|
||||
$calendar = $calendarUtil->markCalendarDaysWithReservations($lodging, $calendar);
|
||||
$calendar = $calendarUtil->mergeWithPaddedCalendar($calendar, $paddedCalendar);
|
||||
|
||||
|
||||
return $this->render('default/pages/cms/fewoTravelProgram.html.twig', [
|
||||
'fewo_lodging' => $lodging,
|
||||
'calendar' => $calendar
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ Route("/admin/fewo/lodgings/{lodgingId}/prices/{priceId}/reservations/new/{fromDate}/booking", requirements={"lodgingId": "\d+", "priceId": "\d+", "fromDate": "\w+"})
|
||||
*/
|
||||
public function adminFewoBookingAction(Request $request, $lodgingId, $priceId, $fromDate)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$fewoLodgingRepo = $em->getRepository('AppBundle:FewoLodging');
|
||||
$fewoPriceRepo = $em->getRepository('AppBundle:FewoPrice');
|
||||
|
||||
$lodging = $fewoLodgingRepo->find($lodgingId);
|
||||
$price = $fewoPriceRepo->find($priceId);
|
||||
|
||||
/** @var FewoSeason $season */
|
||||
$season = $price->getSeason();
|
||||
$minimumStay = $season->getMinimumStay();
|
||||
$fromDate = $this->convertDate($fromDate);
|
||||
$toDate = '';
|
||||
|
||||
$maxPersons = $lodging->getMaximumPersons();
|
||||
|
||||
$fewoBookingRequest = new FewoBookingRequest();
|
||||
$reservation = new FewoReservation();
|
||||
|
||||
if ($request->getMethod() != 'POST')
|
||||
{
|
||||
$dateAppendix = " + ".($minimumStay - 1)." day";
|
||||
if($minimumStay > 1)
|
||||
{
|
||||
$dateAppendix= $dateAppendix."s";
|
||||
}
|
||||
|
||||
$toDate = date('d.m.Y', strtotime($fromDate.$dateAppendix));
|
||||
$fewoBookingRequest->setFromDate($fromDate);
|
||||
$fewoBookingRequest->setToDate($toDate);
|
||||
}
|
||||
|
||||
$form = $this->createForm(FewoBookingRequestType::class, $fewoBookingRequest, [
|
||||
'lodging' => $lodging,
|
||||
'maxPersons' => $maxPersons,
|
||||
'toDate' => $toDate
|
||||
]);
|
||||
|
||||
if ($request->getMethod() == 'POST')
|
||||
{
|
||||
$form->handleRequest($request);
|
||||
$fewoBookingRequest = $form->getData();
|
||||
$fromDateTime = new \DateTime($fromDate);
|
||||
$fewoBookingRequest->setFromDate($fromDateTime);
|
||||
$fewoBookingRequest->setLodging($lodging);
|
||||
}
|
||||
|
||||
|
||||
if ($request->getMethod() == 'POST' && $form->isValid())
|
||||
{
|
||||
$reservation->setFromDate($fewoBookingRequest->getFromDate());
|
||||
$reservation->setToDate($fewoBookingRequest->getToDate());
|
||||
$reservation->setStatus(0); // 0 = belegt; 1 = nicht verfügbar
|
||||
$reservation->setType(0); // 0 = Buchung; 1 = Händisch
|
||||
|
||||
$reservation->setLodging($lodging);
|
||||
$em->persist($reservation);
|
||||
$em->flush();
|
||||
|
||||
|
||||
$crmBookingUrl = $this->get('app.fewo_booking_exporter')->process($fewoBookingRequest, $lodging, $price);//, $travelDate, $bookingPriceInfo);
|
||||
$crmBookingUrl = preg_replace('/\\/api/', '', $crmBookingUrl) .'/edit';
|
||||
|
||||
$this->get('mailer')->send(\Swift_Message::newInstance()
|
||||
->setSubject('Ihr FeWo-Buchungsauftrag bei STERN TOURS')
|
||||
->setFrom('stern@stern-tours.de', 'STERN TOURS')
|
||||
->setTo($fewoBookingRequest->getEmail())
|
||||
->setBody(
|
||||
$this->renderView('default/email/fewoBookingConfirmationEmail.txt.twig', [
|
||||
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
||||
'fewo_booking_request' => $fewoBookingRequest,
|
||||
//'booking_price_info' => $bookingPriceInfo,
|
||||
//'travel_date' => $travelDate,
|
||||
//'breadcrumb_entries' => $breadcrumbEntries,
|
||||
]),
|
||||
'text/plain', 'utf-8'
|
||||
)
|
||||
);
|
||||
|
||||
$this->get('mailer')->send(\Swift_Message::newInstance()
|
||||
->setSubject('FEWO-BUCHUNG: '. $lodging->getName())//$travelProgram->getTitle() .'('. $travelDate->getName() .')') //TODO !!! allein hierfür braucht man mehr infos in $fewoBookingRequest
|
||||
->setFrom('stern@stern-tours.de', 'STERN TOURS')
|
||||
->setTo('stern@stern-tours.de')
|
||||
->setBody(
|
||||
$this->renderView('default/email/fewoBookingServiceEmail.txt.twig', [
|
||||
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
||||
'crm_url' => $crmBookingUrl,
|
||||
//'travel_program_url' => Util::getBaseUrl() . $travelProgramPage->getUrlPath(),
|
||||
'fewo_booking_request' => $fewoBookingRequest,
|
||||
//'booking_price_info' => $bookingPriceInfo,
|
||||
//'travel_date' => $travelDate,
|
||||
//'breadcrumb_entries' => $breadcrumbEntries,
|
||||
]),
|
||||
'text/plain', 'utf-8'
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
return $this->redirect('/admin/fewo/lodgings/'.$lodgingId.'/program');
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return $this->render('default/admin/fewoBooking.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'lodging' => $lodging,
|
||||
'fromDate' => $fromDate,
|
||||
'toDate' => $toDate
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/admin/fewo/lodgings/{lodgingId}/prices/new", requirements={"lodgingId": "\d+"})
|
||||
*/
|
||||
public function adminFewoNewPriceAction(Request $request, $lodgingId)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$fewoLodgingRepo = $em->getRepository('AppBundle:FewoLodging');
|
||||
$lodging = $fewoLodgingRepo->find($lodgingId);
|
||||
|
||||
$price = null;
|
||||
if ($request->getMethod() != 'POST')
|
||||
{
|
||||
$price = new FewoPrice();
|
||||
}
|
||||
|
||||
$this->setChoosableSeasons($lodging);
|
||||
$form = $this->createForm(FewoPriceType::class, $price, [
|
||||
'lodging' => $lodging
|
||||
]);
|
||||
|
||||
if ($request->getMethod() == 'POST')
|
||||
{
|
||||
$form->handleRequest($request);
|
||||
$price = $form->getData();
|
||||
}
|
||||
|
||||
|
||||
if ($request->getMethod() == 'POST' && $form->isValid())
|
||||
{
|
||||
|
||||
if($price == null)
|
||||
{
|
||||
return $this->redirect('/admin/fewo/lodgings/'.$lodgingId);
|
||||
}
|
||||
|
||||
$price->setLodging($lodging);
|
||||
$em->persist($price);
|
||||
$em->flush();
|
||||
|
||||
|
||||
return $this->redirect('/admin/fewo/lodgings/'.$lodgingId);
|
||||
}
|
||||
|
||||
return $this->render('default/admin/pricesNew.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'lodging' => $lodging,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/admin/fewo/lodgings/{lodgingId}/prices/{priceId}", requirements={"lodgingId": "\d+", "priceId": "\d+"})
|
||||
*/
|
||||
public function adminFewoEditPriceAction(Request $request, $lodgingId, $priceId)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$fewoLodgingRepo = $em->getRepository('AppBundle:FewoLodging');
|
||||
$fewoPriceRepo = $em->getRepository('AppBundle:FewoPrice');
|
||||
$lodging = $fewoLodgingRepo->find($lodgingId);
|
||||
$price = $fewoPriceRepo->find($priceId);
|
||||
|
||||
$choosableSeason[] = $price->getSeason();
|
||||
$lodging->setChoosableSeasons($choosableSeason);
|
||||
|
||||
$form = $this->createForm(FewoPriceType::class, $price, [
|
||||
'lodging' => $lodging
|
||||
]);
|
||||
|
||||
if ($request->getMethod() == 'POST')
|
||||
{
|
||||
$form->handleRequest($request);
|
||||
}
|
||||
|
||||
|
||||
if ($request->getMethod() == 'POST' && $form->isValid())
|
||||
{
|
||||
|
||||
if($price == null)
|
||||
{
|
||||
return $this->redirect('/admin/fewo/lodgings/'.$lodgingId);
|
||||
}
|
||||
$em->flush();
|
||||
|
||||
|
||||
return $this->redirect('/admin/fewo/lodgings/'.$lodgingId);
|
||||
}
|
||||
|
||||
return $this->render('default/admin/pricesEdit.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'lodging' => $lodging,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/admin/fewo/lodgings/{lodgingId}/prices/{priceId}/delete", requirements={"lodgingId": "\d+", "priceId": "\d+"})
|
||||
*/
|
||||
public function adminFewoDeletePriceAction(Request $request, $lodgingId, $priceId)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$fewoPriceRepo = $em->getRepository('AppBundle:FewoPrice');
|
||||
$fewoLodgingRepo = $em->getRepository('AppBundle:FewoLodging');
|
||||
$lodging = $fewoLodgingRepo->find($lodgingId);
|
||||
|
||||
$price = $fewoPriceRepo->find($priceId);
|
||||
|
||||
if($price != null)
|
||||
{
|
||||
$em->remove($price);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
return $this->redirect('/admin/fewo/lodgings/'.$lodgingId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Route("/admin/fewo/lodgings/{lodgingId}/reservations/new", requirements={"lodgingId": "\d+"})
|
||||
*/
|
||||
public function adminFewoNewReservationAction(Request $request, $lodgingId)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$fewoLodgingRepo = $em->getRepository('AppBundle:FewoLodging');
|
||||
$lodging = $fewoLodgingRepo->find($lodgingId);
|
||||
|
||||
$reservation = null;
|
||||
if ($request->getMethod() != 'POST')
|
||||
{
|
||||
$reservation = new FewoReservation();
|
||||
}
|
||||
|
||||
$form = $this->createForm(FewoReservationType::class, $reservation, [
|
||||
'lodging' => $lodging
|
||||
]);
|
||||
|
||||
if ($request->getMethod() == 'POST')
|
||||
{
|
||||
$form->handleRequest($request);
|
||||
$reservation = $form->getData();
|
||||
}
|
||||
|
||||
|
||||
if ($request->getMethod() == 'POST' && $form->isValid())
|
||||
{
|
||||
|
||||
if($reservation == null)
|
||||
{
|
||||
return $this->redirect('/admin/fewo/lodgings/'.$lodgingId);
|
||||
}
|
||||
|
||||
$reservation->setLodging($lodging);
|
||||
$em->persist($reservation);
|
||||
|
||||
$em->flush();
|
||||
|
||||
|
||||
return $this->redirect('/admin/fewo/lodgings/'.$lodgingId);
|
||||
}
|
||||
|
||||
return $this->render('default/admin/reservationsNew.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'lodging' => $lodging,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
private function addDaysToDate($date, $days)
|
||||
{
|
||||
$result = date('dd-mm-yyyy', strtotime($date." + ".$days." days"));
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function convertDate($date)
|
||||
{
|
||||
$result = substr($date, 0, 2).'.'.substr($date, 2, 2).'.'.substr($date, 4, 4);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Route("/admin/fewo/lodgings/{lodgingId}/reservations/new/{fromDate}", requirements={"lodgingId": "\d+", "fromDate": "\w+"})
|
||||
*/
|
||||
public function adminFewoNewReservationWithStartingDayAction(Request $request, $lodgingId, $fromDate)
|
||||
{
|
||||
//todo price -> season
|
||||
//todo season.minimumStay
|
||||
$em = $this->getEntityManager();
|
||||
$fewoLodgingRepo = $em->getRepository('AppBundle:FewoLodging');
|
||||
$lodging = $fewoLodgingRepo->find($lodgingId);
|
||||
|
||||
$fromDate = $this->convertDate($fromDate);
|
||||
|
||||
$reservation = null;
|
||||
if ($request->getMethod() != 'POST')
|
||||
{
|
||||
$reservation = new FewoReservation();
|
||||
}
|
||||
|
||||
$form = $this->createForm(FewoReservationType::class, $reservation, [
|
||||
'lodging' => $lodging,
|
||||
'fromDate' => $fromDate
|
||||
]);
|
||||
|
||||
if ($request->getMethod() == 'POST')
|
||||
{
|
||||
$form->handleRequest($request);
|
||||
$reservation = $form->getData();
|
||||
}
|
||||
|
||||
|
||||
if ($request->getMethod() == 'POST' && $form->isValid())
|
||||
{
|
||||
|
||||
if($reservation == null)
|
||||
{
|
||||
return $this->redirect('/admin/fewo/lodgings/'.$lodgingId);
|
||||
}
|
||||
|
||||
$reservation->setLodging($lodging);
|
||||
$em->persist($reservation);
|
||||
$em->flush();
|
||||
|
||||
|
||||
return $this->redirect('/admin/fewo/lodgings/'.$lodgingId);
|
||||
}
|
||||
|
||||
return $this->render('default/admin/reservationsNew.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'lodging' => $lodging,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Route("/admin/fewo/lodgings/{lodgingId}/reservations/{reservationId}", requirements={"lodgingId": "\d+", "reservationId": "\d+"})
|
||||
*/
|
||||
public function adminFewoEditReservationAction(Request $request, $lodgingId, $reservationId)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$fewoLodgingRepo = $em->getRepository('AppBundle:FewoLodging');
|
||||
$fewoReservationRepo = $em->getRepository('AppBundle:FewoReservation');
|
||||
$lodging = $fewoLodgingRepo->find($lodgingId);
|
||||
$reservation = $fewoReservationRepo->find($reservationId);
|
||||
$fromDate = $reservation->getFromDate()->format('d.m.Y');
|
||||
|
||||
$form = $this->createForm(FewoReservationType::class, $reservation, [
|
||||
'lodging' => $lodging,
|
||||
'fromDate' => $fromDate,
|
||||
]);
|
||||
|
||||
if ($request->getMethod() == 'POST')
|
||||
{
|
||||
$form->handleRequest($request);
|
||||
}
|
||||
|
||||
|
||||
if ($request->getMethod() == 'POST' && $form->isValid())
|
||||
{
|
||||
$em->flush();
|
||||
|
||||
return $this->redirect('/admin/fewo/lodgings/'.$lodgingId);
|
||||
}
|
||||
|
||||
return $this->render('default/admin/reservationsEdit.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'lodging' => $lodging,
|
||||
'reservationId' => $reservationId
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/admin/fewo/lodgings/{lodgingId}/reservations/{reservationId}/delete", requirements={"lodgingId": "\d+", "reservationId": "\d+"})
|
||||
*/
|
||||
public function adminFewoDeleteReservationAction(Request $request, $lodgingId, $reservationId)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$fewoLodgingRepo = $em->getRepository('AppBundle:FewoLodging');
|
||||
$fewoReservationRepo = $em->getRepository('AppBundle:FewoReservation');
|
||||
|
||||
$lodging = $fewoLodgingRepo->find($lodgingId);
|
||||
$reservation = $fewoReservationRepo->find($reservationId);
|
||||
|
||||
if($reservation != null)
|
||||
{
|
||||
$em->remove($reservation);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
return $this->redirect('/admin/fewo/lodgings/'.$lodgingId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Route("/admin/fewo/seasons")
|
||||
*/
|
||||
public function adminFewoSeasonsAction(Request $request)
|
||||
{
|
||||
$fewoSeasonRepo = $this->getEntityManager()->getRepository('AppBundle:FewoSeason');
|
||||
|
||||
$seasons = $fewoSeasonRepo->findAll();
|
||||
|
||||
return $this->render('default/admin/seasons.html.twig', [
|
||||
'seasons' => $seasons,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/admin/fewo/seasons/new")
|
||||
*/
|
||||
public function adminFewoNewSeasonAction(Request $request)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$season = null;
|
||||
|
||||
if ($request->getMethod() != 'POST')
|
||||
{
|
||||
$season = new FewoSeason();
|
||||
}
|
||||
|
||||
$form = $this->createForm(FewoSeasonType::class, $season, [
|
||||
|
||||
]);
|
||||
|
||||
if ($request->getMethod() == 'POST')
|
||||
{
|
||||
$form->handleRequest($request);
|
||||
$season = $form->getData();
|
||||
}
|
||||
|
||||
|
||||
if ($request->getMethod() == 'POST' && $form->isValid())
|
||||
{
|
||||
if($season == null)
|
||||
{
|
||||
return $this->redirect('/admin/fewo/seasons');
|
||||
}
|
||||
|
||||
$em->persist($season);
|
||||
$em->flush();
|
||||
|
||||
return $this->redirect('/admin/fewo/seasons');
|
||||
}
|
||||
return $this->render('default/admin/seasonsNew.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'season' => $season,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/admin/fewo/seasons/{seasonId}", requirements={"seasonId": "\d+"})
|
||||
*/
|
||||
public function adminFewoEditSeasonAction(Request $request, $seasonId)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$fewoSeasonsRepo = $em->getRepository('AppBundle:FewoSeason');
|
||||
|
||||
$season = null;
|
||||
$season = $fewoSeasonsRepo->find($seasonId);
|
||||
|
||||
$form = $this->createForm(FewoSeasonType::class, $season, [
|
||||
//options
|
||||
]);
|
||||
|
||||
if($request->getMethod() == 'POST')
|
||||
{
|
||||
$form->handleRequest($request);
|
||||
}
|
||||
|
||||
|
||||
if ($request->getMethod() == 'POST' && $form->isValid())
|
||||
{
|
||||
$em->flush();
|
||||
|
||||
return $this->redirect('/admin/fewo/seasons');
|
||||
}
|
||||
return $this->render('default/admin/seasonsEdit.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'season' => $season,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/admin/fewo/seasons/{seasonId}/delete", requirements={"seasonId": "\d+"})
|
||||
*/
|
||||
public function adminFewoDeleteSeasonAction(Request $request, $seasonId)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$fewoSeasonRepo = $em->getRepository('AppBundle:FewoSeason');
|
||||
|
||||
$season = $fewoSeasonRepo->find($seasonId);
|
||||
|
||||
if($season != null)
|
||||
{
|
||||
$em->remove($season);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
return $this->redirect('/admin/fewo/seasons');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/admin/fewo/lodgings/{lodgingId}/images/new", requirements={"lodgingId": "\d+"})
|
||||
*/
|
||||
public function adminFewoNewImageAction(Request $request, $lodgingId)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$fewoLodgingRepo = $em->getRepository('AppBundle:FewoLodging');
|
||||
|
||||
$lodging = $fewoLodgingRepo->find($lodgingId);
|
||||
|
||||
$image = null;
|
||||
if ($request->getMethod() != 'POST')
|
||||
{
|
||||
$image = new FewoLodgingImage();
|
||||
}
|
||||
|
||||
$form = $this->createForm(FewoLodgingImageType::class, $image, [
|
||||
|
||||
]);
|
||||
|
||||
if ($request->getMethod() == 'POST')
|
||||
{
|
||||
$form->handleRequest($request);
|
||||
$image = $form->getData();
|
||||
}
|
||||
|
||||
|
||||
if ($request->getMethod() == 'POST' && $form->isValid())
|
||||
{
|
||||
|
||||
if($lodging == null)
|
||||
{
|
||||
return $this->redirect('/admin/fewo/lodgings');
|
||||
}
|
||||
|
||||
$image->setLodging($lodging);
|
||||
$em->persist($image);
|
||||
$em->flush();
|
||||
|
||||
return $this->redirect('/admin/fewo/lodgings/'.$lodgingId);
|
||||
}
|
||||
|
||||
return $this->render('default/admin/imagesNew.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'lodging' => $lodging,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/admin/fewo/lodgings/{lodgingId}/images/{imageId}/delete", requirements={"lodgingId": "\d+", "imageId": "\d+"})
|
||||
*/
|
||||
public function adminFewoDeleteImageAction(Request $request, $lodgingId, $imageId)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$fewoLodgingImageRepo = $em->getRepository('AppBundle:FewoLodgingImage');
|
||||
|
||||
$image = $fewoLodgingImageRepo->find($imageId);
|
||||
|
||||
if($image != null)
|
||||
{
|
||||
$em->remove($image);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
return $this->redirect('/admin/fewo/lodgings/'.$lodgingId);
|
||||
}
|
||||
}
|
||||
|
|
@ -123,6 +123,29 @@ class CmsController extends Controller
|
|||
]);
|
||||
}
|
||||
|
||||
public function fewoLodgingAction(Page $page)
|
||||
{
|
||||
//$calendarUtil = new Util\LodgingCalendarUtil();
|
||||
$calendarUtil = $this->container->get('app.lodging_calendar_util');
|
||||
//$fewoLodgingRepo = $this->getEntityManager()->getRepository('AppBundle:FewoLodging');
|
||||
$lodging = $page->getFewoLodging();
|
||||
|
||||
$paddedCalendar = $calendarUtil->getCalendarWithPadding();
|
||||
$calendar = $calendarUtil->getCalendar();
|
||||
$calendar = $calendarUtil->markCalendarDaysWithReservations($lodging, $calendar);
|
||||
$calendar = $calendarUtil->mergeWithPaddedCalendar($calendar, $paddedCalendar);
|
||||
|
||||
|
||||
return $this->render('default/pages/cms/fewoTravelProgram.html.twig', [
|
||||
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
||||
'page' => $page,
|
||||
'fewo_lodging' => $lodging,
|
||||
//'lodging' => $lodging, //so wurde es im AdminController aufgerufen
|
||||
'calendar' => $calendar
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
public function pdfAction(Page $page)
|
||||
{
|
||||
$travelProgram = $page->getTravelProgram();
|
||||
|
|
|
|||
251
trunk/src/AppBundle/Controller/FewoBookingController.php
Normal file
251
trunk/src/AppBundle/Controller/FewoBookingController.php
Normal file
|
|
@ -0,0 +1,251 @@
|
|||
<?php
|
||||
namespace AppBundle\Controller;
|
||||
|
||||
//TODO bereinigen
|
||||
use AppBundle\Entity\BookingRequest;
|
||||
use AppBundle\Entity\BreadcrumbEntry;
|
||||
use AppBundle\Entity\FewoLodging;
|
||||
use AppBundle\Entity\FewoPrice;
|
||||
use AppBundle\Entity\Page;
|
||||
use AppBundle\Entity\TravelDate;
|
||||
use AppBundle\Entity\Traveler;
|
||||
use AppBundle\Entity\TravelPeriodPrice;
|
||||
use AppBundle\Entity\TravelPeriodPriceType;
|
||||
use AppBundle\Form\BookingRequestType;
|
||||
use AppBundle\Util;
|
||||
|
||||
|
||||
use AppBundle\Entity\FewoSeason;
|
||||
use AppBundle\Entity\FewoBookingRequest;
|
||||
use AppBundle\Form\FewoBookingRequestType;
|
||||
use AppBundle\Entity\FewoReservation;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class FewoBookingController extends Controller
|
||||
{
|
||||
public function getEntityManager()
|
||||
{
|
||||
return $this->getDoctrine()->getManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* The routing for this action is entirely controlled by KernelControllerListener!
|
||||
*
|
||||
* @param Page $fewoTravelProgramPage
|
||||
* @param Request $request
|
||||
* @param $action
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function indexAction(Page $fewoTravelProgramPage, $action, Request $request)
|
||||
{
|
||||
|
||||
//$calendarUtils = new Util\LodgingCalendarUtil();
|
||||
$calendarUtil = $this->container->get('app.lodging_calendar_util');
|
||||
$em = $this->getEntityManager();
|
||||
//$fewoLodgingRepo = $em->getRepository('AppBundle:FewoLodging');
|
||||
$fewoPriceRepo = $em->getRepository('AppBundle:FewoPrice');
|
||||
|
||||
if (!$request->query->has('pnr') || !$request->query->has('fd'))
|
||||
{
|
||||
return $this->redirect($fewoTravelProgramPage->getUrlPath());
|
||||
}
|
||||
|
||||
$priceId = $request->query->get('pnr');
|
||||
$fromDate = $request->query->get('fd');
|
||||
|
||||
$lodging = $fewoTravelProgramPage->getFewoLodging();
|
||||
/** @var FewoPrice $price */
|
||||
$price = $fewoPriceRepo->find($priceId);
|
||||
|
||||
/** @var FewoSeason $season */
|
||||
$season = $price->getSeason();
|
||||
$minimumStay = $season->getMinimumStay();
|
||||
|
||||
$fromDate = $calendarUtil->convertDate($fromDate);
|
||||
$fromDateTime = new \DateTime($fromDate);
|
||||
$toDate = '';
|
||||
|
||||
$maxPersons = $lodging->getMaximumPersons();
|
||||
|
||||
|
||||
$fewoBookingRequest = new FewoBookingRequest();
|
||||
$reservation = new FewoReservation();
|
||||
|
||||
$fewoBookingRequest->setFromDate($fromDateTime);
|
||||
//$fewoBookingRequest->setToDate($toDate);
|
||||
$fewoBookingRequest->setNumberDays($minimumStay);
|
||||
$fewoBookingRequest->setLodging($lodging);
|
||||
$fewoBookingRequest->setPrice($price);
|
||||
|
||||
|
||||
if ($request->getMethod() != 'POST')
|
||||
{
|
||||
$dateAppendix = " + ".($minimumStay - 1)." day";
|
||||
if($minimumStay > 1)
|
||||
{
|
||||
$dateAppendix= $dateAppendix."s";
|
||||
}
|
||||
|
||||
$toDate = date('d.m.Y', strtotime($fromDate.$dateAppendix));
|
||||
$fewoBookingRequest->setFromDate($fromDate);
|
||||
$fewoBookingRequest->setToDate($toDate);
|
||||
$fewoBookingRequest->setNumberDays($minimumStay);
|
||||
$fewoBookingRequest->setLodging($lodging);
|
||||
$fewoBookingRequest->setPrice($price);
|
||||
}
|
||||
|
||||
$form = $this->createForm(FewoBookingRequestType::class, $fewoBookingRequest, [
|
||||
'lodging' => $lodging,
|
||||
'maxPersons' => $maxPersons,
|
||||
'toDate' => $toDate
|
||||
]);
|
||||
|
||||
if ($request->getMethod() == 'POST')
|
||||
{
|
||||
$form->handleRequest($request);
|
||||
|
||||
/** @var FewoBookingRequest $fewoBookingRequest */
|
||||
$fewoBookingRequest = $form->getData();
|
||||
$fewoBookingRequest->setFromDate($fromDateTime);
|
||||
|
||||
$finalFromDate = $fewoBookingRequest->getFromDate();
|
||||
$finalToDate = $fewoBookingRequest->getToDate();
|
||||
|
||||
$timeDiff = date_diff($finalFromDate, $finalToDate);
|
||||
|
||||
$numberDays = $timeDiff->days + 1;
|
||||
|
||||
$fewoBookingRequest->setNumberDays($numberDays);
|
||||
$fewoBookingRequest->setLodging($lodging);
|
||||
$fewoBookingRequest->setPrice($price);
|
||||
}
|
||||
|
||||
$totalPrice = $this->calculatePrice($fewoBookingRequest, $lodging, $price);
|
||||
$perDayTotalPrice = $this->calculatePerDayTotalPrice($fewoBookingRequest, $price);
|
||||
$fewoBookingRequest->setTotalPrice($totalPrice);
|
||||
|
||||
if($action == '/fewo-buchen')
|
||||
{
|
||||
|
||||
if ($request->getMethod() == 'POST' && $form->isValid())
|
||||
{
|
||||
$reservation->setFromDate($fewoBookingRequest->getFromDate());
|
||||
$reservation->setToDate($fewoBookingRequest->getToDate());
|
||||
$reservation->setStatus(0); // 0 = belegt; 1 = nicht verfügbar
|
||||
$reservation->setType(0); // 0 = Buchung; 1 = Händisch
|
||||
|
||||
$reservation->setLodging($lodging);
|
||||
$em->persist($reservation);
|
||||
$em->flush();
|
||||
|
||||
$crmBookingUrl = $this->get('app.fewo_booking_exporter')->process($fewoBookingRequest, $lodging, $price);//, $travelDate, $bookingPriceInfo);
|
||||
$crmBookingUrl = preg_replace('/\\/api/', '', $crmBookingUrl) . '/edit';
|
||||
|
||||
$this->get('mailer')->send(\Swift_Message::newInstance()
|
||||
->setSubject('Ihr FeWo-Buchungsauftrag bei STERN TOURS')
|
||||
->setFrom('stern@stern-tours.de', 'STERN TOURS')
|
||||
->setTo($fewoBookingRequest->getEmail())
|
||||
->setBody(
|
||||
$this->renderView('default/email/fewoBookingConfirmationEmail.txt.twig', [
|
||||
'base_dir' => realpath($this->getParameter('kernel.root_dir') . '/..') . DIRECTORY_SEPARATOR,
|
||||
'fewo_booking_request' => $fewoBookingRequest,
|
||||
'fewo_lodging' => $lodging,
|
||||
'fewo_price' => $price,
|
||||
//'booking_price_info' => $bookingPriceInfo,
|
||||
//'travel_date' => $travelDate,
|
||||
//'breadcrumb_entries' => $breadcrumbEntries,
|
||||
]),
|
||||
'text/plain', 'utf-8'
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$this->get('mailer')->send(\Swift_Message::newInstance()
|
||||
->setSubject('FEWO-BUCHUNG: ' . $lodging->getName())
|
||||
->setFrom('stern@stern-tours.de', 'STERN TOURS')
|
||||
->setTo('stern@stern-tours.de')
|
||||
->setBody(
|
||||
$this->renderView('default/email/fewoBookingServiceEmail.txt.twig', [
|
||||
'base_dir' => realpath($this->getParameter('kernel.root_dir') . '/..') . DIRECTORY_SEPARATOR,
|
||||
'crm_url' => $crmBookingUrl,
|
||||
'lodging_url' => Util::getBaseUrl() . $fewoTravelProgramPage->getUrlPath(),
|
||||
'fewo_booking_request' => $fewoBookingRequest,
|
||||
'fewo_lodging' => $lodging,
|
||||
'fewo_price' => $price,
|
||||
//'booking_price_info' => $bookingPriceInfo,
|
||||
//'travel_date' => $travelDate,
|
||||
//'breadcrumb_entries' => $breadcrumbEntries,
|
||||
]),
|
||||
'text/plain', 'utf-8'
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
return $this->render('default/pages/fewoBookingConfirmation.html.twig', [
|
||||
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
||||
'page' => $fewoTravelProgramPage,
|
||||
'fewo_booking_request' => $fewoBookingRequest,
|
||||
'fewo_lodging' => $lodging,
|
||||
'fewo_price' => $price,
|
||||
'total_price' => $totalPrice,
|
||||
'total_price_per_night' => $perDayTotalPrice,
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->render('default/pages/fewoBooking.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'fewo_booking_request' => $fewoBookingRequest,
|
||||
'lodging' => $lodging,
|
||||
'fromDate' => $fromDate,
|
||||
'toDate' => $toDate,
|
||||
'fewo_lodging' => $lodging,
|
||||
'fewo_price' => $price,
|
||||
'total_price' => $totalPrice,
|
||||
'total_price_per_night' => $perDayTotalPrice,
|
||||
|
||||
]);
|
||||
|
||||
}
|
||||
elseif($action == '/fewo-berechne-gesamtpreis')
|
||||
{
|
||||
return $this->render('default/components/booking/fewoSummary.html.twig', [
|
||||
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
|
||||
'fewo_booking_request' => $fewoBookingRequest,
|
||||
'fewo_lodging' => $lodging,
|
||||
'fewo_price' => $price,
|
||||
'total_price' => $totalPrice,
|
||||
'total_price_per_night' => $perDayTotalPrice,
|
||||
]);
|
||||
|
||||
}
|
||||
throw new \Exception('Unknow FewoBookingController action: '. $action);
|
||||
}
|
||||
|
||||
public function calculatePrice(FewoBookingRequest $fewoBookingRequest, FewoLodging $fewoLodging, FewoPrice $fewoPrice)
|
||||
{
|
||||
$result = $fewoLodging->getDeposit();
|
||||
$result = $result + $fewoPrice->getFlatPrice();
|
||||
|
||||
for($i = 0; $i < $fewoBookingRequest->getNumberDays(); $i++)
|
||||
{
|
||||
$result = $result + $fewoPrice->getPerNight();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function calculatePerDayTotalPrice(FewoBookingRequest $fewoBookingRequest, FewoPrice $fewoPrice)
|
||||
{
|
||||
$result = 0;
|
||||
for($i = 0; $i < $fewoBookingRequest->getNumberDays(); $i++)
|
||||
{
|
||||
$result = $result + $fewoPrice->getPerNight();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
428
trunk/src/AppBundle/Entity/FewoBookingRequest.php
Normal file
428
trunk/src/AppBundle/Entity/FewoBookingRequest.php
Normal file
|
|
@ -0,0 +1,428 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Ulrich Hecht <ulrich.hecht@hecht-software.de>
|
||||
* @date 12/16/2016
|
||||
*/
|
||||
|
||||
namespace AppBundle\Entity;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use AppBundle\Validator\Constraints as AppBundleAssert;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
//TODO im folgenden fehlt noch die Validierung
|
||||
/**
|
||||
* Class BookingRequest
|
||||
* @package AppBundle\Entity
|
||||
* @AppBundleAssert\FewoBookingRequest
|
||||
*/
|
||||
class FewoBookingRequest
|
||||
{
|
||||
// Used in SternToursCrmBookingExports, expected to be equivalent to sex (as defined in Traveler)
|
||||
const MR = 1;
|
||||
const MRS = 2;
|
||||
|
||||
/**
|
||||
* @Assert\DateTime()
|
||||
*/
|
||||
private $fromDate;
|
||||
|
||||
/**
|
||||
* @Assert\DateTime()
|
||||
*/
|
||||
private $toDate;
|
||||
|
||||
private $numberDays;
|
||||
|
||||
private $totalPrice;
|
||||
|
||||
private $salutation;
|
||||
|
||||
/**
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
private $firstName;
|
||||
|
||||
/**
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
private $lastName;
|
||||
|
||||
/**
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
private $streetAddress;
|
||||
|
||||
/**
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
private $zipCode;
|
||||
|
||||
/**
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
private $city;
|
||||
|
||||
private $nation;
|
||||
|
||||
/**
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
private $phone;
|
||||
|
||||
private $fax;
|
||||
|
||||
/**
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
private $email;
|
||||
|
||||
private $notes;
|
||||
|
||||
private $travelerCount;
|
||||
|
||||
private $acceptTerms = false;
|
||||
|
||||
private $lodging;
|
||||
|
||||
private $season;
|
||||
|
||||
private $price;
|
||||
|
||||
/**
|
||||
* BookingRequest constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFromDate()
|
||||
{
|
||||
return $this->fromDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $fromDate
|
||||
*/
|
||||
public function setFromDate($fromDate)
|
||||
{
|
||||
$this->fromDate = $fromDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getToDate()
|
||||
{
|
||||
return $this->toDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $toDate
|
||||
*/
|
||||
public function setToDate($toDate)
|
||||
{
|
||||
$this->toDate = $toDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getSalutation()
|
||||
{
|
||||
return $this->salutation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $salutation
|
||||
*/
|
||||
public function setSalutation($salutation)
|
||||
{
|
||||
$this->salutation = $salutation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFirstName()
|
||||
{
|
||||
return $this->firstName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $firstName
|
||||
*/
|
||||
public function setFirstName($firstName)
|
||||
{
|
||||
$this->firstName = $firstName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getLastName()
|
||||
{
|
||||
return $this->lastName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $lastName
|
||||
*/
|
||||
public function setLastName($lastName)
|
||||
{
|
||||
$this->lastName = $lastName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getStreetAddress()
|
||||
{
|
||||
return $this->streetAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $streetAddress
|
||||
*/
|
||||
public function setStreetAddress($streetAddress)
|
||||
{
|
||||
$this->streetAddress = $streetAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getZipCode()
|
||||
{
|
||||
return $this->zipCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $zipCode
|
||||
*/
|
||||
public function setZipCode($zipCode)
|
||||
{
|
||||
$this->zipCode = $zipCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCity()
|
||||
{
|
||||
return $this->city;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $city
|
||||
*/
|
||||
public function setCity($city)
|
||||
{
|
||||
$this->city = $city;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getNation()
|
||||
{
|
||||
return $this->nation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $nation
|
||||
*/
|
||||
public function setNation($nation)
|
||||
{
|
||||
$this->nation = $nation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPhone()
|
||||
{
|
||||
return $this->phone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $phone
|
||||
*/
|
||||
public function setPhone($phone)
|
||||
{
|
||||
$this->phone = $phone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFax()
|
||||
{
|
||||
return $this->fax;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $fax
|
||||
*/
|
||||
public function setFax($fax)
|
||||
{
|
||||
$this->fax = $fax;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $email
|
||||
*/
|
||||
public function setEmail($email)
|
||||
{
|
||||
$this->email = $email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getNotes()
|
||||
{
|
||||
return $this->notes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $notes
|
||||
*/
|
||||
public function setNotes($notes)
|
||||
{
|
||||
$this->notes = $notes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTravelerCount()
|
||||
{
|
||||
return $this->travelerCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $travelerCount
|
||||
*/
|
||||
public function setTravelerCount($travelerCount)
|
||||
{
|
||||
$this->travelerCount = $travelerCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAcceptTerms()
|
||||
{
|
||||
return $this->acceptTerms;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $acceptTerms
|
||||
*/
|
||||
public function setAcceptTerms($acceptTerms)
|
||||
{
|
||||
$this->acceptTerms = $acceptTerms;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getNumberDays()
|
||||
{
|
||||
return $this->numberDays;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $numberDays
|
||||
*/
|
||||
public function setNumberDays($numberDays)
|
||||
{
|
||||
$this->numberDays = $numberDays;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTotalPrice()
|
||||
{
|
||||
return $this->totalPrice;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $totalPrice
|
||||
*/
|
||||
public function setTotalPrice($totalPrice)
|
||||
{
|
||||
$this->totalPrice = $totalPrice;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FewoLodging
|
||||
*/
|
||||
public function getLodging()
|
||||
{
|
||||
return $this->lodging;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FewoLodging $lodging
|
||||
*/
|
||||
public function setLodging($lodging)
|
||||
{
|
||||
$this->lodging = $lodging;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FewoSeason
|
||||
*/
|
||||
public function getSeason()
|
||||
{
|
||||
return $this->season;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FewoSeason $season
|
||||
*/
|
||||
public function setSeason($season)
|
||||
{
|
||||
$this->season = $season;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FewoPrice
|
||||
*/
|
||||
public function getPrice()
|
||||
{
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FewoPrice $price
|
||||
*/
|
||||
public function setPrice($price)
|
||||
{
|
||||
$this->price = $price;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Assert\Callback
|
||||
*/
|
||||
public function validate(ExecutionContextInterface $context, $payload)
|
||||
{
|
||||
//$context->
|
||||
}
|
||||
|
||||
}
|
||||
619
trunk/src/AppBundle/Entity/FewoLodging.php
Normal file
619
trunk/src/AppBundle/Entity/FewoLodging.php
Normal file
|
|
@ -0,0 +1,619 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Entity;
|
||||
|
||||
use AppBundle\AppBundle;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
|
||||
/**
|
||||
* @ORM\Table
|
||||
* @ORM\Entity(repositoryClass="AppBundle\Entity\FewoLodgingRepository")
|
||||
*/
|
||||
class FewoLodging
|
||||
{
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Allgemein
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="name", type="string", length=255, nullable=false)
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var \AppBundle\Entity\FewoLodgingType
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="FewoLodgingType")
|
||||
* @ORM\JoinColumns({
|
||||
* @ORM\JoinColumn(name="type_id", referencedColumnName="id")
|
||||
* })
|
||||
*/
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* @var text
|
||||
*
|
||||
* @ORM\Column(name="description", type="text", nullable=false)
|
||||
*/
|
||||
private $description;
|
||||
|
||||
/**
|
||||
* @var text
|
||||
*
|
||||
* @ORM\Column(name="equipment", type="text", nullable=false)
|
||||
*/
|
||||
private $equipment;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Adresse
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="adress1", type="string", length=255, nullable=false)
|
||||
*/
|
||||
private $adress1;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="adress2", type="string", length=255, nullable=true)
|
||||
*/
|
||||
private $adress2;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="zip_code", type="string", length=255, nullable=false)
|
||||
*/
|
||||
private $zipCode;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="city", type="string", length=255, nullable=false)
|
||||
*/
|
||||
private $city;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Preise
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="maximum_persons", type="integer", nullable=false)
|
||||
*/
|
||||
private $maximumPersons;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*
|
||||
* @ORM\Column(name="deposit", type="float", scale=2, nullable=false)
|
||||
*/
|
||||
private $deposit;
|
||||
|
||||
/**
|
||||
* @var \AppBundle\Entity\FewoPrice
|
||||
*
|
||||
* @ORM\OneToMany(targetEntity="FewoPrice", mappedBy="lodging", cascade={"persist", "remove"})
|
||||
*/
|
||||
private $prices;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Bilder
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="FewoLodgingImage", mappedBy="lodging", cascade={"persist", "remove"})
|
||||
*/
|
||||
private $images;
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Kalender
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="only_weekday", type="integer", nullable=false)
|
||||
*/
|
||||
private $onlyWeekday;
|
||||
|
||||
/**
|
||||
* @var \AppBundle\Entity\FewoReservation
|
||||
*
|
||||
* @ORM\OneToMany(targetEntity="FewoReservation", mappedBy="lodging", cascade={"persist", "remove"})
|
||||
*/
|
||||
private $reservations;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*
|
||||
* @ORM\Column(name="calendar_visible", type="boolean", nullable=false)
|
||||
*/
|
||||
private $calendarVisible;
|
||||
|
||||
private $choosableSeasons;
|
||||
|
||||
/**
|
||||
* @ORM\OneToOne(targetEntity="AppBundle\Entity\Page", mappedBy="fewoLodging")
|
||||
*/
|
||||
private $page;
|
||||
|
||||
|
||||
public function getChoosableSeasons()
|
||||
{
|
||||
return $this->choosableSeasons;
|
||||
}
|
||||
|
||||
public function setChoosableSeasons($choosableSeasons)
|
||||
{
|
||||
$this->choosableSeasons = $choosableSeasons;
|
||||
}
|
||||
|
||||
public function getSeasons()
|
||||
{
|
||||
$prices = $this->getPrices();
|
||||
$seasons = null;
|
||||
for($i = 0; $i < count($prices); $i++)
|
||||
{
|
||||
$seasons[] = $prices->get($i)->getSeason();
|
||||
}
|
||||
return $seasons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->prices = new \Doctrine\Common\Collections\ArrayCollection();
|
||||
$this->images = new \Doctrine\Common\Collections\ArrayCollection();
|
||||
$this->reservations = new \Doctrine\Common\Collections\ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set name
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return FewoLodging
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set description
|
||||
*
|
||||
* @param string $description
|
||||
*
|
||||
* @return FewoLodging
|
||||
*/
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set equipment
|
||||
*
|
||||
* @param string $equipment
|
||||
*
|
||||
* @return FewoLodging
|
||||
*/
|
||||
public function setEquipment($equipment)
|
||||
{
|
||||
$this->equipment = $equipment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get equipment
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEquipment()
|
||||
{
|
||||
return $this->equipment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set adress1
|
||||
*
|
||||
* @param string $adress1
|
||||
*
|
||||
* @return FewoLodging
|
||||
*/
|
||||
public function setAdress1($adress1)
|
||||
{
|
||||
$this->adress1 = $adress1;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get adress1
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAdress1()
|
||||
{
|
||||
return $this->adress1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set adress2
|
||||
*
|
||||
* @param string $adress2
|
||||
*
|
||||
* @return FewoLodging
|
||||
*/
|
||||
public function setAdress2($adress2)
|
||||
{
|
||||
$this->adress2 = $adress2;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get adress2
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAdress2()
|
||||
{
|
||||
return $this->adress2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set zipCode
|
||||
*
|
||||
* @param string $zipCode
|
||||
*
|
||||
* @return FewoLodging
|
||||
*/
|
||||
public function setZipCode($zipCode)
|
||||
{
|
||||
$this->zipCode = $zipCode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get zipCode
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getZipCode()
|
||||
{
|
||||
return $this->zipCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set city
|
||||
*
|
||||
* @param string $city
|
||||
*
|
||||
* @return FewoLodging
|
||||
*/
|
||||
public function setCity($city)
|
||||
{
|
||||
$this->city = $city;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get city
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCity()
|
||||
{
|
||||
return $this->city;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set maximumPersons
|
||||
*
|
||||
* @param integer $maximumPersons
|
||||
*
|
||||
* @return FewoLodging
|
||||
*/
|
||||
public function setMaximumPersons($maximumPersons)
|
||||
{
|
||||
$this->maximumPersons = $maximumPersons;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get maximumPersons
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getMaximumPersons()
|
||||
{
|
||||
return $this->maximumPersons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set deposit
|
||||
*
|
||||
* @param float $deposit
|
||||
*
|
||||
* @return FewoLodging
|
||||
*/
|
||||
public function setDeposit($deposit)
|
||||
{
|
||||
$this->deposit = $deposit;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get deposit
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getDeposit()
|
||||
{
|
||||
return $this->deposit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set onlyWeekday
|
||||
*
|
||||
* @param integer $onlyWeekday
|
||||
*
|
||||
* @return FewoLodging
|
||||
*/
|
||||
public function setOnlyWeekday($onlyWeekday)
|
||||
{
|
||||
$this->onlyWeekday = $onlyWeekday;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get onlyWeekday
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getOnlyWeekday()
|
||||
{
|
||||
return $this->onlyWeekday;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set calendarVisible
|
||||
*
|
||||
* @param boolean $calendarVisible
|
||||
*
|
||||
* @return FewoLodging
|
||||
*/
|
||||
public function setCalendarVisible($calendarVisible)
|
||||
{
|
||||
$this->calendarVisible = $calendarVisible;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get calendarVisible
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getCalendarVisible()
|
||||
{
|
||||
return $this->calendarVisible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set type
|
||||
*
|
||||
* @param \AppBundle\Entity\FewoLodgingType $type
|
||||
*
|
||||
* @return FewoLodging
|
||||
*/
|
||||
public function setType(\AppBundle\Entity\FewoLodgingType $type = null)
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type
|
||||
*
|
||||
* @return \AppBundle\Entity\FewoLodgingType
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add price
|
||||
*
|
||||
* @param \AppBundle\Entity\FewoPrice $price
|
||||
*
|
||||
* @return FewoLodging
|
||||
*/
|
||||
public function addPrice(\AppBundle\Entity\FewoPrice $price)
|
||||
{
|
||||
$this->prices[] = $price;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove price
|
||||
*
|
||||
* @param \AppBundle\Entity\FewoPrice $price
|
||||
*/
|
||||
public function removePrice(\AppBundle\Entity\FewoPrice $price)
|
||||
{
|
||||
$this->prices->removeElement($price);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get prices
|
||||
*
|
||||
* @return \Doctrine\Common\Collections\Collection
|
||||
*/
|
||||
public function getPrices()
|
||||
{
|
||||
return $this->prices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add image
|
||||
*
|
||||
* @param \AppBundle\Entity\FewoLodgingImage $image
|
||||
*
|
||||
* @return FewoLodging
|
||||
*/
|
||||
public function addImage(\AppBundle\Entity\FewoLodgingImage $image)
|
||||
{
|
||||
$this->images[] = $image;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove image
|
||||
*
|
||||
* @param \AppBundle\Entity\FewoLodgingImage $image
|
||||
*/
|
||||
public function removeImage(\AppBundle\Entity\FewoLodgingImage $image)
|
||||
{
|
||||
$this->images->removeElement($image);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get images
|
||||
*
|
||||
* @return \Doctrine\Common\Collections\Collection
|
||||
*/
|
||||
public function getImages()
|
||||
{
|
||||
return $this->images;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add reservation
|
||||
*
|
||||
* @param \AppBundle\Entity\FewoReservation $reservation
|
||||
*
|
||||
* @return FewoLodging
|
||||
*/
|
||||
public function addReservation(\AppBundle\Entity\FewoReservation $reservation)
|
||||
{
|
||||
$this->reservations[] = $reservation;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove reservation
|
||||
*
|
||||
* @param \AppBundle\Entity\FewoReservation $reservation
|
||||
*/
|
||||
public function removeReservation(\AppBundle\Entity\FewoReservation $reservation)
|
||||
{
|
||||
$this->reservations->removeElement($reservation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get reservations
|
||||
*
|
||||
* @return \Doctrine\Common\Collections\Collection
|
||||
*/
|
||||
public function getReservations()
|
||||
{
|
||||
return $this->reservations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set page
|
||||
*
|
||||
* @param \AppBundle\Entity\Page $page
|
||||
*
|
||||
* @return FewoLodging
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function __toString()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
}
|
||||
167
trunk/src/AppBundle/Entity/FewoLodgingImage.php
Normal file
167
trunk/src/AppBundle/Entity/FewoLodgingImage.php
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Entity;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Table
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class FewoLodgingImage
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="full_file_name", type="string", length=255, nullable=false)
|
||||
* @Assert\Image(maxSize="6000000", mimeTypes={"image/jpeg", "image/png"})
|
||||
*/
|
||||
private $file;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="file_name", type="string", length=255, nullable=false)
|
||||
* @Assert\NotBlank
|
||||
*/
|
||||
private $fileName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="description", type="string", length=255, nullable=true)
|
||||
*/
|
||||
private $description;
|
||||
|
||||
/**
|
||||
* @var \AppBundle\Entity\FewoLodging
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="FewoLodging", inversedBy="images")
|
||||
* @ORM\JoinColumns({
|
||||
* @ORM\JoinColumn(name="lodging_id", referencedColumnName="id", onDelete="SET NULL")
|
||||
* })
|
||||
*/
|
||||
private $lodging;
|
||||
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set file
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return FewoLodgingImage
|
||||
*/
|
||||
public function setFile($file)
|
||||
{
|
||||
$this->file = $file;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFile()
|
||||
{
|
||||
return $this->file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set description
|
||||
*
|
||||
* @param string $description
|
||||
*
|
||||
* @return FewoLodgingImage
|
||||
*/
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set lodging
|
||||
*
|
||||
* @param \AppBundle\Entity\FewoLodging $lodging
|
||||
*
|
||||
* @return FewoLodgingImage
|
||||
*/
|
||||
public function setLodging(\AppBundle\Entity\FewoLodging $lodging = null)
|
||||
{
|
||||
$this->lodging = $lodging;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lodging
|
||||
*
|
||||
* @return \AppBundle\Entity\FewoLodging
|
||||
*/
|
||||
public function getLodging()
|
||||
{
|
||||
return $this->lodging;
|
||||
}
|
||||
|
||||
function __toString()
|
||||
{
|
||||
return $this->file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set fileName
|
||||
*
|
||||
* @param string $fileName
|
||||
*
|
||||
* @return FewoLodgingImage
|
||||
*/
|
||||
public function setFileName($fileName)
|
||||
{
|
||||
$this->fileName = $fileName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get fileName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFileName()
|
||||
{
|
||||
return $this->fileName;
|
||||
}
|
||||
}
|
||||
17
trunk/src/AppBundle/Entity/FewoLodgingRepository.php
Normal file
17
trunk/src/AppBundle/Entity/FewoLodgingRepository.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Entity;
|
||||
|
||||
/**
|
||||
* FewoLodgingRepository
|
||||
*
|
||||
* This class was generated by the Doctrine ORM. Add your own custom
|
||||
* repository methods below.
|
||||
*/
|
||||
class FewoLodgingRepository extends \Doctrine\ORM\EntityRepository
|
||||
{
|
||||
public function findWithChoosableSeasons($lodgingId)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
70
trunk/src/AppBundle/Entity/FewoLodgingType.php
Normal file
70
trunk/src/AppBundle/Entity/FewoLodgingType.php
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Entity;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Table
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class FewoLodgingType
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="name", type="string", length=255, nullable=true)
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set name
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return FewoLodgingType
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
function __toString()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
163
trunk/src/AppBundle/Entity/FewoPrice.php
Normal file
163
trunk/src/AppBundle/Entity/FewoPrice.php
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Entity;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Table
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class FewoPrice
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var \AppBundle\Entity\FewoLodging
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="FewoLodging", inversedBy="prices")
|
||||
* @ORM\JoinColumns({
|
||||
* @ORM\JoinColumn(name="lodging_id", referencedColumnName="id")
|
||||
* })
|
||||
*/
|
||||
private $lodging;
|
||||
|
||||
/**
|
||||
* @var \AppBundle\Entity\FewoSeason
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="FewoSeason", inversedBy="prices")
|
||||
* @ORM\JoinColumns({
|
||||
* @ORM\JoinColumn(name="season_id", referencedColumnName="id", onDelete="SET NULL")
|
||||
* })
|
||||
*/
|
||||
private $season;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*
|
||||
* @ORM\Column(name="per_night", type="float", scale=2, nullable=false)
|
||||
*/
|
||||
private $perNight;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*
|
||||
* @ORM\Column(name="flat_price", type="float", scale=2, nullable=false)
|
||||
*/
|
||||
private $flatPrice;
|
||||
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set perNight
|
||||
*
|
||||
* @param float $perNight
|
||||
*
|
||||
* @return FewoPrice
|
||||
*/
|
||||
public function setPerNight($perNight)
|
||||
{
|
||||
$this->perNight = $perNight;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get perNight
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getPerNight()
|
||||
{
|
||||
return $this->perNight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set flatPrice
|
||||
*
|
||||
* @param float $flatPrice
|
||||
*
|
||||
* @return FewoPrice
|
||||
*/
|
||||
public function setFlatPrice($flatPrice)
|
||||
{
|
||||
$this->flatPrice = $flatPrice;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get flatPrice
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getFlatPrice()
|
||||
{
|
||||
return $this->flatPrice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set lodging
|
||||
*
|
||||
* @param \AppBundle\Entity\FewoLodging $lodging
|
||||
*
|
||||
* @return FewoPrice
|
||||
*/
|
||||
public function setLodging(\AppBundle\Entity\FewoLodging $lodging = null)
|
||||
{
|
||||
$this->lodging = $lodging;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lodging
|
||||
*
|
||||
* @return \AppBundle\Entity\FewoLodging
|
||||
*/
|
||||
public function getLodging()
|
||||
{
|
||||
return $this->lodging;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set season
|
||||
*
|
||||
* @param \AppBundle\Entity\FewoSeason $season
|
||||
*
|
||||
* @return FewoPrice
|
||||
*/
|
||||
public function setSeason(\AppBundle\Entity\FewoSeason $season = null)
|
||||
{
|
||||
$this->season = $season;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get season
|
||||
*
|
||||
* @return \AppBundle\Entity\FewoSeason
|
||||
*/
|
||||
public function getSeason()
|
||||
{
|
||||
return $this->season;
|
||||
}
|
||||
}
|
||||
204
trunk/src/AppBundle/Entity/FewoReservation.php
Normal file
204
trunk/src/AppBundle/Entity/FewoReservation.php
Normal file
|
|
@ -0,0 +1,204 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Entity;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use AppBundle\Validator\Constraints as AppBundleAssert;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Table
|
||||
* @ORM\Entity
|
||||
* @AppBundleAssert\FewoReservation
|
||||
*/
|
||||
class FewoReservation
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var \AppBundle\Entity\FewoLodging
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="FewoLodging", inversedBy="reservations")
|
||||
* @ORM\JoinColumns({
|
||||
* @ORM\JoinColumn(name="lodging_id", referencedColumnName="id", onDelete="SET NULL")
|
||||
* })
|
||||
*/
|
||||
private $lodging;
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
*
|
||||
* @ORM\Column(name="from_date", type="date", nullable=false)
|
||||
*/
|
||||
private $fromDate;
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
*
|
||||
* @ORM\Column(name="to_date", type="date", nullable=false)
|
||||
*/
|
||||
private $toDate;
|
||||
|
||||
// belegt, nicht verfügbar
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="status", type="integer", nullable=false)
|
||||
*/
|
||||
private $status;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="type", type="integer", nullable=false)
|
||||
*/
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set fromDate
|
||||
*
|
||||
* @param \DateTime $fromDate
|
||||
*
|
||||
* @return FewoReservation
|
||||
*/
|
||||
public function setFromDate($fromDate)
|
||||
{
|
||||
$this->fromDate = $fromDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get fromDate
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getFromDate()
|
||||
{
|
||||
return $this->fromDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set toDate
|
||||
*
|
||||
* @param \DateTime $toDate
|
||||
*
|
||||
* @return FewoReservation
|
||||
*/
|
||||
public function setToDate($toDate)
|
||||
{
|
||||
$this->toDate = $toDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get toDate
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getToDate()
|
||||
{
|
||||
return $this->toDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set status
|
||||
*
|
||||
* @param integer $status
|
||||
*
|
||||
* @return FewoReservation
|
||||
*/
|
||||
public function setStatus($status)
|
||||
{
|
||||
$this->status = $status;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get status
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set lodging
|
||||
*
|
||||
* @param \AppBundle\Entity\FewoLodging $lodging
|
||||
*
|
||||
* @return FewoReservation
|
||||
*/
|
||||
public function setLodging(\AppBundle\Entity\FewoLodging $lodging = null)
|
||||
{
|
||||
$this->lodging = $lodging;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lodging
|
||||
*
|
||||
* @return \AppBundle\Entity\FewoLodging
|
||||
*/
|
||||
public function getLodging()
|
||||
{
|
||||
return $this->lodging;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set type
|
||||
*
|
||||
* @param integer $type
|
||||
*
|
||||
* @return FewoReservation
|
||||
*/
|
||||
public function setType($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Assert\Callback
|
||||
*/
|
||||
public function validate(ExecutionContextInterface $context, $payload)
|
||||
{
|
||||
//$context->
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
245
trunk/src/AppBundle/Entity/FewoSeason.php
Normal file
245
trunk/src/AppBundle/Entity/FewoSeason.php
Normal file
|
|
@ -0,0 +1,245 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Entity;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\Date;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Table
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class FewoSeason
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
// es gab hier lodgings, wird aber über prices geholt
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="name", type="string", length=255, nullable=false)
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var \AppBundle\Entity\FewoPrice
|
||||
*
|
||||
* @ORM\OneToMany(targetEntity="FewoPrice", mappedBy="season", cascade={"persist", "remove"})
|
||||
*/
|
||||
private $prices;
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
*
|
||||
* @ORM\Column(name="from_date", type="date", nullable=false)
|
||||
*/
|
||||
private $fromDate;
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
*
|
||||
* @ORM\Column(name="to_date", type="date", nullable=false)
|
||||
*/
|
||||
private $toDate;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="minimum_stay", type="integer", nullable=false)
|
||||
*/
|
||||
private $minimumStay;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="description", type="text", nullable=true)
|
||||
*/
|
||||
private $description;
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->prices = new \Doctrine\Common\Collections\ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set fromDate
|
||||
*
|
||||
* @param \DateTime $fromDate
|
||||
*
|
||||
* @return FewoSeason
|
||||
*/
|
||||
public function setFromDate($fromDate)
|
||||
{
|
||||
$this->fromDate = $fromDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get fromDate
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getFromDate()
|
||||
{
|
||||
return $this->fromDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set toDate
|
||||
*
|
||||
* @param \DateTime $toDate
|
||||
*
|
||||
* @return FewoSeason
|
||||
*/
|
||||
public function setToDate($toDate)
|
||||
{
|
||||
$this->toDate = $toDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get toDate
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getToDate()
|
||||
{
|
||||
return $this->toDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set minimumStay
|
||||
*
|
||||
* @param integer $minimumStay
|
||||
*
|
||||
* @return FewoSeason
|
||||
*/
|
||||
public function setMinimumStay($minimumStay)
|
||||
{
|
||||
$this->minimumStay = $minimumStay;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get minimumStay
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getMinimumStay()
|
||||
{
|
||||
return $this->minimumStay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set description
|
||||
*
|
||||
* @param string $description
|
||||
*
|
||||
* @return FewoSeason
|
||||
*/
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add price
|
||||
*
|
||||
* @param \AppBundle\Entity\FewoPrice $price
|
||||
*
|
||||
* @return FewoSeason
|
||||
*/
|
||||
public function addPrice(\AppBundle\Entity\FewoPrice $price)
|
||||
{
|
||||
$this->prices[] = $price;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove price
|
||||
*
|
||||
* @param \AppBundle\Entity\FewoPrice $price
|
||||
*/
|
||||
public function removePrice(\AppBundle\Entity\FewoPrice $price)
|
||||
{
|
||||
$this->prices->removeElement($price);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get prices
|
||||
*
|
||||
* @return \Doctrine\Common\Collections\Collection
|
||||
*/
|
||||
public function getPrices()
|
||||
{
|
||||
return $this->prices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set name
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return FewoSeason
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
function __toString()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -100,10 +100,18 @@ class Page
|
|||
* @var TravelProgram
|
||||
*
|
||||
* @ORM\OneToOne(targetEntity="AppBundle\Entity\TravelProgram", inversedBy="page")
|
||||
* @ORM\JoinColumn(name="travel_program", referencedColumnName="id")
|
||||
* @ORM\JoinColumn(name="travel_program", referencedColumnName="id", onDelete="SET NULL")
|
||||
*/
|
||||
private $travelProgram;
|
||||
|
||||
/**
|
||||
* @var FewoLodging
|
||||
*
|
||||
* @ORM\OneToOne(targetEntity="AppBundle\Entity\FewoLodging", inversedBy="page")
|
||||
* @ORM\JoinColumn(name="fewo_lodging", referencedColumnName="id", onDelete="SET NULL")
|
||||
*/
|
||||
private $fewoLodging;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
|
|
@ -1070,6 +1078,30 @@ class Page
|
|||
return $this->travelProgram;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set fewoLodging
|
||||
*
|
||||
* @param \AppBundle\Entity\FewoLodging $fewoLodging
|
||||
*
|
||||
* @return Page
|
||||
*/
|
||||
public function setFewoLodging(\AppBundle\Entity\FewoLodging $fewoLodging = null)
|
||||
{
|
||||
$this->fewoLodging = $fewoLodging;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get fewoLodging
|
||||
*
|
||||
* @return \AppBundle\Entity\FewoLodging
|
||||
*/
|
||||
public function getFewoLodging()
|
||||
{
|
||||
return $this->fewoLodging;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $realUrlPath
|
||||
*
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class Traveler
|
|||
|
||||
/**
|
||||
* @Assert\NotNull
|
||||
* @ Assert\Choice(choices={1,2})
|
||||
* @Assert\Choice(choices={1,2})
|
||||
*/
|
||||
private $sex;
|
||||
|
||||
|
|
|
|||
144
trunk/src/AppBundle/Export/FewoBookingSternToursCrmExporter.php
Normal file
144
trunk/src/AppBundle/Export/FewoBookingSternToursCrmExporter.php
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Export;
|
||||
|
||||
|
||||
use AppBundle\Entity\BookingRequest;
|
||||
use AppBundle\Entity\FewoBookingRequest;
|
||||
use AppBundle\Entity\FewoLodging;
|
||||
use AppBundle\Entity\FewoPrice;
|
||||
use AppBundle\Entity\TravelDate;
|
||||
use AppBundle\Entity\Traveler;
|
||||
use AppBundle\Util;
|
||||
use Monolog\Logger;
|
||||
|
||||
class FewoBookingSternToursCrmExporter extends SternToursCrmExporter
|
||||
{
|
||||
|
||||
public function __construct(Logger $logger)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
public function process(FewoBookingRequest $fewoBookingRequest, FewoLodging $fewoLodging, FewoPrice $fewoPrice)
|
||||
{
|
||||
$lead = $this->createLead($fewoBookingRequest);
|
||||
if ($lead === null)
|
||||
{
|
||||
$this->warn('Failed creating lead in CRM', $fewoBookingRequest, Logger::ERROR);
|
||||
return false;
|
||||
}
|
||||
$bookingUrl = $this->createBooking($fewoBookingRequest, $fewoLodging, $fewoPrice, $lead['customer_id'], $lead['id']);
|
||||
if ($bookingUrl === false)
|
||||
{
|
||||
$this->warn('Failed creating booking in CRM', $fewoBookingRequest, Logger::ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
if(!$this->createTraveler($bookingUrl, $fewoBookingRequest))
|
||||
{
|
||||
$this->warn('Failed creating traveler in CRM.', $fewoBookingRequest);
|
||||
}
|
||||
*/
|
||||
|
||||
return $bookingUrl;
|
||||
}
|
||||
|
||||
private function createLead(FewoBookingRequest $fewoBookingRequest)
|
||||
{
|
||||
$resp = $this->httpPost('lead', ['lead' => [
|
||||
'customerForm' => [
|
||||
'salutation_id' => $fewoBookingRequest->getSalutation(),
|
||||
'name' => $fewoBookingRequest->getLastName(),
|
||||
'firstname' => $fewoBookingRequest->getFirstName(),
|
||||
'street' => $fewoBookingRequest->getStreetAddress(),
|
||||
'zip' => $fewoBookingRequest->getZipCode(),
|
||||
'city' => $fewoBookingRequest->getCity(),
|
||||
'country_id' => $fewoBookingRequest->getNation(),
|
||||
'phone' => $fewoBookingRequest->getPhone(),
|
||||
'fax' => $fewoBookingRequest->getFax(),
|
||||
'email' => $fewoBookingRequest->getEmail()
|
||||
],
|
||||
'request_date' => (new \DateTime())->format('Y-m-d'),
|
||||
'sf_guard_user_id' => self::API_USER_ID,
|
||||
'status_id' => 7, // 'gebucht'
|
||||
'travelperiod_start' => $fewoBookingRequest->getFromDate()->format('Y-m-d'),
|
||||
'travelperiod_end' => $fewoBookingRequest->getToDate()->format('Y-m-d'),
|
||||
//'travelcategory_id'
|
||||
'is_closed' => 1,
|
||||
'website_id' => self::WEBSITE_ID,
|
||||
'initialcontacttype_id' => 14,
|
||||
// 'travelperiod_length
|
||||
'remarks' => $fewoBookingRequest->getNotes()
|
||||
]]);
|
||||
|
||||
if ($resp['success'])
|
||||
{
|
||||
$ret = $this->httpGet($resp['location']);
|
||||
if ($ret == null)
|
||||
{
|
||||
$this->warn('Failed retrieving newly created lead object', $fewoBookingRequest);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private function createBooking(FewoBookingRequest $fewoBookingRequest, FewoLodging $lodging, FewoPrice $price, $customerId, $leadId)
|
||||
{
|
||||
$resp = $this->httpPost('booking', ['booking' => [
|
||||
'booking_date' => (new \DateTime())->format('Y-m-d'),
|
||||
'customer_id' => $customerId,
|
||||
'lead_id' => $leadId,
|
||||
//'travel_country_id' => $tp->getTravelCountry(),
|
||||
//'travel_category_id' => $tp->getTravelCategory(),
|
||||
//'travelagenda_id' => $tp->getTravelAgenda(),
|
||||
'sf_guard_user_id' => self::API_USER_ID,
|
||||
'branch_id' => 4,
|
||||
'website_id' => self::WEBSITE_ID,
|
||||
'title' => $lodging->getName(),
|
||||
'start_date' => $fewoBookingRequest->getFromDate()->format('Y-m-d'),
|
||||
'end_date' => $fewoBookingRequest->getToDate()->format('Y-m-d'),
|
||||
'pax' => $fewoBookingRequest->getTravelerCount(),
|
||||
'travel_number' => $lodging->getName()." - ".$price->getSeason()->getName(),
|
||||
'price' => $fewoBookingRequest->getTotalPrice(),
|
||||
|
||||
'participant_salutation_id' => $fewoBookingRequest->getSalutation(),
|
||||
'participant_name' => $fewoBookingRequest->getLastName(),
|
||||
'participant_firstname' => $fewoBookingRequest->getFirstName(),
|
||||
//'participant_birthdate' => $bookingRequest->getTravelers()[0]->getBirthDate(),
|
||||
]]);
|
||||
|
||||
if (!$resp['success'])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return $resp['location'];
|
||||
}
|
||||
|
||||
private function createTraveler($bookingUrl, FewoBookingRequest $fewoBookingRequest)
|
||||
{
|
||||
$resp = $this->httpPost($bookingUrl .'/participant.json', ['participant' => [
|
||||
'participant_salutation_id' => $fewoBookingRequest->getSalutation(),
|
||||
'participant_name' => $fewoBookingRequest->getLastName(),
|
||||
'participant_firstname' => $fewoBookingRequest->getFirstName(),
|
||||
//'participant_birthdate' => $traveler->getBirthDate(),
|
||||
]], true);
|
||||
return $resp['success'];
|
||||
}
|
||||
|
||||
private function warn($msg, FewoBookingRequest $fewoBookingRequest = null, $level = Logger::WARNING)
|
||||
{
|
||||
$this->logger->log($level, 'SternToursCrmBookingExporter: '. $msg);
|
||||
$this->logger->log($level, '*** Date: '. (new \DateTime())->format('d.m.Y'));
|
||||
|
||||
if ($fewoBookingRequest !== null)
|
||||
{
|
||||
$this->logger->log($level, '*** Booking date: '. $fewoBookingRequest->getFromDate()->format('d.m.Y') .
|
||||
' - '. $fewoBookingRequest->getToDate()->format('d.m.Y') .')');
|
||||
|
||||
$this->logger->log($level, '*** User name: '. $fewoBookingRequest->getFirstName() .' '. $fewoBookingRequest->getLastName());
|
||||
}
|
||||
}
|
||||
}
|
||||
118
trunk/src/AppBundle/Form/FewoBookingRequestType.php
Normal file
118
trunk/src/AppBundle/Form/FewoBookingRequestType.php
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Form;
|
||||
|
||||
//TODO bereinigen
|
||||
use AppBundle\Entity\BookingRequest;
|
||||
use AppBundle\Entity\TravelDate;
|
||||
use AppBundle\Entity\Traveler;
|
||||
use AppBundle\Entity\TravelProgram;
|
||||
use AppBundle\Util;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use AppBundle\Form\StPlainDateType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\RangeType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Validator\Constraints\Choice;
|
||||
use Symfony\Component\Validator\Constraints\NotNull;
|
||||
|
||||
class FewoBookingRequestType extends AbstractType
|
||||
{
|
||||
|
||||
public static $SALUTATION_CHOICES = [
|
||||
'Herr' => 1,
|
||||
'Frau' => 2
|
||||
];
|
||||
|
||||
public static $NATION_CHOICES = [
|
||||
'Deutschland' => 27,
|
||||
'Österreich' => 34,
|
||||
'Schweiz' => 181,
|
||||
'Niederlande' => 196,
|
||||
'Sonstiges' => 197,
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'lodging' => null,
|
||||
'maxPersons' => null,
|
||||
'toDate' => null,
|
||||
'data_class' => 'AppBundle\Entity\FewoBookingRequest',
|
||||
]);
|
||||
|
||||
$resolver->setAllowedTypes('lodging', ['AppBundle\Entity\FewoLodging']);
|
||||
$resolver->setAllowedTypes('toDate', ['string', 'NULL']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$maxPersons = $options['maxPersons'];
|
||||
$toDate = $options['toDate'];
|
||||
$toDateDateTime = new \DateTime($toDate);
|
||||
|
||||
$TRAVELERS_CHOICES = [
|
||||
'1' => 1,
|
||||
];
|
||||
|
||||
if($maxPersons > 1)
|
||||
{
|
||||
for($i = 2; $i <= $maxPersons; $i++)
|
||||
{
|
||||
$TRAVELERS_CHOICES[] = $i;
|
||||
}
|
||||
}
|
||||
|
||||
$builder
|
||||
->add('toDate', StDateType::class, [
|
||||
//options
|
||||
//'widget' => 'single_text',
|
||||
'data' => $toDateDateTime,
|
||||
'format' => 'd.M.y'
|
||||
])
|
||||
->add('travelerCount', ChoiceType::class, [
|
||||
'choices' => $TRAVELERS_CHOICES,
|
||||
'constraints' => [
|
||||
new NotNull(),
|
||||
new Choice(['choices' => $TRAVELERS_CHOICES])
|
||||
]
|
||||
])
|
||||
->add('salutation', ChoiceType::class,[
|
||||
'choices' => self::$SALUTATION_CHOICES,
|
||||
'constraints' => [
|
||||
new NotNull(),
|
||||
new Choice(['choices' => self::$SALUTATION_CHOICES])
|
||||
]
|
||||
])
|
||||
->add('firstName')
|
||||
->add('lastName')
|
||||
->add('streetAddress')
|
||||
->add('zipCode')
|
||||
->add('city')
|
||||
->add('phone')
|
||||
->add('fax')
|
||||
->add('email')
|
||||
->add('notes', TextareaType::class, ['required' => false])
|
||||
;
|
||||
|
||||
}
|
||||
}
|
||||
46
trunk/src/AppBundle/Form/FewoLodgingImageType.php
Normal file
46
trunk/src/AppBundle/Form/FewoLodgingImageType.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FileType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class FewoLodgingImageType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('file', FileType::class, [
|
||||
|
||||
])
|
||||
->add('fileName')
|
||||
->add('description')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'AppBundle\Entity\FewoLodgingImage'
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'appbundle_fewolodgingimage';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
92
trunk/src/AppBundle/Form/FewoLodgingType.php
Normal file
92
trunk/src/AppBundle/Form/FewoLodgingType.php
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Form;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Validator\Constraints\Choice;
|
||||
use Symfony\Component\Validator\Constraints\NotNull;
|
||||
use AppBundle\Entity\FewoSeason;
|
||||
|
||||
|
||||
class FewoLodgingType extends AbstractType
|
||||
{
|
||||
public static $WEEKDAY_CHOICES = [
|
||||
'keiner' => 0,
|
||||
'Montag' => 1,
|
||||
'Dienstag' => 2,
|
||||
'Mittwoch' => 3,
|
||||
'Donnerstag' => 4,
|
||||
'Freitag' => 5,
|
||||
'Samstag' => 6,
|
||||
'Sonntag' => 7
|
||||
];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('name')
|
||||
->add('description')
|
||||
->add('equipment')
|
||||
->add('adress1')
|
||||
->add('adress2')
|
||||
->add('zipCode')
|
||||
->add('city')
|
||||
->add('maximumPersons', TextType::class, [
|
||||
|
||||
])
|
||||
->add('deposit')
|
||||
->add('onlyWeekday', ChoiceType::class, [
|
||||
'choices' => self::$WEEKDAY_CHOICES,
|
||||
'constraints' => [
|
||||
new Choice(['choices' => self::$WEEKDAY_CHOICES])
|
||||
]
|
||||
])
|
||||
->add('calendarVisible')
|
||||
->add('type', EntityType::class, [
|
||||
'placeholder' => '(Bitte wählen) *',
|
||||
'class' => 'AppBundle\Entity\FewoLodgingType',
|
||||
'constraints' => [
|
||||
new NotNull()
|
||||
]
|
||||
])
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'AppBundle\Entity\FewoLodging'
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'appbundle_fewolodging';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
60
trunk/src/AppBundle/Form/FewoPriceType.php
Normal file
60
trunk/src/AppBundle/Form/FewoPriceType.php
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Validator\Constraints\Choice;
|
||||
use Symfony\Component\Validator\Constraints\NotNull;
|
||||
|
||||
class FewoPriceType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$lodging = $options['lodging'];
|
||||
|
||||
$builder
|
||||
->add('perNight')
|
||||
->add('flatPrice')
|
||||
->add('season', EntityType::class, [
|
||||
'placeholder' => 'Bitte wählen',
|
||||
'class' => 'AppBundle\Entity\FewoSeason',
|
||||
'choices' => $lodging->getChoosableSeasons(),
|
||||
'constraints' => [
|
||||
new NotNull(),
|
||||
new Choice([
|
||||
'choices' => $lodging->getChoosableSeasons()
|
||||
]
|
||||
)]
|
||||
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'lodging' => null,
|
||||
'data_class' => 'AppBundle\Entity\FewoPrice'
|
||||
));
|
||||
$resolver->setAllowedTypes('lodging', ['AppBundle\Entity\FewoLodging']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'appbundle_fewoprice';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
95
trunk/src/AppBundle/Form/FewoReservationType.php
Normal file
95
trunk/src/AppBundle/Form/FewoReservationType.php
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Form;
|
||||
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Validator\Constraints\Choice;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use AppBundle\Form\StDateType;
|
||||
|
||||
class FewoReservationType extends AbstractType
|
||||
{
|
||||
public static $STATUS_CHOICES = [
|
||||
'Belegt' => 0,
|
||||
'Nicht verfügbar' => 1,
|
||||
];
|
||||
|
||||
public static $TYPE_CHOICES = [
|
||||
'Buchung' => 0,
|
||||
'Händisch' => 1
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$lodging = $options['lodging'];
|
||||
$fromDate = $options['fromDate'];
|
||||
$fromDateDateTime = new \DateTime($fromDate);
|
||||
$lodgingArr[] = $lodging;
|
||||
|
||||
$builder
|
||||
->add('lodging', EntityType::class, [
|
||||
'class' => 'AppBundle\Entity\FewoLodging',
|
||||
'choices' => $lodgingArr,
|
||||
'constraints' => [
|
||||
new Choice(['choices' => $lodgingArr])
|
||||
],
|
||||
'required'=> true
|
||||
])
|
||||
->add('fromDate', StDateType::class, [
|
||||
//options
|
||||
'data' => $fromDateDateTime
|
||||
])
|
||||
->add('toDate', StDateType::class, [
|
||||
])
|
||||
->add('status', ChoiceType::class, [
|
||||
'placeholder' => 'Status (Bitte wählen) *',
|
||||
'choices' => self::$STATUS_CHOICES,
|
||||
'constraints' => [
|
||||
new Choice(['choices' => self::$STATUS_CHOICES])
|
||||
],
|
||||
'required' => true,
|
||||
])
|
||||
->add('type', ChoiceType::class, [
|
||||
'placeholder' => 'Buchungstyp (Bitte wählen) *',
|
||||
'choices' => self::$TYPE_CHOICES,
|
||||
'constraints' => [
|
||||
new Choice(['choices' => self::$TYPE_CHOICES])
|
||||
],
|
||||
'required' => true,
|
||||
])
|
||||
//->add('lodging') // wird händisch gesetzt
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'lodging' => null,
|
||||
'fromDate' => null,
|
||||
'data_class' => 'AppBundle\Entity\FewoReservation'
|
||||
));
|
||||
$resolver->setAllowedTypes('lodging', ['AppBundle\Entity\FewoLodging']);
|
||||
$resolver->setAllowedTypes('fromDate', ['string', 'NULL']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'appbundle_feworeservation';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
63
trunk/src/AppBundle/Form/FewoSeasonType.php
Normal file
63
trunk/src/AppBundle/Form/FewoSeasonType.php
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Form;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use AppBundle\Form\StDateType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Validator\Constraints\Choice;
|
||||
use Symfony\Component\Validator\Constraints\NotNull;
|
||||
|
||||
class FewoSeasonType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('name')
|
||||
->add('fromDate', StDateType::class, [
|
||||
//options
|
||||
])
|
||||
->add('toDate', StDateType::class, [
|
||||
//options
|
||||
])
|
||||
->add('minimumStay', TextType::class, [
|
||||
|
||||
])
|
||||
->add('description')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'AppBundle\Entity\FewoSeason'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'appbundle_fewoseason';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
76
trunk/src/AppBundle/Listener/DoctrineFileListener.php
Normal file
76
trunk/src/AppBundle/Listener/DoctrineFileListener.php
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Listener;
|
||||
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Doctrine\ORM\Event\LifecycleEventArgs;
|
||||
use Doctrine\ORM\Event\PreUpdateEventArgs;
|
||||
use AppBundle\Entity\FewoLodgingImage;
|
||||
use AppBundle\Service\FileManager;
|
||||
|
||||
class DoctrineFileListener
|
||||
{
|
||||
private $uploader;
|
||||
|
||||
public function __construct(FileManager $uploader)
|
||||
{
|
||||
$this->uploader = $uploader;
|
||||
}
|
||||
|
||||
public function prePersist(LifecycleEventArgs $args)
|
||||
{
|
||||
$entity = $args->getEntity();
|
||||
|
||||
$this->uploadFile($entity);
|
||||
}
|
||||
|
||||
public function preUpdate(PreUpdateEventArgs $args)
|
||||
{
|
||||
$entity = $args->getEntity();
|
||||
|
||||
$this->uploadFile($entity);
|
||||
}
|
||||
|
||||
public function preRemove(LifecycleEventArgs $args)
|
||||
{
|
||||
$entity = $args->getEntity();
|
||||
|
||||
$this->deleteFile($entity);
|
||||
}
|
||||
|
||||
private function uploadFile($entity)
|
||||
{
|
||||
|
||||
if (!$entity instanceof FewoLodgingImage)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$file = $entity->getFile();
|
||||
|
||||
|
||||
// man könnte hier noch anpassungen tätigen, wie zb. dass man den dateinamen selbst über fileName angeben kann
|
||||
// oder man nutzt (so wie es jetzt ist) fileName dafür, es als alt-Name usw. zu benutzen und der dateiname bleibt kryptisch
|
||||
|
||||
|
||||
// only upload new files
|
||||
if (!$file instanceof UploadedFile)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$fileName = $this->uploader->upload($file);
|
||||
$entity->setFile($fileName);
|
||||
}
|
||||
|
||||
private function deleteFile($entity)
|
||||
{
|
||||
if(!$entity instanceof FewoLodgingImage)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->uploader->delete($entity);
|
||||
}
|
||||
}
|
||||
|
|
@ -145,6 +145,18 @@ class KernelControllerListener
|
|||
}
|
||||
$request->attributes->set('_controller', 'AppBundle:Cms:travelProgram');
|
||||
}
|
||||
elseif ($node->getFewoLodging() != null && ($restOfPath == '/fewo-buchen' || $restOfPath == '/fewo-berechne-gesamtpreis'))
|
||||
{
|
||||
$request->attributes->set('fewoTravelProgramPage', $node);
|
||||
$request->attributes->set('action', $restOfPath);
|
||||
$request->attributes->set('_controller', 'AppBundle:FewoBooking:index');
|
||||
}
|
||||
elseif ($node->getFewoLodging() != null)
|
||||
{
|
||||
$request->attributes->set('fewoLodgingPage', $node);
|
||||
$request->attributes->set('action', $restOfPath);
|
||||
$request->attributes->set('_controller', 'AppBundle:Cms:fewoLodging');
|
||||
}
|
||||
else
|
||||
{
|
||||
$handler = $node->getTemplate() ? ucfirst($node->getTemplate()) : 'Default';
|
||||
|
|
|
|||
|
|
@ -506,4 +506,21 @@
|
|||
}
|
||||
.widget .sidebar-price .btn {
|
||||
color:#ffffff !important;
|
||||
}
|
||||
|
||||
.calendarEven{
|
||||
float: left;
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
.calendarOdd{
|
||||
float: left;
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
.calendarGradient{
|
||||
background: -webkit-gradient(linear, left top, right bottom, color-stop(1%, darkgray), color-stop(52%, darkgray), color-stop(52%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(100%, #f2f2f2));
|
||||
background: -moz-gradient(linear, left top, right bottom, color-stop(1%, darkgray), color-stop(52%, darkgray), color-stop(52%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(100%, #f2f2f2));
|
||||
background: -o-gradient(linear, left top, right bottom, color-stop(1%, darkgray), color-stop(52%, darkgray), color-stop(52%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(100%, #f2f2f2));
|
||||
background: gradient(linear, left top, right bottom, color-stop(1%, darkgray), color-stop(52%, darkgray), color-stop(52%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(100%, #f2f2f2));
|
||||
}
|
||||
|
|
@ -1057,6 +1057,20 @@ a[id^="video_"]:before,
|
|||
.widget .sidebar-price .btn {
|
||||
color: #ffffff !important;
|
||||
}
|
||||
.calendarEven {
|
||||
float: left;
|
||||
width: 50%;
|
||||
}
|
||||
.calendarOdd {
|
||||
float: left;
|
||||
width: 50%;
|
||||
}
|
||||
.calendarGradient {
|
||||
background: -webkit-gradient(linear, left top, right bottom, color-stop(1%, #a9a9a9), color-stop(52%, #a9a9a9), color-stop(52%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(100%, #f2f2f2));
|
||||
background: -moz-gradient(linear, left top, right bottom, color-stop(1%, #a9a9a9), color-stop(52%, #a9a9a9), color-stop(52%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(100%, #f2f2f2));
|
||||
background: -o-gradient(linear, left top, right bottom, color-stop(1%, #a9a9a9), color-stop(52%, #a9a9a9), color-stop(52%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(100%, #f2f2f2));
|
||||
background: gradient(linear, left top, right bottom, color-stop(1%, #a9a9a9), color-stop(52%, #a9a9a9), color-stop(52%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(100%, #f2f2f2));
|
||||
}
|
||||
/*
|
||||
7) SHORTCODES
|
||||
===============================================================
|
||||
|
|
|
|||
32
trunk/src/AppBundle/Resources/public/js/fewoBooking.js
Normal file
32
trunk/src/AppBundle/Resources/public/js/fewoBooking.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
$(document).ready(function() {
|
||||
|
||||
var frm$ = $('.st-booking-form');
|
||||
var summary$ = $('.st-booking-summary');
|
||||
|
||||
var toDateDay$ = $('#fewo_booking_request_toDate_day');
|
||||
var toDateMonth$ = $('#fewo_booking_request_toDate_month');
|
||||
var toDateYear$ = $('#fewo_booking_request_toDate_year');
|
||||
|
||||
frm$.find('input, select').change(function() {
|
||||
var tmp = location.href.split('?');
|
||||
var tmp2 = tmp[0].split('/');
|
||||
tmp2.pop();
|
||||
var url = tmp2.join('/') + '/fewo-berechne-gesamtpreis';
|
||||
if (tmp[1])
|
||||
{
|
||||
url += '?'+ tmp[1];
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'post',
|
||||
data: frm$.serialize()
|
||||
|
||||
}).then(function(r) {
|
||||
summary$.html(r);
|
||||
|
||||
}, function() {
|
||||
summary$.html('Aufgrund eines Fehlers konnte kein Angebot ermittelt werden.');
|
||||
})
|
||||
});
|
||||
});
|
||||
37
trunk/src/AppBundle/Service/FileManager.php
Normal file
37
trunk/src/AppBundle/Service/FileManager.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
namespace AppBundle\Service;
|
||||
|
||||
use AppBundle\Entity\FewoLodgingImage;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
class FileManager
|
||||
{
|
||||
private $targetDir;
|
||||
|
||||
public function __construct($targetDir)
|
||||
{
|
||||
$this->targetDir = $targetDir;
|
||||
}
|
||||
|
||||
public function upload(UploadedFile $file)
|
||||
{
|
||||
$fileName = md5(uniqid()).'.'.$file->guessExtension();
|
||||
|
||||
$file->move($this->getTargetDir(), $fileName);
|
||||
|
||||
return $fileName;
|
||||
}
|
||||
|
||||
public function delete(FewoLodgingImage $image)
|
||||
{
|
||||
$filesystem = new Filesystem();
|
||||
|
||||
$filesystem->remove($this->getTargetDir().'/'.$image->getFile());
|
||||
}
|
||||
|
||||
public function getTargetDir()
|
||||
{
|
||||
return $this->targetDir;
|
||||
}
|
||||
}
|
||||
620
trunk/src/AppBundle/Util/LodgingCalendarUtil.php
Normal file
620
trunk/src/AppBundle/Util/LodgingCalendarUtil.php
Normal file
|
|
@ -0,0 +1,620 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Util;
|
||||
|
||||
use AppBundle\Entity\FewoLodging;
|
||||
use AppBundle\Entity\FewoPrice;
|
||||
use AppBundle\Entity\FewoReservation;
|
||||
use AppBundle\Entity\FewoSeason;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
|
||||
class LodgingCalendarUtil
|
||||
{
|
||||
private $em;
|
||||
|
||||
public function __construct(EntityManager $entityManager)
|
||||
{
|
||||
$this->em = $entityManager;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function daysInMonth($month, $year)
|
||||
{
|
||||
return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31);
|
||||
}
|
||||
|
||||
public function getCalendarWithPadding()
|
||||
{
|
||||
$calendar = null;
|
||||
$currentMonth = date('n');
|
||||
$currentYear = date('Y');
|
||||
$weekDays = ['So','Mo','Di','Mi','Do','Fr','Sa'];
|
||||
|
||||
setlocale(LC_TIME, "german");
|
||||
|
||||
for($m = $currentMonth; $m < ($currentMonth + 12); $m++)
|
||||
{
|
||||
if($m < 13)
|
||||
{
|
||||
$actualMonth = $m;
|
||||
$actualCurrentYear = $currentYear;
|
||||
}
|
||||
else
|
||||
{
|
||||
$actualMonth = $m % 12;
|
||||
$actualCurrentYear = $currentYear + 1;
|
||||
}
|
||||
|
||||
$date = getdate(mktime(0,0,0, $actualMonth, 1, $actualCurrentYear));
|
||||
$weekDay = $weekDays[$date['wday']];
|
||||
|
||||
$numberDays = $this->daysInMonth($actualMonth, $actualCurrentYear);
|
||||
$data = null;
|
||||
|
||||
$actualStartingWeekDay = $date['wday'];
|
||||
|
||||
if($actualStartingWeekDay == 0)
|
||||
{
|
||||
$actualStartingWeekDay = 7;
|
||||
}
|
||||
|
||||
for($fwd = 0; $fwd < $actualStartingWeekDay - 1; $fwd++)
|
||||
{
|
||||
$data[] = 0;
|
||||
}
|
||||
|
||||
for($d = 1; $d <= $numberDays; $d++)
|
||||
{
|
||||
$data[] = $d;
|
||||
}
|
||||
|
||||
$startIndex = count($data);
|
||||
|
||||
for($lwd = $startIndex; $lwd < 42; $lwd++)
|
||||
{
|
||||
$data[] = 0;
|
||||
}
|
||||
|
||||
$calendar[] = [
|
||||
'numberDays' => $numberDays,
|
||||
'monthNumber' => $actualMonth,
|
||||
'monthName' => utf8_encode(strftime("%B", mktime(0, 0, 0, $actualMonth, 1, $actualCurrentYear))),
|
||||
'year' => $actualCurrentYear,
|
||||
'startWeekDay' => $weekDay,
|
||||
'data' => $data,
|
||||
'marked' => 0
|
||||
];
|
||||
}
|
||||
|
||||
return $calendar;
|
||||
}
|
||||
|
||||
|
||||
public function getCalendar()
|
||||
{
|
||||
|
||||
$calendar = null;
|
||||
$currentMonth = date('n');
|
||||
$currentYear = date('Y');
|
||||
$weekDays = ['So','Mo','Di','Mi','Do','Fr','Sa'];
|
||||
|
||||
setlocale(LC_TIME, "german");
|
||||
|
||||
for($m = $currentMonth; $m < ($currentMonth + 12); $m++)
|
||||
{
|
||||
if($m < 13)
|
||||
{
|
||||
$actualMonth = $m;
|
||||
$actualCurrentYear = $currentYear;
|
||||
}
|
||||
else
|
||||
{
|
||||
$actualMonth = $m % 12;
|
||||
$actualCurrentYear = $currentYear + 1;
|
||||
}
|
||||
|
||||
$date = getdate(mktime(0,0,0, $actualMonth, 1, $actualCurrentYear));
|
||||
$weekDay = $weekDays[$date['wday']];
|
||||
|
||||
$numberDays = $this->daysInMonth($actualMonth, $actualCurrentYear);
|
||||
$data = null;
|
||||
|
||||
// alle Wochentage
|
||||
for($d = 1; $d <= $numberDays; $d++)
|
||||
{
|
||||
$data[] = $d;
|
||||
}
|
||||
|
||||
$calendar[] = [
|
||||
'numberDays' => $numberDays,
|
||||
'monthNumber' => $actualMonth,
|
||||
'monthName' => utf8_encode(strftime("%B", mktime(0, 0, 0, $actualMonth, 1, $actualCurrentYear))),
|
||||
'year' => $actualCurrentYear,
|
||||
'startWeekDay' => $weekDay,
|
||||
'data' => $data,
|
||||
'marked' => 0
|
||||
];
|
||||
}
|
||||
|
||||
return $calendar;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FewoLodging $lodging
|
||||
* @return array|null
|
||||
*/
|
||||
public function getReservations(FewoLodging $lodging)
|
||||
{
|
||||
$reservations = $lodging->getReservations();
|
||||
$ret = null;
|
||||
|
||||
for($i = 0; $i < count($reservations); $i++)
|
||||
{
|
||||
$fromDate = $reservations[$i]->getFromDate();
|
||||
$toDate = $reservations[$i]->getToDate();
|
||||
|
||||
$ret[] = [
|
||||
'startDay' => $fromDate->format('j'),
|
||||
'startMonth' => $fromDate->format('n'),
|
||||
'startYear' => $fromDate->format('Y'),
|
||||
'endDay' => $toDate->format('j'),
|
||||
'endMonth' => $toDate->format('n'),
|
||||
'endYear' => $toDate->format('Y')
|
||||
];
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
private function getMonthIndex($calendar, $month)
|
||||
{
|
||||
$result = 0;
|
||||
for($i = 0; $i < count($calendar); $i++)
|
||||
{
|
||||
if($calendar[$i]['monthNumber'] == $month)
|
||||
{
|
||||
$result = $i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $calendar
|
||||
* @param \DateTime $fromDate
|
||||
* @param \DateTime $toDate
|
||||
* @param $appendix
|
||||
* @return mixed
|
||||
*/
|
||||
private function markCalendarDays($calendar, \DateTime $fromDate, \DateTime $toDate, $appendix, $reservationMode = false)
|
||||
{
|
||||
$startDay = $fromDate->format('j');
|
||||
$startMonth = $fromDate->format('n');
|
||||
$startYear = $fromDate->format('Y');
|
||||
$endDay = $toDate->format('j');
|
||||
$endMonth = $toDate->format('n');
|
||||
$endYear = $toDate->format('Y');
|
||||
$today = new \DateTime();
|
||||
$todayDay = $today->format('j');
|
||||
$todayMonth = $today->format('n');
|
||||
$todayYear = $today->format('Y');
|
||||
|
||||
|
||||
if($startMonth < $todayMonth && $startYear == $todayYear)
|
||||
{
|
||||
$startDay = 1;
|
||||
$startMonth = $today->format('n');
|
||||
$startYear = $today->format('Y');
|
||||
}
|
||||
|
||||
$startCalendarIndex = $this->getMonthIndex($calendar, $startMonth);
|
||||
$endCalendarIndex = $this->getMonthIndex($calendar, $endMonth);
|
||||
|
||||
|
||||
if($startCalendarIndex == $endCalendarIndex)
|
||||
{
|
||||
$data = $calendar[$startCalendarIndex]['data'];
|
||||
|
||||
$calendar[$startCalendarIndex]['marked'] = 1;
|
||||
|
||||
$startIndex = $startDay - 1;
|
||||
$endIndex = $endDay - 1;
|
||||
|
||||
$firstDay = explode(',', $data[$startIndex]);
|
||||
|
||||
if(count($firstDay) > 1 && $reservationMode == false)
|
||||
$startIndex = $startIndex + 1;
|
||||
|
||||
for($i = $startIndex; $i <= $endIndex; $i++)
|
||||
{
|
||||
|
||||
if($i == $startIndex && $reservationMode)
|
||||
{
|
||||
$data[$i] = $data[$i].$appendix.",from";
|
||||
} elseif($i == $endIndex && $reservationMode) {
|
||||
$data[$i] = $data[$i].$appendix.",to";
|
||||
} else {
|
||||
$data[$i] = $data[$i].$appendix;
|
||||
}
|
||||
}
|
||||
$calendar[$startCalendarIndex]['data'] = $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
$data = $calendar[$startCalendarIndex]['data'];
|
||||
|
||||
$calendar[$startCalendarIndex]['marked'] = 1;
|
||||
|
||||
$startIndex = $startDay - 1;
|
||||
|
||||
$firstDay = explode(',', $data[$startIndex]);
|
||||
|
||||
if(count($firstDay) > 1 && $reservationMode == false)
|
||||
$startIndex = $startIndex + 1;
|
||||
|
||||
$endIndex = count($data) - 1;
|
||||
for($i = $startIndex; $i <= $endIndex; $i++)
|
||||
{
|
||||
if($i == $startIndex && $reservationMode)
|
||||
{
|
||||
$data[$i] = $data[$i].$appendix.",from";
|
||||
} else {
|
||||
$data[$i] = $data[$i].$appendix;
|
||||
}
|
||||
}
|
||||
$calendar[$startCalendarIndex]['data'] = $data;
|
||||
|
||||
$data = $calendar[$endCalendarIndex]['data'];
|
||||
|
||||
$calendar[$endCalendarIndex]['marked'] = 1;
|
||||
|
||||
$startIndex = 0;
|
||||
$endIndex = $endDay - 1;
|
||||
for($i = $startIndex; $i <= $endIndex; $i++)
|
||||
{
|
||||
if($i == $endIndex && $reservationMode)
|
||||
{
|
||||
$data[$i] = $data[$i].$appendix.",to";
|
||||
} else {
|
||||
$data[$i] = $data[$i].$appendix;
|
||||
}
|
||||
}
|
||||
$calendar[$endCalendarIndex]['data'] = $data;
|
||||
|
||||
for($i = $startCalendarIndex + 1; $i < $endCalendarIndex; $i++)
|
||||
{
|
||||
$data = $calendar[$i]['data'];
|
||||
|
||||
$calendar[$i]['marked'] = 1;
|
||||
|
||||
$startIndex = 0;
|
||||
$endIndex = count($data) - 1;
|
||||
for($j = $startIndex; $j <= $endIndex; $j++)
|
||||
{
|
||||
$data[$j] = $data[$j].$appendix;
|
||||
}
|
||||
$calendar[$i]['data'] = $data;
|
||||
}
|
||||
}
|
||||
return $calendar;
|
||||
}
|
||||
|
||||
private function mergeCalendars($calendar, $extensionCalendar, $withFromTo = false)
|
||||
{
|
||||
for($i = 0; $i < 12; $i++)
|
||||
{
|
||||
if($calendar[$i]['marked'] == 1 && $extensionCalendar[$i]['marked'] == 1)
|
||||
{
|
||||
$calendarData = $calendar[$i]['data'];
|
||||
$extensionCalendarData = $extensionCalendar[$i]['data'];
|
||||
|
||||
$endIndex = count($calendarData);
|
||||
|
||||
for($j = 0; $j < $endIndex; $j++)
|
||||
{
|
||||
if(strlen($extensionCalendarData[$j]) > 2)
|
||||
{
|
||||
if($withFromTo)
|
||||
{
|
||||
$calDay = explode(',', $calendarData[$j]);
|
||||
$extCalDay = explode(',', $extensionCalendarData[$j]);
|
||||
|
||||
if(count ($calDay) > 1 && $calDay[1] == "reservable" && count($extCalDay) > 2 && $extCalDay[2] == 'to')
|
||||
{
|
||||
$calendarData[$j] = $extensionCalendarData[$j].",reservable".','.$calDay[2];
|
||||
}
|
||||
else
|
||||
$calendarData[$j] = $extensionCalendarData[$j];
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$calendarData[$j] = $extensionCalendarData[$j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$calendar[$i]['data'] = $calendarData;
|
||||
}
|
||||
}
|
||||
|
||||
return $calendar;
|
||||
}
|
||||
|
||||
public function mergeWithPaddedCalendar($calendar, $paddedCalendar)
|
||||
{
|
||||
for($i = 0; $i < count($paddedCalendar); $i++)
|
||||
{
|
||||
$calendarDataCurrMonth = $calendar[$i]['data'];
|
||||
$paddedCalendarDataCurrMonth = $paddedCalendar[$i]['data'];
|
||||
$startIndex = array_search(1, $paddedCalendarDataCurrMonth);
|
||||
for($j = 0; $j < count($calendarDataCurrMonth); $j++, $startIndex++)
|
||||
{
|
||||
$paddedCalendarDataCurrMonth[$startIndex] = $calendarDataCurrMonth[$j];
|
||||
}
|
||||
$paddedCalendar[$i]['data'] = $paddedCalendarDataCurrMonth;
|
||||
}
|
||||
return $paddedCalendar;
|
||||
}
|
||||
|
||||
private function isNextDay($current, $next)
|
||||
{
|
||||
$result = false;
|
||||
|
||||
$calculatedNextDate = date('d.m.Y', strtotime($current." + 1 day"));
|
||||
|
||||
|
||||
if($calculatedNextDate == $next)
|
||||
{
|
||||
$result = true;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getMonthFromCalendar($calendar, $monthNumber)
|
||||
{
|
||||
$result = [];
|
||||
|
||||
for($i = 0; $i < count($calendar); $i++)
|
||||
{
|
||||
if($calendar[$i]['monthNumber'] == $monthNumber)
|
||||
{
|
||||
$result = $calendar[$i];
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FewoLodging $lodging
|
||||
* @param $calendar
|
||||
* @return array|null
|
||||
*/
|
||||
private function filterReservableDays(FewoLodging $lodging, $calendar)
|
||||
{
|
||||
$priceRepo = $this->em->getRepository('AppBundle:FewoPrice');
|
||||
|
||||
$today = new \DateTime();
|
||||
$seasons = $lodging->getSeasons();
|
||||
$prices = $lodging->getPrices();
|
||||
$cleanCalendar = $this->getCalendar();
|
||||
|
||||
$potentiallyReservableDays = [];
|
||||
$actuallyReservableDays = [];
|
||||
$lastReservablePriceId = 0;
|
||||
$priceId = 0;
|
||||
|
||||
for($currMonthIndex = 0; $currMonthIndex < count($calendar); $currMonthIndex++)
|
||||
{
|
||||
$currMonth = $calendar[$currMonthIndex];
|
||||
$data = $currMonth['data'];
|
||||
|
||||
for($currDayIndex = 0; $currDayIndex < count($data); $currDayIndex++)
|
||||
{
|
||||
$currDay = explode(',', $data[$currDayIndex]);
|
||||
|
||||
if(count($currDay) > 1)
|
||||
{
|
||||
if($currDay[1] == "reservable")
|
||||
{
|
||||
$priceId = $currDay[2];
|
||||
|
||||
if($lastReservablePriceId == 0)
|
||||
$lastReservablePriceId = $priceId;
|
||||
|
||||
|
||||
if($lastReservablePriceId != $priceId)
|
||||
{
|
||||
$price = $priceRepo->find($lastReservablePriceId);
|
||||
/** @var FewoSeason $season */
|
||||
$season = $price->getSeason();
|
||||
|
||||
$actuallyReservableDays = $this->processPotentiallyReservableDays($potentiallyReservableDays, $season->getMinimumStay());
|
||||
$this->processRest($actuallyReservableDays, $lastReservablePriceId, $cleanCalendar);
|
||||
|
||||
$lastReservablePriceId = $priceId;
|
||||
$potentiallyReservableDays = [];
|
||||
$actuallyReservableDays = [];
|
||||
|
||||
}
|
||||
|
||||
$currentDayDate = date("d.m.Y", strtotime($currMonth['year']."-".$currMonth['monthNumber']."-".$currDay[0]));
|
||||
$potentiallyReservableDays[] = $currentDayDate;
|
||||
}
|
||||
elseif(count($currDay) > 2 && $currDay[2] == "from")
|
||||
{
|
||||
$currentDayDate = date("d.m.Y", strtotime($currMonth['year']."-".$currMonth['monthNumber']."-".$currDay[0]));
|
||||
$potentiallyReservableDays[] = $currentDayDate;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if($lastReservablePriceId == $priceId)
|
||||
{
|
||||
$price = $priceRepo->find($lastReservablePriceId);
|
||||
/** @var FewoSeason $season */
|
||||
$season = $price->getSeason();
|
||||
|
||||
$actuallyReservableDays = $this->processPotentiallyReservableDays($potentiallyReservableDays, $season->getMinimumStay());
|
||||
$this->processRest($actuallyReservableDays, $lastReservablePriceId, $cleanCalendar);
|
||||
|
||||
$lastReservablePriceId = $priceId;
|
||||
$potentiallyReservableDays = [];
|
||||
$actuallyReservableDays = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return $cleanCalendar;
|
||||
}
|
||||
|
||||
private function processPotentiallyReservableDays($potentiallyReservableDays, $minimumStay)
|
||||
{
|
||||
$coherentDays = [];
|
||||
$actuallyReservableDays = [];
|
||||
//$coherentDays[] = $potentiallyReservableDays[0];
|
||||
for($i = 1; $i < count($potentiallyReservableDays); $i++)
|
||||
{
|
||||
|
||||
if($this->isNextDay($potentiallyReservableDays[$i - 1], $potentiallyReservableDays[$i]))
|
||||
{
|
||||
if(count($coherentDays) == 0)
|
||||
{
|
||||
$coherentDays[] = $potentiallyReservableDays[$i - 1];
|
||||
}
|
||||
$coherentDays[] = $potentiallyReservableDays[$i];
|
||||
}
|
||||
else
|
||||
{
|
||||
if(count($coherentDays) < $minimumStay)
|
||||
{
|
||||
$coherentDays = [];
|
||||
$coherentDays[] = $potentiallyReservableDays[$i];
|
||||
}
|
||||
else
|
||||
{
|
||||
$coherentDaysCount = count($coherentDays);
|
||||
|
||||
$offset = $coherentDaysCount - ($minimumStay - 1);
|
||||
|
||||
$coherentDays = array_splice($coherentDays, 0, $offset);
|
||||
for($j = 0; $j < count($coherentDays); $j++)
|
||||
{
|
||||
$actuallyReservableDays[] = $coherentDays[$j];
|
||||
}
|
||||
$coherentDays = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(count($coherentDays) > 0)
|
||||
{
|
||||
$coherentDaysCount = count($coherentDays);
|
||||
|
||||
$offset = $coherentDaysCount - ($minimumStay - 1);
|
||||
|
||||
$coherentDays = array_splice($coherentDays, 0, $offset);
|
||||
for($j = 0; $j < count($coherentDays); $j++)
|
||||
{
|
||||
$actuallyReservableDays[] = $coherentDays[$j];
|
||||
}
|
||||
}
|
||||
|
||||
return $actuallyReservableDays;
|
||||
}
|
||||
|
||||
private function processRest($actuallyReservableDays, $priceId, &$cleanCalendar)
|
||||
{
|
||||
for($currMonthIndex = 0; $currMonthIndex < count($cleanCalendar); $currMonthIndex++)
|
||||
{
|
||||
$currMonth = $cleanCalendar[$currMonthIndex];
|
||||
$data = $currMonth['data'];
|
||||
|
||||
$startIndex = array_search(1, $data);
|
||||
$endIndex = $startIndex + ($currMonth['numberDays']);
|
||||
|
||||
for($currDayIndex = $startIndex; $currDayIndex < $endIndex; $currDayIndex++)
|
||||
{
|
||||
$currDay = explode(',', $data[$currDayIndex]);
|
||||
|
||||
$currentDate = date("d.m.Y", strtotime($currMonth['year']."-".$currMonth['monthNumber']."-".$currDay[0]));
|
||||
|
||||
if(in_array($currentDate, $actuallyReservableDays))
|
||||
{
|
||||
$data[$currDayIndex] = $data[$currDayIndex].",reservable,".$priceId;
|
||||
$currMonth['marked'] = 1;
|
||||
}
|
||||
}
|
||||
$currMonth['data'] = $data;
|
||||
$cleanCalendar[$currMonthIndex] = $currMonth;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param FewoLodging $lodging
|
||||
* @param $calendar
|
||||
* @return mixed
|
||||
*/
|
||||
public function markCalendarDaysWithReservations(FewoLodging $lodging, $calendar)
|
||||
{
|
||||
$today = new \DateTime();
|
||||
$pricesCalendar = $calendar;
|
||||
$reservationsCalendar = $calendar;
|
||||
|
||||
$reservations = $lodging->getReservations();
|
||||
$prices = $lodging->getPrices();
|
||||
|
||||
$lodgingId = $lodging->getId();
|
||||
|
||||
foreach($prices as $price)
|
||||
{
|
||||
/** @var FewoSeason $season */
|
||||
$season = $price->getSeason();
|
||||
$appendix = ',reservable,'.$price->getId();
|
||||
$fromDate = $season->getFromDate();
|
||||
$toDate = $season->getToDate();
|
||||
|
||||
if($toDate < $today)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$pricesCalendar = $this->markCalendarDays($pricesCalendar, $fromDate, $toDate, $appendix, false);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($reservations as $reservation)
|
||||
{
|
||||
$reservationId = $reservation->getId();
|
||||
$appendix = ','.$reservationId;
|
||||
$fromDate = $reservation->getFromDate();
|
||||
$toDate = $reservation->getToDate();
|
||||
|
||||
$reservationsCalendar = $this->markCalendarDays($reservationsCalendar, $fromDate, $toDate, $appendix, true);
|
||||
}
|
||||
|
||||
$mergedPricesAndReservationsCalendar = $this->mergeCalendars($pricesCalendar, $reservationsCalendar, false);
|
||||
$actuallyReservableDaysCalendar = $this->filterReservableDays($lodging, $mergedPricesAndReservationsCalendar);
|
||||
$resultCalendar = $this->mergeCalendars($actuallyReservableDaysCalendar, $reservationsCalendar, true);
|
||||
|
||||
return $resultCalendar;
|
||||
}
|
||||
|
||||
public function convertDate($date)
|
||||
{
|
||||
$result = substr($date, 0, 2).'.'.substr($date, 2, 2).'.'.substr($date, 4, 4);
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
*/
|
||||
class FewoBookingRequest extends Constraint
|
||||
{
|
||||
public $message = 'Ungültige Eingabe!';
|
||||
|
||||
public function getTargets()
|
||||
{
|
||||
return self::CLASS_CONSTRAINT;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Validator\Constraints;
|
||||
|
||||
use AppBundle\Entity\FewoBookingRequest;
|
||||
use AppBundle\Entity\FewoReservation;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use AppBundle\Validator\Constraints;
|
||||
|
||||
/**
|
||||
* Class FewoReservationValidator
|
||||
* @package AppBundle\Validator
|
||||
*/
|
||||
class FewoBookingRequestValidator extends ConstraintValidator
|
||||
{
|
||||
|
||||
private function withinDates($date, $fromDate, $toDate)
|
||||
{
|
||||
$result = false;
|
||||
if($date >= $fromDate && $date <= $toDate)
|
||||
{
|
||||
$result = true;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function alreadyReserved($fromDate, $toDate, $reservationFromDate, $reservationToDate)
|
||||
{
|
||||
$result = true;
|
||||
|
||||
if($fromDate >= $reservationToDate || $toDate <= $reservationFromDate)
|
||||
{
|
||||
$result = false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the passed value is valid.
|
||||
*
|
||||
* @param FewoBookingRequest $bookingRequest The value that should be validated
|
||||
* @param Constraint $constraint The constraint for the validation
|
||||
*/
|
||||
public function validate($bookingRequest, Constraint $constraint)
|
||||
{
|
||||
$fromDate = $bookingRequest->getFromDate();
|
||||
$toDate = $bookingRequest->getToDate();
|
||||
|
||||
$lodging = $bookingRequest->getLodging();
|
||||
$price = $bookingRequest->getPrice();
|
||||
$season = $price->getSeason();
|
||||
$reservations = $lodging->getReservations();
|
||||
|
||||
$timeDiff = date_diff($fromDate, $toDate);
|
||||
$numberDays = $timeDiff->days + 1;
|
||||
|
||||
$withinSeason = false;
|
||||
$alreadyReserved = false;
|
||||
|
||||
if($fromDate >= $season->getFromDate()
|
||||
&& $toDate <= $season->getToDate())
|
||||
{
|
||||
$withinSeason = true;
|
||||
}
|
||||
|
||||
/** @var FewoReservation $reservation */
|
||||
foreach($reservations as $reservation)
|
||||
{
|
||||
$reservationFromDate = $reservation->getFromDate();
|
||||
$reservationToDate = $reservation->getToDate();
|
||||
|
||||
|
||||
if($this->alreadyReserved($fromDate, $toDate, $reservationFromDate, $reservationToDate))
|
||||
{
|
||||
$alreadyReserved = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!$withinSeason)
|
||||
{
|
||||
$this->context->buildViolation("Zeitraum außerhalb der Saison!")
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
if($alreadyReserved)
|
||||
{
|
||||
$this->context->buildViolation("Es gibt bereits Reservierungen innerhalb des gewünschten Zeitraums!")
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
if($numberDays < $season->getMinimumStay())
|
||||
{
|
||||
$this->context->buildViolation("Mindestanzahl an Tagen nicht erreicht!")
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
if($bookingRequest->getTravelerCount() > $lodging->getMaximumPersons())
|
||||
{
|
||||
$this->context->buildViolation("Anzahl der Reisenden übersteigt die maximale Personenanzahl!")
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
*/
|
||||
class FewoReservation extends Constraint
|
||||
{
|
||||
public $message = 'Die Daten müssen innerhalb einer Saison liegen!';
|
||||
|
||||
public function getTargets()
|
||||
{
|
||||
return self::CLASS_CONSTRAINT;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Validator\Constraints;
|
||||
|
||||
use AppBundle\Entity\FewoReservation;
|
||||
use AppBundle\Form\FewoReservationType;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
|
||||
/**
|
||||
* Class FewoReservationValidator
|
||||
* @package AppBundle\Validator
|
||||
*/
|
||||
class FewoReservationValidator extends ConstraintValidator
|
||||
{
|
||||
|
||||
private function alreadyReserved($fromDate, $toDate, $reservationFromDate, $reservationToDate)
|
||||
{
|
||||
$result = true;
|
||||
|
||||
if($fromDate >= $reservationToDate || $toDate <= $reservationFromDate)
|
||||
{
|
||||
$result = false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the passed value is valid.
|
||||
*
|
||||
* @param FewoReservation $reservation The value that should be validated
|
||||
* @param Constraint $constraint The constraint for the validation
|
||||
*/
|
||||
public function validate($reservation, Constraint $constraint)
|
||||
{
|
||||
$lodging = $reservation->getLodging();
|
||||
$reservations = $lodging->getReservations();
|
||||
$seasons = $lodging->getSeasons();
|
||||
|
||||
$withinAnySeason = false;
|
||||
$alreadyReserved = false;
|
||||
|
||||
for($i = 0; $i < count($seasons); $i++)
|
||||
{
|
||||
if($reservation->getFromDate() >= $seasons[$i]->getFromDate()
|
||||
&& $reservation->getToDate() <= $seasons[$i]->getToDate())
|
||||
{
|
||||
$withinAnySeason = true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($reservations as $reservation)
|
||||
{
|
||||
$reservationFromDate = $reservation->getFromDate();
|
||||
$reservationToDate = $reservation->getToDate();
|
||||
|
||||
|
||||
if($this->alreadyReserved($reservation->getFromDate(), $reservation->getToDate(), $reservationFromDate, $reservationToDate))
|
||||
{
|
||||
$alreadyReserved = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$withinAnySeason)
|
||||
{
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
if($alreadyReserved)
|
||||
{
|
||||
$this->context->buildViolation("Es gibt bereits Reservierungen innerhalb des gewünschten Zeitraums!")
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue