diff options
author | WENDLING NICOLAS <nicolas.wendling2@etu.unistra.fr> | 2021-01-26 16:45:53 +0100 |
---|---|---|
committer | Sean Molenaar <SMillerDev@users.noreply.github.com> | 2021-04-08 22:31:21 +0200 |
commit | ca2b8c65667df763dda85021c8bbc7cea073b4b3 (patch) | |
tree | c215bff0baf84015dfddb2528761f1c210f692b8 /lib | |
parent | 5fc486a84f2ebd5d03120766241dcabff03ae5ea (diff) |
✨ Add count for unread items
Signed-off-by: Marco Nassabain <marco.nassabain@hotmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Db/ItemMapper.php | 16 | ||||
-rw-r--r-- | lib/Service/ItemService.php | 11 |
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/Db/ItemMapper.php b/lib/Db/ItemMapper.php index 9420395c3..92993bdba 100644 --- a/lib/Db/ItemMapper.php +++ b/lib/Db/ItemMapper.php @@ -542,6 +542,22 @@ class ItemMapper extends NewsMapper return $this->findEntitiesIgnoringNegativeLimit($sql, $params, $limit); } + + /** + * Returns the count of unread shared items for user $userId + */ + public function sharedCount(string $userId) + { + $sql = 'SELECT COUNT(*) AS size FROM `*PREFIX*news_items` `items` ' . + 'WHERE `items`.`shared_with` = ? ' . + 'AND `items`.`unread` = `1`'; + + $params = [$userId]; + + $result = $this->execute($sql, $params)->fetch(); + + return (int)$result['size']; + } public function shareItem($itemId, $shareWithId, $userId) { diff --git a/lib/Service/ItemService.php b/lib/Service/ItemService.php index f1f3c968b..946c1ad30 100644 --- a/lib/Service/ItemService.php +++ b/lib/Service/ItemService.php @@ -361,4 +361,15 @@ class ItemService extends Service throw new ServiceNotFoundException($ex->getMessage()); } } + + /** + * Returns the shared count + * + * @param string $userId the name of the user + * @return int the count + */ + public function starredShared($userId) + { + return $this->itemMapper->sharedCount($userId); + } } |