diff options
author | Joas Schilling <coding@schilljs.com> | 2019-03-14 12:30:34 +0100 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2019-03-19 13:06:55 +0100 |
commit | 3022ef687a7bef87fc8eff7e29a68d8cf64542e9 (patch) | |
tree | beba5dd9a6d407107a4f2d3b8b2fe07f503f55cf /apps/files | |
parent | 403b673b93b98b7158838c232581ad221aeccd09 (diff) | |
download | nextcloud-server-3022ef687a7bef87fc8eff7e29a68d8cf64542e9.tar.gz nextcloud-server-3022ef687a7bef87fc8eff7e29a68d8cf64542e9.zip |
Use rich objects instead of name, link and icon
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/files')
-rw-r--r-- | apps/files/lib/Collaboration/Resources/ResourceProvider.php | 73 |
1 files changed, 31 insertions, 42 deletions
diff --git a/apps/files/lib/Collaboration/Resources/ResourceProvider.php b/apps/files/lib/Collaboration/Resources/ResourceProvider.php index 27b155b7641..f29c99abc96 100644 --- a/apps/files/lib/Collaboration/Resources/ResourceProvider.php +++ b/apps/files/lib/Collaboration/Resources/ResourceProvider.php @@ -25,26 +25,32 @@ namespace OCA\Files\Collaboration\Resources; use OCP\Collaboration\Resources\IProvider; use OCP\Collaboration\Resources\IResource; +use OCP\Collaboration\Resources\ResourceException; use OCP\Files\IRootFolder; use OCP\Files\Node; +use OCP\IPreview; use OCP\IURLGenerator; use OCP\IUser; class ResourceProvider implements IProvider { - const RESOURCE_TYPE = 'files'; + public const RESOURCE_TYPE = 'file'; /** @var IRootFolder */ protected $rootFolder; - + /** @var IPreview */ + private $preview; /** @var IURLGenerator */ private $urlGenerator; /** @var array */ protected $nodes = []; - public function __construct(IRootFolder $rootFolder, IURLGenerator $urlGenerator) { + public function __construct(IRootFolder $rootFolder, + IPreview $preview, + IURLGenerator $urlGenerator) { $this->rootFolder = $rootFolder; + $this->preview = $preview; $this->urlGenerator = $urlGenerator; } @@ -61,21 +67,34 @@ class ResourceProvider implements IProvider { } /** - * Get the display name of a resource - * * @param IResource $resource - * @return string + * @return array * @since 16.0.0 */ - public function getName(IResource $resource): string { + public function getResourceRichObject(IResource $resource): array { if (isset($this->nodes[(int) $resource->getId()])) { - return $this->nodes[(int) $resource->getId()]->getPath(); + $node = $this->nodes[(int) $resource->getId()]->getPath(); + } else { + $node = $this->getNode($resource); } - $node = $this->getNode($resource); - if ($node) { - return $node->getName(); + + if ($node instanceof Node) { + $link = $this->urlGenerator->linkToRouteAbsolute( + 'files.viewcontroller.showFile', + ['fileid' => $resource->getId()] + ); + return [ + 'type' => 'file', + 'id' => $resource->getId(), + 'name' => $node->getName(), + 'path' => $node->getInternalPath(), + 'link' => $link, + 'mimetype' => $node->getMimetype(), + 'preview-available' => $this->preview->isAvailable($node), + ]; } - return ''; + + throw new ResourceException('File not found'); } /** @@ -103,25 +122,6 @@ class ResourceProvider implements IProvider { } /** - * Get the icon class of a resource - * - * @param IResource $resource - * @return string - * @since 16.0.0 - */ - public function getIconLink(IResource $resource): string { - $node = $this->getNode($resource); - if ($node && $node->getMimetype() === 'httpd/unix-directory') { - return $this->urlGenerator->getAbsoluteURL( - $this->urlGenerator->imagePath('core', 'places/files') - ); - } - return $this->urlGenerator->getAbsoluteURL( - $this->urlGenerator->imagePath('core', 'filetypes/file') - ); - } - - /** * Get the resource type of the provider * * @return string @@ -130,15 +130,4 @@ class ResourceProvider implements IProvider { public function getType(): string { return self::RESOURCE_TYPE; } - - /** - * Get the link to a resource - * - * @param IResource $resource - * @return string - * @since 16.0.0 - */ - public function getLink(IResource $resource): string { - return $this->urlGenerator->linkToRoute('files.viewcontroller.showFile', ['fileid' => $resource->getId()]); - } } |