2017 © Pedro Peláez
 

symfony-bundle melifaro-booking-bundle

Adds some booking functionality to your Symfony 2 project

image

melifaro/melifaro-booking-bundle

Adds some booking functionality to your Symfony 2 project

  • Friday, February 3, 2017
  • by ama3ing
  • Repository
  • 3 Watchers
  • 31 Stars
  • 455 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 11 Forks
  • 4 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

MelifaroBookingBundle

SensioLabsInsight, (*1)

Build Status, (*2)


Booking Bundle for Symfony 2 Applications. Bundle provides some useful functionality for handling bookings on your website., (*3)

Installation

1. Download

Prefered way to install this bundle is using composer, (*4)

Download the bundle:, (*5)

$ php composer.phar require "melifaro/melifaro-booking-bundle:dev-master"

2. Add it to your Kernel:

<?php

// app/AppKernel.php


public function registerBundles()
{
    $bundles = array(
        // ...

        new Melifaro\BookingBundle\MelifaroBookingBundle(),
    );
}

3. Create your entity

Doctrine ORM

Bundle has all necessary mappings for your entity. Just create your entity class and extend it from Melifaro\BookingBundle\Entity\Booking, create your id field and setup proper relation for item you want to be booked., (*6)

<?php

namespace Vendor\Bundle\Entity;

use Melifaro\BookingBundle\Entity\Booking as BaseClass;

/**
 * Booking
 *
 * @ORM\Entity()
 * @ORM\Table(name="booking")
 */
class Booking extends BaseClass
{
    /**
         * @var integer
         *
         * @ORM\Column(name="id", type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        protected $id;

        /**
         * @var \Vendor\Bundle\Entity\BookableItem
         *
         * @ORM\ManyToOne(targetEntity="BookableItem", inversedBy="bookings")
         * @ORM\JoinColumn(name="property_id", referencedColumnName="id")
         */
        protected $item;

        // Don't forget about getters and setters
}

Now we are ready to rock!, (*7)

Booker Service

Core component of this bundle is booker service. You can get it in your controller by using, (*8)

<?php

public function bookingAction()
{
    $this->get('booker'); /** @var \Melifaro\BookingBundle\Helper\Booker */
}

Booker Service has following methods:

isAvailableForPeriod($item, \DateTime $start, \DateTime $end) Checks is your item available for period, returns boolean, (*9)


isAvailableForDate($item, \DateTime $date) Checks is your item available for date, returns boolean, (*10)


whereAvailableForPeriod(QueryBuilder $queryBuilder, $join, \DateTime $start, \DateTime $end) Updates your QueryBuilder and returns the same QueryBuilder object with added join and where clause., (*11)

Note: $join is array('field', 'alias'), (*12)


whereAvailableForDate(QueryBuilder $queryBuilder, $join, \DateTime $date) Updates your QueryBuilder and returns the same QueryBuilder object with added join and where clause., (*13)

Note: $join is array('field', 'alias'), (*14)


book($item, \DateTime $start, \DateTime $end) Books your item returns Entity | false (Entity on success, false on failure), (*15)

Calendar Twig Extension

Bundle also provides cool Twig extension. To use it in your template just try following:, (*16)

{{ melifaro_booking_calendar(item, "now", 4) }}

Where, (*17)

item - is object of your bookable item, (*18)

now - is any date allowed for \DateTime::__construct(), (*19)

4 - number of months to be rendered after desired date, (*20)

Overriding template

Template can be overridden as usual in Symfony 2 application. Just create following directory structure:, (*21)

app/Resources/views/MelifaroBookingBundle/Calendar/month.html.twig

The Versions