nextcloud/lib/private/share20/share.php

390 lines
6.6 KiB
PHP
Raw Normal View History

<?php
/**
* @author Roeland Jago Douma <rullzer@owncloud.com>
*
2016-01-12 17:02:16 +03:00
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @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/>
*
*/
namespace OC\Share20;
use OCP\Files\File;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\IUser;
use OCP\IGroup;
2016-01-27 14:13:53 +03:00
class Share implements \OCP\Share\IShare {
/** @var string */
private $id;
/** @var string */
private $providerId;
/** @var Node */
private $node;
/** @var int */
private $fileId;
/** @var string */
private $nodeType;
/** @var int */
private $shareType;
/** @var string */
private $sharedWith;
/** @var string */
private $sharedBy;
/** @var string */
private $shareOwner;
/** @var int */
private $permissions;
/** @var \DateTime */
private $expireDate;
/** @var string */
private $password;
/** @var string */
private $token;
/** @var int */
private $parent;
2015-11-02 23:06:55 +03:00
/** @var string */
private $target;
/** @var \DateTime */
private $shareTime;
/** @var bool */
private $mailSend;
2015-11-02 23:06:55 +03:00
/** @var IRootFolder */
private $rootFolder;
public function __construct(IRootFolder $rootFolder) {
$this->rootFolder = $rootFolder;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
public function setId($id) {
$this->id = $id;
return $this;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
public function getId() {
return $this->id;
}
/**
* @inheritdoc
*/
public function getFullId() {
if ($this->providerId === null || $this->id === null) {
2016-02-08 17:28:36 +03:00
throw new \UnexpectedValueException;
}
return $this->providerId . ':' . $this->id;
}
/**
* @inheritdoc
*/
public function setProviderId($id) {
$this->providerId = $id;
return $this;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
public function setNode(Node $node) {
$this->fileId = null;
$this->nodeType = null;
$this->node = $node;
return $this;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
public function getNode() {
if ($this->node === null) {
if ($this->shareOwner === null || $this->fileId === null) {
throw new NotFoundException();
}
$userFolder = $this->rootFolder->getUserFolder($this->shareOwner);
$nodes = $userFolder->getById($this->fileId);
if (empty($nodes)) {
throw new NotFoundException();
}
$this->node = $nodes[0];
}
return $this->node;
}
/**
* @inheritdoc
*/
public function setNodeId($fileId) {
$this->node = null;
$this->fileId = $fileId;
return $this;
}
/**
* @inheritdoc
*/
public function getNodeId() {
if ($this->fileId === null) {
$this->fileId = $this->getNode()->getId();
}
return $this->fileId;
}
/**
* @inheritdoc
*/
public function setNodeType($type) {
if ($type !== 'file' && $type !== 'folder') {
throw new \InvalidArgumentException();
}
$this->nodeType = $type;
2016-02-09 12:36:44 +03:00
return $this;
}
/**
* @inheritdoc
*/
public function getNodeType() {
if ($this->nodeType === null) {
$node = $this->getNode();
$this->nodeType = $node instanceof File ? 'file' : 'folder';
}
return $this->nodeType;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
public function setShareType($shareType) {
$this->shareType = $shareType;
return $this;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
public function getShareType() {
return $this->shareType;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
public function setSharedWith($sharedWith) {
if (!is_string($sharedWith)) {
throw new \InvalidArgumentException();
}
$this->sharedWith = $sharedWith;
return $this;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
public function getSharedWith() {
return $this->sharedWith;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
public function setPermissions($permissions) {
//TODO checkes
$this->permissions = $permissions;
return $this;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
public function getPermissions() {
return $this->permissions;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
public function setExpirationDate($expireDate) {
//TODO checks
$this->expireDate = $expireDate;
return $this;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
public function getExpirationDate() {
return $this->expireDate;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
public function setSharedBy($sharedBy) {
if (!is_string($sharedBy)) {
throw new \InvalidArgumentException();
}
//TODO checks
$this->sharedBy = $sharedBy;
return $this;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
public function getSharedBy() {
//TODO check if set
return $this->sharedBy;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
public function setShareOwner($shareOwner) {
if (!is_string($shareOwner)) {
throw new \InvalidArgumentException();
}
//TODO checks
$this->shareOwner = $shareOwner;
return $this;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
public function getShareOwner() {
//TODO check if set
return $this->shareOwner;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
public function setPassword($password) {
$this->password = $password;
return $this;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
public function getPassword() {
return $this->password;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
public function setToken($token) {
$this->token = $token;
return $this;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
public function getToken() {
return $this->token;
}
/**
* Set the parent of this share
*
* @param int parent
* @return \OCP\Share\IShare
* @deprecated The new shares do not have parents. This is just here for legacy reasons.
*/
public function setParent($parent) {
$this->parent = $parent;
return $this;
}
/**
* Get the parent of this share.
*
* @return int
* @deprecated The new shares do not have parents. This is just here for legacy reasons.
*/
public function getParent() {
return $this->parent;
}
2015-11-02 23:06:55 +03:00
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
2015-11-02 23:06:55 +03:00
*/
public function setTarget($target) {
$this->target = $target;
return $this;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
2015-11-02 23:06:55 +03:00
*/
public function getTarget() {
return $this->target;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
public function setShareTime(\DateTime $shareTime) {
$this->shareTime = $shareTime;
return $this;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
2016-01-27 13:50:49 +03:00
public function getShareTime() {
return $this->shareTime;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
public function setMailSend($mailSend) {
$this->mailSend = $mailSend;
return $this;
}
/**
2016-01-27 13:50:49 +03:00
* @inheritdoc
*/
public function getMailSend() {
return $this->mailSend;
}
}