diff options
author | Joas Schilling <coding@schilljs.com> | 2018-04-18 11:29:49 +0200 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2018-07-25 18:53:44 +0200 |
commit | 8c7969e7301cb88dc6a94565ef8903c70117e750 (patch) | |
tree | b6b8026ac451449f4137feb9115b26628d86ec62 /lib/private | |
parent | 80207d72fa5de7b88dd8fd180acc528a3d9fa8da (diff) | |
download | nextcloud-server-8c7969e7301cb88dc6a94565ef8903c70117e750.tar.gz nextcloud-server-8c7969e7301cb88dc6a94565ef8903c70117e750.zip |
Allow to search by comments
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Comments/Manager.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php index d96c22aad51..a06a2a0ec59 100644 --- a/lib/private/Comments/Manager.php +++ b/lib/private/Comments/Manager.php @@ -494,6 +494,48 @@ class Manager implements ICommentsManager { } /** + * Search for comments with a given content + * + * @param string $search content to search for + * @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 + * @return IComment[] + */ + public function search(string $search, string $objectType, string $objectId, string $verb): array { + $query = $this->dbConn->getQueryBuilder(); + + $query->select('*') + ->from('comments') + ->where($query->expr()->iLike('message', $query->createNamedParameter( + '%' . $this->dbConn->escapeLikeParameter($search). '%' + ))) + ->orderBy('creation_timestamp', 'DESC') + ->addOrderBy('id', 'DESC'); + + if ($objectType !== '') { + $query->andWhere($query->expr()->eq('object_type', $query->createNamedParameter($objectType))); + } + if ($objectId !== '') { + $query->andWhere($query->expr()->eq('object_id', $query->createNamedParameter($objectId))); + } + if ($verb !== '') { + $query->andWhere($query->expr()->eq('verb', $query->createNamedParameter($verb))); + } + + $comments = []; + $result = $query->execute(); + while ($data = $result->fetch()) { + $comment = new Comment($this->normalizeDatabaseData($data)); + $this->cache($comment); + $comments[] = $comment; + } + $result->closeCursor(); + + return $comments; + } + + /** * @param $objectType string the object type, e.g. 'files' * @param $objectId string the id of the object * @param \DateTime $notOlderThan optional, timestamp of the oldest comments |