Menu

#8963 DPCalendar joomla events

Parent Category:
DPCalendar
Category:
Developer corner
Last Updated:
Allon Moritz, Wednesday, 24 January 2024 12:04
Created:
Thursday, 20 January 2022 09:45
Hits:
1365

Introduction

DPCalendar lets 3rd party Joomla extensions interact with DPCalendar easily through plugin events. How a Joomla plugin can be developed is described in this article.

Want to integrate your own DPCalendar calendar plugin with data from an external system? Please have a look at the Create a DPCalendar plugin article.

Content events

DPCalendar fires the Joomla content events when an event, location, booking or ticket is saved or displayed. This allows other plugins to interfere into the processes. The Joomla custom fields are integrated like that into the forms and when displaying these items.

DPCalendarPlugin specific events

Beside the default Joomla events, DPCalendar fires some specific events where plugins can hook in.

onDPCalendarBeforeExecute

Description
Before DPCalendar is executed in the back end. This allows plugins to perform certain tasks or redirect to different pages.

Parameters

  1. input (required)
    The input of the actual request.

Return value
Nothing.

onDPCalendarBeforeSendMail

Description
Is triggered before a mail is sent in DPCalendar. This event allows to to customize the sent out mail, with attachments a new subject, body or addresses.

Actually the following contexts are supported:

  • com_dpcalendar.booking.new: When a new booking is created
  • com_dpcalendar.event.save.notify.tickets: When a ticket holder is notified

Parameters

  1. context The context where the mail is sent.
  2. mailer
    The mailer instance to send out the mail.
  3. item
    The item for which the mail is sent out.

Return value
Nothing.

onDPCalendarAfterSendMail

Description
Is triggered after a mail is sent in DPCalendar. This event allows to to cleanup some stuff.

Parameters

  1. context The context where the mail is sent.
  2. mailer
    The mailer instance to send out the mail.
  3. item
    The item for which the mail is sent out.

Return value
Nothing.

onDPCalendarAfterToolbar

Description
Is triggered when the toolbar is filled with actions. Does allow the plugin to add custom actions.

Parameters

  1. name The name of the view.
  2. toolbar
    The toolbar to work on.

Return value
Nothing.

onDPCalendarAfterBookingFinished

Description
Is triggered when the whole booking is saved and mails were sent out.

Parameters

  1. booking The booking instance.
  2. tickets
    The array of tickets which are created or updated during the booking save process.

Return value
Nothing.

plg_dpcalendar_helloworld
--- helloworld.xml
--- helloworld.php
--- index.html
--- language
--- ---- en-GB
--- ---- ---- en-GB.plg_dpcalendar_helloworld.ini
--- ---- ---- en-GB.plg_dpcalendar_helloworld.sys.ini

Manifest (dpcalendar_helloworld.xml) The manifest file describes the plugin and delivers Joomla the necessary information during installation. An example is shown below.

<?xml version="1.0" encoding="utf-8"?>
<extension version="3.9" type="plugin" group="dpcalendar" method="upgrade">
    <name>plg_dpcalendar_helloworld</name>
    <author>Digital Peak</author>
    <creationDate>Aug 2018</creationDate>
    <copyright>(C) 2018 Digital Peak GmbH. <https://www.digital-peak.com>
    </copyright>
    <license>https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL</license>
    <authorEmail>info@digital-peak.com</authorEmail>
    <authorUrl>joomla.digital-peak.com</authorUrl>
    <version>7.0.0</version>
    <description>PLG_DPCALENDAR_HELLOWORLD_XML_DESCRIPTION</description>
    <files>
        <filename plugin="helloworld">helloworld.php</filename>
        <folder>language</folder>
    </files>
    <config>
        <fields name="params"
                addfieldpath="/administrator/components/com_dpcalendar/models/fields">
            <fieldset name="basic">
                <field name="ext" type="extcalendar" plugin="helloworld" label="" description=""/>
            </fieldset>
            <fieldset name="advanced">
                <fieldset name="advanced">
                    <field name="cache" type="list" default="1"
                           label="PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_LABEL" description="PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_DESC">
                        <option value="1">PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_JOOMLA</option>
                        <option value="2">PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_DB</option>
                        <option value="0">PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_NEVER</option>
                    </field>
                    <field name="cache_time" type="text" default="900" showon="cache:1"
                           label="PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_TIME_LABEL"
                           description="PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_TIME_DESC"/>
                    <field name="sync_start" type="text" default="-3 year" showon="cache:2"
                           label="PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_SYNC_START_LABEL"
                           description="PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_SYNC_START_DESC"/>
                    <field name="sync_end" type="text" default="+3 year" showon="cache:2"
                           label="PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_SYNC_END_LABEL"
                           description="PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_SYNC_END_DESC"/>
                    <field name="sync_steps" type="text" default="1 year" showon="cache:2"
                           label="PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_SYNC_STEPS_LABEL"
                           description="PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_SYNC_STEPS_DESC"/>
                </fieldset>
            </fieldset>
        </fields>
    </config>
</extension>

The file /administrator/components/com_dpcalendar/libraries/dpcalendar/DPCalendar/Plugin/DPCalendarPlugin.php can be used as base class to create the PHP file. Here is an example how it is recommended to implement a DPCalendar plugin.

<?php
/**
 * @package    DPCalendar
 * @copyright  Copyright (C) 2018 Digital Peak GmbH. <https://www.digital-peak.com>
 * @license    https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
 */defined('_JEXEC') or die();use Joomla\CMS\Date\Date;
use Joomla\Registry\Registry;class PlgDPCalendarHelloworld extends \DPCalendar\Plugin\DPCalendarPlugin
{    protected $identifier = 'hw';    protected function getContent ($calendarId, Date $startDate = null, Date $endDate = null, Registry $options = null)
    {
        $start = DPCalendarHelper::getDate();
        $start->modify('+1 day');        $end = clone $start;
        $end->modify('+2 hour');        $buffer = "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//DPCalendar
BEGIN:VEVENT
UID:sdfsf8erhklf89zrjklh890hoih89
DTSTAMP:20140714T170000Z
ORGANIZER;CN=John Doe:MAILTO:john.doe@example.com
DTSTART:" . $start->format('Ymd\THis\Z') . "
DTEND:" . $end->format('Ymd\THis\Z') . "
SUMMARY:Demo Hello world event
DESCRIPTION:This is a demo event in the hello world DPCalendar plugin.
LOCATION:New York
END:VEVENT
END:VCALENDAR";
        return $buffer;
    }
}

Comments (0)

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.