Add link to resource provider

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2019-01-24 12:03:52 +01:00
parent 506eb885bc
commit 3777df64ae
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
5 changed files with 64 additions and 1 deletions

View File

@ -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()]);
}
}

View File

@ -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 '';
}
}

View File

@ -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
*

View File

@ -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
*

View File

@ -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
*