From 3777df64ae0a4a3d79e000541c0c512fb3ebf304 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Julius=20H=C3=A4rtl?= Date: Thu, 24 Jan 2019 12:03:52 +0100 Subject: [PATCH] Add link to resource provider MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .../Resources/ResourceProvider.php | 18 ++++++++++++++++- .../Collaboration/Resources/Manager.php | 20 +++++++++++++++++++ .../Collaboration/Resources/Resource.php | 12 +++++++++++ .../Collaboration/Resources/IProvider.php | 9 +++++++++ .../Collaboration/Resources/IResource.php | 6 ++++++ 5 files changed, 64 insertions(+), 1 deletion(-) diff --git a/apps/files/lib/Collaboration/Resources/ResourceProvider.php b/apps/files/lib/Collaboration/Resources/ResourceProvider.php index 4beb882ae3f..155dcbd7b14 100644 --- a/apps/files/lib/Collaboration/Resources/ResourceProvider.php +++ b/apps/files/lib/Collaboration/Resources/ResourceProvider.php @@ -27,6 +27,7 @@ use OCP\Collaboration\Resources\IResource; use OCP\Collaboration\Resources\ResourceException; use OCP\Files\IRootFolder; use OCP\Files\Node; +use OCP\IURLGenerator; use OCP\IUser; class ResourceProvider implements IProvider { @@ -36,11 +37,15 @@ class ResourceProvider implements IProvider { /** @var IRootFolder */ protected $rootFolder; + /** @var IURLGenerator */ + private $urlGenerator; + /** @var array */ protected $nodes = []; - public function __construct(IRootFolder $rootFolder) { + public function __construct(IRootFolder $rootFolder, IURLGenerator $urlGenerator) { $this->rootFolder = $rootFolder; + $this->urlGenerator = $urlGenerator; } /** @@ -102,4 +107,15 @@ class ResourceProvider implements IProvider { public function getType(): string { return self::RESOURCE_TYPE; } + + /** + * Get the link to a resource + * + * @param IResource $resource + * @return string + * @since 15.0.0 + */ + public function getLink(IResource $resource): string { + return $this->urlGenerator->linkToRoute('files.viewcontroller.showFile', ['fileid' => $resource->getId()]); + } } diff --git a/lib/private/Collaboration/Resources/Manager.php b/lib/private/Collaboration/Resources/Manager.php index 1214145bd03..c11382c2f1d 100644 --- a/lib/private/Collaboration/Resources/Manager.php +++ b/lib/private/Collaboration/Resources/Manager.php @@ -179,4 +179,24 @@ class Manager implements IManager { public function getType(): string { return ''; } + + /** + * Get the link to a resource + * + * @param IResource $resource + * @return string + * @since 15.0.0 + */ + public function getLink(IResource $resource): string { + foreach ($this->getProviders() as $provider) { + if ($provider->getType() === $resource->getType()) { + try { + return $provider->getLink($resource); + } catch (ResourceException $e) { + } + } + } + + return ''; + } } diff --git a/lib/private/Collaboration/Resources/Resource.php b/lib/private/Collaboration/Resources/Resource.php index 2f491663a88..eafba8555e8 100644 --- a/lib/private/Collaboration/Resources/Resource.php +++ b/lib/private/Collaboration/Resources/Resource.php @@ -50,6 +50,9 @@ class Resource implements IResource { /** @var string|null */ protected $iconClass; + /** @var string|null */ + protected $link; + public function __construct( IManager $manager, IDBConnection $connection, @@ -102,6 +105,15 @@ class Resource implements IResource { return $this->iconClass; } + public function getLink(): string { + if ($this->link === null) { + $this->link = $this->manager->getLink($this); + } + + return $this->link; + } + + /** * Can a user/guest access the resource * diff --git a/lib/public/Collaboration/Resources/IProvider.php b/lib/public/Collaboration/Resources/IProvider.php index 0299bfd0ddf..9ffc5f4324b 100644 --- a/lib/public/Collaboration/Resources/IProvider.php +++ b/lib/public/Collaboration/Resources/IProvider.php @@ -53,6 +53,15 @@ interface IProvider { */ public function getIconClass(IResource $resource): string; + /** + * Get the link to a resource + * + * @param IResource $resource + * @return string + * @since 15.0.0 + */ + public function getLink(IResource $resource): string; + /** * Can a user/guest access the collection * diff --git a/lib/public/Collaboration/Resources/IResource.php b/lib/public/Collaboration/Resources/IResource.php index 9a4b2b30d10..d16b4c131d8 100644 --- a/lib/public/Collaboration/Resources/IResource.php +++ b/lib/public/Collaboration/Resources/IResource.php @@ -53,6 +53,12 @@ interface IResource { */ public function getIconClass(): string; + /** + * @return string + * @since 15.0.0 + */ + public function getLink(): string; + /** * Can a user/guest access the resource * -- 2.39.5