diff --git a/src/com_tjnotifications/admin/language/en-GB.com_tjnotifications.ini b/src/com_tjnotifications/admin/language/en-GB.com_tjnotifications.ini index 19810d2e..260e7833 100644 --- a/src/com_tjnotifications/admin/language/en-GB.com_tjnotifications.ini +++ b/src/com_tjnotifications/admin/language/en-GB.com_tjnotifications.ini @@ -217,7 +217,10 @@ COM_TJNOTIFICATIONS_FORM_SUBSCRIPTION_TITLE_LBL="Title" COM_TJNOTIFICATIONS_FORM_SUBSCRIPTION_TITLE_DESC="Enter Title" COM_TJNOTIFICATIONS_MSG_SUCCESS_SAVE_SUBSCRIPTION="Subscription saved successfully" ; Backends list -COM_TJNOTIFICATIONS_BACKEND_LIST_CHOOSE="Choose Backend" +COM_TJNOTIFICATIONS_BACKEND_LIST_CHOOSE="Choose backend" +COM_TJNOTIFICATIONS_BACKEND_EMAIL="Email" +COM_TJNOTIFICATIONS_BACKEND_PUSH="Push" +COM_TJNOTIFICATIONS_BACKEND_SMS="SMS" COM_TJNOTIFICATIONS_BACKEND_WHATSAPP="Whatsapp" COM_TJNOTIFICATIONS_PLATFORM_LIST_CHOOSE="Choose platform" COM_TJNOTIFICATIONS_PLATFORM_ANDROID="Android" @@ -230,15 +233,20 @@ COM_TJNOTIFICATIONS_FILTER_STATE="Status" COM_TJNOTIFICATIONS_FILTER_STATE_DESC="Status" COM_TJNOTIFICATIONS_LIST_FULL_ORDERING="Sort By" COM_TJNOTIFICATIONS_LIST_FULL_ORDERING_DESC="Sort By" + +; General COM_TJNOTIFICATIONS_N_ITEMS_ARCHIVED="%d records successfully archived" COM_TJNOTIFICATIONS_N_ITEMS_ARCHIVED_1="%d record successfully archived" COM_TJNOTIFICATIONS_N_ITEMS_CHECKED_IN_0="No record successfully checked in" COM_TJNOTIFICATIONS_N_ITEMS_CHECKED_IN_1="%d record successfully checked in" COM_TJNOTIFICATIONS_N_ITEMS_CHECKED_IN_MORE="%d records successfully checked in" +COM_TJNOTIFICATIONS_N_ITEMS_DELETED="%d records successfully deleted" COM_TJNOTIFICATIONS_N_ITEMS_DELETED_1="%d record successfully deleted" +COM_TJNOTIFICATIONS_N_ITEMS_PUBLISHED="%d records successfully published" COM_TJNOTIFICATIONS_N_ITEMS_PUBLISHED_1="%d record successfully published" COM_TJNOTIFICATIONS_N_ITEMS_TRASHED="%d records successfully trashed" COM_TJNOTIFICATIONS_N_ITEMS_TRASHED_1="%d record successfully trashed" +COM_TJNOTIFICATIONS_N_ITEMS_UNPUBLISHED="%d records successfully unpublished" COM_TJNOTIFICATIONS_N_ITEMS_UNPUBLISHED_1="%d record successfully unpublished" ; Subscriptions - list view diff --git a/src/com_tjnotifications/site/controllers/messages.php b/src/com_tjnotifications/site/controllers/messages.php index 8017a1e5..6717d9a6 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; @@ -125,6 +126,10 @@ protected function getNotifications($type = 'new') */ public function getMessages() { + // Uncomment below line if we directaly call the API, and gives the cors Error + // (as Server sent events not allows us to sent the bearer token, then we can use this function directly by sending the user id.) + + // header("Access-Control-Allow-Origin: *"); $notifications = $this->getNotifications('all'); echo json_encode($notifications); jexit(); diff --git a/src/com_tjnotifications/site/models/messages.php b/src/com_tjnotifications/site/models/messages.php index aeaec044..9e343df3 100644 --- a/src/com_tjnotifications/site/models/messages.php +++ b/src/com_tjnotifications/site/models/messages.php @@ -132,7 +132,7 @@ public function getUndeliveredNotifications($userid) $query = $db->getQuery(true); // Select the required fields from the table. - $query->select('a.id, a.title, a.body, a.icon, a.link, a.created_on'); + $query->select('a.id, a.title, a.body, a.icon, a.link, a.created_on, a.read'); $query->from('`#__tjnotifications_notifications` AS a'); // Filter by userid @@ -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; + } } diff --git a/src/plugins/api/tjnotifications/tjnotifications/notificationlogs.php b/src/plugins/api/tjnotifications/tjnotifications/notificationlogs.php new file mode 100755 index 00000000..a75427b4 --- /dev/null +++ b/src/plugins/api/tjnotifications/tjnotifications/notificationlogs.php @@ -0,0 +1,50 @@ + + * @package JTicketing + * @author Techjoomla + * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. + * @license GNU General Public License version 2 or later. + */ + +defined('_JEXEC') or die; + +use Joomla\CMS\Factory; + +/** + * Class for notification logs + * + * @package Tjnotifications + * @subpackage component + * @since 1.0 + */ +class TjnotificationsApiResourceNotificationlogs extends ApiResource +{ + /** + * Get method + * + * @return void + * + * @since 1.0 + */ + public function get() + { + $user = Factory::getUser(); + + $db = Factory::getDbo(); + $query = $db->getQuery(true); + $query->select('l.*'); + $query->from($db->quoteName('#__tj_notification_logs', 'l')); + $query->join('LEFT', $db->quoteName('#__tjnotifications_subscriptions', 's') . + ' ON (' . $db->quoteName('l.to') . ' = ' . $db->quoteName('s.address') . ')'); + $query->where($db->quoteName('s.user_id') . ' = ' . $db->q($user->id)); + $query->order($db->quoteName('l.date') . ' DESC'); + $query->setLimit('50'); + + $db->setQuery($query); + + $logs = $db->loadObjectList(); + + $this->plugin->setResponse($logs); + } +}