lzaplata/booking

Simple booking for Nette

Installs: 54

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 0

Open Issues: 0

Language:JavaScript

dev-master 2019-11-20 11:23 UTC

This package is auto-updated.

Last update: 2024-04-20 21:15:56 UTC


README

This is a simple Nette Framework booking component.

Installation

The easiest way to install library is via Composer.

$ composer require lzaplata/booking: dev-master

or edit composer.json in your project

"require": {
        "lzaplata/booking": "dev-master"
}

You have to register the library as an extension in config.neon file.

extensions:
        booking: LZaplata\Booking\DI\BookingExtension

Autowire a library to a presenter and autowire a template factory

use LZaplata\Booking\Booking;
use Nette\Application\UI\ITemplateFactory;

/** @var Booking @inject */
public $booking;

/** @var ITemplateFactory @inject */
public $templateFactory;

Usage

Create a booking room as a component.

/**
* @param string $name
*/
public function createComponentParkBookingRoom($name)
{
    // create days objects
    
    $monday = new Day(); // creates single day object using LZaplata\Booking\Day
    $monday->setDayOfWeek(Day::MONDAY); // sets day of week 
    $monday->setStartDateTime(new \DateTime()); // sets day start time (you can also use Nette\Utils\DateTime)
    $monday->setEndDateTime(new DateTime()); // sets day end time (you can also use Nette\Utils\DateTime)
    $monday->addDisabledPeriod(new \DatePeriod()); // you can disable period for lunch
    
    // for other days you can create its own objects or you can clone day object
    
    $tuesday = clone $monday;
    $tuesday->setDayOfWeek(Day::TUESDAY); // you must set corresponding day of week
    
    // create booking room
    
    $room = $this->booking->createRoom(string $roomName, string $name); // first parameter is your room name, second is component name
    $room->setDays([$monday, $tuesday, $wednesday, $thursday, $friday, $saturday, $sunday]); // sets days as array of objects
    $room->setCapacity(int $capacity); // sets capacity of each period
    $room->setInterval(new \DateInterval()); // sets booking interval
    $room->setDelay(int $hours); // set hours from now you can make booking
    $room->setCapacityExceededMessage(string $message); // sets booking form error message if capacity is exceeded
    $room->addDisabledPeriod(new \DatePeriod()); // disable year period
    $room->setupBookingFormStreetInput(bool $visible, bool $required); // configure form street input
    $room->setupBookingFormZipInput(bool $visible, bool $required); // configure form ZIP input
    $room->setupBookingFormConditionsInput(bool $visibility, bool $required, Nette\Utils\Html $html); // configure form conditions input
    $room->setWeeksOptions(int $count, int $history); // sets week selection options
    $room->setTemplate($file); // sets template for override some booking room blocks (example below)
    
    // setup confirmation emails for customer
    
    $customerMessageTemplate = $this->templateFactory->createTemplate();
    $customerMessageTemplate->setFile(string $file);
    
    $customerMessage = new Message(); // create message using Nette\Mail\Message
    $customerMessage->setFrom(string $email);
    $customerMessage->setSubject(string $subject);
    
    $customerMail = $room->setupCustomerMail($customerMessage);
    $customerMail->setTemplate($customerMessageTemplate);
    
    // setup confirmation emails for office
        
    $officeMessageTemplate = $this->templateFactory->createTemplate();
    $officeMessageTemplate->setFile(string $file);
    
    $officeMessage = new Message(); // create message using Nette\Mail\Message
    $officeMessage->addTo(string $email);
    $officeMessage->setSubject(string $subject);
    
    $officeMail = $room->setupCustomerMail($officeMessage);
    $officeMail->setTemplate($officeMessageTemplate);
    
    // setup cancel booking email
    
    $bookingCancelMessageTemplate = $this->templateFactory->createTemplate();
    $bookingCancelMessageTemplate->setFile(string $file);

    $bookingCancelMessage = new Message();
    $bookingCancelMessage->addTo(string $email);
    $bookingCancelMessage->setSubject(string $subject);
    
    $bookingCancelMail = $room->setupBookingCancelMail($bookingCancelMessage);
    $bookingCancelMail->setTemplate($bookingCancelMessageTemplate);
    
    // end finally return whole component
    
    return $room;
}

Variables

In customer, office or booking cancel mail latte templates you can use those variables.

{$id} {*booking ID*}
{$amount} {*booked capacity*}
{$name}
{$surname}
{$street}
{$street_no}
{$city}
{$zip}
{$mail}
{$phone}
{$text}
{$date} {*you can format it using {$date->format()} or {$date|date:""}*}
{$cancelLink} {*booking cancel link*}

Booking room template

You can override some booking room blocks

{extends $defaultTemplate} {*first of all you have to extend default template*}

{define date}
    {$dateTime->format("j. n. Y")} {*formats header date*}
{/define}

{define time}
    {$dateTime->format("H:i")} {*formats header time*}
{/define}

{define period}
    {$bookingsCount}/{$capacity} {*formats capacity of individual period blocks*}
{/define}

{define formText} {*define booking form text*}
    <p>
        Some text...
    </p>
{/define}