这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Pages/Admin/ManageConfigurationPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public function SetPostReservationPluginValues($values);
*/
public function SetStylingPluginValues($values);

/**
* @param string[] $values
*/
public function SetExportPluginValues($values);

/**
* @return int
*/
Expand Down Expand Up @@ -262,6 +267,10 @@ public function SetStylingPluginValues($values)
{
$this->Set('StylingPluginValues', $values);
}
public function SetExportPluginValues($values)
{
$this->Set('ExportPluginValues', $values);
}

public function GetHomePageId()
{
Expand Down
1 change: 1 addition & 0 deletions Presenters/Admin/ManageConfigurationPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ private function PopulatePlugins()
$this->page->SetPreReservationPluginValues($plugins['PreReservation']);
$this->page->SetPostReservationPluginValues($plugins['PostReservation']);
$this->page->SetStylingPluginValues($plugins['Styling']);
$this->page->SetExportPluginValues($plugins['Export']);
}

public function Update()
Expand Down
1 change: 1 addition & 0 deletions config/config.devel.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
*/
$conf['settings']['plugins']['Authentication'] = '';
$conf['settings']['plugins']['Authorization'] = '';
$conf['settings']['plugins']['Export'] = '';
$conf['settings']['plugins']['Permission'] = '';
$conf['settings']['plugins']['PostRegistration'] = '';
$conf['settings']['plugins']['PreReservation'] = '';
Expand Down
1 change: 1 addition & 0 deletions config/config.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
*/
$conf['settings']['plugins']['Authentication'] = '';
$conf['settings']['plugins']['Authorization'] = '';
$conf['settings']['plugins']['Export'] = '';
$conf['settings']['plugins']['Permission'] = '';
$conf['settings']['plugins']['PostRegistration'] = '';
$conf['settings']['plugins']['PreReservation'] = '';
Expand Down
41 changes: 41 additions & 0 deletions lib/Application/Export/ExportFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

interface IExportFactory
{
/**
* Returns the ICal Classification for an item (https://icalendar.org/iCalendar-RFC-5545/3-8-1-3-classification.html)
* @param IReservedItemView $item
* @return string
*/
public function GetIcalendarClassification(IReservedItemView $item);

/**
* Optionally returns some lines to add to the iCalendar event.
* @param IReservedItemView $item
* @return null|string
*/
public function GetIcalendarExtraLines(IReservedItemView $item);
}

class ExportFactory implements IExportFactory
{
public function __construct() {}

/**
* Returns the ICal Classification for an item (https://icalendar.org/iCalendar-RFC-5545/3-8-1-3-classification.html)
* @param IReservedItemView $item
* @return string
*/
public function GetIcalendarClassification(IReservedItemView $item) {
return 'PUBLIC';
}

/**
* Optionally returns some lines to add to the iCalendar event.
* @param IReservedItemView $item
* @return null|string
*/
public function GetIcalendarExtraLines(IReservedItemView $item) {
return null;
}
}
3 changes: 3 additions & 0 deletions lib/Application/Export/namespace.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

