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
|
|
@ -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