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..d874e74b 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..bd39cd08 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 unread 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 read = 0 + $query->where('a.read = 0'); + + $unreadNotificationsCount = $db->setQuery($query)->loadResult(); + + if (empty($unreadNotificationsCount)) + { + return; + } + + return $unreadNotificationsCount; + } }