SladBookingBundle
this project is forked from melifaro/melifaro-booking-bundle
Changes will be made to match with car rental business, (*1)
Booking Bundle for Symfony 2 Applications. Bundle provides some useful functionality for handling bookings
on your website., (*2)
Installation
1. Download
Prefered way to install this bundle is using composer, (*3)
Download the bundle:, (*4)
$ php composer.phar require "slad/slad-booking-bundle:dev-master"
2. Add it to your Kernel:
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Slad\BookingBundle\SladBookingBundle(),
);
}
3. Create your entity
Doctrine ORM
Bundle has all necessary mappings for your entity. Just create your entity class and extend it from
Slad\BookingBundle\Entity\Booking
, create your id
field and setup proper relation for
item you want to be booked., (*5)
<?php
namespace Vendor\Bundle\Entity;
use Slad\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
}
# Booking
slad_booking:
entity_class: AppBundle\Entity\Booking
Now we are ready to rock!, (*6)
Booker Service
Core component of this bundle is booker service. You can get it in your controller by using, (*7)
<?php
public function bookingAction()
{
$this->get('booker'); /** @var \Slad\BookingBundle\Helper\Booker */
}
Booker Service has following methods:
isAvailableForPeriod($item, \DateTime $start, \DateTime $end)
Checks is your item available for period,
returns boolean
, (*8)
isAvailableForDate($item, \DateTime $date)
Checks is your item available for date, returns boolean
, (*9)
whereAvailableForPeriod(QueryBuilder $queryBuilder, $join, \DateTime $start, \DateTime $end)
Updates your
QueryBuilder
and returns the same QueryBuilder
object with added join and where clause., (*10)
Note: $join
is array('field', 'alias')
, (*11)
whereAvailableForDate(QueryBuilder $queryBuilder, $join, \DateTime $date)
Updates your
QueryBuilder
and returns the same QueryBuilder
object with added join and where clause., (*12)
Note: $join
is array('field', 'alias')
, (*13)
book($item, \DateTime $start, \DateTime $end)
Books your item returns Entity | false
(Entity
on success, false
on failure), (*14)
Calendar Twig Extension
Bundle also provides cool Twig extension. To use it in your template just try following:, (*15)
{{ slad_booking_calendar(item, "now", 4) }}
Where, (*16)
item
- is object of your bookable item, (*17)
now
- is any date allowed for \DateTime::__construct()
, (*18)
4
- number of months to be rendered after desired date, (*19)
Overriding template
Template can be overridden as usual in Symfony 2 application.
Just create following directory structure:, (*20)
app/Resources/views/SladBookingBundle/Calendar/month.html.twig