From e520d9bb761c0dc5c3345fdd23dd14fd963cf20d Mon Sep 17 00:00:00 2001 From: nilesh5995 Date: Mon, 1 Feb 2021 15:14:59 +0530 Subject: [PATCH 1/3] Task #168295 : Add the unread message count in TJnotification component --- src/com_tjnotifications/admin/defines.php | 2 +- .../site/controllers/messages.php | 7 ++-- .../site/models/messages.php | 40 +++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/com_tjnotifications/admin/defines.php b/src/com_tjnotifications/admin/defines.php index 6dbd0a01..d3705a0a 100644 --- a/src/com_tjnotifications/admin/defines.php +++ b/src/com_tjnotifications/admin/defines.php @@ -12,5 +12,5 @@ if (!defined('TJNOTIFICATIONS_CONST_BACKENDS_ARRAY')) { - define('TJNOTIFICATIONS_CONST_BACKENDS_ARRAY', "email,sms"); + define('TJNOTIFICATIONS_CONST_BACKENDS_ARRAY', "email,sms, push, onsite"); } diff --git a/src/com_tjnotifications/site/controllers/messages.php b/src/com_tjnotifications/site/controllers/messages.php index 8017a1e5..b6198b30 100644 --- a/src/com_tjnotifications/site/controllers/messages.php +++ b/src/com_tjnotifications/site/controllers/messages.php @@ -108,9 +108,10 @@ protected function getNotifications($type = 'new') } else { - $result['success'] = true; - $result['notifications'] = $notifications; - $result['notifications']['total'] = $model->getTotal(); + $result['success'] = true; + $result['notifications'] = $notifications; + $result['total'] = $model->getTotal(); + $result['unread_notifications_count'] = (int) $model->getUnreadNotificationsCount($userid); } return $result; diff --git a/src/com_tjnotifications/site/models/messages.php b/src/com_tjnotifications/site/models/messages.php index aeaec044..e2fab126 100644 --- a/src/com_tjnotifications/site/models/messages.php +++ b/src/com_tjnotifications/site/models/messages.php @@ -166,4 +166,44 @@ public function getUndeliveredNotifications($userid) return $undeliveredNotifications; } + + /** + * Get read message count + * + * @param string $userid Userid + * + * @return void|array + */ + public function getUnreadNotificationsCount($userid) + { + // Create a new query object. + $db = $this->getDbo(); + $query = $db->getQuery(true); + + // Select the required fields from the table. + $query->select('COUNT(*)'); + $query->from('`#__tjnotifications_notifications` AS a'); + + // Filter by userid + if (!is_numeric($userid)) + { + return; + } + else + { + $query->where('a.recepient = ' . (int) $userid); + } + + // Filter by delivered = 0 + $query->where('a.read = 0'); + + $unreadNotificationsCount = $db->setQuery($query)->loadResult(); + + if (empty($unreadNotificationsCount)) + { + return; + } + + return $unreadNotificationsCount; + } } From 3e95b70473586edf82c0999770d32b8a73fb0634 Mon Sep 17 00:00:00 2001 From: nilesh5995 Date: Mon, 1 Feb 2021 15:20:41 +0530 Subject: [PATCH 2/3] The total message node is chanes --- src/com_tjnotifications/site/controllers/messages.php | 4 ++-- src/com_tjnotifications/site/models/messages.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/com_tjnotifications/site/controllers/messages.php b/src/com_tjnotifications/site/controllers/messages.php index b6198b30..960ac0c4 100644 --- a/src/com_tjnotifications/site/controllers/messages.php +++ b/src/com_tjnotifications/site/controllers/messages.php @@ -108,8 +108,8 @@ protected function getNotifications($type = 'new') } else { - $result['success'] = true; - $result['notifications'] = $notifications; + $result['success'] = true; + $result['notifications'] = $notifications; $result['total'] = $model->getTotal(); $result['unread_notifications_count'] = (int) $model->getUnreadNotificationsCount($userid); } diff --git a/src/com_tjnotifications/site/models/messages.php b/src/com_tjnotifications/site/models/messages.php index e2fab126..bd39cd08 100644 --- a/src/com_tjnotifications/site/models/messages.php +++ b/src/com_tjnotifications/site/models/messages.php @@ -168,7 +168,7 @@ public function getUndeliveredNotifications($userid) } /** - * Get read message count + * Get unread message count * * @param string $userid Userid * @@ -194,7 +194,7 @@ public function getUnreadNotificationsCount($userid) $query->where('a.recepient = ' . (int) $userid); } - // Filter by delivered = 0 + // Filter by read = 0 $query->where('a.read = 0'); $unreadNotificationsCount = $db->setQuery($query)->loadResult(); From a9f681aabc97d6bcce74e3f4a7879add652bac47 Mon Sep 17 00:00:00 2001 From: nilesh5995 Date: Mon, 1 Feb 2021 15:24:27 +0530 Subject: [PATCH 3/3] indentation changes --- src/com_tjnotifications/site/controllers/messages.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/com_tjnotifications/site/controllers/messages.php b/src/com_tjnotifications/site/controllers/messages.php index 960ac0c4..d874e74b 100644 --- a/src/com_tjnotifications/site/controllers/messages.php +++ b/src/com_tjnotifications/site/controllers/messages.php @@ -108,9 +108,9 @@ protected function getNotifications($type = 'new') } else { - $result['success'] = true; - $result['notifications'] = $notifications; - $result['total'] = $model->getTotal(); + $result['success'] = true; + $result['notifications'] = $notifications; + $result['total'] = $model->getTotal(); $result['unread_notifications_count'] = (int) $model->getUnreadNotificationsCount($userid); }