2018-11-23 20:41:46 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Nextcloud - Social Support
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later. See the COPYING file.
|
|
|
|
*
|
|
|
|
* @author Maxence Lange <maxence@artificial-owl.com>
|
|
|
|
* @copyright 2018, Maxence Lange <maxence@artificial-owl.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\Social\Model\ActivityPub;
|
|
|
|
|
|
|
|
|
2018-11-26 12:33:48 +00:00
|
|
|
use DateTime;
|
2018-11-23 20:41:46 +00:00
|
|
|
use JsonSerializable;
|
|
|
|
use OCA\Social\Exceptions\UrlCloudException;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Document
|
|
|
|
*
|
|
|
|
* @package OCA\Social\Model\ActivityPub
|
|
|
|
*/
|
|
|
|
class Document extends ACore implements JsonSerializable {
|
|
|
|
|
|
|
|
|
|
|
|
const TYPE = 'Document';
|
|
|
|
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $mediaType = '';
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $mimeType = '';
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $localCopy = '';
|
|
|
|
|
2018-11-26 12:33:48 +00:00
|
|
|
/** @var int */
|
|
|
|
private $caching = 0;
|
2018-11-23 20:41:46 +00:00
|
|
|
|
2018-11-24 14:08:19 +00:00
|
|
|
/** @var bool */
|
|
|
|
private $public = false;
|
|
|
|
|
2018-11-25 12:50:12 +00:00
|
|
|
/** @var int */
|
|
|
|
private $error = 0;
|
|
|
|
|
2018-11-23 20:41:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Document constructor.
|
|
|
|
*
|
|
|
|
* @param ACore $parent
|
|
|
|
*/
|
|
|
|
public function __construct($parent = null) {
|
|
|
|
parent::__construct($parent);
|
|
|
|
|
|
|
|
$this->setType(self::TYPE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getMediaType(): string {
|
|
|
|
return $this->mediaType;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $mediaType
|
|
|
|
*
|
|
|
|
* @return ACore
|
|
|
|
*/
|
|
|
|
public function setMediaType(string $mediaType): ACore {
|
|
|
|
$this->mediaType = $mediaType;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getMimeType(): string {
|
|
|
|
return $this->mimeType;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $mimeType
|
|
|
|
*
|
|
|
|
* @return ACore
|
|
|
|
*/
|
|
|
|
public function setMimeType(string $mimeType): ACore {
|
|
|
|
$this->mimeType = $mimeType;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getLocalCopy(): string {
|
|
|
|
return $this->localCopy;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $localCopy
|
|
|
|
*
|
|
|
|
* @return Document
|
|
|
|
*/
|
|
|
|
public function setLocalCopy(string $localCopy): Document {
|
|
|
|
$this->localCopy = $localCopy;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-24 14:08:19 +00:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isPublic(): bool {
|
|
|
|
return $this->public;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool $public
|
|
|
|
*
|
|
|
|
* @return Document
|
|
|
|
*/
|
|
|
|
public function setPublic(bool $public): Document {
|
|
|
|
$this->public = $public;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-25 12:50:12 +00:00
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getError(): int {
|
|
|
|
return $this->error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $error
|
|
|
|
*
|
|
|
|
* @return Document
|
|
|
|
*/
|
|
|
|
public function setError(int $error): Document {
|
|
|
|
$this->error = $error;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-23 20:41:46 +00:00
|
|
|
/**
|
2018-11-26 12:33:48 +00:00
|
|
|
* @return int
|
2018-11-23 20:41:46 +00:00
|
|
|
*/
|
2018-11-26 12:33:48 +00:00
|
|
|
public function getCaching(): int {
|
2018-11-23 20:41:46 +00:00
|
|
|
return $this->caching;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-11-26 12:33:48 +00:00
|
|
|
* @param int $caching
|
2018-11-23 20:41:46 +00:00
|
|
|
*
|
|
|
|
* @return Document
|
|
|
|
*/
|
2018-11-26 12:33:48 +00:00
|
|
|
public function setCaching(int $caching): Document {
|
2018-11-23 20:41:46 +00:00
|
|
|
$this->caching = $caching;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
*
|
|
|
|
* @throws UrlCloudException
|
|
|
|
*/
|
|
|
|
public function import(array $data) {
|
|
|
|
parent::import($data);
|
|
|
|
|
|
|
|
$this->setMediaType($this->get('mediaType', $data, ''));
|
|
|
|
|
|
|
|
if ($this->getId() === '') {
|
|
|
|
$this->generateUniqueId('/documents/g');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
*/
|
|
|
|
public function importFromDatabase(array $data) {
|
|
|
|
parent::importFromDatabase($data);
|
|
|
|
|
2018-11-24 14:08:19 +00:00
|
|
|
$this->setPublic(($this->getInt('public', $data, 0) === 1) ? true : false);
|
2018-11-25 12:50:12 +00:00
|
|
|
$this->setError($this->getInt('error', $data, 0));
|
2018-11-24 14:08:19 +00:00
|
|
|
$this->setLocalCopy($this->get('local_copy', $data, ''));
|
2018-11-23 20:41:46 +00:00
|
|
|
$this->setMediaType($this->get('media_type', $data, ''));
|
|
|
|
$this->setMimeType($this->get('mime_type', $data, ''));
|
2018-11-26 12:33:48 +00:00
|
|
|
|
|
|
|
if ($this->get('caching', $data, '') === '') {
|
|
|
|
$this->setCaching(0);
|
|
|
|
} else {
|
|
|
|
$date = new DateTime($this->get('caching', $data, ''));
|
|
|
|
$this->setCaching($date->getTimestamp());
|
|
|
|
}
|
2018-11-23 20:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function jsonSerialize(): array {
|
|
|
|
return array_merge(
|
|
|
|
parent::jsonSerialize(),
|
|
|
|
[
|
|
|
|
'mediaType' => $this->getMediaType(),
|
|
|
|
'mimeType' => $this->getMimeType(),
|
|
|
|
'localCopy' => $this->getLocalCopy()
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|