diff options
author | Marco Nassabain <marco.nassabain@hotmail.com> | 2021-02-24 22:30:33 +0100 |
---|---|---|
committer | Sean Molenaar <SMillerDev@users.noreply.github.com> | 2021-04-08 22:31:21 +0200 |
commit | c3cc70b15ef0748f987cdb1c31b578c2b1a8c3a4 (patch) | |
tree | b67d2a00d47403b835f68f26250f94676b7fbf23 /lib/Db | |
parent | 907e7647493ee10a6a41d0a8e39b6214ce2752cd (diff) |
✨ ItemMapperV2: added findAllSharedWithUser funct
- return all items shared with a given user
Signed-off-by: Marco Nassabain <marco.nassabain@hotmail.com>
Diffstat (limited to 'lib/Db')
-rw-r--r-- | lib/Db/ItemMapperV2.php | 58 |
1 files changed, 52 insertions, 6 deletions
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 |