From c3cc70b15ef0748f987cdb1c31b578c2b1a8c3a4 Mon Sep 17 00:00:00 2001 From: Marco Nassabain Date: Wed, 24 Feb 2021 22:30:33 +0100 Subject: =?UTF-8?q?=E2=9C=A8=20ItemMapperV2:=20added=20findAllSharedWithUs?= =?UTF-8?q?er=20funct=20-=20return=20all=20items=20shared=20with=20a=20giv?= =?UTF-8?q?en=20user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marco Nassabain --- lib/Db/ItemMapperV2.php | 58 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/Db/ItemMapperV2.php b/lib/Db/ItemMapperV2.php index 44d1740cd..64b640a11 100644 --- a/lib/Db/ItemMapperV2.php +++ b/lib/Db/ItemMapperV2.php @@ -563,12 +563,58 @@ class ItemMapperV2 extends NewsMapperV2 } /** - * @param string $userId User identifier - * @param int $type Type of items to retrieve - * @param int $limit Max items to retrieve - * @param int $offset First item ID to retrieve - * @param bool $oldestFirst Chronological sort - * @param array $search Search terms + * Returns all items shared with a user + * + * @param string $userId + * @param int $limit + * @param int $offset + * @param bool $hideRead + * @param bool $oldestFirst + * @param array $search + * + * @return Item[] + */ + public function findAllSharedWithUser( + string $userId, + int $limit, + int $offset, + bool $hideRead, + bool $oldestFirst, + array $search + ): array { + $builder = $this->db->getQueryBuilder(); + + $builder->select('items.*') + ->from($this->tableName, 'items') + ->andWhere('items.shared_with = :sharedWith') + ->setParameter('sharedWith', $userId) + ->setMaxResults($limit) + ->setFirstResult($offset) + ->orderBy('items.last_modified', ($oldestFirst ? 'ASC' : 'DESC')) + ->addOrderBy('items.id', ($oldestFirst ? 'ASC' : 'DESC')); + + if ($search !== []) { + foreach ($search as $key => $term) { + $term = $this->db->escapeLikeParameter($term); + $builder->andWhere("items.search_index LIKE :term${key}") + ->setParameter("term${key}", "%$term%"); + } + } + + if ($hideRead === true) { + $builder->andWhere('items.unread = 1'); + } + + return $this->findEntities($builder); + } + + /** + * @param string $userId + * @param int $type + * @param int $limit + * @param int $offset + * @param bool $oldestFirst + * @param array $search * * @return Item[] * @throws ServiceValidationException -- cgit v1.2.3