From ef13a690835265d962186b565cb0bd0c99d114ad Mon Sep 17 00:00:00 2001 From: p1907961 Date: Sat, 16 Jan 2021 23:17:02 +0100 Subject: [PATCH] Added limitation on editing Rooms & Beds informations --- controller/accomodation.php | 34 +++++++++++++++++++++++++++++++--- view/date_accomodation.php | 1 + 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/controller/accomodation.php b/controller/accomodation.php index 5314279..2d2bd43 100644 --- a/controller/accomodation.php +++ b/controller/accomodation.php @@ -8,7 +8,7 @@ if ($_SESSION['USER']->isLoggedIn() && $_SESSION['USER']->getType() == 'Accomoda if (isset($path[1])) { switch ($path[1]) { case 'add': - if (!$_SESSION['USER']->getAccomodationId() && $_SESSION['USER']->getType() == 'AccomodationOwner') { + if (!$_SESSION['USER']->getAccomodationId()) { /* * Creating Accomodation */ @@ -87,10 +87,33 @@ if ($_SESSION['USER']->isLoggedIn() && $_SESSION['USER']->getType() == 'Accomoda case 'date': if ($_SESSION['USER']->getAccomodationId()) { $allRange = AccomodationLoad::getByAccomodationId($_SESSION['USER']->getAccomodationId()); + /* + * Calcul des minimum / disponibilités + */ + $minimum = AccomodationLoad::getRange(); + $reservations = AccomodationReservation::fetchByAccomodationId($_SESSION['USER']->getAccomodationId()); + forEach($reservations as $reservation){ + $start = date_create($reservation->getStartDate()); + $end = date_create($reservation->getEndDate()); + $end->add(new DateInterval('P1D')); + $period = new DatePeriod( + $start, + new DateInterval('P1D'), + $end + ); + foreach ($period as $key => $value) { + if(in_array($value->format('Y-m-d'), array_keys($minimum))){ + $minimum[$value->format('Y-m-d')]['rooms'] += $reservation->getRoomCount(); + $minimum[$value->format('Y-m-d')]['beds'] += $reservation->getPeopleCount(); + } + } + } + /* * Formulaire POST */ $filteredPost = []; + $error = false; forEach($_POST as $key=>$value){ $parts = explode('-', $key); $last = array_pop($parts); @@ -101,11 +124,16 @@ if ($_SESSION['USER']->isLoggedIn() && $_SESSION['USER']->getType() == 'Accomoda */ $col = $parts[1]; if(in_array($col, ['beds','rooms'])){ - $filteredPost[$parts[0]][$col] = (int)$value; + if($minimum[$parts[0]][$col] > (int)$value){ + $error = true; + $alert = alert('danger','Impossible de réduire le compte de \'' .$col. '\' pour le ' . dateToFrench($parts[0], "j F Y") . ' due a des reservations déjà enregistrées.'); + }else { + $filteredPost[$parts[0]][$col] = (int)$value; + } } } } - if(count($filteredPost) > 0){ + if(count($filteredPost) > 0 && $error == false){ AccomodationLoad::setAccomodationLoad($_SESSION['USER']->getAccomodationId(), $filteredPost); $allRange = AccomodationLoad::getByAccomodationId($_SESSION['USER']->getAccomodationId()); } diff --git a/view/date_accomodation.php b/view/date_accomodation.php index 73f6966..ec4d6cb 100644 --- a/view/date_accomodation.php +++ b/view/date_accomodation.php @@ -8,6 +8,7 @@ require_once('template/head.php');

Gestion des disponibilités de "getName() ?>"