2013-10-21 22:46:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Sabre\CardDAV;
|
|
|
|
|
|
|
|
use Sabre\DAV;
|
2016-05-11 00:26:44 +00:00
|
|
|
use Sabre\DAV\MkCol;
|
2013-10-21 22:46:31 +00:00
|
|
|
use Sabre\DAVACL;
|
2016-05-11 00:26:44 +00:00
|
|
|
use Sabre\Uri;
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
/**
|
2016-05-11 00:26:44 +00:00
|
|
|
* AddressBook Home class
|
2013-10-21 22:46:31 +00:00
|
|
|
*
|
2016-05-11 00:26:44 +00:00
|
|
|
* This collection contains a list of addressbooks associated with one user.
|
2013-10-21 22:46:31 +00:00
|
|
|
*
|
2016-05-11 00:26:44 +00:00
|
|
|
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
|
2013-10-21 22:46:31 +00:00
|
|
|
* @author Evert Pot (http://evertpot.com/)
|
2014-06-28 20:28:08 +00:00
|
|
|
* @license http://sabre.io/license/ Modified BSD License
|
2013-10-21 22:46:31 +00:00
|
|
|
*/
|
2016-05-11 00:26:44 +00:00
|
|
|
class AddressBookHome extends DAV\Collection implements DAV\IExtendedCollection, DAVACL\IACL {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Principal uri
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $principalUri;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* carddavBackend
|
|
|
|
*
|
|
|
|
* @var Backend\BackendInterface
|
|
|
|
*/
|
|
|
|
protected $carddavBackend;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param Backend\BackendInterface $carddavBackend
|
|
|
|
* @param string $principalUri
|
|
|
|
*/
|
2016-05-11 00:26:44 +00:00
|
|
|
function __construct(Backend\BackendInterface $carddavBackend, $principalUri) {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$this->carddavBackend = $carddavBackend;
|
|
|
|
$this->principalUri = $principalUri;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the name of this object
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-05-11 00:26:44 +00:00
|
|
|
function getName() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
list(, $name) = Uri\split($this->principalUri);
|
2013-10-21 22:46:31 +00:00
|
|
|
return $name;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the name of this object
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-05-11 00:26:44 +00:00
|
|
|
function setName($name) {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
throw new DAV\Exception\MethodNotAllowed();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes this object
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-05-11 00:26:44 +00:00
|
|
|
function delete() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
throw new DAV\Exception\MethodNotAllowed();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the last modification date
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
2016-05-11 00:26:44 +00:00
|
|
|
function getLastModified() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new file under this object.
|
|
|
|
*
|
|
|
|
* This is currently not allowed
|
|
|
|
*
|
|
|
|
* @param string $filename
|
|
|
|
* @param resource $data
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-05-11 00:26:44 +00:00
|
|
|
function createFile($filename, $data = null) {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
throw new DAV\Exception\MethodNotAllowed('Creating new files in this collection is not supported');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new directory under this object.
|
|
|
|
*
|
|
|
|
* This is currently not allowed.
|
|
|
|
*
|
|
|
|
* @param string $filename
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-05-11 00:26:44 +00:00
|
|
|
function createDirectory($filename) {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
throw new DAV\Exception\MethodNotAllowed('Creating new collections in this collection is not supported');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-11 00:26:44 +00:00
|
|
|
* Returns a single addressbook, by name
|
2013-10-21 22:46:31 +00:00
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @todo needs optimizing
|
|
|
|
* @return \AddressBook
|
|
|
|
*/
|
2016-05-11 00:26:44 +00:00
|
|
|
function getChild($name) {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
foreach ($this->getChildren() as $child) {
|
|
|
|
if ($name == $child->getName())
|
2013-10-21 22:46:31 +00:00
|
|
|
return $child;
|
|
|
|
|
|
|
|
}
|
|
|
|
throw new DAV\Exception\NotFound('Addressbook with name \'' . $name . '\' could not be found');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of addressbooks
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2016-05-11 00:26:44 +00:00
|
|
|
function getChildren() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$addressbooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri);
|
|
|
|
$objs = [];
|
|
|
|
foreach ($addressbooks as $addressbook) {
|
2013-10-21 22:46:31 +00:00
|
|
|
$objs[] = new AddressBook($this->carddavBackend, $addressbook);
|
|
|
|
}
|
|
|
|
return $objs;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-11 00:26:44 +00:00
|
|
|
* Creates a new address book.
|
2013-10-21 22:46:31 +00:00
|
|
|
*
|
|
|
|
* @param string $name
|
2016-05-11 00:26:44 +00:00
|
|
|
* @param MkCol $mkCol
|
|
|
|
* @throws DAV\Exception\InvalidResourceType
|
2013-10-21 22:46:31 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2016-05-11 00:26:44 +00:00
|
|
|
function createExtendedCollection($name, MkCol $mkCol) {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
if (!$mkCol->hasResourceType('{' . Plugin::NS_CARDDAV . '}addressbook')) {
|
2013-10-21 22:46:31 +00:00
|
|
|
throw new DAV\Exception\InvalidResourceType('Unknown resourceType for this collection');
|
|
|
|
}
|
2016-05-11 00:26:44 +00:00
|
|
|
$properties = $mkCol->getRemainingValues();
|
|
|
|
$mkCol->setRemainingResultCode(201);
|
2013-10-21 22:46:31 +00:00
|
|
|
$this->carddavBackend->createAddressBook($this->principalUri, $name, $properties);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the owner principal
|
|
|
|
*
|
|
|
|
* This must be a url to a principal, or null if there's no owner
|
|
|
|
*
|
|
|
|
* @return string|null
|
|
|
|
*/
|
2016-05-11 00:26:44 +00:00
|
|
|
function getOwner() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
return $this->principalUri;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a group principal
|
|
|
|
*
|
|
|
|
* This must be a url to a principal, or null if there's no owner
|
|
|
|
*
|
|
|
|
* @return string|null
|
|
|
|
*/
|
2016-05-11 00:26:44 +00:00
|
|
|
function getGroup() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of ACE's for this node.
|
|
|
|
*
|
|
|
|
* Each ACE has the following properties:
|
|
|
|
* * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
|
|
|
|
* currently the only supported privileges
|
|
|
|
* * 'principal', a url to the principal who owns the node
|
|
|
|
* * 'protected' (optional), indicating that this ACE is not allowed to
|
|
|
|
* be updated.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2016-05-11 00:26:44 +00:00
|
|
|
function getACL() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
return [
|
|
|
|
[
|
2013-10-21 22:46:31 +00:00
|
|
|
'privilege' => '{DAV:}read',
|
|
|
|
'principal' => $this->principalUri,
|
|
|
|
'protected' => true,
|
2016-05-11 00:26:44 +00:00
|
|
|
],
|
|
|
|
[
|
2013-10-21 22:46:31 +00:00
|
|
|
'privilege' => '{DAV:}write',
|
|
|
|
'principal' => $this->principalUri,
|
|
|
|
'protected' => true,
|
2016-05-11 00:26:44 +00:00
|
|
|
],
|
|
|
|
];
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the ACL
|
|
|
|
*
|
|
|
|
* This method will receive a list of new ACE's.
|
|
|
|
*
|
|
|
|
* @param array $acl
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-05-11 00:26:44 +00:00
|
|
|
function setACL(array $acl) {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
throw new DAV\Exception\MethodNotAllowed('Changing ACL is not yet supported');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the list of supported privileges for this node.
|
|
|
|
*
|
|
|
|
* The returned data structure is a list of nested privileges.
|
|
|
|
* See Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple
|
|
|
|
* standard structure.
|
|
|
|
*
|
|
|
|
* If null is returned from this method, the default privilege set is used,
|
|
|
|
* which is fine for most common usecases.
|
|
|
|
*
|
|
|
|
* @return array|null
|
|
|
|
*/
|
2016-05-11 00:26:44 +00:00
|
|
|
function getSupportedPrivilegeSet() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|