Allow to search on multiple objects with one query

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2020-10-21 09:16:42 +02:00
parent 326640462b
commit 89651c5233
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
2 changed files with 34 additions and 2 deletions

View File

@ -521,6 +521,25 @@ class Manager implements ICommentsManager {
* @return IComment[] * @return IComment[]
*/ */
public function search(string $search, string $objectType, string $objectId, string $verb, int $offset, int $limit = 50): array { public function search(string $search, string $objectType, string $objectId, string $verb, int $offset, int $limit = 50): array {
$objectIds = [];
if ($objectId) {
$objectIds[] = $objectIds;
}
return $this->searchForObjects($search, $objectType, $objectIds, $verb, $offset, $limit);
}
/**
* Search for comments on one or more objects with a given content
*
* @param string $search content to search for
* @param string $objectType Limit the search by object type
* @param array $objectIds Limit the search by object ids
* @param string $verb Limit the verb of the comment
* @param int $offset
* @param int $limit
* @return IComment[]
*/
public function searchForObjects(string $search, string $objectType, array $objectIds, string $verb, int $offset, int $limit = 50): array {
$query = $this->dbConn->getQueryBuilder(); $query = $this->dbConn->getQueryBuilder();
$query->select('*') $query->select('*')
@ -535,8 +554,8 @@ class Manager implements ICommentsManager {
if ($objectType !== '') { if ($objectType !== '') {
$query->andWhere($query->expr()->eq('object_type', $query->createNamedParameter($objectType))); $query->andWhere($query->expr()->eq('object_type', $query->createNamedParameter($objectType)));
} }
if ($objectId !== '') { if (!empty($objectIds)) {
$query->andWhere($query->expr()->eq('object_id', $query->createNamedParameter($objectId))); $query->andWhere($query->expr()->in('object_id', $query->createNamedParameter($objectIds, IQueryBuilder::PARAM_STR_ARRAY)));
} }
if ($verb !== '') { if ($verb !== '') {
$query->andWhere($query->expr()->eq('verb', $query->createNamedParameter($verb))); $query->andWhere($query->expr()->eq('verb', $query->createNamedParameter($verb)));

View File

@ -155,6 +155,19 @@ interface ICommentsManager {
*/ */
public function search(string $search, string $objectType, string $objectId, string $verb, int $offset, int $limit = 50): array; public function search(string $search, string $objectType, string $objectId, string $verb, int $offset, int $limit = 50): array;
/**
* Search for comments on one or more objects with a given content
*
* @param string $search content to search for
* @param string $objectType Limit the search by object type
* @param array $objectIds Limit the search by object ids
* @param string $verb Limit the verb of the comment
* @param int $offset
* @param int $limit
* @return IComment[]
*/
public function searchForObjects(string $search, string $objectType, array $objectIds, string $verb, int $offset, int $limit = 50): array;
/** /**
* @param $objectType string the object type, e.g. 'files' * @param $objectType string the object type, e.g. 'files'
* @param $objectId string the id of the object * @param $objectId string the id of the object