diff options
author | Louis Chemineau <louis@chmn.me> | 2022-07-27 11:47:27 +0200 |
---|---|---|
committer | Louis Chemineau <louis@chmn.me> | 2022-08-22 20:04:58 +0200 |
commit | c8bf3a52d6affb175b17ed3380a6f39746e1c28a (patch) | |
tree | db04fc10248c33dc05f42c760880c008b31ddb0d /lib/Sabre/Album/AlbumsHome.php | |
parent | 0f2bcdaab726739e16930e73e9e00b6079374e78 (diff) |
Add Albums view
Signed-off-by: Louis Chemineau <louis@chmn.me>
Diffstat (limited to 'lib/Sabre/Album/AlbumsHome.php')
-rw-r--r-- | lib/Sabre/Album/AlbumsHome.php | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/lib/Sabre/Album/AlbumsHome.php b/lib/Sabre/Album/AlbumsHome.php index 1c070b59..a2bc2fe7 100644 --- a/lib/Sabre/Album/AlbumsHome.php +++ b/lib/Sabre/Album/AlbumsHome.php @@ -39,6 +39,11 @@ class AlbumsHome implements ICollection { private IRootFolder $rootFolder; private Folder $userFolder; + /** + * @var AlbumRoot[] + */ + private ?array $children = null; + public function __construct( array $principalInfo, AlbumMapper $albumMapper, @@ -52,6 +57,9 @@ class AlbumsHome implements ICollection { $this->userFolder = $rootFolder->getUserFolder($user->getUID()); } + /** + * @return never + */ public function delete() { throw new Forbidden(); } @@ -60,6 +68,9 @@ class AlbumsHome implements ICollection { return 'albums'; } + /** + * @return never + */ public function setName($name) { throw new Forbidden('Permission denied to rename this folder'); } @@ -68,6 +79,9 @@ class AlbumsHome implements ICollection { throw new Forbidden('Not allowed to create files in this folder'); } + /** + * @return void + */ public function createDirectory($name) { $uid = $this->user->getUID(); $this->albumMapper->create($uid, $name); @@ -87,10 +101,14 @@ class AlbumsHome implements ICollection { * @return AlbumRoot[] */ public function getChildren(): array { - $folders = $this->albumMapper->getForUserWithFiles($this->user->getUID()); - return array_map(function (AlbumWithFiles $folder) { - return new AlbumRoot($this->albumMapper, $folder, $this->rootFolder, $this->userFolder, $this->user); - }, $folders); + if ($this->children === null) { + $folders = $this->albumMapper->getForUserWithFiles($this->user->getUID()); + $this->children = array_map(function (AlbumWithFiles $folder) { + return new AlbumRoot($this->albumMapper, $folder, $this->rootFolder, $this->userFolder, $this->user); + }, $folders); + } + + return $this->children; } public function childExists($name): bool { |