lzaplata/booking

Nette 简单预订组件

安装: 54

依赖: 0

建议者: 0

安全性: 0

星标: 1

关注者: 2

分支: 0

开放问题: 0

语言:JavaScript

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

This package is auto-updated.

Last update: 2024-09-20 22:07:17 UTC


README

这是一个简单的 Nette 框架预订组件。

安装

安装库的最简单方法是使用 Composer。

$ composer require lzaplata/booking: dev-master

或者编辑项目中的 composer.json 文件

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

您需要在 config.neon 文件中将库注册为扩展

extensions:
        booking: LZaplata\Booking\DI\BookingExtension

自动装配库到 presenter 以及模板工厂

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

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

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

用法

将预订房间作为组件创建。

/**
* @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;
}

变量

在客户、办公室或预订取消的 latte 模板邮件中,您可以使用这些变量。

{$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*}

预订房间模板

您可以覆盖一些预订房间块

{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}