markocupic/resource-booking-bundle

适用于学校或其他机构的资源预订插件。预订预定义时间段的资源。此扩展是Contao CMS的插件。


README

Logo

resource-booking-bundle

使用此Contao模块可以管理简单的在线资源。本模块是为学校开发的,需要房间预订系统。当然,该插件也可以与其他资源一起使用。

从3.x版本开始,可以设置资源可以预订的物品数量。这样可以允许多人预订资源,直到预订完毕。一个典型的用例是可以预订的设备/计算机。

向后兼容性

!注意:从2.x版本更新到3.x版本时,模板发生了重大更改。其中包括将模板拆分以更好地提高可读性。之前自定义的模板需要重新编写。

查看

preview animated

下载为mp4

带有周视图的预订表

preview frontend

预订窗口

preview frontend

配置

使用Contao Manager安装后,必须执行以下操作:

  • 至少创建一个预订时间窗口类型。
  • 然后创建预订时间窗口,格式为H:i(例如08:00至08:45)。
  • 创建资源类型。
  • 在每个资源类型中至少创建一个资源(例如房间)。
  • 至少创建一个成员(前端用户)。(预订模块仅在登录用户中显示。)

App Konfiguration anpassen

该扩展程序附带标准配置。可以创建更多配置集。有关详细信息,请参阅下文

该工具依赖于vue.jsFontawesomeBootstrap。所需的库/框架将自动安装并在模板中嵌入。

注意:安装时,除了上述扩展外,还会安装codefog/contao-haste

通知

通过Contao Notification Center进行预订/取消预订的通知是付费的附加功能。请联系扩展程序的作者联系

扩展模板以包含额外的成员数据

如果要在预订概览中显示额外的成员数据,则需要调整两个设置。

首先,必须在模块设置中选择要显示的额外字段。

Alt text

其次,必须调整模板。使用{{ booking.bookedByCompany }}可以显示公司名称,或使用{{ booking.bookedByCity }}显示居住地。注意!这里不是Contao插入标记,而是“vue.js Mustache Syntax”书写方式。在花括号前后必须有空格。

Alt text

事件

《rbb.event.pre_booking》事件在数据库插入前立即触发。通过一个事件订阅者类,可以修改数据库条目,例如。

《rbb.event.post_booking》事件在预订请求后触发。通过监听该事件的订阅者类,可以在预订后立即执行操作。例如,可以发送通知或在数据库中添加更多条目。

《rbb.event.pre_canceling》事件在取消预订前触发。

《rbb.event.post_canceling》事件在取消预订后触发。

事件订阅者

通过事件订阅者,可以在应用程序的多个位置进行扩展。为此,需要创建一个订阅者类并将其注册。

# Registrierung anhand des rbb.event.post_booking Events in listener.yml
services:
  App\EventSubscriber\PostBookingEventSubscriber:
    tags:
    - { name: kernel.event_subscriber }

还需要创建一个相应的事件订阅者类(以《rbb.event.post_booking》为例)

<?php

declare(strict_types=1);

namespace App\EventSubscriber;

use Contao\Date;
use Markocupic\ResourceBookingBundle\Event\PostBookingEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

final class PostBookingEventSubscriber implements EventSubscriberInterface
{
   const priority = 10000;

   public static function getSubscribedEvents(): array
    {
        return [
            PostBookingEvent::NAME => ['onPostBooking', self::PRIORITY],
        ];
    }

    public function onPostBooking(PostBookingEvent $objPostBookingEvent): void
    {
        // For demo usage only
        $objBookingCollection = $objPostBookingEvent->getBookingCollection();
        $objUser = $objPostBookingEvent->getUser();

        while ($objBookingCollection->next()) {
            if (null !== $objUser) {
                // Send notifications, manipulate database
                // or do some other insane stuff
                $strMessage = sprintf(
                    'Dear %s %s'."\n".'You have successfully booked %s on %s from %s to %s.',
                    $objUser->firstname,
                    $objUser->lastname,
                    $objBookingCollection->getRelated('pid')->title,
                    Date::parse('d.m.Y', $objBookingCollection->startTime),
                    Date::parse('H:i', $objBookingCollection->startTime),
                    Date::parse('H:i', $objBookingCollection->endTime)
                );
                mail(
                    $objUser->email,
                    utf8_decode((string) $objBookingCollection->title),
                    utf8_decode((string) $strMessage)
                );
            }
        }
    }
}

