Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to filter the unread count by verb #10444

Merged
merged 1 commit into from
Jul 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/private/Comments/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -546,12 +546,13 @@ public function search(string $search, string $objectType, string $objectId, str
* @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')))
Expand All @@ -564,6 +565,10 @@ public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $
->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();
Expand Down
3 changes: 2 additions & 1 deletion lib/public/Comments/ICommentsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,11 @@ public function search(string $search, string $objectType, string $objectId, str
* @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
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Comments/FakeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getForObjectSince(
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 [];
Expand Down