require_once(ROOT_DIR . 'lib/Application/Export/ExportFactory.php');
14 changes: 14 additions & 0 deletions lib/Application/Schedule/iCalendarReservationView.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class iCalendarReservationView
{
public $Classification;
public $DateCreated;
public $DateEnd;
public $DateStart;
Expand All @@ -17,6 +18,12 @@ class iCalendarReservationView
public $EndReminder;
public $LastModified;
public $IsPending;
public $ExtraIcalLines;

/**
* @var ExportFactory
*/
private $ExportFactory;

/**
* @var ReservationItemView
Expand All @@ -39,11 +46,16 @@ public function __construct($res, UserSession $currentUser, IPrivacyFilter $priv
$canViewUser = $privacyFilter->CanViewUser($currentUser, $res, $res->OwnerId);
$canViewDetails = $privacyFilter->CanViewDetails($currentUser, $res, $res->OwnerId);

$this->ExportFactory = PluginManager::Instance()->LoadExport();

$privateNotice = 'Private';

$this->Classification = method_exists($this->ExportFactory, 'GetIcalendarClassification') ? $this->ExportFactory->GetIcalendarClassification($res) : 'PUBLIC';
if ($res->DateCreated){
$this->DateCreated = $res->DateCreated;
}
else $this->DateCreated = Date::Now();

$this->DateEnd = $res->EndDate;
$this->DateStart = $res->StartDate;
$this->Description = $canViewDetails ? $factory->Format($res, $summaryFormat) : $privateNotice;
Expand All @@ -70,6 +82,8 @@ public function __construct($res, UserSession $currentUser, IPrivacyFilter $priv
if ($res->OwnerId == $currentUser->UserId) {
$this->OrganizerEmail = str_replace('@', '-noreply@', $res->OwnerEmailAddress);
}

$this->ExtraIcalLines = method_exists($this->ExportFactory, 'GetIcalendarExtraLines') ? $this->ExportFactory->GetIcalendarExtraLines($res) : null;
}

/**
Expand Down
25 changes: 23 additions & 2 deletions lib/Common/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ public function LoadPostRegistration()

/**
* Loads the configured Styling plugin, if one exists
* If no plugin exists, the default PreReservationFactory class is returned
* If no plugin exists, the default StylingFactory class is returned
*
* @return IPreReservationFactory
* @return IStylingFactory
*/
public function LoadStyling()
{
Expand All @@ -188,6 +188,27 @@ public function LoadStyling()
return $factory;
}

/**
* Loads the configured Export plugin, if one exists
* If no plugin exists, the default ExportFactory class is returned
*
* @return IExportFactory
*/
public function LoadExport()
{
require_once(ROOT_DIR . 'lib/Application/Export/namespace.php');

$factory = new ExportFactory();

$plugin = $this->LoadPlugin(ConfigKeys::PLUGIN_EXPORT, 'Export', $factory);

if (!is_null($plugin)) {
return $plugin;
}

return $factory;
}

/**
* @param string $configKey key to use
* @param string $pluginSubDirectory subdirectory name under 'plugins'
Expand Down
1 change: 1 addition & 0 deletions lib/Config/ConfigKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class ConfigKeys

public const PLUGIN_AUTHENTICATION = 'Authentication';
public const PLUGIN_AUTHORIZATION = 'Authorization';
public const PLUGIN_EXPORT = 'Export';
public const PLUGIN_PERMISSION = 'Permission';
public const PLUGIN_POSTREGISTRATION = 'PostRegistration';
public const PLUGIN_PRERESERVATION = 'PreReservation';
Expand Down
22 changes: 22 additions & 0 deletions plugins/Export/ExportExample/ExportExample.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

class ExportExample implements IExportFactory
{
/**
* @var ExportFactory
*/
private $factoryToDecorate;

public function __construct(ExportFactory $factoryToDecorate)
{
$this->factoryToDecorate = $factoryToDecorate;
}

public function GetIcalendarClassification(IReservedItemView $item) {
return 'PRIVATE';
}

public function GetIcalendarExtraLines(IReservedItemView $item) {
return "TRANSP:TRANSPARENT\n";
}
}
8 changes: 8 additions & 0 deletions tests/Presenters/Admin/ManageConfigurationPresenterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,14 @@ public function SetStylingPluginValues($values)
// TODO: Implement SetStylingPluginValues() method.
}

/**
* @param string[] $values
*/
public function SetExportPluginValues($values)
{
// TODO: Implement SetExportPluginValues() method.
}

/**
* @return int
*/
Expand Down
4 changes: 3 additions & 1 deletion tpl/Export/ical.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ METHOD:REQUEST
PRODID:-//LibreBooking//NONSGML {$bookedVersion}//EN
{foreach from=$Reservations item=reservation}
BEGIN:VEVENT
CLASS:PUBLIC
CLASS:{$reservation->Classification}
CREATED:{formatdate date=$reservation->DateCreated key=ical}
DESCRIPTION:{$reservation->Description|regex_replace:"/\r\n|\n|\r/m":"\n "}
DTSTAMP:{formatdate date=$reservation->DateCreated key=ical}
Expand All @@ -23,6 +23,8 @@ UID:{$reservation->ReferenceNumber}&{$UID}
SEQUENCE:0
URL:{$reservation->ReservationUrl}
X-MICROSOFT-CDO-BUSYSTATUS:BUSY
{if $reservation->ExtraIcalLines != null}
{$reservation->ExtraIcalLines}{/if}
{if $reservation->StartReminder != null}
BEGIN:VALARM
TRIGGER;RELATED=START:-PT{$reservation->StartReminder->MinutesPrior()}M
Expand Down