diff options
5 files changed, 64 insertions, 1 deletions
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 @@ -54,6 +54,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 * * @param IResource $resource 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 @@ -54,6 +54,12 @@ interface IResource { public function getIconClass(): string; /** + * @return string + * @since 15.0.0 + */ + public function getLink(): string; + + /** * Can a user/guest access the resource * * @param IUser $user |