2019-08-09 21:25:21 +03:00
|
|
|
<?php
|
2019-12-03 21:57:53 +03:00
|
|
|
|
2019-08-09 21:25:21 +03:00
|
|
|
declare(strict_types=1);
|
2019-12-03 21:57:53 +03:00
|
|
|
|
2019-08-09 21:25:21 +03:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2019, Thomas Citharel
|
|
|
|
* @copyright Copyright (c) 2019, Georg Ehrke
|
|
|
|
*
|
2020-04-29 12:57:22 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2019-08-09 21:25:21 +03:00
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2020-08-24 15:54:25 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2019-08-09 21:25:21 +03:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2019-08-09 21:25:21 +03:00
|
|
|
*
|
|
|
|
*/
|
2019-11-22 22:52:10 +03:00
|
|
|
|
2019-08-09 21:25:21 +03:00
|
|
|
namespace OCA\DAV\CalDAV\Reminder\NotificationProvider;
|
|
|
|
|
|
|
|
use OCA\DAV\CalDAV\Reminder\INotificationProvider;
|
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IL10N;
|
|
|
|
use OCP\ILogger;
|
|
|
|
use OCP\IURLGenerator;
|
|
|
|
use OCP\IUser;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\L10N\IFactory as L10NFactory;
|
2019-08-09 21:25:21 +03:00
|
|
|
use Sabre\VObject\Component\VEvent;
|
|
|
|
use Sabre\VObject\DateTimeParser;
|
|
|
|
use Sabre\VObject\Property;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class AbstractProvider
|
|
|
|
*
|
|
|
|
* @package OCA\DAV\CalDAV\Reminder\NotificationProvider
|
|
|
|
*/
|
2020-04-10 15:19:56 +03:00
|
|
|
abstract class AbstractProvider implements INotificationProvider {
|
2019-08-09 21:25:21 +03:00
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
public const NOTIFICATION_TYPE = '';
|
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
/** @var ILogger */
|
|
|
|
protected $logger;
|
2019-08-09 21:25:21 +03:00
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
/** @var L10NFactory */
|
2020-06-23 09:45:01 +03:00
|
|
|
protected $l10nFactory;
|
2019-08-09 21:25:21 +03:00
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
/** @var IL10N[] */
|
2019-08-09 21:25:21 +03:00
|
|
|
private $l10ns;
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $fallbackLanguage;
|
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
/** @var IURLGenerator */
|
|
|
|
protected $urlGenerator;
|
2019-08-09 21:25:21 +03:00
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
/** @var IConfig */
|
2019-08-09 21:25:21 +03:00
|
|
|
protected $config;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param ILogger $logger
|
|
|
|
* @param L10NFactory $l10nFactory
|
|
|
|
* @param IConfig $config
|
|
|
|
* @param IUrlGenerator $urlGenerator
|
|
|
|
*/
|
|
|
|
public function __construct(ILogger $logger,
|
|
|
|
L10NFactory $l10nFactory,
|
|
|
|
IURLGenerator $urlGenerator,
|
|
|
|
IConfig $config) {
|
|
|
|
$this->logger = $logger;
|
|
|
|
$this->l10nFactory = $l10nFactory;
|
2019-08-12 14:20:03 +03:00
|
|
|
$this->urlGenerator = $urlGenerator;
|
2019-08-09 21:25:21 +03:00
|
|
|
$this->config = $config;
|
2019-08-12 14:20:03 +03:00
|
|
|
}
|
2019-08-09 21:25:21 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Send notification
|
|
|
|
*
|
|
|
|
* @param VEvent $vevent
|
|
|
|
* @param string $calendarDisplayName
|
|
|
|
* @param IUser[] $users
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-08-12 14:20:03 +03:00
|
|
|
abstract public function send(VEvent $vevent,
|
2019-08-09 21:25:21 +03:00
|
|
|
string $calendarDisplayName,
|
2020-10-05 16:12:57 +03:00
|
|
|
array $users = []): void;
|
2019-08-09 21:25:21 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2019-08-12 14:20:03 +03:00
|
|
|
protected function getFallbackLanguage():string {
|
|
|
|
if ($this->fallbackLanguage) {
|
|
|
|
return $this->fallbackLanguage;
|
2019-08-09 21:25:21 +03:00
|
|
|
}
|
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
$fallbackLanguage = $this->l10nFactory->findLanguage();
|
|
|
|
$this->fallbackLanguage = $fallbackLanguage;
|
2019-08-09 21:25:21 +03:00
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
return $fallbackLanguage;
|
2019-08-09 21:25:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $lang
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
protected function hasL10NForLang(string $lang):bool {
|
2019-08-12 14:20:03 +03:00
|
|
|
return $this->l10nFactory->languageExists('dav', $lang);
|
2019-08-09 21:25:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $lang
|
|
|
|
* @return IL10N
|
|
|
|
*/
|
|
|
|
protected function getL10NForLang(string $lang):IL10N {
|
|
|
|
if (isset($this->l10ns[$lang])) {
|
|
|
|
return $this->l10ns[$lang];
|
|
|
|
}
|
|
|
|
|
|
|
|
$l10n = $this->l10nFactory->get('dav', $lang);
|
|
|
|
$this->l10ns[$lang] = $l10n;
|
|
|
|
|
|
|
|
return $l10n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param VEvent $vevent
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function getStatusOfEvent(VEvent $vevent):string {
|
|
|
|
if ($vevent->STATUS) {
|
|
|
|
return (string) $vevent->STATUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Doesn't say so in the standard,
|
|
|
|
// but we consider events without a status
|
|
|
|
// to be confirmed
|
|
|
|
return 'CONFIRMED';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param VEvent $vevent
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
protected function isEventTentative(VEvent $vevent):bool {
|
|
|
|
return $this->getStatusOfEvent($vevent) === 'TENTATIVE';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param VEvent $vevent
|
|
|
|
* @return Property\ICalendar\DateTime
|
|
|
|
*/
|
|
|
|
protected function getDTEndFromEvent(VEvent $vevent):Property\ICalendar\DateTime {
|
|
|
|
if (isset($vevent->DTEND)) {
|
|
|
|
return $vevent->DTEND;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($vevent->DURATION)) {
|
|
|
|
$isFloating = $vevent->DTSTART->isFloating();
|
|
|
|
/** @var Property\ICalendar\DateTime $end */
|
|
|
|
$end = clone $vevent->DTSTART;
|
|
|
|
$endDateTime = $end->getDateTime();
|
|
|
|
$endDateTime = $endDateTime->add(DateTimeParser::parse($vevent->DURATION->getValue()));
|
|
|
|
$end->setDateTime($endDateTime, $isFloating);
|
|
|
|
|
|
|
|
return $end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$vevent->DTSTART->hasTime()) {
|
|
|
|
$isFloating = $vevent->DTSTART->isFloating();
|
|
|
|
/** @var Property\ICalendar\DateTime $end */
|
|
|
|
$end = clone $vevent->DTSTART;
|
|
|
|
$endDateTime = $end->getDateTime();
|
|
|
|
$endDateTime = $endDateTime->modify('+1 day');
|
|
|
|
$end->setDateTime($endDateTime, $isFloating);
|
|
|
|
|
|
|
|
return $end;
|
|
|
|
}
|
|
|
|
|
|
|
|
return clone $vevent->DTSTART;
|
|
|
|
}
|
|
|
|
}
|