Allow to filter the unread count by verb

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2018-07-30 09:41:51 +02:00
parent 566800b29c
commit 66945f9574
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
3 changed files with 10 additions and 4 deletions

View File

@ -546,12 +546,13 @@ class Manager implements ICommentsManager {
* @param $objectId string the id of the object
* @param \DateTime $notOlderThan optional, timestamp of the oldest comments
* that may be returned
* @param string $verb Limit the verb of the comment - Added in 14.0.0
* @return Int
* @since 9.0.0
*/
public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null) {
public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null, $verb = '') {
$qb = $this->dbConn->getQueryBuilder();
$query = $qb->select($qb->createFunction('COUNT(`id`)'))
$query = $qb->select($qb->createFunction('COUNT(' . $qb->getColumnName('id') . ')'))
->from('comments')
->where($qb->expr()->eq('object_type', $qb->createParameter('type')))
->andWhere($qb->expr()->eq('object_id', $qb->createParameter('id')))
@ -564,6 +565,10 @@ class Manager implements ICommentsManager {
->setParameter('notOlderThan', $notOlderThan, 'datetime');
}
if ($verb !== '') {
$query->andWhere($qb->expr()->eq('verb', $qb->createNamedParameter($verb)));
}
$resultStatement = $query->execute();
$data = $resultStatement->fetch(\PDO::FETCH_NUM);
$resultStatement->closeCursor();

View File

@ -157,10 +157,11 @@ interface ICommentsManager {
* @param $objectId string the id of the object
* @param \DateTime|null $notOlderThan optional, timestamp of the oldest comments
* that may be returned
* @param string $verb Limit the verb of the comment - Added in 14.0.0
* @return Int
* @since 9.0.0
*/
public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null);
public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null, $verb = '');
/**
* Get the number of unread comments for all files in a folder

View File

@ -30,7 +30,7 @@ class FakeManager implements ICommentsManager {
int $limit = 30
): array { return []; }
public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null) {}
public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null, $verb = '') {}
public function search(string $search, string $objectType, string $objectId, string $verb, int $offset, int $limit = 50): array {
return [];