XmlHttp事件订阅者

预订工具几乎完全基于Ajax请求。通过一个自己的事件订阅者类,可以调整这些Ajax请求的响应,或者也可以实现自定义请求。《rbb.event.xml_http_request》事件在发送响应前触发。

为此,需要在listener.yml中注册监听《rbb.event.xml_http_request》事件的订阅者类。

services:
  App\EventSubscriber\AjaxRequestEventSubscriber:
    arguments:
    '@request_stack'
    tags:
    - { name: kernel.event_subscriber }

还需要创建一个相应的事件订阅者类。使用“priority”常数可以设置顺序。数值越大,订阅者被调用的越早。原始订阅者的优先级被设置为1000。

<?php

declare(strict_types=1);

namespace App\EventSubscriber;

use Markocupic\ResourceBookingBundle\Event\AjaxRequestEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RequestStack;

final class AjaxRequestEventSubscriber implements EventSubscriberInterface
{
    const priority = 1010;

    public function __construct(private readonly RequestStack $requestStack)
    {
    }

    public static function getSubscribedEvents(): array
    {
        return [
            AjaxRequestEvent::NAME => ['onXmlHttpRequest', self::PRIORITY],
        ];
    }

    public function onXmlHttpRequest(AjaxRequestEvent $ajaxRequestEvent): void
    {
        $request = $this->requestStack->getCurrentRequest();

        if ($request->isXmlHttpRequest()) {
            $action = $request->request->get('action', null);

            if (null !== $action) {
                if (\is_callable([self::class, 'on'.ucfirst($action)])) {
                    $this->{'on'.ucfirst($action)}($ajaxRequestEvent);
                }
            }
        }
    }

    /**
     * @throws \Exception
     */
    protected function onFetchDataRequest(AjaxRequestEvent $ajaxRequestEvent): void
    {
        // Stop propagation and do not run original event handler
        // Works only if the priority is > 10
        $ajaxRequestEvent->stopPropagation();

        // Get response object
        $ajaxResponse = $ajaxRequestEvent->getAjaxResponse();

        // Add some custom data to the response object
        $ajaxResponse->setData('foo', 'bar');
        $ajaxResponse->setStatus(AjaxResponse::STATUS_SUCCESS);
    }

    protected function onMyCustomRequest(AjaxRequestEvent $ajaxRequestEvent): void
    {
        // Respond to custom ajax requests
    }

    protected function onApplyFilterRequest(AjaxRequestEvent $ajaxRequestEvent): void
    {
        // Do some stuff here
    }

    protected function onJumpWeekRequest(AjaxRequestEvent $ajaxRequestEvent): void
    {
        // Do some stuff here
    }

    protected function onBookingRequest(AjaxRequestEvent $ajaxRequestEvent): void
    {
        // Do some stuff here
    }

    protected function onBookingFormValidationRequest(AjaxRequestEvent $ajaxRequestEvent): void
    {
        // Do some stuff here
    }

    protected function onCancelBookingRequest(AjaxRequestEvent $ajaxRequestEvent): void
    {
        // Do some stuff here
    }
}

调整应用程序配置

扩展程序使用默认配置安装。在config/config.yml中可以创建更多的配置集,然后在前端模块设置中选择这些配置集。

为此,需要在config/config.yml中创建一个条目。

# config/config.yml

markocupic_resource_booking:
    apps:
        my_rbb_custom:
            beginnWeek: 'monday'
            intBackWeeks: -10
            intAheadWeeks: 60