From 2af7fb8bd43c0e8670dfc8790daf1ae93b60c598 Mon Sep 17 00:00:00 2001 From: ivant75 Date: Sat, 17 Dec 2016 15:39:43 +0100 Subject: [PATCH 1/4] update za Twig funkcije nova funkcija za prijevod broja u ime mjeseca --- .../src/AppBundle/Twig/CalendarExtension.php | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/booking/src/AppBundle/Twig/CalendarExtension.php b/booking/src/AppBundle/Twig/CalendarExtension.php index 849b8d2..159d861 100644 --- a/booking/src/AppBundle/Twig/CalendarExtension.php +++ b/booking/src/AppBundle/Twig/CalendarExtension.php @@ -9,6 +9,7 @@ public function getFunctions() return [ new \Twig_SimpleFunction('generateDatesForMonth', [$this, 'generateDatesForMonth']), new \Twig_SimpleFunction('getDayClass', [$this, 'getDayClass']), + new \Twig_SimpleFunction('getMonthName', [$this, 'getMonthName']) ]; } @@ -60,9 +61,28 @@ private function isReservedDate(\DateTimeImmutable $day, array $reservedDates) return false; } + + public function getMonthName(int $month) + { + switch($month) { + case 1: return 'Siječanj'; + case 2: return 'Veljača'; + case 3: return 'Ožujak'; + case 4: return 'Travanj'; + case 5: return 'Svibanj'; + case 6: return 'Lipanj'; + case 7: return 'Srpanj'; + case 8: return 'Kolovoz'; + case 9: return 'Rujan'; + case 10: return 'Listopad'; + case 11: return 'Studeni'; + case 12: return 'Prosinac'; + default: return ''; + } + } public function getName() { return 'calendar_extension'; } -} \ No newline at end of file +} From e68f28b997c9b2f03ea1120d6dfa4108a8d01457 Mon Sep 17 00:00:00 2001 From: ivant75 Date: Sat, 17 Dec 2016 15:41:28 +0100 Subject: [PATCH 2/4] update za accommodationAction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dodana podrška za neobvezan odabir mjeseca i godine za mali kalendar --- .../Controller/AccommodationController.php | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/booking/src/AppBundle/Controller/AccommodationController.php b/booking/src/AppBundle/Controller/AccommodationController.php index 5b9bf60..d7e2b8e 100644 --- a/booking/src/AppBundle/Controller/AccommodationController.php +++ b/booking/src/AppBundle/Controller/AccommodationController.php @@ -15,22 +15,31 @@ class AccommodationController extends Controller { /** - * @Route("/accommodation/{accommodationId}", name="AppBundle_Accommodation_accommodation") + * @Route("/accommodation/{accommodationId}/{month}/{year}", name="AppBundle_Accommodation_accommodation") */ - public function accommodationAction($accommodationId) + public function accommodationAction($accommodationId, $month = null, $year = null) { - $accommodationRepository = $this->getDoctrine()->getManager()->getRepository('AppBundle:Accommodation'); - $accommodation = $accommodationRepository->findByIdWithPlace($accommodationId); + $now = new \DateTime('now'); - $availability = $this->get('app.view.availability'); - $reservedDates = $availability->forAccommodationAndDate($accommodationId, 7, date('Y')); + if ($year == null) { + $year = $now->format('Y'); + } + if ($month == null) { + $month = $now->format('m'); + } + + $em = $this->getDoctrine()->getManager(); + $accommodation = $em->getRepository('AppBundle:Accommodation') + ->findByIdWithPlace($accommodationId); - if(!$accommodation) - throw $this->createNotFoundException(sprintf('Accommodation with id "%s" not found.', $accommodationId)); + $availability = $this->get('app.view.availability'); + $reservedDates = $availability->forAccommodationAndDate($accommodationId, $month, $year); return $this->render('AppBundle:Accommodation:accommodation.html.twig', [ 'accommodation' => $accommodation, 'reservedDates' => $reservedDates, + 'year' => $year, + 'month' => $month ]); } From ede4b24a053c169913ea90151048a8d093a917d9 Mon Sep 17 00:00:00 2001 From: ivant75 Date: Sat, 17 Dec 2016 15:43:13 +0100 Subject: [PATCH 3/4] update za accommodation view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dodana podrška za naprijed-nazad navigaciju po malom kalendaru --- .../Accommodation/accommodation.html.twig | 53 ++++++++++++++----- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/booking/src/AppBundle/Resources/views/Accommodation/accommodation.html.twig b/booking/src/AppBundle/Resources/views/Accommodation/accommodation.html.twig index e8f7525..c0e54b7 100644 --- a/booking/src/AppBundle/Resources/views/Accommodation/accommodation.html.twig +++ b/booking/src/AppBundle/Resources/views/Accommodation/accommodation.html.twig @@ -33,30 +33,59 @@ {{ helper.printPrice(accommodation.pricePerDay) }}
+ {% if month != 1 %} + + {% endif %} + {% if month == 1 %} + + {% endif %} +
+
+ + {% if month != 12 %} + + {% endif %} + {% if month == 12 %} + + {% endif %} +
+
- + - - - - - - - + + + + + + + - {% set month = 7 %} - {% for day in generateDatesForMonth(month, 'now'|date('Y')) %} + {% for day in generateDatesForMonth(month , year) %} {% if loop.index % 7 == 1 %}{% endif %} - + {% if loop.index % 7 == 0 %}{% endif %} {% endfor %}
July{{ getMonthName(month) }}
MonTueWedThuFriSatSunPoUtSrČePeSuNe
{{ day.format('d') }}{{ day.format('d') }}
+ -{% endblock %} \ No newline at end of file +{% endblock %} From f36ab5d954db0990556c63c78310328125c727ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Tomi=C4=87?= Date: Sat, 17 Dec 2016 15:54:23 +0100 Subject: [PATCH 4/4] update #2 za accommodation action dodan exception za not found --- booking/src/AppBundle/Controller/AccommodationController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/booking/src/AppBundle/Controller/AccommodationController.php b/booking/src/AppBundle/Controller/AccommodationController.php index d7e2b8e..fe518f2 100644 --- a/booking/src/AppBundle/Controller/AccommodationController.php +++ b/booking/src/AppBundle/Controller/AccommodationController.php @@ -31,6 +31,9 @@ public function accommodationAction($accommodationId, $month = null, $year = nul $em = $this->getDoctrine()->getManager(); $accommodation = $em->getRepository('AppBundle:Accommodation') ->findByIdWithPlace($accommodationId); + + if (!$accommodation) + throw $this->createNotFoundException(sprintf('Accommodation with id "%s" not found.', $accommodationId)); $availability = $this->get('app.view.availability'); $reservedDates = $availability->forAccommodationAndDate($accommodationId, $month, $year);