From ac2314e3d0e195b2af06473a6acfa5f76534cd63 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 23 Apr 2018 14:58:43 +0200 Subject: Add pagination support Signed-off-by: Joas Schilling --- lib/private/Comments/Manager.php | 10 ++++++++-- lib/public/Comments/ICommentsManager.php | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php index a06a2a0ec59..8f76d49b192 100644 --- a/lib/private/Comments/Manager.php +++ b/lib/private/Comments/Manager.php @@ -500,9 +500,11 @@ class Manager implements ICommentsManager { * @param string $objectType Limit the search by object type * @param string $objectId Limit the search by object id * @param string $verb Limit the verb of the comment + * @param int $offset + * @param int $limit * @return IComment[] */ - public function search(string $search, string $objectType, string $objectId, string $verb): array { + public function search(string $search, string $objectType, string $objectId, string $verb, int $offset, int $limit = 50): array { $query = $this->dbConn->getQueryBuilder(); $query->select('*') @@ -511,7 +513,8 @@ class Manager implements ICommentsManager { '%' . $this->dbConn->escapeLikeParameter($search). '%' ))) ->orderBy('creation_timestamp', 'DESC') - ->addOrderBy('id', 'DESC'); + ->addOrderBy('id', 'DESC') + ->setMaxResults($limit); if ($objectType !== '') { $query->andWhere($query->expr()->eq('object_type', $query->createNamedParameter($objectType))); @@ -522,6 +525,9 @@ class Manager implements ICommentsManager { if ($verb !== '') { $query->andWhere($query->expr()->eq('verb', $query->createNamedParameter($verb))); } + if ($offset !== 0) { + $query->setFirstResult($offset); + } $comments = []; $result = $query->execute(); diff --git a/lib/public/Comments/ICommentsManager.php b/lib/public/Comments/ICommentsManager.php index 2ea5ef29291..ca98214cd72 100644 --- a/lib/public/Comments/ICommentsManager.php +++ b/lib/public/Comments/ICommentsManager.php @@ -145,10 +145,12 @@ interface ICommentsManager { * @param string $objectType Limit the search by object type * @param string $objectId Limit the search by object id * @param string $verb Limit the verb of the comment + * @param int $offset + * @param int $limit * @return IComment[] * @since 14.0.0 */ - public function search(string $search, string $objectType, string $objectId, string $verb): array; + public function search(string $search, string $objectType, string $objectId, string $verb, int $offset, int $limit = 50): array; /** * @param $objectType string the object type, e.g. 'files' -- cgit v1.2.3