Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/com_tjnotifications/admin/defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
7 changes: 4 additions & 3 deletions src/com_tjnotifications/site/controllers/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
40 changes: 40 additions & 0 deletions src/com_tjnotifications/site/models/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}