Add methods to get the number of comments and last comment since a date
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
2cc35cc65d
commit
326640462b
|
@ -591,6 +591,61 @@ class Manager implements ICommentsManager {
|
|||
return (int)$data[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $objectType
|
||||
* @param string $objectId
|
||||
* @param int $lastRead
|
||||
* @param string $verb
|
||||
* @return int
|
||||
* @since 21.0.0
|
||||
*/
|
||||
public function getNumberOfCommentsForObjectSinceComment(string $objectType, string $objectId, int $lastRead, string $verb = ''): int {
|
||||
$query = $this->dbConn->getQueryBuilder();
|
||||
$query->select($query->func()->count('id', 'num_messages'))
|
||||
->from('comments')
|
||||
->where($query->expr()->eq('object_type', $query->createNamedParameter($objectType)))
|
||||
->andWhere($query->expr()->eq('object_id', $query->createNamedParameter($objectId)))
|
||||
->andWhere($query->expr()->gt('id', $query->createNamedParameter($lastRead)));
|
||||
|
||||
if ($verb !== '') {
|
||||
$query->andWhere($query->expr()->eq('verb', $query->createNamedParameter($verb)));
|
||||
}
|
||||
|
||||
$result = $query->execute();
|
||||
$data = $result->fetch();
|
||||
$result->closeCursor();
|
||||
|
||||
return (int) ($data['num_messages'] ?? 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $objectType
|
||||
* @param string $objectId
|
||||
* @param \DateTime $beforeDate
|
||||
* @param string $verb
|
||||
* @return int
|
||||
* @since 21.0.0
|
||||
*/
|
||||
public function getLastCommentBeforeDate(string $objectType, string $objectId, \DateTime $beforeDate, string $verb = ''): int {
|
||||
$query = $this->dbConn->getQueryBuilder();
|
||||
$query->select('id')
|
||||
->from('comments')
|
||||
->where($query->expr()->eq('object_type', $query->createNamedParameter($objectType)))
|
||||
->andWhere($query->expr()->eq('object_id', $query->createNamedParameter($objectId)))
|
||||
->andWhere($query->expr()->lt('creation_timestamp', $query->createNamedParameter($beforeDate, IQueryBuilder::PARAM_DATE)))
|
||||
->orderBy('creation_timestamp', 'desc');
|
||||
|
||||
if ($verb !== '') {
|
||||
$query->andWhere($query->expr()->eq('verb', $query->createNamedParameter($verb)));
|
||||
}
|
||||
|
||||
$result = $query->execute();
|
||||
$data = $result->fetch();
|
||||
$result->closeCursor();
|
||||
|
||||
return (int) ($data['id'] ?? 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of unread comments for all files in a folder
|
||||
*
|
||||
|
|
|
@ -166,6 +166,26 @@ interface ICommentsManager {
|
|||
*/
|
||||
public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null, $verb = '');
|
||||
|
||||
/**
|
||||
* @param string $objectType
|
||||
* @param string $objectId
|
||||
* @param int $lastRead
|
||||
* @param string $verb
|
||||
* @return int
|
||||
* @since 21.0.0
|
||||
*/
|
||||
public function getNumberOfCommentsForObjectSinceComment(string $objectType, string $objectId, int $lastRead, string $verb = ''): int;
|
||||
|
||||
/**
|
||||
* @param string $objectType
|
||||
* @param string $objectId
|
||||
* @param \DateTime $beforeDate
|
||||
* @param string $verb
|
||||
* @return int
|
||||
* @since 21.0.0
|
||||
*/
|
||||
public function getLastCommentBeforeDate(string $objectType, string $objectId, \DateTime $beforeDate, string $verb = ''): int;
|
||||
|
||||
/**
|
||||
* Get the number of unread comments for all files in a folder
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue