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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue