#1342
#1343
#1345
#1346
#1349

git-svn-id: http://78.47.251.156/svn/dev/sterntours-3@3340 f459cee4-fb09-11de-96c3-f9c5f16c3c76
This commit is contained in:
valentin.wacker 2017-07-20 09:59:11 +00:00
parent 27d2713283
commit 652eeb16cb
27 changed files with 994 additions and 204 deletions

View file

@ -64,7 +64,8 @@ class BookingController extends Controller
$bookingRequest = new BookingRequest();
if ($request->getMethod() != 'POST')
{
$bookingRequest->setTravelerCount(2);
$bookingRequest->setDoubleRoomCount(1);
$bookingRequest->setRoomCount(2);
$bookingRequest->setDeparture($travelDate->getDepartures()[0]);
}
$form = $this->createForm(BookingRequestType::class, $bookingRequest, [
@ -85,6 +86,8 @@ class BookingController extends Controller
$breadcrumbEntries = Util::createBreadcrumb($travelProgramPage);
$breadcrumbEntries[] = new BreadcrumbEntry('Buchen');
if ($request->getMethod() == 'POST' && $form->isValid())
{
$booking = $this->getDoctrine()->getRepository('AppBundle:TravelBooking')->createFromBookingRequest(
@ -187,7 +190,11 @@ class BookingController extends Controller
{
$ret = 0;
$insuranceAssessmentBasis = 0;
$travelerCount = $bookingRequest->getTravelerCount();
$singleRoomCount = $bookingRequest->getSingleRoomCount();
$doubleRoomCount = $bookingRequest->getDoubleRoomCount();
$tripleRoomCount = $bookingRequest->getTripleRoomCount();
if (isset($outHtmlSummary))
{
$insuranceHtmlSummary = [];
@ -242,24 +249,19 @@ class BookingController extends Controller
}
}
$persons = [
'total' => $travelerCount,
'adults' => $travelerCount,
'children' => 0
'singleRoomPersons' => $singleRoomCount,
'doubleRoomPersons' => $doubleRoomCount * 2,
'tripleRoomPersons' => $tripleRoomCount * 3,
'children' => 0 //TODO
];
$possibleRooms = $this->searchRooms($travelDate->getPrices(), $persons);
if (empty($possibleRooms))
{
if ($travelerCount % 2 == 0)
{
$possibleRooms = $this->splitIntoTwoGroups($travelDate->getPrices(), $persons, 'equal');
}
elseif ($travelerCount >= 3)
{
$possibleRooms = $this->splitIntoTwoGroups($travelDate->getPrices(), $persons, 'move_without_children');
}
}
$possibleRooms = $this->getRooms($travelDate->getPrices(), $persons);
if ($bookingRequest->getComfort())
{
@ -385,52 +387,61 @@ class BookingController extends Controller
*
* @return array
*/
private function searchRooms($prices, $persons)
private function getRooms($prices, $persons)
{
$ret = [];
foreach ($prices as $price)
foreach($prices as $price)
{
$priceType = $this->priceTypeById[$price->getPriceTypeId()];
if ($priceType->getMax() == $persons['total'] &&
$priceType->getMaxAdults() >= $persons['adults'] &&
$priceType->getMinAdults() <= $persons['adults'] &&
$priceType->getMaxChildren() >= $persons['children'])
$priceTypeId = $price->getPriceTypeId();
$priceType = $this->priceTypeById[$priceTypeId];
if($priceTypeId == 1 && $persons['singleRoomPersons'] > 0)
{
$currentPersons = [
'total' => $persons['singleRoomPersons'],
'adults' => $persons['singleRoomPersons'],
'children' => 0 //TODO
];
$ret[] = [
'priceType' => $priceType,
'persons' => $persons,
'persons' => $currentPersons,
'price' => $price
];
}
if($priceTypeId == 3 && $persons['doubleRoomPersons'] > 0)
{
$currentPersons = [
'total' => $persons['doubleRoomPersons'],
'adults' => $persons['doubleRoomPersons'],
'children' => 0
];
$ret[] = [
'priceType' => $priceType,
'persons' => $currentPersons,
'price' => $price
];
}
if($priceTypeId == 5 && $persons['tripleRoomPersons'] > 0)
{
$currentPersons = [
'total' => $persons['tripleRoomPersons'],
'adults' => $persons['tripleRoomPersons'],
'children' => 0
];
$ret[] = [
'priceType' => $priceType,
'persons' => $currentPersons,
'price' => $price
];
}
}
return $ret;
}
private function splitIntoTwoGroups($prices, $persons, $mode)
{
$group1 = [];
$group2 = [];
if($mode == 'equal')
{
$group1['adults'] = $group2['adults'] = $persons['adults'] / 2;
$group1['children'] = $group2['children'] = $persons['children'] / 2;
$group1['total'] = $group2['total'] = $group1['adults'] + $group2['children'];
}
elseif($mode = 'move_without_children')
{
$group1['adults'] = $persons['adults'] - 1;
$group1['children'] = 0;
$group1['total'] = $group1['adults'] + $group1['children'];
$group2['adults'] = 1;
$group2['children'] = 0;
$group2['total'] = $group2['adults'] + $group2['children'];
}
$possibleRoomsGroup1 = $this->searchRooms($prices, $group1);
$possibleRoomsGroup2 = $this->searchRooms($prices, $group2);
return array_merge($possibleRoomsGroup1, $possibleRoomsGroup2);
}
}