diff --git a/trunk/app/Resources/views/default/admin/lodgingsEditCalendar.html.twig b/trunk/app/Resources/views/default/admin/lodgingsEditCalendar.html.twig index 481ccf55..184316ff 100644 --- a/trunk/app/Resources/views/default/admin/lodgingsEditCalendar.html.twig +++ b/trunk/app/Resources/views/default/admin/lodgingsEditCalendar.html.twig @@ -1,100 +1,106 @@ - {% for month in calendar %} - - +{% for monthIndex in 0..11 %} + + + + + + + + + + + + + + + + {% for weekIndex in 0..5 %} - - - - - - - - - - - - - - {% for weekIndex in 0..5 %} - - {% for dayIndex in 0..6 %} - {% set day = month['data'][(weekIndex * 7) + dayIndex]|split(',') %} - {% if day|length > 1 %} - {% if day[1] == 'reservable' %} - + {% elseif dayState.isReserved %} + {% if dayState.isReservationBegin %} + {# @var prevState \AppBundle\Util\CalendarDayState #} + {% set prevState = calendar[monthIndex]['data'][(weekIndex * 7) + (dayIndex - 1)] %} + {% if prevState.day == 0 or prevState.isReservationEnd %} + + {% else %} + + {% endif %} + {% elseif dayState.isReservationEnd %} + {# @var nextState \AppBundle\Util\CalendarDayState #} + {% set nextState = calendar[monthIndex]['data'][(weekIndex * 7) + (dayIndex + 1)] %} + {% if nextState.isReservationBegin %} + + {% else %} + + {% endif %} + {% else %} + - {% else %} - {% if day|length > 3%} - - {% elseif day|length > 2 and day[2] == 'from' %} - - {% elseif day|length > 2 and day[2] == 'to' %} - - {% else %} - - {% endif %} {% endif %} - {% else %} - {% endif %} - {% endfor %} - - {% endfor %} - + {% else %} + {% if dayState.day == 0 %} + + {% else %} + + {% endif %} + {% endif %} + {% endfor %} + {% endfor %} -
+ {{ calendar[monthIndex]['monthName'] }} {{ calendar[monthIndex]['year'] }} +
MoDiMiDoFrSaSo
- {{ month['monthName'] }} {{ month['year'] }} -
MoDiMiDoFrSaSo
- + + {{ dayState.day }} + + + + {{ dayState.day }} + + + + {{ dayState.day }} + + + + {{ dayState.day }} + + + + {{ dayState.day }} + + + - {{ day[0] }} + {{ dayState.day }} - - {{ day[0] }} - - - - {{ day[0] }} - - - - {{ day[0] }} - - - - {{ day[0] }} - - - {% if day[0] == 0 %} - - - {% else %} - {{ day[0] }} - {% endif %} -
+ - + {{ dayState.day }}
+ + {% endfor %} + \ No newline at end of file diff --git a/trunk/app/Resources/views/default/components/pageBoxImage.html.twig b/trunk/app/Resources/views/default/components/pageBoxImage.html.twig index 1e86a1d1..83c0ab18 100644 --- a/trunk/app/Resources/views/default/components/pageBoxImage.html.twig +++ b/trunk/app/Resources/views/default/components/pageBoxImage.html.twig @@ -4,7 +4,7 @@ {% elseif page.travelProgram is not empty and page.travelProgram.previewImage is not empty %} {% set image_url = '/uploads/travel_program/' ~ page.travelProgram.previewImage.fileNameWithExtension %} {% set image_alt = page.title %} -{% elseif page.fewoLodging is not empty and page.fewoLodging.images[0] is not empty %} +{% elseif page.fewoLodging is not empty and page.fewoLodging.images is not empty and page.fewoLodging.images[0] is not empty %} {% set image_url = asset('uploads/images/' ~ page.fewoLodging.images[0].file) %} {% set image_alt = page.title %} {% else %} diff --git a/trunk/app/Resources/views/default/pages/cms/calendarLodgingProgram.html.twig b/trunk/app/Resources/views/default/pages/cms/calendarLodgingProgram.html.twig index ae36ddfc..f8210089 100644 --- a/trunk/app/Resources/views/default/pages/cms/calendarLodgingProgram.html.twig +++ b/trunk/app/Resources/views/default/pages/cms/calendarLodgingProgram.html.twig @@ -24,57 +24,70 @@ {% for weekIndex in 0..5 %} {% for dayIndex in 0..6 %} - {% set day = calendar[monthIndex]['data'][(weekIndex * 7) + dayIndex]|split(',') %} - {% if day|length > 1 %} - {% if day[1] == 'reservable' %} + {# @var dayState \AppBundle\Util\CalendarDayState #} + {% set dayState = calendar[monthIndex]['data'][(weekIndex * 7) + dayIndex] %} + {% if dayState.isBookable or dayState.isReserved %} + {% if dayState.isBookable %} - - {{ day[0] }} + {{ dayState.day }} - {% else %} - {% if day|length > 3%} - - {{ day[0] }} - - {% elseif day|length > 2 and day[2] == 'from' %} - - {{ day[0] }} - - {% elseif day|length > 2 and day[2] == 'to' %} - {% set nextDay = calendar[monthIndex]['data'][(weekIndex * 7) + (dayIndex + 1)]|split(',') %} - - - {{ day[0] }} - - + {% elseif dayState.isReserved %} + {% if dayState.isReservationBegin %} + {# @var prevState \AppBundle\Util\CalendarDayState #} + {% set prevState = calendar[monthIndex]['data'][(weekIndex * 7) + (dayIndex - 1)] %} + {% if prevState.day == 0 or prevState.isReservationEnd %} + + {{ dayState.day }} + + {% else %} + + {{ dayState.day }} + + {% endif %} + {% elseif dayState.isReservationEnd %} + {# @var nextState \AppBundle\Util\CalendarDayState #} + {% set nextState = calendar[monthIndex]['data'][(weekIndex * 7) + (dayIndex + 1)] %} + {% if nextState.isReservationBegin %} + + {{ dayState.day }} + + {% else %} + + + {{ dayState.day }} + + + {% endif %} {% else %} - {{ day[0] }} + {{ dayState.day }} {% endif %} {% endif %} - {% else %} - - {% if day[0] == 0 %} + {% if dayState.day == 0 %} - {% else %} - - {{ day[0] }} - + {% if dayState.isInSeason and not(dayState.isBookable) and not(dayState.isReserved) %} + + {{ dayState.day }} + + {% else %} + + {{ dayState.day }} + + {% endif %} {% endif %} - {% endif %} {% endfor %} diff --git a/trunk/src/AppBundle/Controller/AdminController.php b/trunk/src/AppBundle/Controller/AdminController.php index aac45748..a1dcced2 100644 --- a/trunk/src/AppBundle/Controller/AdminController.php +++ b/trunk/src/AppBundle/Controller/AdminController.php @@ -164,7 +164,6 @@ class AdminController extends Controller $lodging = $fewoLodgingRepo->find($lodgingId); $reservations = $calendarUtil->getReservations($lodging); - $paddedCalendar = $calendarUtil->getCalendarWithPadding(); $calendar = $calendarUtil->getCalendar(); if (count($lodging->getPrices()->toArray()) != 0) @@ -220,6 +219,8 @@ class AdminController extends Controller return $this->redirect('/admin/fewo/lodgings'); } + + // todo, WEG /** * @Route("/admin/fewo/lodgings/{lodgingId}/program", requirements={"lodgingId": "\d+"}) */ @@ -243,6 +244,7 @@ class AdminController extends Controller $calendar = $paddedCalendar; } + return $this->render('default/pages/cms/fewoTravelProgram.html.twig', [ 'fewo_lodging' => $lodging, 'calendar' => $calendar diff --git a/trunk/src/AppBundle/Resources/assets/less/includes/travel.less b/trunk/src/AppBundle/Resources/assets/less/includes/travel.less index 344ad0ae..2aba90e8 100644 --- a/trunk/src/AppBundle/Resources/assets/less/includes/travel.less +++ b/trunk/src/AppBundle/Resources/assets/less/includes/travel.less @@ -518,9 +518,30 @@ width: 50%; } -.calendarGradient{ - background: -webkit-gradient(linear, left top, right bottom, color-stop(1%, darkgray), color-stop(52%, darkgray), color-stop(52%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(100%, #f2f2f2)); - background: -moz-gradient(linear, left top, right bottom, color-stop(1%, darkgray), color-stop(52%, darkgray), color-stop(52%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(100%, #f2f2f2)); - background: -o-gradient(linear, left top, right bottom, color-stop(1%, darkgray), color-stop(52%, darkgray), color-stop(52%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(100%, #f2f2f2)); - background: gradient(linear, left top, right bottom, color-stop(1%, darkgray), color-stop(52%, darkgray), color-stop(52%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(100%, #f2f2f2)); -} \ No newline at end of file +.calendarGradientTravelBegin { + background: -webkit-gradient(linear, left top, right bottom, color-stop(1%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(52%, darkgrey), color-stop(52%, darkgrey), color-stop(100%, darkgrey)); + background: -moz-gradient(linear, left top, right bottom, color-stop(1%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(52%, darkgrey), color-stop(52%, darkgrey), color-stop(100%, darkgrey)); + background: -o-gradient(linear, left top, right bottom, color-stop(1%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(52%, darkgrey), color-stop(52%, darkgrey), color-stop(100%, darkgrey)); + background: gradient(linear, left top, right bottom, color-stop(1%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(52%, darkgrey), color-stop(52%, darkgrey), color-stop(100%, darkgrey)); +} + +.calendarGradientTravelEnd { + background: -webkit-gradient(linear, left top, right bottom, color-stop(1%, darkgray), color-stop(52%, darkgray), color-stop(52%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(100%, #f2f2f2)); + background: -moz-gradient(linear, left top, right bottom, color-stop(1%, darkgray), color-stop(52%, darkgray), color-stop(52%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(100%, #f2f2f2)); + background: -o-gradient(linear, left top, right bottom, color-stop(1%, darkgray), color-stop(52%, darkgray), color-stop(52%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(100%, #f2f2f2)); + background: gradient(linear, left top, right bottom, color-stop(1%, darkgray), color-stop(52%, darkgray), color-stop(52%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(100%, #f2f2f2)); + } + +.calendarGradientAdminBegin { + background: -webkit-gradient(linear, left top, right bottom, color-stop(1%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(52%, red), color-stop(52%, red), color-stop(100%, red)); + background: -moz-gradient(linear, left top, right bottom, color-stop(1%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(52%, red), color-stop(52%, red), color-stop(100%, red)); + background: -o-gradient(linear, left top, right bottom, color-stop(1%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(52%, red), color-stop(52%, red), color-stop(100%, red)); + background: gradient(linear, left top, right bottom, color-stop(1%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(52%, red), color-stop(52%, red), color-stop(100%, red)); +} + +.calendarGradientAdminEnd { + background: -webkit-gradient(linear, left top, right bottom, color-stop(1%, red), color-stop(52%, red), color-stop(52%, green), color-stop(52%, green), color-stop(100%, green)); + background: -moz-gradient(linear, left top, right bottom, color-stop(1%, red), color-stop(52%, red), color-stop(52%, green), color-stop(52%, green), color-stop(100%, green)); + background: -o-gradient(linear, left top, right bottom, color-stop(1%, red), color-stop(52%, red), color-stop(52%, green), color-stop(52%, green), color-stop(100%, green)); + background: gradient(linear, left top, right bottom, color-stop(1%, red), color-stop(52%, red), color-stop(52%, green), color-stop(52%, green), color-stop(100%, green)); +} diff --git a/trunk/src/AppBundle/Resources/public/css/custom.css b/trunk/src/AppBundle/Resources/public/css/custom.css index 57c47d19..fed598de 100644 --- a/trunk/src/AppBundle/Resources/public/css/custom.css +++ b/trunk/src/AppBundle/Resources/public/css/custom.css @@ -1065,12 +1065,30 @@ a[id^="video_"]:before, float: left; width: 50%; } -.calendarGradient { +.calendarGradientTravelBegin { + background: -webkit-gradient(linear, left top, right bottom, color-stop(1%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(52%, #a9a9a9), color-stop(52%, #a9a9a9), color-stop(100%, #a9a9a9)); + background: -moz-gradient(linear, left top, right bottom, color-stop(1%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(52%, #a9a9a9), color-stop(52%, #a9a9a9), color-stop(100%, #a9a9a9)); + background: -o-gradient(linear, left top, right bottom, color-stop(1%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(52%, #a9a9a9), color-stop(52%, #a9a9a9), color-stop(100%, #a9a9a9)); + background: gradient(linear, left top, right bottom, color-stop(1%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(52%, #a9a9a9), color-stop(52%, #a9a9a9), color-stop(100%, #a9a9a9)); +} +.calendarGradientTravelEnd { background: -webkit-gradient(linear, left top, right bottom, color-stop(1%, #a9a9a9), color-stop(52%, #a9a9a9), color-stop(52%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(100%, #f2f2f2)); background: -moz-gradient(linear, left top, right bottom, color-stop(1%, #a9a9a9), color-stop(52%, #a9a9a9), color-stop(52%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(100%, #f2f2f2)); background: -o-gradient(linear, left top, right bottom, color-stop(1%, #a9a9a9), color-stop(52%, #a9a9a9), color-stop(52%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(100%, #f2f2f2)); background: gradient(linear, left top, right bottom, color-stop(1%, #a9a9a9), color-stop(52%, #a9a9a9), color-stop(52%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(100%, #f2f2f2)); } +.calendarGradientAdminBegin { + background: -webkit-gradient(linear, left top, right bottom, color-stop(1%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(52%, #ff0000), color-stop(52%, #ff0000), color-stop(100%, #ff0000)); + background: -moz-gradient(linear, left top, right bottom, color-stop(1%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(52%, #ff0000), color-stop(52%, #ff0000), color-stop(100%, #ff0000)); + background: -o-gradient(linear, left top, right bottom, color-stop(1%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(52%, #ff0000), color-stop(52%, #ff0000), color-stop(100%, #ff0000)); + background: gradient(linear, left top, right bottom, color-stop(1%, #f2f2f2), color-stop(52%, #f2f2f2), color-stop(52%, #ff0000), color-stop(52%, #ff0000), color-stop(100%, #ff0000)); +} +.calendarGradientAdminEnd { + background: -webkit-gradient(linear, left top, right bottom, color-stop(1%, #ff0000), color-stop(52%, #ff0000), color-stop(52%, #008000), color-stop(52%, #008000), color-stop(100%, #008000)); + background: -moz-gradient(linear, left top, right bottom, color-stop(1%, #ff0000), color-stop(52%, #ff0000), color-stop(52%, #008000), color-stop(52%, #008000), color-stop(100%, #008000)); + background: -o-gradient(linear, left top, right bottom, color-stop(1%, #ff0000), color-stop(52%, #ff0000), color-stop(52%, #008000), color-stop(52%, #008000), color-stop(100%, #008000)); + background: gradient(linear, left top, right bottom, color-stop(1%, #ff0000), color-stop(52%, #ff0000), color-stop(52%, #008000), color-stop(52%, #008000), color-stop(100%, #008000)); +} /* 7) SHORTCODES =============================================================== diff --git a/trunk/src/AppBundle/Util/CalendarDayState.php b/trunk/src/AppBundle/Util/CalendarDayState.php new file mode 100644 index 00000000..f1e64bc6 --- /dev/null +++ b/trunk/src/AppBundle/Util/CalendarDayState.php @@ -0,0 +1,184 @@ +day; + } + + /** + * @param int $day + */ + public function setDay(int $day) + { + $this->day = $day; + } + + /** + * @return FewoPrice + */ + public function getPrice(): FewoPrice + { + return $this->price; + } + + /** + * @param FewoPrice $price + */ + public function setPrice(FewoPrice $price) + { + $this->price = $price; + } + + /** + * @return FewoReservation + */ + public function getReservation(): FewoReservation + { + return $this->reservation; + } + + /** + * @param FewoReservation $reservation + */ + public function setReservation(FewoReservation $reservation) + { + $this->reservation = $reservation; + } + + /** + * @return bool + */ + public function getIsInSeason(): bool + { + return $this->isInSeason; + } + + /** + * @param bool $isInSeason + */ + public function setIsInSeason(bool $isInSeason) + { + $this->isInSeason = $isInSeason; + } + + /** + * @return bool + */ + public function getIsReserved(): bool + { + return $this->isReserved; + } + + /** + * @param bool $isReserved + */ + public function setIsReserved(bool $isReserved) + { + $this->isReserved = $isReserved; + } + + /** + * @return bool + */ + public function getIsBookable(): bool + { + return $this->isBookable; + } + + /** + * @param bool $isBookable + */ + public function setIsBookable(bool $isBookable) + { + $this->isBookable = $isBookable; + } + + /** + * @return bool + */ + public function getIsReservationBegin(): bool + { + return $this->isReservationBegin; + } + + /** + * @param bool $isReservationBegin + */ + public function setIsReservationBegin(bool $isReservationBegin) + { + $this->isReservationBegin = $isReservationBegin; + } + + /** + * @return bool + */ + public function getIsReservationEnd(): bool + { + return $this->isReservationEnd; + } + + /** + * @param bool $isReservationEnd + */ + public function setIsReservationEnd(bool $isReservationEnd) + { + $this->isReservationEnd = $isReservationEnd; + } + + + +} diff --git a/trunk/src/AppBundle/Util/LodgingCalendarUtil.php b/trunk/src/AppBundle/Util/LodgingCalendarUtil.php index bc7860e8..1d4e85f5 100644 --- a/trunk/src/AppBundle/Util/LodgingCalendarUtil.php +++ b/trunk/src/AppBundle/Util/LodgingCalendarUtil.php @@ -8,6 +8,7 @@ use AppBundle\Entity\FewoReservation; use AppBundle\Entity\FewoSeason; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\EntityManager; +use AppBundle\Util\CalendarDayState; class LodgingCalendarUtil { @@ -62,19 +63,43 @@ class LodgingCalendarUtil for($fwd = 0; $fwd < $actualStartingWeekDay - 1; $fwd++) { - $data[] = 0; + $day = new CalendarDayState(); + $day->setDay(0); + $day->setIsBookable(false); + $day->setIsInSeason(false); + $day->setIsReserved(false); + $day->setIsReservationBegin(false); + $day->setIsReservationEnd(false); + + $data[] = $day; } for($d = 1; $d <= $numberDays; $d++) { - $data[] = $d; + $day = new CalendarDayState(); + $day->setDay($d); + $day->setIsBookable(false); + $day->setIsInSeason(false); + $day->setIsReserved(false); + $day->setIsReservationBegin(false); + $day->setIsReservationEnd(false); + + $data[] = $day; } $startIndex = count($data); for($lwd = $startIndex; $lwd < 42; $lwd++) { - $data[] = 0; + $day = new CalendarDayState(); + $day->setDay(0); + $day->setIsBookable(false); + $day->setIsInSeason(false); + $day->setIsReserved(false); + $day->setIsReservationBegin(false); + $day->setIsReservationEnd(false); + + $data[] = $day; } $calendar[] = [ @@ -119,12 +144,23 @@ class LodgingCalendarUtil $weekDay = $weekDays[$date['wday']]; $numberDays = $this->daysInMonth($actualMonth, $actualCurrentYear); + + /** @var CalendarDayState[] $data */ $data = null; // alle Wochentage for($d = 1; $d <= $numberDays; $d++) { - $data[] = $d; + // standard-vorbelegung + $day = new CalendarDayState(); + $day->setDay($d); + $day->setIsBookable(false); + $day->setIsInSeason(false); + $day->setIsReserved(false); + $day->setIsReservationBegin(false); + $day->setIsReservationEnd(false); + + $data[] = $day; } $calendar[] = [ @@ -141,6 +177,7 @@ class LodgingCalendarUtil return $calendar; } + /** * @param FewoLodging $lodging * @return array|null @@ -190,7 +227,9 @@ class LodgingCalendarUtil * @param $appendix * @return mixed */ - private function markCalendarDays($calendar, \DateTime $fromDate, \DateTime $toDate, $appendix, $reservationMode = false) + private function markCalendarDays($calendar, \DateTime $fromDate, \DateTime $toDate, + $reservationMode = false, + FewoPrice $price = null, FewoReservation $reservation = null) { $startDay = $fromDate->format('j'); $startMonth = $fromDate->format('n'); @@ -215,8 +254,10 @@ class LodgingCalendarUtil $endCalendarIndex = $this->getMonthIndex($calendar, $endMonth); + // anfang und ende innerhalb eines monats if($startCalendarIndex == $endCalendarIndex) { + /** @var CalendarDayState[] $data */ $data = $calendar[$startCalendarIndex]['data']; $calendar[$startCalendarIndex]['marked'] = 1; @@ -224,50 +265,90 @@ class LodgingCalendarUtil $startIndex = $startDay - 1; $endIndex = $endDay - 1; - $firstDay = explode(',', $data[$startIndex]); - - if(count($firstDay) > 1 && $reservationMode == false) - $startIndex = $startIndex + 1; - - for($i = $startIndex; $i <= $endIndex; $i++) + for ($i = $startIndex; $i <= $endIndex; $i++) { - - if($i == $startIndex && $reservationMode) + if ($reservationMode) { - $data[$i] = $data[$i].$appendix.",from"; - } elseif($i == $endIndex && $reservationMode) { - $data[$i] = $data[$i].$appendix.",to"; - } else { - $data[$i] = $data[$i].$appendix; + if ($i == $startIndex) + { + $data[$i]->setIsReserved(true); + $data[$i]->setIsReservationBegin(true); + $data[$i]->setReservation($reservation); + $data[$i]->setIsInSeason(true); + $data[$i]->setIsBookable(false); + } + elseif ($i == $endIndex) + { + $data[$i]->setIsReserved(true); + $data[$i]->setIsReservationEnd(true); + $data[$i]->setReservation($reservation); + $data[$i]->setIsInSeason(true); + $data[$i]->setIsBookable(false); + //$data[$i]->setIsBookable(true); + } + else + { + $data[$i]->setIsReserved(true); + $data[$i]->setReservation($reservation); + $data[$i]->setIsInSeason(true); + $data[$i]->setIsBookable(false); + } + } + else + { + $data[$i]->setIsReserved(false); + $data[$i]->setPrice($price); + $data[$i]->setIsInSeason(true); + $data[$i]->setIsBookable(true); } } $calendar[$startCalendarIndex]['data'] = $data; } else { + // erster monat + + /** @var CalendarDayState[] $data */ $data = $calendar[$startCalendarIndex]['data']; $calendar[$startCalendarIndex]['marked'] = 1; $startIndex = $startDay - 1; - $firstDay = explode(',', $data[$startIndex]); - - if(count($firstDay) > 1 && $reservationMode == false) - $startIndex = $startIndex + 1; - $endIndex = count($data) - 1; for($i = $startIndex; $i <= $endIndex; $i++) { - if($i == $startIndex && $reservationMode) + if ($reservationMode) { - $data[$i] = $data[$i].$appendix.",from"; - } else { - $data[$i] = $data[$i].$appendix; + if ($i == $startIndex) + { + $data[$i]->setIsReserved(true); + $data[$i]->setIsReservationBegin(true); + $data[$i]->setReservation($reservation); + $data[$i]->setIsInSeason(true); + $data[$i]->setIsBookable(false); + } + else + { + $data[$i]->setIsReserved(true); + $data[$i]->setReservation($reservation); + $data[$i]->setIsInSeason(true); + $data[$i]->setIsBookable(false); + } + } + else + { + $data[$i]->setIsReserved(false); + $data[$i]->setPrice($price); + $data[$i]->setIsInSeason(true); + $data[$i]->setIsBookable(true); } } $calendar[$startCalendarIndex]['data'] = $data; + // letzter monat + + /** @var CalendarDayState[] $data */ $data = $calendar[$endCalendarIndex]['data']; $calendar[$endCalendarIndex]['marked'] = 1; @@ -276,17 +357,41 @@ class LodgingCalendarUtil $endIndex = $endDay - 1; for($i = $startIndex; $i <= $endIndex; $i++) { - if($i == $endIndex && $reservationMode) + + if ($reservationMode) { - $data[$i] = $data[$i].$appendix.",to"; - } else { - $data[$i] = $data[$i].$appendix; + if ($i == $endIndex) + { + $data[$i]->setIsReserved(true); + $data[$i]->setIsReservationEnd(true); + $data[$i]->setReservation($reservation); + $data[$i]->setIsInSeason(true); + $data[$i]->setIsBookable(false); // todo, hier evtl direkt true + //$data[$i]->setIsBookable(true); + } + else + { + $data[$i]->setIsReserved(true); + $data[$i]->setReservation($reservation); + $data[$i]->setIsInSeason(true); + $data[$i]->setIsBookable(false); + } + } + else + { + $data[$i]->setIsReserved(false); + $data[$i]->setPrice($price); + $data[$i]->setIsInSeason(true); + $data[$i]->setIsBookable(true); } } $calendar[$endCalendarIndex]['data'] = $data; + + // alle monate dazwischen for($i = $startCalendarIndex + 1; $i < $endCalendarIndex; $i++) { + /** @var CalendarDayState[] $data */ $data = $calendar[$i]['data']; $calendar[$i]['marked'] = 1; @@ -295,7 +400,20 @@ class LodgingCalendarUtil $endIndex = count($data) - 1; for($j = $startIndex; $j <= $endIndex; $j++) { - $data[$j] = $data[$j].$appendix; + if ($reservationMode) + { + $data[$j]->setIsReserved(true); + $data[$j]->setReservation($reservation); + $data[$j]->setIsInSeason(true); + $data[$j]->setIsBookable(false); + } + else + { + $data[$j]->setIsReserved(false); + $data[$j]->setPrice($price); + $data[$j]->setIsInSeason(true); + $data[$j]->setIsBookable(true); + } } $calendar[$i]['data'] = $data; } @@ -307,42 +425,107 @@ class LodgingCalendarUtil { for($i = 0; $i < 12; $i++) { - if($calendar[$i]['marked'] == 1 && $extensionCalendar[$i]['marked'] == 1) + /** @var CalendarDayState[] $calendarData */ + $calendarData = $calendar[$i]['data']; + + /** @var CalendarDayState[] $extensionCalendarData */ + $extensionCalendarData = $extensionCalendar[$i]['data']; + + $endIndex = count($calendarData); + + for($j = 0; $j < $endIndex; $j++) { - $calendarData = $calendar[$i]['data']; - $extensionCalendarData = $extensionCalendar[$i]['data']; + //$mergedPricesAndReservationsCalendar = $this->mergeCalendarsNew($pricesCalendar, $reservationsCalendar, false); + //$actuallyReservableDaysCalendar = $this->filterReservableDays($lodging, $mergedPricesAndReservationsCalendar); + //$resultCalendar = $this->mergeCalendars($actuallyReservableDaysCalendar, $reservationsCalendar, true); - $endIndex = count($calendarData); - - for($j = 0; $j < $endIndex; $j++) + if ($withFromTo) { - if(strlen($extensionCalendarData[$j]) > 2) + if ($extensionCalendarData[$j]->getIsInSeason()) { - if($withFromTo) - { - $calDay = explode(',', $calendarData[$j]); - $extCalDay = explode(',', $extensionCalendarData[$j]); - - if(count ($calDay) > 1 && $calDay[1] == "reservable" && count($extCalDay) > 2 && $extCalDay[2] == 'to') - { - $calendarData[$j] = $extensionCalendarData[$j].",reservable".','.$calDay[2]; - } - else - $calendarData[$j] = $extensionCalendarData[$j]; - - } - else - { - $calendarData[$j] = $extensionCalendarData[$j]; - } + //$calendarData[$j] = $extensionCalendarData[$j]; + $price = $extensionCalendarData[$j]->getPrice(); + $calendarData[$j]->setIsInSeason(true); + $calendarData[$j]->setPrice($price); } } - $calendar[$i]['data'] = $calendarData; + + if ($extensionCalendarData[$j]->getIsReserved()) + { + // braucht man das überhaupt noch? + if ($withFromTo) + { + // zweite runde $actuallyReservableDaysCalendar merge mit $reservationsCalendar + + if (!($calendarData[$j]->getIsBookable() && $extensionCalendarData[$j]->getIsReservationEnd())) + { + //$calendarData[$j] = $extensionCalendarData[$j]; + + $price = $calendarData[$j]->getPrice(); + + //$calendarData[$j] = $extensionCalendarData[$j];// todo + $calendarData[$j]->setIsBookable(false); + $calendarData[$j]->setIsReserved(true); + $calendarData[$j]->setReservation($extensionCalendarData[$j]->getReservation()); + + $calendarData[$j]->setIsReservationBegin($extensionCalendarData[$j]->getIsReservationBegin()); + $calendarData[$j]->setIsReservationEnd($extensionCalendarData[$j]->getIsReservationEnd()); + + + + if ($calendarData[$j]->getIsReservationEnd() && $extensionCalendarData[$j]->getIsReservationBegin()) + { + $calendarData[$j]->setIsReservationBegin(false); + $calendarData[$j]->setIsReservationEnd(false); + } + + $calendarData[$j]->setIsInSeason(true); + $calendarData[$j]->setPrice($price); + } + } + else + { + // erste runde $pricesCalendar merge mit $reservationsCalendar + + $price = $calendarData[$j]->getPrice(); + $reservation = $calendarData[$j]->getReservation(); + $calendarData[$j] = $extensionCalendarData[$j]; + + if ($calendarData[$j]->getIsReservationEnd() && $extensionCalendarData[$j]->getIsReservationBegin()) + { + $calendarData[$j]->setReservation($reservation); + + $calendarData[$j]->setIsReservationBegin(false); + $calendarData[$j]->setIsReservationEnd(false); + } + + /** @var FewoPrice $price */ + $calendarData[$j]->setIsInSeason(true); + $calendarData[$j]->setPrice($price); + } + } + } + + $calendar[$i]['data'] = $calendarData; + } + return $calendar; + } + + + /** @var CalendarDayState[] $calendarMonth */ + private function findCalendarDayIndexInMonth($dayNumber, $calendarMonth) + { + $result = 0; + for ($i = 0; $i < count($calendarMonth); $i++) + { + if ($calendarMonth[$i]->getDay() == $dayNumber) + { + $result = $i; + break; } } - - return $calendar; + return $result; } public function mergeWithPaddedCalendar($calendar, $paddedCalendar) @@ -351,7 +534,10 @@ class LodgingCalendarUtil { $calendarDataCurrMonth = $calendar[$i]['data']; $paddedCalendarDataCurrMonth = $paddedCalendar[$i]['data']; - $startIndex = array_search(1, $paddedCalendarDataCurrMonth); + + $startIndex = $this->findCalendarDayIndexInMonth(1, $paddedCalendarDataCurrMonth); + //$startIndex = array_search(1, $paddedCalendarDataCurrMonth); + for($j = 0; $j < count($calendarDataCurrMonth); $j++, $startIndex++) { $paddedCalendarDataCurrMonth[$startIndex] = $calendarDataCurrMonth[$j]; @@ -361,6 +547,7 @@ class LodgingCalendarUtil return $paddedCalendar; } + private function isNextDay($current, $next) { $result = false; @@ -413,69 +600,73 @@ class LodgingCalendarUtil for($currMonthIndex = 0; $currMonthIndex < count($calendar); $currMonthIndex++) { $currMonth = $calendar[$currMonthIndex]; + /** @var CalendarDayState[] $data */ $data = $currMonth['data']; for($currDayIndex = 0; $currDayIndex < count($data); $currDayIndex++) { - $currDay = explode(',', $data[$currDayIndex]); + //$currDay = explode(',', $data[$currDayIndex]); + $currDay = $data[$currDayIndex]; - if(count($currDay) > 1) + if ($currDay->getIsBookable() || $currDay->getIsReserved()) { - if($currDay[1] == "reservable") + if ($currDay->getIsBookable()) { - $priceId = $currDay[2]; + $price = $currDay->getPrice(); + $priceId = $price->getId(); - if($lastReservablePriceId == 0) + if ($lastReservablePriceId == 0) + { $lastReservablePriceId = $priceId; - + } if($lastReservablePriceId != $priceId) { - $price = $priceRepo->find($lastReservablePriceId); + $lastPrice = $priceRepo->find($lastReservablePriceId); /** @var FewoSeason $season */ - $season = $price->getSeason(); + $season = $lastPrice->getSeason(); $actuallyReservableDays = $this->processPotentiallyReservableDays($potentiallyReservableDays, $season->getMinimumStay()); - $this->processRest($actuallyReservableDays, $lastReservablePriceId, $cleanCalendar); + $this->processRest($actuallyReservableDays, $lastPrice, $cleanCalendar); //todo $lastReservablePriceId = $priceId; $potentiallyReservableDays = []; $actuallyReservableDays = []; - } - $currentDayDate = date("d.m.Y", strtotime($currMonth['year']."-".$currMonth['monthNumber']."-".$currDay[0])); + $currentDayDate = date("d.m.Y", strtotime($currMonth['year']."-".$currMonth['monthNumber']."-".$currDay->getDay())); $potentiallyReservableDays[] = $currentDayDate; } - elseif(count($currDay) > 2 && $currDay[2] == "from") + elseif ($currDay->getIsReserved() && $currDay->getIsReservationBegin()) { - $currentDayDate = date("d.m.Y", strtotime($currMonth['year']."-".$currMonth['monthNumber']."-".$currDay[0])); + $currentDayDate = date("d.m.Y", strtotime($currMonth['year']."-".$currMonth['monthNumber']."-".$currDay->getDay())); $potentiallyReservableDays[] = $currentDayDate; } - } else { if($lastReservablePriceId == $priceId && $lastReservablePriceId != 0) { - $price = $priceRepo->find($lastReservablePriceId); + $lastPrice = $priceRepo->find($lastReservablePriceId); /** @var FewoSeason $season */ - $season = $price->getSeason(); + $season = $lastPrice->getSeason(); $actuallyReservableDays = $this->processPotentiallyReservableDays($potentiallyReservableDays, $season->getMinimumStay()); - $this->processRest($actuallyReservableDays, $lastReservablePriceId, $cleanCalendar); + $this->processRest($actuallyReservableDays, $lastPrice, $cleanCalendar); //todo $lastReservablePriceId = $priceId; $potentiallyReservableDays = []; $actuallyReservableDays = []; } + } } - } return $cleanCalendar; } + + private function processPotentiallyReservableDays($potentiallyReservableDays, $minimumStay) { $coherentDays = []; @@ -531,35 +722,40 @@ class LodgingCalendarUtil return $actuallyReservableDays; } - private function processRest($actuallyReservableDays, $priceId, &$cleanCalendar) + + private function processRest($actuallyReservableDays, FewoPrice $price, &$cleanCalendar) { for($currMonthIndex = 0; $currMonthIndex < count($cleanCalendar); $currMonthIndex++) { $currMonth = $cleanCalendar[$currMonthIndex]; + /** @var CalendarDayState[] $data */ $data = $currMonth['data']; - $startIndex = array_search(1, $data); - $endIndex = $startIndex + ($currMonth['numberDays']); - - for($currDayIndex = $startIndex; $currDayIndex < $endIndex; $currDayIndex++) + for($currDayIndex = 0; $currDayIndex < count($data); $currDayIndex++) { - $currDay = explode(',', $data[$currDayIndex]); + $currDay = $data[$currDayIndex]; - $currentDate = date("d.m.Y", strtotime($currMonth['year']."-".$currMonth['monthNumber']."-".$currDay[0])); + $currentDate = date("d.m.Y", strtotime($currMonth['year']."-".$currMonth['monthNumber']."-".$currDay->getDay())); - if(in_array($currentDate, $actuallyReservableDays)) + if (in_array($currentDate, $actuallyReservableDays)) { - $data[$currDayIndex] = $data[$currDayIndex].",reservable,".$priceId; + $data[$currDayIndex]->setIsInSeason(true); + $data[$currDayIndex]->setIsReserved(false); // todo ? + $data[$currDayIndex]->setIsBookable(true); + $data[$currDayIndex]->setIsReservationBegin(false); + $data[$currDayIndex]->setIsReservationEnd(false); // todo ? + $data[$currDayIndex]->setPrice($price); + $currMonth['marked'] = 1; } } $currMonth['data'] = $data; $cleanCalendar[$currMonthIndex] = $currMonth; } - } + /** * @param FewoLodging $lodging * @param $calendar @@ -580,17 +776,12 @@ class LodgingCalendarUtil { /** @var FewoSeason $season */ $season = $price->getSeason(); - $appendix = ',reservable,'.$price->getId(); $fromDate = $season->getFromDate(); $toDate = $season->getToDate(); - if($toDate < $today) + if(!($toDate < $today)) { - - } - else - { - $pricesCalendar = $this->markCalendarDays($pricesCalendar, $fromDate, $toDate, $appendix, false); + $pricesCalendar = $this->markCalendarDays($pricesCalendar, $fromDate, $toDate, false, $price, null); //TODO fast fertig } } @@ -601,7 +792,7 @@ class LodgingCalendarUtil $fromDate = $reservation->getFromDate(); $toDate = $reservation->getToDate(); - $reservationsCalendar = $this->markCalendarDays($reservationsCalendar, $fromDate, $toDate, $appendix, true); + $reservationsCalendar = $this->markCalendarDays($reservationsCalendar, $fromDate, $toDate, true, null, $reservation); //TODO fast fertig } $mergedPricesAndReservationsCalendar = $this->mergeCalendars($pricesCalendar, $reservationsCalendar, false); @@ -611,6 +802,7 @@ class LodgingCalendarUtil return $resultCalendar; } + public function convertDate($date) { $result = substr($date, 0, 2).'.'.substr($date, 2, 2).'.'.substr($date, 4, 4); diff --git a/trunk/src/AppBundle/Validator/Constraints/FewoReservationValidator.php b/trunk/src/AppBundle/Validator/Constraints/FewoReservationValidator.php index 8be79c31..779e7684 100644 --- a/trunk/src/AppBundle/Validator/Constraints/FewoReservationValidator.php +++ b/trunk/src/AppBundle/Validator/Constraints/FewoReservationValidator.php @@ -35,6 +35,10 @@ class FewoReservationValidator extends ConstraintValidator */ public function validate($reservation, Constraint $constraint) { + $fromDate = $reservation->getFromDate(); + $toDate = $reservation->getToDate(); + + $lodging = $reservation->getLodging(); $reservations = $lodging->getReservations(); $seasons = $lodging->getSeasons(); @@ -57,7 +61,7 @@ class FewoReservationValidator extends ConstraintValidator $reservationToDate = $reservation->getToDate(); - if($this->alreadyReserved($reservation->getFromDate(), $reservation->getToDate(), $reservationFromDate, $reservationToDate)) + if($this->alreadyReserved($fromDate, $toDate, $reservationFromDate, $reservationToDate)) { $alreadyReserved = true; }