From 0d27af39e37e6d7b18015e153231e3a4ef14b167 Mon Sep 17 00:00:00 2001 From: Jonathan Treffler Date: Sat, 2 Nov 2024 20:11:28 +0100 Subject: [PATCH] improved groupfolder query functions --- lib/Db/TagMapper.php | 33 ++++++++++++++++++++++++++++++++- lib/Service/TagService.php | 8 ++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/Db/TagMapper.php b/lib/Db/TagMapper.php index 4e65e4e..3d3b322 100644 --- a/lib/Db/TagMapper.php +++ b/lib/Db/TagMapper.php @@ -110,6 +110,13 @@ class TagMapper extends QBMapper { ->selectAlias('g.folder_id', 'id') ->from(self::GROUP_FOLDERS_TABLENAME, alias: "g"); + $this->filterGroupfolderQuery($qb, $filters); + $this->addAdditionalReturnTagsToGroupfolderQuery($qb, $additionalReturnTags); + + return $qb; + } + + private function filterGroupfolderQuery(IQueryBuilder $qb, array $filters): void { $index = 0; foreach($filters as $filter) { $alias = 'filter_' . $index; @@ -130,7 +137,9 @@ class TagMapper extends QBMapper { $index++; } + } + private function addAdditionalReturnTagsToGroupfolderQuery(IQueryBuilder $qb, array $additionalReturnTags): void { $index = 0; foreach($additionalReturnTags as $additionalReturnTag) { $alias = 'additional_' . $index; @@ -144,8 +153,30 @@ class TagMapper extends QBMapper { $index++; } + } - return $qb; + /** + * Get a single groupfolder by id, only if all filters match it + * filter format: indexed array of asociative arrays with attributes: key, value, includeInOutput + * Returns array with groupfolder attributes (id, mount_point, quota, acl) and the values of additionalreturntags and filters with includeInOutput === true + * + * @param int $groupfolderId + * @param array $filters + * @param array|null $additionalReturnTags + * @return array + */ + public function findGroupfolderWithTags(int $groupFolderId, array $filters, array $additionalReturnTags = []): array { + /* @var $qb IQueryBuilder */ + $qb = $this->db->getQueryBuilder(); + $qb->select('g.mount_point', 'g.quota', 'g.acl') + ->selectAlias('g.folder_id', 'id') + ->from(self::GROUP_FOLDERS_TABLENAME, alias: "g") + ->where($qb->expr()->eq('g.folder_id', $qb->createNamedParameter($groupFolderId, IQueryBuilder::PARAM_INT))); + + $this->filterGroupfolderQuery($qb, $filters); + $this->addAdditionalReturnTagsToGroupfolderQuery($qb, $additionalReturnTags); + + return $this->findOneQuery($qb); } /** diff --git a/lib/Service/TagService.php b/lib/Service/TagService.php index 1885488..d7dd137 100644 --- a/lib/Service/TagService.php +++ b/lib/Service/TagService.php @@ -51,6 +51,14 @@ class TagService { } } + public function findGroupfolderWithTags(int $groupFolderId, array $filters, array $additionalReturnTags = []): ?array { + try { + return $this->mapper->findGroupfolderWithTags($groupFolderId, $filters, $additionalReturnTags); + } catch (DoesNotExistException $e) { + return null; + } + } + public function update(int $groupFolderId, string $key, ?string $value = null): Tag { try { $tag = $this->find($groupFolderId, $key);