smaller syntax changes to CalDAV reminder classes

Signed-off-by: Georg Ehrke <developer@georgehrke.com>
This commit is contained in:
Georg Ehrke 2019-08-02 16:34:39 +02:00 committed by Roeland Jago Douma
parent 36b9b51297
commit 11fa45196e
No known key found for this signature in database
GPG Key ID: F941078878347C0C
7 changed files with 38 additions and 56 deletions

View File

@ -37,9 +37,9 @@ use Sabre\VObject\DateTimeParser;
use Sabre\VObject\Parameter;
use Sabre\VObject\Property;
abstract class AbstractNotificationProvider
{
abstract class AbstractNotificationProvider {
/** @var string */
public const NOTIFICATION_TYPE = '';
/** @var ILogger */
@ -78,7 +78,7 @@ abstract class AbstractNotificationProvider
* @param IUser $user
* @return void
*/
public function send(VCalendar $vcalendar, string $calendarDisplayName, IUser $user): void {}
abstract function send(VCalendar $vcalendar, string $calendarDisplayName, IUser $user): void;
/**
* @var VCalendar $vcalendar
@ -86,8 +86,7 @@ abstract class AbstractNotificationProvider
* @return array
* @throws \Exception
*/
protected function extractEventDetails(VCalendar $vcalendar, $defaultValue = ''): array
{
protected function extractEventDetails(VCalendar $vcalendar, $defaultValue = ''):array {
/** @var VEvent $vevent */
$vevent = $vcalendar->VEVENT;
@ -129,8 +128,7 @@ abstract class AbstractNotificationProvider
* @return string
* @throws \Exception
*/
private function generateWhenString(Property $dtstart, Property $dtend): string
{
private function generateWhenString(Property $dtstart, Property $dtend):string {
$isAllDay = $dtstart instanceof Property\ICalendar\Date;
/** @var Property\ICalendar\Date | Property\ICalendar\DateTime $dtstart */
@ -201,8 +199,7 @@ abstract class AbstractNotificationProvider
* @param DateTime $dtEnd
* @return bool
*/
private function isDayEqual(DateTime $dtStart, DateTime $dtEnd): bool
{
private function isDayEqual(DateTime $dtStart, DateTime $dtEnd):bool {
return $dtStart->format('Y-m-d') === $dtEnd->format('Y-m-d');
}
}

View File

@ -56,8 +56,7 @@ class Backend {
* @param int $notificationDate
* @param int $eventStartDate
*/
public function insertReminder(string $uid, string $calendarId, string $uri, string $type, int $notificationDate, int $eventStartDate): void
{
public function insertReminder(string $uid, string $calendarId, string $uri, string $type, int $notificationDate, int $eventStartDate):void {
$query = $this->db->getQueryBuilder();
$query->insert('calendar_reminders')
->values([
@ -76,8 +75,7 @@ class Backend {
* @param int $calendarId
* @param string $objectUri
*/
public function cleanRemindersForEvent(int $calendarId, string $objectUri): void
{
public function cleanRemindersForEvent(int $calendarId, string $objectUri):void {
$query = $this->db->getQueryBuilder();
$query->delete('calendar_reminders')
@ -92,8 +90,7 @@ class Backend {
* @param integer $calendarId
* @return void
*/
public function cleanRemindersForCalendar(int $calendarId): void
{
public function cleanRemindersForCalendar(int $calendarId):void {
$query = $this->db->getQueryBuilder();
$query->delete('calendar_reminders')
@ -107,8 +104,7 @@ class Backend {
* @param integer $reminderId
* @return void
*/
public function removeReminder(int $reminderId): void
{
public function removeReminder(int $reminderId):void {
$query = $this->db->getQueryBuilder();
$query->delete('calendar_reminders')
@ -122,8 +118,7 @@ class Backend {
* @return array
* @throws \Exception
*/
public function getRemindersToProcess(): array
{
public function getRemindersToProcess():array {
$query = $this->db->getQueryBuilder();
$fields = ['cr.id', 'cr.calendarid', 'cr.objecturi', 'cr.type', 'cr.notificationdate', 'cr.uid', 'co.calendardata', 'c.displayname'];
$stmt = $query->select($fields)

View File

@ -33,11 +33,12 @@ use OCP\Mail\IMailer;
use OCP\IUser;
use Sabre\VObject\Component\VCalendar;
class EmailProvider extends AbstractNotificationProvider
{
class EmailProvider extends AbstractNotificationProvider {
/** @var IMailer */
private $mailer;
/** @var string */
public const NOTIFICATION_TYPE = 'EMAIL';
/**
@ -63,8 +64,7 @@ class EmailProvider extends AbstractNotificationProvider
* @return void
* @throws \Exception
*/
public function send(VCalendar $vcalendar, string $calendarDisplayName, IUser $user): void
{
public function send(VCalendar $vcalendar, string $calendarDisplayName, IUser $user):void {
if ($user->getEMailAddress() === null) {
return;
}
@ -111,8 +111,7 @@ class EmailProvider extends AbstractNotificationProvider
* @param IEMailTemplate $template
* @param string $summary
*/
private function addSubjectAndHeading(IEMailTemplate $template, string $summary): void
{
private function addSubjectAndHeading(IEMailTemplate $template, string $summary):void {
$template->setSubject('Notification: ' . $summary);
$template->addHeading($summary);
}
@ -122,8 +121,7 @@ class EmailProvider extends AbstractNotificationProvider
* @param array $eventData
* @param string $calendarDisplayName
*/
private function addBulletList(IEMailTemplate $template, array $eventData, string $calendarDisplayName): void
{
private function addBulletList(IEMailTemplate $template, array $eventData, string $calendarDisplayName):void {
$template->addBodyListItem($calendarDisplayName, $this->l10n->t('Calendar:'),
$this->getAbsoluteImagePath('actions/info.svg'));
@ -148,8 +146,7 @@ class EmailProvider extends AbstractNotificationProvider
* @param string $path
* @return string
*/
private function getAbsoluteImagePath($path): string
{
private function getAbsoluteImagePath(string $path):string {
return $this->urlGenerator->getAbsoluteURL(
$this->urlGenerator->imagePath('core', $path)
);

View File

@ -35,9 +35,9 @@ use OCP\Notification\INotification;
use Sabre\VObject\Component\VCalendar;
use OCP\AppFramework\Utility\ITimeFactory;
class PushProvider extends AbstractNotificationProvider
{
class PushProvider extends AbstractNotificationProvider {
/** @var string */
public const NOTIFICATION_TYPE = 'DISPLAY';
/**
@ -75,9 +75,7 @@ class PushProvider extends AbstractNotificationProvider
* @return void
* @throws \Exception
*/
public function send(VCalendar $vcalendar, string $calendarDisplayName, IUser $user): void
{
public function send(VCalendar $vcalendar, string $calendarDisplayName, IUser $user):void {
$lang = $this->config->getUserValue($user->getUID(), 'core', 'lang', $this->l10nFactory->findLanguage());
$this->l10n = $this->l10nFactory->get('dav', $lang);

View File

@ -31,8 +31,7 @@ class NotificationProviderManager {
* @throws ProviderNotAvailableException
* @throws NotificationTypeDoesNotExistException
*/
public function getProvider(string $type): AbstractNotificationProvider
{
public function getProvider(string $type):AbstractNotificationProvider {
if (in_array($type, ReminderService::REMINDER_TYPES, true)) {
if (isset($this->providers[$type])) {
return $this->providers[$type];
@ -46,8 +45,7 @@ class NotificationProviderManager {
* @param string $providerClassName
* @throws \OCP\AppFramework\QueryException
*/
public function registerProvider(string $providerClassName): void
{
public function registerProvider(string $providerClassName):void {
$provider = \OC::$server->query($providerClassName);
if (!$provider instanceof AbstractNotificationProvider) {

View File

@ -31,14 +31,15 @@ use OCP\IURLGenerator;
class Notifier implements INotifier {
public static $units = array(
/** @var array */
public static $units = [
'y' => 'year',
'm' => 'month',
'd' => 'day',
'h' => 'hour',
'i' => 'minute',
's' => 'second',
);
];
/** @var IFactory */
protected $factory;
@ -60,8 +61,7 @@ class Notifier implements INotifier {
* @return INotification
* @throws \Exception
*/
public function prepare(INotification $notification, $languageCode): INotification
{
public function prepare(INotification $notification, string $languageCode):INotification {
if ($notification->getApp() !== Application::APP_ID) {
throw new \InvalidArgumentException('Notification not from this app');
}
@ -87,8 +87,7 @@ class Notifier implements INotifier {
* @return string
* @throws \Exception
*/
private function processEventTitle(array $event): string
{
private function processEventTitle(array $event):string {
$event_datetime = new \DateTime();
$event_datetime->setTimestamp($event['start']);
$now = new \DateTime();
@ -112,8 +111,7 @@ class Notifier implements INotifier {
* @param string $title
* @return string
*/
private function getPluralizedTitle(int $count, int $invert, string $unit, string $title): string
{
private function getPluralizedTitle(int $count, int $invert, string $unit, string $title):string {
if ($invert) {
return $this->l->n('%s (in one %s)', '%s (in %n %ss)', $count, [$title, $unit]);
}
@ -125,8 +123,7 @@ class Notifier implements INotifier {
* @param array $event
* @return string
*/
private function processEventDescription(array $event): string
{
private function processEventDescription(array $event):string {
$description = [
$this->l->t('Calendar: %s', $event['calendar']),
$this->l->t('Date: %s', $event['when']),

View File

@ -49,7 +49,11 @@ class ReminderService {
public const REMINDER_TYPE_DISPLAY = 'DISPLAY';
public const REMINDER_TYPE_AUDIO = 'AUDIO';
public const REMINDER_TYPES = [self::REMINDER_TYPE_EMAIL, self::REMINDER_TYPE_DISPLAY, self::REMINDER_TYPE_AUDIO];
public const REMINDER_TYPES = [
self::REMINDER_TYPE_EMAIL,
self::REMINDER_TYPE_DISPLAY,
self::REMINDER_TYPE_AUDIO
];
public function __construct(Backend $backend,
NotificationProviderManager $notificationProviderManager,
@ -70,9 +74,7 @@ class ReminderService {
* @throws NotificationProvider\ProviderNotAvailableException
* @throws NotificationTypeDoesNotExistException
*/
public function processReminders(): void
{
public function processReminders():void {
$reminders = $this->backend->getRemindersToProcess();
foreach ($reminders as $reminder) {
@ -101,8 +103,7 @@ class ReminderService {
* @throws VObject\InvalidDataException
* @throws NoUserException
*/
public function onTouchCalendarObject(string $action, array $calendarData, array $shares, array $objectData): void
{
public function onTouchCalendarObject(string $action, array $calendarData, array $shares, array $objectData):void {
if (!isset($calendarData['principaluri'])) {
return;
}
@ -157,8 +158,7 @@ class ReminderService {
* @param array $shares
* @return string[]
*/
private function getUsersForShares(array $shares): array
{
private function getUsersForShares(array $shares):array {
$users = $groups = [];
foreach ($shares as $share) {
$principal = explode('/', $share['{http://owncloud.org/ns}principal']);