2016-10-13 12:04:22 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\DAV\CalDAV\Activity;
|
|
|
|
|
|
|
|
|
2016-11-29 18:21:36 +03:00
|
|
|
use OCA\DAV\CalDAV\Activity\Provider\Calendar;
|
|
|
|
use OCA\DAV\CalDAV\Activity\Provider\Event;
|
2016-10-13 12:04:22 +03:00
|
|
|
use OCP\Activity\IEvent;
|
|
|
|
use OCP\Activity\IManager as IActivityManager;
|
|
|
|
use OCP\IGroup;
|
|
|
|
use OCP\IGroupManager;
|
|
|
|
use OCP\IUser;
|
|
|
|
use OCP\IUserSession;
|
2016-10-13 13:16:43 +03:00
|
|
|
use Sabre\VObject\Reader;
|
2016-10-13 12:04:22 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Backend
|
|
|
|
*
|
|
|
|
* @package OCA\DAV\CalDAV\Activity
|
|
|
|
*/
|
|
|
|
class Backend {
|
|
|
|
|
|
|
|
/** @var IActivityManager */
|
|
|
|
protected $activityManager;
|
|
|
|
|
|
|
|
/** @var IGroupManager */
|
|
|
|
protected $groupManager;
|
|
|
|
|
|
|
|
/** @var IUserSession */
|
|
|
|
protected $userSession;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IActivityManager $activityManager
|
|
|
|
* @param IGroupManager $groupManager
|
|
|
|
* @param IUserSession $userSession
|
|
|
|
*/
|
2016-10-13 16:34:26 +03:00
|
|
|
public function __construct(IActivityManager $activityManager, IGroupManager $groupManager, IUserSession $userSession) {
|
2016-10-13 12:04:22 +03:00
|
|
|
$this->activityManager = $activityManager;
|
|
|
|
$this->groupManager = $groupManager;
|
|
|
|
$this->userSession = $userSession;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates activities when a calendar was creates
|
|
|
|
*
|
2016-10-13 16:34:26 +03:00
|
|
|
* @param array $calendarData
|
2016-10-13 12:04:22 +03:00
|
|
|
*/
|
2016-10-13 16:34:26 +03:00
|
|
|
public function onCalendarAdd(array $calendarData) {
|
2016-11-29 18:21:36 +03:00
|
|
|
$this->triggerCalendarActivity(Calendar::SUBJECT_ADD, $calendarData);
|
2016-10-13 12:04:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates activities when a calendar was updated
|
|
|
|
*
|
2016-10-13 16:34:26 +03:00
|
|
|
* @param array $calendarData
|
|
|
|
* @param array $shares
|
2016-10-13 12:04:22 +03:00
|
|
|
* @param array $properties
|
|
|
|
*/
|
2016-10-13 16:34:26 +03:00
|
|
|
public function onCalendarUpdate(array $calendarData, array $shares, array $properties) {
|
2016-11-29 18:21:36 +03:00
|
|
|
$this->triggerCalendarActivity(Calendar::SUBJECT_UPDATE, $calendarData, $shares, $properties);
|
2016-10-13 12:04:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates activities when a calendar was deleted
|
|
|
|
*
|
2016-10-13 16:34:26 +03:00
|
|
|
* @param array $calendarData
|
|
|
|
* @param array $shares
|
2016-10-13 12:04:22 +03:00
|
|
|
*/
|
2016-10-13 16:34:26 +03:00
|
|
|
public function onCalendarDelete(array $calendarData, array $shares) {
|
2016-11-29 18:21:36 +03:00
|
|
|
$this->triggerCalendarActivity(Calendar::SUBJECT_DELETE, $calendarData, $shares);
|
2016-10-13 12:04:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates activities for all related users when a calendar was touched
|
|
|
|
*
|
|
|
|
* @param string $action
|
2016-10-13 16:34:26 +03:00
|
|
|
* @param array $calendarData
|
|
|
|
* @param array $shares
|
2016-10-13 12:04:22 +03:00
|
|
|
* @param array $changedProperties
|
|
|
|
*/
|
2016-10-13 16:34:26 +03:00
|
|
|
protected function triggerCalendarActivity($action, array $calendarData, array $shares = [], array $changedProperties = []) {
|
|
|
|
if (!isset($calendarData['principaluri'])) {
|
2016-10-13 12:04:22 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-13 16:34:26 +03:00
|
|
|
$principal = explode('/', $calendarData['principaluri']);
|
2016-12-15 18:59:46 +03:00
|
|
|
$owner = array_pop($principal);
|
2016-10-13 12:04:22 +03:00
|
|
|
|
|
|
|
$currentUser = $this->userSession->getUser();
|
|
|
|
if ($currentUser instanceof IUser) {
|
|
|
|
$currentUser = $currentUser->getUID();
|
|
|
|
} else {
|
|
|
|
$currentUser = $owner;
|
|
|
|
}
|
|
|
|
|
|
|
|
$event = $this->activityManager->generateEvent();
|
|
|
|
$event->setApp('dav')
|
2016-11-29 18:21:36 +03:00
|
|
|
->setObject('calendar', (int) $calendarData['id'])
|
|
|
|
->setType('calendar')
|
2016-10-13 12:04:22 +03:00
|
|
|
->setAuthor($currentUser);
|
|
|
|
|
|
|
|
$changedVisibleInformation = array_intersect([
|
|
|
|
'{DAV:}displayname',
|
|
|
|
'{http://apple.com/ns/ical/}calendar-color'
|
|
|
|
], array_keys($changedProperties));
|
|
|
|
|
2016-11-29 18:21:36 +03:00
|
|
|
if (empty($shares) || ($action === Calendar::SUBJECT_UPDATE && empty($changedVisibleInformation))) {
|
2016-10-13 12:04:22 +03:00
|
|
|
$users = [$owner];
|
|
|
|
} else {
|
2016-10-13 16:34:26 +03:00
|
|
|
$users = $this->getUsersForShares($shares);
|
2016-10-13 12:04:22 +03:00
|
|
|
$users[] = $owner;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($users as $user) {
|
|
|
|
$event->setAffectedUser($user)
|
|
|
|
->setSubject(
|
|
|
|
$user === $currentUser ? $action . '_self' : $action,
|
|
|
|
[
|
|
|
|
$currentUser,
|
2016-10-13 16:34:26 +03:00
|
|
|
$calendarData['{DAV:}displayname'],
|
2016-10-13 12:04:22 +03:00
|
|
|
]
|
|
|
|
);
|
|
|
|
$this->activityManager->publish($event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates activities for all related users when a calendar was (un-)shared
|
|
|
|
*
|
2016-10-13 16:34:26 +03:00
|
|
|
* @param array $calendarData
|
|
|
|
* @param array $shares
|
2016-10-13 12:04:22 +03:00
|
|
|
* @param array $add
|
|
|
|
* @param array $remove
|
|
|
|
*/
|
2016-10-13 16:34:26 +03:00
|
|
|
public function onCalendarUpdateShares(array $calendarData, array $shares, array $add, array $remove) {
|
|
|
|
$principal = explode('/', $calendarData['principaluri']);
|
2016-10-13 12:04:22 +03:00
|
|
|
$owner = $principal[2];
|
|
|
|
|
|
|
|
$currentUser = $this->userSession->getUser();
|
|
|
|
if ($currentUser instanceof IUser) {
|
|
|
|
$currentUser = $currentUser->getUID();
|
|
|
|
} else {
|
|
|
|
$currentUser = $owner;
|
|
|
|
}
|
|
|
|
|
|
|
|
$event = $this->activityManager->generateEvent();
|
|
|
|
$event->setApp('dav')
|
2016-11-29 18:21:36 +03:00
|
|
|
->setObject('calendar', (int) $calendarData['id'])
|
|
|
|
->setType('calendar')
|
2016-10-13 12:04:22 +03:00
|
|
|
->setAuthor($currentUser);
|
|
|
|
|
|
|
|
foreach ($remove as $principal) {
|
|
|
|
// principal:principals/users/test
|
|
|
|
$parts = explode(':', $principal, 2);
|
|
|
|
if ($parts[0] !== 'principal') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$principal = explode('/', $parts[1]);
|
|
|
|
|
|
|
|
if ($principal[1] === 'users') {
|
|
|
|
$this->triggerActivityUser(
|
|
|
|
$principal[2],
|
|
|
|
$event,
|
2016-10-13 16:34:26 +03:00
|
|
|
$calendarData,
|
2016-11-29 18:21:36 +03:00
|
|
|
Calendar::SUBJECT_UNSHARE_USER,
|
|
|
|
Calendar::SUBJECT_DELETE . '_self'
|
2016-10-13 12:04:22 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
if ($owner !== $principal[2]) {
|
|
|
|
$parameters = [
|
|
|
|
$principal[2],
|
2016-10-13 16:34:26 +03:00
|
|
|
$calendarData['{DAV:}displayname'],
|
2016-10-13 12:04:22 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
if ($owner === $event->getAuthor()) {
|
2016-11-29 18:21:36 +03:00
|
|
|
$subject = Calendar::SUBJECT_UNSHARE_USER . '_you';
|
2016-10-13 12:04:22 +03:00
|
|
|
} else if ($principal[2] === $event->getAuthor()) {
|
2016-11-29 18:21:36 +03:00
|
|
|
$subject = Calendar::SUBJECT_UNSHARE_USER . '_self';
|
2016-10-13 12:04:22 +03:00
|
|
|
} else {
|
|
|
|
$event->setAffectedUser($event->getAuthor())
|
2016-11-29 18:21:36 +03:00
|
|
|
->setSubject(Calendar::SUBJECT_UNSHARE_USER . '_you', $parameters);
|
2016-10-13 12:04:22 +03:00
|
|
|
$this->activityManager->publish($event);
|
|
|
|
|
2016-11-29 18:21:36 +03:00
|
|
|
$subject = Calendar::SUBJECT_UNSHARE_USER . '_by';
|
2016-10-13 12:04:22 +03:00
|
|
|
$parameters[] = $event->getAuthor();
|
|
|
|
}
|
|
|
|
|
|
|
|
$event->setAffectedUser($owner)
|
|
|
|
->setSubject($subject, $parameters);
|
|
|
|
$this->activityManager->publish($event);
|
|
|
|
}
|
|
|
|
} else if ($principal[1] === 'groups') {
|
2016-11-29 18:21:36 +03:00
|
|
|
$this->triggerActivityGroup($principal[2], $event, $calendarData, Calendar::SUBJECT_UNSHARE_USER);
|
2016-10-13 12:04:22 +03:00
|
|
|
|
|
|
|
$parameters = [
|
|
|
|
$principal[2],
|
2016-10-13 16:34:26 +03:00
|
|
|
$calendarData['{DAV:}displayname'],
|
2016-10-13 12:04:22 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
if ($owner === $event->getAuthor()) {
|
2016-11-29 18:21:36 +03:00
|
|
|
$subject = Calendar::SUBJECT_UNSHARE_GROUP . '_you';
|
2016-10-13 12:04:22 +03:00
|
|
|
} else {
|
|
|
|
$event->setAffectedUser($event->getAuthor())
|
2016-11-29 18:21:36 +03:00
|
|
|
->setSubject(Calendar::SUBJECT_UNSHARE_GROUP . '_you', $parameters);
|
2016-10-13 12:04:22 +03:00
|
|
|
$this->activityManager->publish($event);
|
|
|
|
|
2016-11-29 18:21:36 +03:00
|
|
|
$subject = Calendar::SUBJECT_UNSHARE_GROUP . '_by';
|
2016-10-13 12:04:22 +03:00
|
|
|
$parameters[] = $event->getAuthor();
|
|
|
|
}
|
|
|
|
|
|
|
|
$event->setAffectedUser($owner)
|
|
|
|
->setSubject($subject, $parameters);
|
|
|
|
$this->activityManager->publish($event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($add as $share) {
|
|
|
|
if ($this->isAlreadyShared($share['href'], $shares)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// principal:principals/users/test
|
|
|
|
$parts = explode(':', $share['href'], 2);
|
|
|
|
if ($parts[0] !== 'principal') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$principal = explode('/', $parts[1]);
|
|
|
|
|
|
|
|
if ($principal[1] === 'users') {
|
2016-11-29 18:21:36 +03:00
|
|
|
$this->triggerActivityUser($principal[2], $event, $calendarData, Calendar::SUBJECT_SHARE_USER);
|
2016-10-13 12:04:22 +03:00
|
|
|
|
|
|
|
if ($owner !== $principal[2]) {
|
|
|
|
$parameters = [
|
|
|
|
$principal[2],
|
2016-10-13 16:34:26 +03:00
|
|
|
$calendarData['{DAV:}displayname'],
|
2016-10-13 12:04:22 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
if ($owner === $event->getAuthor()) {
|
2016-11-29 18:21:36 +03:00
|
|
|
$subject = Calendar::SUBJECT_SHARE_USER . '_you';
|
2016-10-13 12:04:22 +03:00
|
|
|
} else {
|
|
|
|
$event->setAffectedUser($event->getAuthor())
|
2016-11-29 18:21:36 +03:00
|
|
|
->setSubject(Calendar::SUBJECT_SHARE_USER . '_you', $parameters);
|
2016-10-13 12:04:22 +03:00
|
|
|
$this->activityManager->publish($event);
|
|
|
|
|
2016-11-29 18:21:36 +03:00
|
|
|
$subject = Calendar::SUBJECT_SHARE_USER . '_by';
|
2016-10-13 12:04:22 +03:00
|
|
|
$parameters[] = $event->getAuthor();
|
|
|
|
}
|
|
|
|
|
|
|
|
$event->setAffectedUser($owner)
|
|
|
|
->setSubject($subject, $parameters);
|
|
|
|
$this->activityManager->publish($event);
|
|
|
|
}
|
|
|
|
} else if ($principal[1] === 'groups') {
|
2016-11-29 18:21:36 +03:00
|
|
|
$this->triggerActivityGroup($principal[2], $event, $calendarData, Calendar::SUBJECT_SHARE_USER);
|
2016-10-13 12:04:22 +03:00
|
|
|
|
|
|
|
$parameters = [
|
|
|
|
$principal[2],
|
2016-10-13 16:34:26 +03:00
|
|
|
$calendarData['{DAV:}displayname'],
|
2016-10-13 12:04:22 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
if ($owner === $event->getAuthor()) {
|
2016-11-29 18:21:36 +03:00
|
|
|
$subject = Calendar::SUBJECT_SHARE_GROUP . '_you';
|
2016-10-13 12:04:22 +03:00
|
|
|
} else {
|
|
|
|
$event->setAffectedUser($event->getAuthor())
|
2016-11-29 18:21:36 +03:00
|
|
|
->setSubject(Calendar::SUBJECT_SHARE_GROUP . '_you', $parameters);
|
2016-10-13 12:04:22 +03:00
|
|
|
$this->activityManager->publish($event);
|
|
|
|
|
2016-11-29 18:21:36 +03:00
|
|
|
$subject = Calendar::SUBJECT_SHARE_GROUP . '_by';
|
2016-10-13 12:04:22 +03:00
|
|
|
$parameters[] = $event->getAuthor();
|
|
|
|
}
|
|
|
|
|
|
|
|
$event->setAffectedUser($owner)
|
|
|
|
->setSubject($subject, $parameters);
|
|
|
|
$this->activityManager->publish($event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a calendar is already shared with a principal
|
|
|
|
*
|
|
|
|
* @param string $principal
|
|
|
|
* @param array[] $shares
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
protected function isAlreadyShared($principal, $shares) {
|
|
|
|
foreach ($shares as $share) {
|
|
|
|
if ($principal === $share['href']) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the given activity for all members of the given group
|
|
|
|
*
|
|
|
|
* @param string $gid
|
|
|
|
* @param IEvent $event
|
|
|
|
* @param array $properties
|
|
|
|
* @param string $subject
|
|
|
|
*/
|
|
|
|
protected function triggerActivityGroup($gid, IEvent $event, array $properties, $subject) {
|
|
|
|
$group = $this->groupManager->get($gid);
|
|
|
|
|
|
|
|
if ($group instanceof IGroup) {
|
|
|
|
foreach ($group->getUsers() as $user) {
|
|
|
|
// Exclude current user
|
|
|
|
if ($user->getUID() !== $event->getAuthor()) {
|
|
|
|
$this->triggerActivityUser($user->getUID(), $event, $properties, $subject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the given activity for the given user
|
|
|
|
*
|
|
|
|
* @param string $user
|
|
|
|
* @param IEvent $event
|
|
|
|
* @param array $properties
|
|
|
|
* @param string $subject
|
|
|
|
* @param string $subjectSelf
|
|
|
|
*/
|
|
|
|
protected function triggerActivityUser($user, IEvent $event, array $properties, $subject, $subjectSelf = '') {
|
|
|
|
$event->setAffectedUser($user)
|
|
|
|
->setSubject(
|
|
|
|
$user === $event->getAuthor() && $subjectSelf ? $subjectSelf : $subject,
|
|
|
|
[
|
|
|
|
$event->getAuthor(),
|
|
|
|
$properties['{DAV:}displayname'],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->activityManager->publish($event);
|
|
|
|
}
|
|
|
|
|
2016-10-13 13:16:43 +03:00
|
|
|
/**
|
2016-10-13 16:34:26 +03:00
|
|
|
* Creates activities when a calendar object was created/updated/deleted
|
2016-10-13 13:16:43 +03:00
|
|
|
*
|
|
|
|
* @param string $action
|
2016-10-13 16:34:26 +03:00
|
|
|
* @param array $calendarData
|
|
|
|
* @param array $shares
|
|
|
|
* @param array $objectData
|
2016-10-13 13:16:43 +03:00
|
|
|
*/
|
2016-10-13 16:34:26 +03:00
|
|
|
public function onTouchCalendarObject($action, array $calendarData, array $shares, array $objectData) {
|
|
|
|
if (!isset($calendarData['principaluri'])) {
|
2016-10-13 13:16:43 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-13 16:34:26 +03:00
|
|
|
$principal = explode('/', $calendarData['principaluri']);
|
2016-12-15 18:59:46 +03:00
|
|
|
$owner = array_pop($principal);
|
2016-10-13 13:16:43 +03:00
|
|
|
|
|
|
|
$currentUser = $this->userSession->getUser();
|
|
|
|
if ($currentUser instanceof IUser) {
|
|
|
|
$currentUser = $currentUser->getUID();
|
|
|
|
} else {
|
|
|
|
$currentUser = $owner;
|
|
|
|
}
|
|
|
|
|
2016-10-13 16:34:26 +03:00
|
|
|
$object = $this->getObjectNameAndType($objectData);
|
2016-10-13 13:16:43 +03:00
|
|
|
$action = $action . '_' . $object['type'];
|
|
|
|
|
2016-11-29 18:21:36 +03:00
|
|
|
if ($object['type'] === 'todo' && strpos($action, Event::SUBJECT_OBJECT_UPDATE) === 0 && $object['status'] === 'COMPLETED') {
|
2016-10-13 13:16:43 +03:00
|
|
|
$action .= '_completed';
|
2016-11-29 18:21:36 +03:00
|
|
|
} else if ($object['type'] === 'todo' && strpos($action, Event::SUBJECT_OBJECT_UPDATE) === 0 && $object['status'] === 'NEEDS-ACTION') {
|
2016-10-13 13:16:43 +03:00
|
|
|
$action .= '_needs_action';
|
|
|
|
}
|
|
|
|
|
|
|
|
$event = $this->activityManager->generateEvent();
|
|
|
|
$event->setApp('dav')
|
2016-11-29 18:21:36 +03:00
|
|
|
->setObject('calendar', (int) $calendarData['id'])
|
|
|
|
->setType($object['type'] === 'event' ? 'calendar_event' : 'calendar_todo')
|
2016-10-13 13:16:43 +03:00
|
|
|
->setAuthor($currentUser);
|
|
|
|
|
2016-10-13 16:34:26 +03:00
|
|
|
$users = $this->getUsersForShares($shares);
|
2016-10-13 13:16:43 +03:00
|
|
|
$users[] = $owner;
|
|
|
|
|
|
|
|
foreach ($users as $user) {
|
|
|
|
$event->setAffectedUser($user)
|
|
|
|
->setSubject(
|
|
|
|
$user === $currentUser ? $action . '_self' : $action,
|
|
|
|
[
|
|
|
|
$currentUser,
|
2016-10-13 16:34:26 +03:00
|
|
|
$calendarData['{DAV:}displayname'],
|
2016-11-29 18:21:36 +03:00
|
|
|
[
|
|
|
|
'id' => $object['id'],
|
|
|
|
'name' => $object['name'],
|
|
|
|
],
|
2016-10-13 13:16:43 +03:00
|
|
|
]
|
|
|
|
);
|
|
|
|
$this->activityManager->publish($event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-10-13 16:34:26 +03:00
|
|
|
* @param array $objectData
|
2016-10-13 13:16:43 +03:00
|
|
|
* @return string[]|bool
|
|
|
|
*/
|
2016-10-13 16:34:26 +03:00
|
|
|
protected function getObjectNameAndType(array $objectData) {
|
|
|
|
$vObject = Reader::read($objectData['calendardata']);
|
2016-10-13 13:16:43 +03:00
|
|
|
$component = $componentType = null;
|
|
|
|
foreach($vObject->getComponents() as $component) {
|
|
|
|
if (in_array($component->name, ['VEVENT', 'VTODO'])) {
|
|
|
|
$componentType = $component->name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$componentType) {
|
|
|
|
// Calendar objects must have a VEVENT or VTODO component
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($componentType === 'VEVENT') {
|
2016-11-29 18:21:36 +03:00
|
|
|
return ['id' => (string) $component->UID, 'name' => (string) $component->SUMMARY, 'type' => 'event'];
|
2016-10-13 13:16:43 +03:00
|
|
|
}
|
2016-11-29 18:21:36 +03:00
|
|
|
return ['id' => (string) $component->UID, 'name' => (string) $component->SUMMARY, 'type' => 'todo', 'status' => (string) $component->STATUS];
|
2016-10-13 13:16:43 +03:00
|
|
|
}
|
|
|
|
|
2016-10-13 12:04:22 +03:00
|
|
|
/**
|
|
|
|
* Get all users that have access to a given calendar
|
|
|
|
*
|
2016-10-13 16:34:26 +03:00
|
|
|
* @param array $shares
|
2016-10-13 12:04:22 +03:00
|
|
|
* @return string[]
|
|
|
|
*/
|
2016-10-13 16:34:26 +03:00
|
|
|
protected function getUsersForShares(array $shares) {
|
2016-10-13 12:04:22 +03:00
|
|
|
$users = $groups = [];
|
|
|
|
foreach ($shares as $share) {
|
|
|
|
$prinical = explode('/', $share['{http://owncloud.org/ns}principal']);
|
|
|
|
if ($prinical[1] === 'users') {
|
|
|
|
$users[] = $prinical[2];
|
|
|
|
} else if ($prinical[1] === 'groups') {
|
|
|
|
$groups[] = $prinical[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($groups)) {
|
|
|
|
foreach ($groups as $gid) {
|
|
|
|
$group = $this->groupManager->get($gid);
|
|
|
|
if ($group instanceof IGroup) {
|
|
|
|
foreach ($group->getUsers() as $user) {
|
|
|
|
$users[] = $user->getUID();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-13 13:16:43 +03:00
|
|
|
return array_unique($users);
|
2016-10-13 12:04:22 +03:00
|
|
|
}
|
|
|
|
}
|