2019-12-27 20:01:43 +00:00
|
|
|
<?php
|
2020-09-21 12:25:50 +00:00
|
|
|
/*
|
2024-02-02 18:27:50 +00:00
|
|
|
* Copyright (c) 2020-2024. The Nextcloud Bookmarks contributors.
|
2020-09-21 12:25:50 +00:00
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
|
|
|
|
*/
|
2019-12-28 16:41:31 +00:00
|
|
|
|
2019-12-27 20:01:43 +00:00
|
|
|
namespace OCA\Bookmarks\Db;
|
|
|
|
|
2024-05-24 09:28:59 +00:00
|
|
|
use OCA\Bookmarks\Service\CirclesService;
|
2019-12-27 20:01:43 +00:00
|
|
|
use OCP\AppFramework\Db\Entity;
|
2024-05-24 09:28:59 +00:00
|
|
|
use OCP\IGroupManager;
|
|
|
|
use OCP\IUserManager;
|
|
|
|
use OCP\Share\IShare;
|
|
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
|
|
use Psr\Container\NotFoundExceptionInterface;
|
2019-12-27 20:01:43 +00:00
|
|
|
|
2020-03-05 11:45:42 +00:00
|
|
|
/**
|
|
|
|
* Class Share
|
|
|
|
*
|
|
|
|
* @package OCA\Bookmarks\Db
|
|
|
|
*
|
2021-01-20 16:38:11 +00:00
|
|
|
* @method int getFolderId()
|
2020-03-05 11:45:42 +00:00
|
|
|
* @method setFolderId(int $folderId)
|
2021-01-20 16:38:11 +00:00
|
|
|
* @method string getOwner()
|
2020-03-05 11:45:42 +00:00
|
|
|
* @method setOwner(string $owner)
|
2021-01-20 16:38:11 +00:00
|
|
|
* @method string getParticipant
|
2020-03-05 11:45:42 +00:00
|
|
|
* @method setParticipant(string $participant)
|
2021-01-20 16:38:11 +00:00
|
|
|
* @method string getType()
|
2020-03-05 11:45:42 +00:00
|
|
|
* @method setType(string $type)
|
2021-01-20 16:38:11 +00:00
|
|
|
* @method bool getCanWrite()
|
2020-03-05 11:45:42 +00:00
|
|
|
* @method setCanWrite(bool $canWrite)
|
2021-01-20 16:38:11 +00:00
|
|
|
* @method bool getCanShare()
|
2020-03-05 11:45:42 +00:00
|
|
|
* @method setCanShare(bool $canShare)
|
2021-01-20 16:38:11 +00:00
|
|
|
* @method int getCreatedAt()
|
2020-03-05 11:45:42 +00:00
|
|
|
* @method setCreatedAt(int $createdAt)
|
|
|
|
*/
|
2019-12-27 20:01:43 +00:00
|
|
|
class Share extends Entity {
|
|
|
|
protected $folderId;
|
|
|
|
protected $owner;
|
|
|
|
protected $participant;
|
|
|
|
protected $type;
|
|
|
|
protected $canWrite;
|
|
|
|
protected $canShare;
|
|
|
|
protected $createdAt;
|
|
|
|
|
|
|
|
public static $columns = ['id', 'folder_id', 'owner', 'participant', 'type', 'can_write', 'can_share', 'created_at'];
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
// add types in constructor
|
|
|
|
$this->addType('folderId', 'integer');
|
|
|
|
$this->addType('parentId', 'integer');
|
|
|
|
$this->addType('owner', 'string');
|
|
|
|
$this->addType('type', 'integer');
|
|
|
|
$this->addType('participant', 'string');
|
|
|
|
$this->addType('canWrite', 'boolean');
|
|
|
|
$this->addType('canShare', 'boolean');
|
|
|
|
$this->addType('createdAt', 'integer');
|
|
|
|
}
|
2019-12-29 14:18:36 +00:00
|
|
|
|
2021-01-20 14:42:41 +00:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*
|
|
|
|
* @psalm-return array{id: mixed, folderId: mixed, owner: mixed, participant: mixed, type: mixed, canWrite: mixed, canShare: mixed, createdAt: mixed}
|
|
|
|
*/
|
2020-09-21 12:17:46 +00:00
|
|
|
public function toArray(): array {
|
2024-05-24 09:28:59 +00:00
|
|
|
return [
|
|
|
|
'id' => $this->id,
|
|
|
|
'folderId' => $this->folderId,
|
|
|
|
'owner' => $this->owner,
|
|
|
|
'participant' => $this->participant,
|
|
|
|
'type' => $this->type,
|
|
|
|
'canWrite' => $this->canWrite,
|
|
|
|
'canShare' => $this->canShare,
|
|
|
|
'createdAt' => $this->createdAt,
|
|
|
|
'participantDisplayName' => self::getParticipantDisplayName($this->type, $this->participant),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function getParticipantDisplayName($type, $participant) {
|
|
|
|
try {
|
|
|
|
if ($type === IShare::TYPE_USER) {
|
|
|
|
return \OCP\Server::get(IUserManager::class)->get($participant)->getDisplayName();
|
|
|
|
}
|
|
|
|
if ($type === IShare::TYPE_GROUP) {
|
|
|
|
return \OCP\Server::get(IGroupManager::class)->get($participant)->getDisplayName();
|
|
|
|
}
|
|
|
|
if ($type === IShare::TYPE_CIRCLE) {
|
|
|
|
return \OCP\Server::get(CirclesService::class)->getCircle($participant)->getName();
|
|
|
|
}
|
|
|
|
} catch (NotFoundExceptionInterface|ContainerExceptionInterface $e) {
|
|
|
|
return $participant;
|
|
|
|
}
|
2019-12-29 14:18:36 +00:00
|
|
|
}
|
2019-12-27 20:01:43 +00:00
|
|
|
}
|