sterntours/trunk/src/AppBundle/Entity/BookingRequest.php
2018-03-09 15:14:40 +00:00

627 lines
No EOL
13 KiB
PHP

<?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;
/**
* Class BookingRequest
* @package AppBundle\Entity
* @AppBundleAssert\BookingRequest
*/
class BookingRequest
{
// Used in SternToursCrmBookingExports, expected to be equivalent to sex (as defined in Traveler)
const MR = 1;
const MRS = 2;
/**
* @var TravelDeparturePoint $departure
*/
private $departure;
private $singleRoomCount;
private $doubleRoomCount;
private $tripleRoomCount;
private $roomCount;
/**
* @var TravelInsurance $insurance
*/
private $insurance;
private $comfort = false;
private $travelOptions = [];
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 $travelers = [];
private $singleRooms = [];
private $doubleRooms = [];
private $tripleRooms = [];
private $notes;
/**
* @Assert\IsTrue()
*/
private $acceptTerms = false;
/**
* BookingRequest constructor.
*/
public function __construct()
{
for($i = 0; $i < 5; ++$i)
{
$this->singleRooms[] = new Room(1);
$this->doubleRooms[] = new Room(2);
$this->tripleRooms[] = new Room(3);
}
}
/**
* @return TravelDeparturePoint
*/
public function getDeparture()
{
return $this->departure;
}
/**
* @param TravelDeparturePoint $departure
*/
public function setDeparture(TravelDeparturePoint $departure)
{
$this->departure = $departure;
}
/**
* @return mixed
*/
public function getTravelerCount()
{
$allUsedTravelersCount = 0;
for($i = 0; $i < $this->singleRoomCount; ++$i)
{
$allUsedTravelersCount += $this->singleRooms[$i]->getTravelerCount();
}
for($i = 0; $i < $this->doubleRoomCount; ++$i)
{
$allUsedTravelersCount += $this->doubleRooms[$i]->getTravelerCount();
}
for($i = 0; $i < $this->tripleRoomCount; ++$i)
{
$allUsedTravelersCount += $this->tripleRooms[$i]->getTravelerCount();
}
return $allUsedTravelersCount;
}
/**
* @param mixed $travelerCount
*/
public function setTravelerCount($travelerCount)
{
$this->travelerCount = $travelerCount;
}
/**
* @return mixed
*/
public function getRoomCount()
{
return $this->roomCount;
}
/**
* @param mixed $travelers
*/
public function setRoomCount($travelers)
{
// nicht so kompliziert
// übliche Anzahl der Reisenden war 2 -> Standardraum: 1 Doppelzimmer
$this->travelerCount = $travelers;
if($travelers % 2 != 0)
{
$times = ($travelers - 1) / 2;
$this->singleRoomCount = 1;
$this->doubleRoomCount = $times;
$this->tripleRoomCount = 0;
$this->roomCount = $times + 1;
}
else
{
$times = $travelers / 2;
$this->singleRoomCount = 0;
$this->doubleRoomCount = $times;
$this->tripleRoomCount = 0;
$this->roomCount = $times;
}
}
/**
* @return mixed
*/
public function getSingleRoomCount()
{
return $this->singleRoomCount;
}
/**
* @param mixed $singleRoomCount
*/
public function setSingleRoomCount($singleRoomCount)
{
$this->singleRoomCount = $singleRoomCount;
}
/**
* @return mixed
*/
public function getDoubleRoomCount()
{
return $this->doubleRoomCount;
}
/**
* @param mixed $doubleRoomCount
*/
public function setDoubleRoomCount($doubleRoomCount)
{
$this->doubleRoomCount = $doubleRoomCount;
}
/**
* @return mixed
*/
public function getTripleRoomCount()
{
return $this->tripleRoomCount;
}
/**
* @param mixed $tripleRoomCount
*/
public function setTripleRoomCount($tripleRoomCount)
{
$this->tripleRoomCount = $tripleRoomCount;
}
/**
* @return TravelInsurance
*/
public function getInsurance()
{
return $this->insurance;
}
/**
* @param TravelInsurance $insurance
*/
public function setInsurance(TravelInsurance $insurance)
{
$this->insurance = $insurance;
}
/**
* @return mixed
*/
public function getComfort()
{
return $this->comfort;
}
/**
* @param mixed $comfort
*/
public function setComfort($comfort)
{
$this->comfort = $comfort;
}
/**
* @return TravelOption[]
*/
public function getTravelOptions()
{
return $this->travelOptions;
}
/**
* @param mixed $travelOptions
*/
public function setTravelOptions($travelOptions)
{
$this->travelOptions = $travelOptions;
}
/**
* @return int
*/
public function getSalutation()
{
return $this->salutation;
}
/**
* @param int $salutation
*/
public function setSalutation($salutation)
{
$this->salutation = $salutation;
}
/**
* @return string
*/
public function getFirstName()
{
return $this->firstName;
}
/**
* @param string $firstName
*/
public function setFirstName($firstName)
{
$this->firstName = $firstName;
}
/**
* @return string
*/
public function getLastName()
{
return $this->lastName;
}
/**
* @param string $lastName
*/
public function setLastName($lastName)
{
$this->lastName = $lastName;
}
/**
* @return string
*/
public function getStreetAddress()
{
return $this->streetAddress;
}
/**
* @param string $streetAddress
*/
public function setStreetAddress($streetAddress)
{
$this->streetAddress = $streetAddress;
}
/**
* @return string
*/
public function getZipCode()
{
return $this->zipCode;
}
/**
* @param string $zipCode
*/
public function setZipCode($zipCode)
{
$this->zipCode = $zipCode;
}
/**
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* @param string $city
*/
public function setCity($city)
{
$this->city = $city;
}
/**
* @return int
*/
public function getNation()
{
return $this->nation;
}
/**
* @param int $nation
*/
public function setNation($nation)
{
$this->nation = $nation;
}
/**
* @return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* @param string $phone
*/
public function setPhone($phone)
{
$this->phone = $phone;
}
/**
* @return string
*/
public function getFax()
{
return $this->fax;
}
/**
* @param string $fax
*/
public function setFax($fax)
{
$this->fax = $fax;
}
/**
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* @param string $email
*/
public function setEmail($email)
{
$this->email = $email;
}
// get und set der Travelers liegt jetzt in Room; sollte so nicht mehr verwendet werden!
/**
* @return Traveler[]
*/
public function getTravelers()
{
$allUsedTravelers = [];
// könnte man eventuell in eine for-Schleife packen, wenn man garantiert, dass es immer gleich viele Räume von jedem Typ gibt
for ($i = 0; $i < $this->singleRoomCount; ++$i)
{
$allUsedTravelers = array_merge($allUsedTravelers, $this->singleRooms[$i]->getTravelers());
}
for ($i = 0; $i < $this->doubleRoomCount; ++$i)
{
$allUsedTravelers = array_merge($allUsedTravelers, $this->doubleRooms[$i]->getTravelers());
}
for ($i = 0; $i < $this->tripleRoomCount; ++$i)
{
$allUsedTravelers = array_merge($allUsedTravelers, $this->tripleRooms[$i]->getTravelers());
}
// $this->travelers = $allUsedTravelers; // schlecht, getter sollte kein setter sein
// return $this->travelers; // aber wenn man es so verwenden würde, dann sollte man auch das verwenden
return $allUsedTravelers;
}
/**
* @param Traveler[] $travelers
*/
public function setTravelers($travelers)
{
$this->travelers = $travelers;
}
/**
* @return Room[]
*/
public function getSingleRooms()
{
return $this->singleRooms;
}
/**
* @param Room[] $singleRooms
*/
public function setSingleRooms($singleRooms)
{
$this->singleRooms = $singleRooms;
}
/**
* @return Room[]
*/
public function getDoubleRooms()
{
return $this->doubleRooms;
}
/**
* @param Room[] $doubleRooms
*/
public function setDoubleRooms($doubleRooms)
{
$this->doubleRooms = $doubleRooms;
}
/**
* @return Room[]
*/
public function getTripleRooms()
{
return $this->tripleRooms;
}
/**
* @param Room[] $tripleRooms
*/
public function setTripleRooms($tripleRooms)
{
$this->tripleRooms = $tripleRooms;
}
/**
* @return Room[]
*/
public function getRooms()
{
$allRooms = [];
$allRooms = array_merge($allRooms, $this->singleRooms);
$allRooms = array_merge($allRooms, $this->doubleRooms);
$allRooms = array_merge($allRooms, $this->tripleRooms);
return $allRooms;
}
/**
* @param Room[] $tripleRooms
*/
public function setRooms($rooms)
{
// falls man es braucht, nachziehen und oder umstrukturieren (booking.html.twig)
}
public function getOccupiedRooms()
{
$allRooms = [];
for($i = 0; $i < $this->singleRoomCount; $i++)
{
$allRooms[] = $this->singleRooms[$i];
//$allRooms = array_push($allRooms, $this->singleRooms[$i]);
}
for($i = 0; $i < $this->doubleRoomCount; $i++)
{
$allRooms[] = $this->doubleRooms[$i];
//$allRooms = array_push($allRooms, $this->doubleRooms[$i]);
}
for($i = 0; $i < $this->tripleRoomCount; $i++)
{
$allRooms[] = $this->tripleRooms[$i];
//$allRooms = array_push($allRooms, $this->tripleRooms[$i]);
}
return $allRooms;
}
/*
public function addTraveler(Traveler $traveler)
{
$this->travelers[] = $traveler;
}
*/
/**
* @return string
*/
public function getNotes()
{
return $this->notes;
}
/**
* @param string $notes
*/
public function setNotes($notes)
{
$this->notes = $notes;
}
/**
* @return bool
*/
public function isAcceptTerms()
{
return $this->acceptTerms;
}
/**
* @param bool $acceptTerms
*/
public function setAcceptTerms($acceptTerms)
{
$this->acceptTerms = $acceptTerms;
}
/**
* @Assert\Callback
*/
public function validate(ExecutionContextInterface $context, $payload)
{
//$context->
}
}