nextcloud/apps/dav/lib/SystemTag/SystemTagsObjectTypeCollect...

176 lines
4.0 KiB
PHP
Raw Normal View History

2015-11-27 14:54:31 +03:00
<?php
/**
2016-07-21 17:49:16 +03:00
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
2016-07-21 17:49:16 +03:00
* @author Joas Schilling <coding@schilljs.com>
* @author Roeland Jago Douma <roeland@famdouma.nl>
2016-01-12 17:02:16 +03:00
* @author Thomas Müller <thomas.mueller@tmit.eu>
* @author Vincent Petry <vincent@nextcloud.com>
2015-11-27 14:54:31 +03:00
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
2015-11-27 14:54:31 +03:00
*
*/
namespace OCA\DAV\SystemTag;
use OCP\IGroupManager;
use OCP\IUserSession;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\ISystemTagObjectMapper;
2015-11-27 14:54:31 +03:00
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\MethodNotAllowed;
use Sabre\DAV\Exception\NotFound;
2015-11-27 14:54:31 +03:00
use Sabre\DAV\ICollection;
/**
* Collection containing object ids by object type
*/
class SystemTagsObjectTypeCollection implements ICollection {
/**
* @var string
*/
private $objectType;
/**
* @var ISystemTagManager
*/
private $tagManager;
/**
* @var ISystemTagObjectMapper
*/
private $tagMapper;
/**
* @var IGroupManager
*/
private $groupManager;
/**
* @var IUserSession
*/
private $userSession;
/**
* @var \Closure
**/
protected $childExistsFunction;
2015-11-27 14:54:31 +03:00
/**
* Constructor
*
* @param string $objectType object type
* @param ISystemTagManager $tagManager
* @param ISystemTagObjectMapper $tagMapper
* @param IUserSession $userSession
* @param IGroupManager $groupManager
* @param \Closure $childExistsFunction
2015-11-27 14:54:31 +03:00
*/
public function __construct(
$objectType,
ISystemTagManager $tagManager,
ISystemTagObjectMapper $tagMapper,
IUserSession $userSession,
IGroupManager $groupManager,
\Closure $childExistsFunction
) {
2015-11-27 14:54:31 +03:00
$this->tagManager = $tagManager;
$this->tagMapper = $tagMapper;
$this->objectType = $objectType;
$this->userSession = $userSession;
$this->groupManager = $groupManager;
$this->childExistsFunction = $childExistsFunction;
}
/**
* @param string $name
2015-12-10 18:43:10 +03:00
* @param resource|string $data Initial payload
2016-05-24 16:26:02 +03:00
* @return null|string
2015-12-10 18:43:10 +03:00
* @throws Forbidden
*/
public function createFile($name, $data = null) {
2015-12-04 19:30:22 +03:00
throw new Forbidden('Permission denied to create nodes');
2015-11-27 14:54:31 +03:00
}
/**
* @param string $name
2016-05-24 16:26:02 +03:00
* @throws Forbidden
*/
public function createDirectory($name) {
2015-11-27 14:54:31 +03:00
throw new Forbidden('Permission denied to create collections');
}
/**
* @param string $objectId
2016-05-24 16:26:02 +03:00
* @return SystemTagsObjectMappingCollection
* @throws NotFound
*/
public function getChild($objectId) {
// make sure the object exists and is reachable
if (!$this->childExists($objectId)) {
throw new NotFound('Entity does not exist or is not available');
}
2015-11-27 14:54:31 +03:00
return new SystemTagsObjectMappingCollection(
$objectId,
$this->objectType,
$this->userSession->getUser(),
2015-11-27 14:54:31 +03:00
$this->tagManager,
$this->tagMapper
);
}
public function getChildren() {
2015-11-27 14:54:31 +03:00
// do not list object ids
throw new MethodNotAllowed();
}
/**
* Checks if a child-node with the specified name exists
*
* @param string $name
* @return bool
*/
public function childExists($name) {
return call_user_func($this->childExistsFunction, $name);
2015-11-27 14:54:31 +03:00
}
public function delete() {
2015-11-27 14:54:31 +03:00
throw new Forbidden('Permission denied to delete this collection');
}
public function getName() {
2015-11-27 14:54:31 +03:00
return $this->objectType;
}
/**
* @param string $name
2016-05-24 16:26:02 +03:00
* @throws Forbidden
*/
public function setName($name) {
2015-11-27 14:54:31 +03:00
throw new Forbidden('Permission denied to rename this collection');
}
/**
* Returns the last modification time, as a unix timestamp
*
* @return int
*/
public function getLastModified() {
2015-11-27 14:54:31 +03:00
return null;
}
}