The code is provided as a regular Bundle under the namespace Dp\CalendarBundle\Controller.
To use it, just copy the folder Dp in your src, register it it in your AppKernel.php:

public function registerBundles()
    $bundles = array(
        new Dp\CalendarBundle\DpCalendarBundle(),

Import the routing in app/routing.yml:

    resource: "@DpCalendarBundle/Resources/config/routing.yml"

It is important to note that the templates in the bundle extend layout.html.twig in app/Resources/views, so you have to create such a file or change the templates to use your own.
Update your database and create at least one item and one state. If you use the admin before creating a state, there will be a booking with a null state_id which then creates troubles.
In the calendarstyle.css, the following state classes are already styled, feel free to use them: available, booked, provisional, transition.
Load the css and jQuery and you are good to go!

Also, the code to render a controller from a view has changed since Symfony 2.1. If you are using a version >=2.2, you have to modify both src/Dp/CalendarBundle/Resources/views/Default/index.html.twig and indexAdmin.html.twig and replace line 5 with:

    {{ render(controller('DpCalendarBundle:Default:calendarDisplay', { 'admin': false })) }}

for index.html.twig, and

    {{ render(controller('DpCalendarBundle:Default:calendarDisplay', { 'admin': true })) }}

for indexAdmin.html.twig, thank you Pere for noticing.


October 23, 2013: this one hurts, thank you Gustav for reporting it. I promised myself I'd never fall for the classic Math.floor(-1.1) = -2. For those wondering, the best way in javascript to get the integer part of a decimal number (positive or negative) is:

    IntegerPart = MyDecimalNumber - MyDecimalNumber%1;

Applied to our case, you should replace line 95 of src/Dp/CalendarBundle/Resources/views/Default/calendar.html.twig:

    var newYear = year + Math.floor((3 * gap)/12);

with the 2 following lines:

    var gapYear = (3 * gap)/12;
    var newYear = year + gapYear - gapYear%1;

My to do.

  • Create an easy way to be able to chose the number of months displayed.
    It is feasible but requires to get into the code.
  • Create an easy way to be able to switch between starting weeks on Monday vs Sunday.
  • Add multilingual support.