Skip to content
This repository was archived by the owner on Nov 14, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions booking/src/AppBundle/Controller/AccommodationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,34 @@
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');
}

if(!$accommodation)
$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
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,59 @@
{{ helper.printPrice(accommodation.pricePerDay) }}

<div class="kalendarWrap">
{% if month != 1 %}
<a href="{{ url('AppBundle_Accommodation_accommodation', {
'accommodationId': accommodation.id,
'month' : month - 1,
'year' : year }) }}">
{% endif %}
{% if month == 1 %}
<a href="{{ url('AppBundle_Accommodation_accommodation', {
'accommodationId': accommodation.id,
'month' : 12,
'year' : year - 1 }) }}">
{% endif %}
<div class="arrowPrev"></div>
</a>

{% if month != 12 %}
<a href="{{ url('AppBundle_Accommodation_accommodation', {
'accommodationId': accommodation.id,
'month' : month + 1,
'year' : year }) }}">
{% endif %}
{% if month == 12 %}
<a href="{{ url('AppBundle_Accommodation_accommodation', {
'accommodationId': accommodation.id,
'month' : 1,
'year' : year + 1 }) }}">
{% endif %}
<div class="arrowNext"></div>
</a>
<table class="kalendar">
<caption>July</caption>
<caption>{{ getMonthName(month) }}</caption>
<thead>
<tr>
<th>Mon</th>
<th>Tue</th>
<th>Wed</th>
<th>Thu</th>
<th>Fri</th>
<th class="weekend">Sat</th>
<th class="weekend">Sun</th>
<th>Po</th>
<th>Ut</th>
<th>Sr</th>
<th>Če</th>
<th>Pe</th>
<th class="weekend">Su</th>
<th class="weekend">Ne</th>
</tr>
</thead>
<tbody>
{% set month = 7 %}
{% for day in generateDatesForMonth(month, 'now'|date('Y')) %}
{% for day in generateDatesForMonth(month , year) %}
{% if loop.index % 7 == 1 %}<tr>{% endif %}
<td class="{{ getDayClass(day, month, reservedDates) }}">{{ day.format('d') }}</td>
<td class="{{ getDayClass(day, reservedDates) }}">{{ day.format('d') }}</td>
{% if loop.index % 7 == 0 %}</tr>{% endif %}
{% endfor %}
</tbody>
</table>
</div>

</div>
</div>

{% endblock %}
{% endblock %}
22 changes: 21 additions & 1 deletion booking/src/AppBundle/Twig/CalendarExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
];
}

Expand Down Expand Up @@ -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';
}
}
}