Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task #0000: Update the Onsite Notification code #128

Open
wants to merge 2 commits into
base: onsite-notifications
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
11 changes: 8 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 All @@ -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();
Expand Down
42 changes: 41 additions & 1 deletion src/com_tjnotifications/site/models/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down 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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* @version SVN: <svn_id>
* @package JTicketing
* @author Techjoomla <[email protected]>
* @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);
}
}