Skip to content

Error when rendering calendar #3

@tdumalin

Description

@tdumalin

Hi,
I've noticed two bugs:

  • When we are the 30th of the month and using kami_booking_calendar twig function, month render is false, for exemple I changed the date of my system to 2018-09-30 and march 2019 appears twice, I have : january ,march,march, Apri etc..
    I rewrite some code if you want to re-use it:
    `

             {% set year = start|date('Y') %}
    
      {% set month = start|date('m') %}		
    
      {% for i in 1..months %}
      
      	{% if month ==13 %}			
      	    {% set month = 1 %}
      	    {% set year = year +1 %}
      	{% endif %}
      	
      	{% set date =year~"-"~month~"-01" %}
      	{% set first_day_index= date|date('w') %}
      	{% set number_of_days = date|date_modify('last day of this month')|date('d')   %}
      	{% set number_of_rows =(((number_of_days+first_day_index)-1)/7)|round(0, 'ceil')  %}
      	{% set current_day = 1 %}
    
          <table class="cf-booking-calendar table table-bordered {% if loop.last %}last{% endif %}" id="month{{ loop.index }}" data-item="{{ loop.index }}">
              <tr class="cf-booking-calendar-m">
                  <th colspan="7">{{ date|date("F Y") }}</th>
              </tr>
              <tr>
                  <th class="cf-booking-calendar-dow">Mon</th>
                  <th class="cf-booking-calendar-dow">Tue</th>
                  <th class="cf-booking-calendar-dow">Wed</th>
                  <th class="cf-booking-calendar-dow">Thi</th>
                  <th class="cf-booking-calendar-dow">Fri</th>
                  <th class="cf-booking-calendar-dow">Sat</th>
                  <th class="cf-booking-calendar-dow">Sun</th>
              </tr>
      		{% for row_index in 1..number_of_rows  %}	
      			<tr>
      				{% for day_index in 1..7 %}						
      					
      					{% if (row_index ==1 and day_index >= first_day_index)  or (row_index > 1  and current_day<=number_of_days) %}
      					
      						{% set day_string = current_day <10 ? "0"~current_day : current_day  %}
      						{% set current_date = year~"-"~month~"-"~day_string %}
      						
      	                    {% set booked = 0 %}
      	                    {% set is_opener = 0 %}
      	                    {% set is_closer = 0 %}
      	                    
      	                    {% for booking in bookings %}
      	                        {% if current_date|date("U") >= booking.start|date("U") and current_date|date("U") <= booking.end|date("U") %}
      	                            {% set booked = 1 %}
      	                        {% endif %}
      	                        {% if current_date|date("d F Y") == booking.start|date("d F Y") %}
      	                            {% set is_opener = 1 %}
      	                        {% endif %}
      	                        {% if current_date|date("d F Y") == booking.end|date("d F Y") %}
      	                            {% set is_closer = 1 %}
      	                        {% endif %}
      	                    {% endfor %}
      					    
      						<td data-formatdate="{{ current_date| date("U") }}" class="cf-booking-calendar-d {{ booked == 1 ? 'booked' : '' }} {{ is_opener == 1 ? 'opener':''}} {{ is_closer == 1 ? 'closer':'' }} {{ current_date|date("U") < "now" |date("U") ? 'muted':'' }}">
      						    {{ current_day }}
      					    </td>									    
      						{% set current_day=current_day+1  %}
      					{% else %}
      						<td class="cf-booking-calendar-empty "></td>
      					{% endif %}
      					
      				{% endfor %}
      			</tr>
      		{% endfor %}
          </table>
          {% set month = month+1 %}
      {% endfor %}`
    
  • Apparently the definition of your twig extension service 'booking_calendar' is false, first given argument is '%kami.booking_calendar.class%' but i think it must be '%kami.booker.entity_class%' because you call doctrine repository using this argument.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions