backend !== 'push')
+ // @TODO - detect of body is json insted of checking for backends
+ if ($logTable->backend !== 'push' && $logTable->backend !== 'onsite')
{
echo $logTable->body;
}
diff --git a/src/com_tjnotifications/site/controllers/messageform.json.php b/src/com_tjnotifications/site/controllers/messageform.json.php
new file mode 100644
index 00000000..18464884
--- /dev/null
+++ b/src/com_tjnotifications/site/controllers/messageform.json.php
@@ -0,0 +1,66 @@
+getModel('MessageForm', 'TjnotificationsModel');
+ $pk = $app->input->post->get('id');
+ $result = array();
+
+ if (empty($pk))
+ {
+ $result['success'] = false;
+ $result['message'] = Text::_('COM_TJNOTIFICATIONS_ERROR_NO_ID_PASSED');
+ }
+ else
+ {
+ // Attempt to update data
+ try
+ {
+ $model->markAsRead($pk);
+
+ $result['success'] = true;
+ }
+ catch (Exception $e)
+ {
+ $result['success'] = false;
+ $result['message'] = Text::_($e->getMessage());
+ }
+ }
+
+ echo json_encode($result);
+ jexit();
+ }
+}
diff --git a/src/com_tjnotifications/site/controllers/messages.php b/src/com_tjnotifications/site/controllers/messages.php
new file mode 100644
index 00000000..8017a1e5
--- /dev/null
+++ b/src/com_tjnotifications/site/controllers/messages.php
@@ -0,0 +1,197 @@
+ true));
+
+ return $model;
+ }
+
+ /**
+ * Method to get list of notification messages
+ *
+ * @param string $type Type of messages
+ *
+ * @return array
+ *
+ * @since 2.1.0
+ */
+ protected function getNotifications($type = 'new')
+ {
+ $result = array();
+
+ $model = $this->getModel('Messages');
+ $jinput = Factory::getApplication()->input;
+ $userid = $jinput->get('userid', '', 'int');
+
+ // Return result related to specified activity type
+ if (empty($userid))
+ {
+ $result['success'] = false;
+ $result['message'] = Text::_('COM_TJNOTIFICATIONS_ERROR_NO_USERID_PASSED');
+
+ return $result;
+ }
+
+ if ($type == 'new')
+ {
+ // Set model state
+ // $model->setState("filter.recepient", $userid);
+ $notifications = $model->getUndeliveredNotifications($userid);
+
+ // To mark these as delivered, get keys
+ $notificationPks = array();
+
+ foreach ($notifications as $notficationItem)
+ {
+ $notificationPks[] = $notficationItem->id;
+ }
+
+ BaseDatabaseModel::addIncludePath(JPATH_SITE . '/components/com_tjnotifications/models', 'MessageformModel');
+ $messageFormModel = BaseDatabaseModel::getInstance('Messageform', 'TjnotificationsModel');
+
+ // Mark these as delivered
+ $messageFormModel->updateNotificationStatus('delivered', $notificationPks, 1, $userid);
+ }
+ elseif ($type == 'all')
+ {
+ $start = $jinput->get('start', '0');
+ $limit = $jinput->get('limit');
+
+ // Set model state
+ $model->setState("list.limit", $limit);
+ $model->setState("list.start", $start);
+ $model->setState("filter.recepient", $userid);
+ $notifications = $model->getItems();
+ }
+
+ // If no activities found then return the error message
+ if (empty($notifications))
+ {
+ $result['success'] = false;
+ $result['message'] = Text::_("COM_TJNOTIFICATIONS_MSG_NO_NOTIFICATIONS_FOUND");
+ }
+ else
+ {
+ $result['success'] = true;
+ $result['notifications'] = $notifications;
+ $result['notifications']['total'] = $model->getTotal();
+ }
+
+ return $result;
+ }
+
+ /**
+ * Method to get list of notification messages
+ *
+ * @return string
+ *
+ * @since 2.1.0
+ */
+ public function getMessages()
+ {
+ $notifications = $this->getNotifications('all');
+ echo json_encode($notifications);
+ jexit();
+ }
+
+ /**
+ * Method to get list of unread messages as SSE - server sent events
+ * Code based on com_easysocial/polling.php [v4.0]
+ *
+ * @return string
+ *
+ * @since 2.1.0
+ */
+ public function getNewMessagesStream()
+ {
+ header("Content-Type: text/event-stream");
+ header("Cache-Control: no-cache");
+ header("X-Accel-Buffering: no");
+ header("Access-Control-Allow-Origin: *");
+
+ while (true)
+ {
+ $notifications = $this->getNotifications('new');
+
+ ob_start();
+ ?>
+
+
+data:
+
+data:
+
+
+
+ buffer:
+
+ getDbo();
+ $query = $db->getQuery(true);
+
+ // Fields to update.
+ if ($statusType == 'delivered')
+ {
+ $fields = array($db->quoteName('delivered') . ' = ' . (int) $status);
+ }
+
+ if ($statusType == 'read')
+ {
+ $fields = array($db->quoteName('read') . ' = ' . (int) $status);
+ }
+
+ // Conditions
+ $whereConditions = array();
+
+ if (is_array($notificationPks) && count($notificationPks))
+ {
+ $whereConditions[] = $db->quoteName('id') . ' IN (' . implode(', ', $notificationPks) . ')';
+ }
+ else
+ {
+ $whereConditions[] = $db->quoteName('id') . ' = ' . $notificationPks;
+ }
+
+ if ($userId)
+ {
+ $whereConditions[] = $db->quoteName('recepient') . ' = ' . (int) $userId;
+ }
+ else
+ {
+ $whereConditions[] = $db->quoteName('recepient') . ' = ' . Factory::getUser()->id;
+ }
+
+ $query
+ ->update($db->quoteName('#__tjnotifications_notifications'))
+ ->set($fields)
+ ->where($whereConditions);
+
+ $db->setQuery($query);
+
+ return $db->execute();
+ }
+
+ /**
+ * Method to mark notifications as read
+ *
+ * @param int $pk The id of the row to mark as read
+ *
+ * @return boolean True on success, false on failure.
+ *
+ * @since 2.1.0
+ */
+ public function markAsRead($pk)
+ {
+ return $this->updateNotificationStatus('read', $pk, 1);
+ }
+}
diff --git a/src/com_tjnotifications/site/models/messages.php b/src/com_tjnotifications/site/models/messages.php
new file mode 100644
index 00000000..aeaec044
--- /dev/null
+++ b/src/com_tjnotifications/site/models/messages.php
@@ -0,0 +1,169 @@
+getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
+ $this->setState('filter.search', $context);
+ }
+
+ /**
+ * Build an SQL query to load the list data.
+ *
+ * @return JDatabaseQuery
+ *
+ * @since 2.1.0
+ */
+ protected function getListQuery()
+ {
+ // Create a new query object.
+ $db = $this->getDbo();
+ $query = $db->getQuery(true);
+
+ // Select the required fields from the table.
+ // $query->select($this->getState('list.select, DISTINCT a.*'));
+ $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 published state
+ $recepient = $this->getState('filter.recepient');
+
+ if (is_numeric($recepient))
+ {
+ $query->where('a.recepient = ' . (int) $recepient);
+ }
+
+ // Add the list ordering clause.
+ $orderCol = $this->state->get('list.ordering', "a.id");
+ $orderDirn = $this->state->get('list.direction', "desc");
+
+ if ($orderCol && $orderDirn)
+ {
+ $query->order($db->escape($orderCol . ' ' . $orderDirn));
+ }
+
+ return $query;
+ }
+
+ /**
+ * Get an array of data items
+ *
+ * @return mixed Array of data items on success, false on failure.
+ */
+ public function getItems()
+ {
+ $items = parent::getItems();
+
+ // Do processing as needed
+
+ return $items;
+ }
+
+ /**
+ * Get undelivered notifications
+ *
+ * @param string $userid Userid
+ *
+ * @return void|array
+ */
+ public function getUndeliveredNotifications($userid)
+ {
+ // Create a new query object.
+ $db = $this->getDbo();
+ $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->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.delivered = 0');
+
+ // Add the list ordering clause.
+ $orderCol = $this->state->get('list.ordering', "a.id");
+ $orderDirn = $this->state->get('list.direction', "desc");
+
+ if ($orderCol && $orderDirn)
+ {
+ $query->order($db->escape($orderCol . ' ' . $orderDirn));
+ }
+
+ $undeliveredNotifications = $db->setQuery($query)->loadObjectList();
+
+ if (empty($undeliveredNotifications))
+ {
+ return;
+ }
+
+ return $undeliveredNotifications;
+ }
+}
diff --git a/src/com_tjnotifications/tjnotifications.xml b/src/com_tjnotifications/tjnotifications.xml
index 0a7d543c..4ce33d7d 100644
--- a/src/com_tjnotifications/tjnotifications.xml
+++ b/src/com_tjnotifications/tjnotifications.xml
@@ -4,10 +4,10 @@
Techjoomla
extensions@techjoomla.com
https://techjoomla.com
-
Copyright (C) 2016 - 2020 Techjoomla. All rights reserved.
+
Copyright (C) 2016 - 2021 Techjoomla. All rights reserved.
http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
-
17th Jun 2020
-
2.0.0
+
27th Jan 2021
+
2.1.0
sql/install.mysql.utf8.sql
diff --git a/src/plugins/actionlog/tjnotification/tjnotification.xml b/src/plugins/actionlog/tjnotification/tjnotification.xml
index 31dff045..f5d84350 100644
--- a/src/plugins/actionlog/tjnotification/tjnotification.xml
+++ b/src/plugins/actionlog/tjnotification/tjnotification.xml
@@ -2,12 +2,12 @@
plg_actionlog_tjnotification
Techjoomla
- 17th Jun 2020
- Copyright (C) 2016 - 2020 Techjoomla. All rights reserved.
+ 27th Jan 2021
+ Copyright (C) 2016 - 2021 Techjoomla. All rights reserved.
http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
extensions@techjoomla.com
https://techjoomla.com
- 2.0.0
+ 2.1.0
PLG_ACTIONLOG_TJNOTIFICATION_XML_DESCRIPTION
tjnotification.php
diff --git a/src/plugins/api/tjnotifications/tjnotifications.xml b/src/plugins/api/tjnotifications/tjnotifications.xml
index c5624b25..57449fe8 100644
--- a/src/plugins/api/tjnotifications/tjnotifications.xml
+++ b/src/plugins/api/tjnotifications/tjnotifications.xml
@@ -5,10 +5,10 @@
Techjoomla
extensions@techjoomla.com
https://techjoomla.com
- 17th Jun 2020
- Copyright (C) 2016 - 2020 Techjoomla. All rights reserved.
+ 27th Jan 2021
+ Copyright (C) 2016 - 2021 Techjoomla. All rights reserved.
http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
- 2.0.0
+ 2.1.0
tjnotifications.php
diff --git a/src/plugins/api/tjnotifications/tjnotifications/messagemarkasread.php b/src/plugins/api/tjnotifications/tjnotifications/messagemarkasread.php
new file mode 100644
index 00000000..5f322011
--- /dev/null
+++ b/src/plugins/api/tjnotifications/tjnotifications/messagemarkasread.php
@@ -0,0 +1,75 @@
+input;
+ $pk = $input->post->get('id', 0, 'int');
+
+ if (empty($pk))
+ {
+ ApiError::raiseError(400, Text::_('ID field not passed'));
+ }
+
+ // Get TJNotifications notifications list
+ BaseDatabaseModel::addIncludePath(JPATH_SITE . '/components/com_tjnotifications/models', 'MessageformModel');
+ $messageFormModel = BaseDatabaseModel::getInstance('Messageform', 'TjnotificationsModel');
+
+ $result = array();
+
+ try
+ {
+ // Mark these as read
+ $messageFormModel->updateNotificationStatus('read', $pk, 1);
+ $result['success'] = true;
+ }
+ catch (\Exception $e)
+ {
+ ApiError::raiseError(400, Text::_($e->getMessage()));
+ }
+
+ $this->plugin->setResponse($result);
+ }
+}
diff --git a/src/plugins/api/tjnotifications/tjnotifications/messages.php b/src/plugins/api/tjnotifications/tjnotifications/messages.php
new file mode 100644
index 00000000..8fb99f1f
--- /dev/null
+++ b/src/plugins/api/tjnotifications/tjnotifications/messages.php
@@ -0,0 +1,83 @@
+input;
+ $user = Factory::getUser();
+
+ $start = $input->get('start', 0, 'int');
+ $limit = $input->get('limit', '', 'int');
+ $userid = $input->get('userid', '', 'int');
+
+ if (empty($userid))
+ {
+ $userid = $user->id;
+ }
+
+ // Get TJNotifications notifications list
+ BaseDatabaseModel::addIncludePath(JPATH_SITE . '/components/com_tjnotifications/models', 'MessagesModel');
+ $model = ListModel::getInstance('Messages', 'TjnotificationsModel', array('ignore_request' => true));
+
+ $model->setState("list.limit", $limit);
+ $model->setState("list.start", $start);
+ $model->setState("filter.recepient", $userid);
+ $notifications = $model->getItems();
+
+ $result = array();
+
+ if (empty($notifications))
+ {
+ $result['message'] = Text::_("No data");
+ }
+ else
+ {
+ $result['notifications'] = $notifications;
+ $result['notifications']['total'] = $model->getTotal();
+ }
+
+ $this->plugin->setResponse($result);
+ }
+}
diff --git a/src/plugins/api/tjnotifications/tjnotifications/subscription.php b/src/plugins/api/tjnotifications/tjnotifications/subscription.php
index 87de374d..c7cfef06 100644
--- a/src/plugins/api/tjnotifications/tjnotifications/subscription.php
+++ b/src/plugins/api/tjnotifications/tjnotifications/subscription.php
@@ -1,13 +1,14 @@
- * @package JTicketing
- * @author Techjoomla
- * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved.
- * @license GNU General Public License version 2 or later.
+ * @package Tjnotifications
+ * @subpackage api.tjnotifications
+ *
+ * @copyright Copyright (C) 2009 - 2021 Techjoomla. All rights reserved.
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/
-defined('_JEXEC') or die;
+// No direct access
+defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
@@ -48,6 +49,7 @@ public function get()
public function post()
{
$input = Factory::getApplication()->input;
+ $user = Factory::getUser();
$title = $input->post->get('title', '', 'string');
$backend = $input->post->get('backend', '', 'string');
@@ -57,10 +59,16 @@ public function post()
$state = $input->post->get('state', '', 'int');
$isConfirmed = $input->post->get('is_confirmed', '', 'int');
+ if (empty($backend) || empty($address) || empty($state) || empty($isConfirmed))
+ {
+ ApiError::raiseError(400, Text::_('Missing required fields'));
+ }
+
// GLOBAL - Get TJNotifications subscriptions details for current user
$model = ListModel::getInstance('Subscriptions', 'TjnotificationsModel', array('ignore_request' => true));
- $model->setState('filter.backend', $backend);
$model->setState('filter.address', $address);
+ $model->setState('filter.backend', $backend);
+ $model->setState('filter.user_id', $user->id);
$userSubscriptions = $model->getItems();
if (empty($userSubscriptions))
@@ -75,8 +83,6 @@ public function post()
Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjnotifications/tables');
$table = Table::getInstance('Subscription', 'TjnotificationsTable');
- $user = Factory::getUser();
-
$data = array (
'user_id' => $user->id,
'title' => $title,
diff --git a/src/plugins/privacy/tjnotification/tjnotification.xml b/src/plugins/privacy/tjnotification/tjnotification.xml
index 165335bf..428f7f5f 100644
--- a/src/plugins/privacy/tjnotification/tjnotification.xml
+++ b/src/plugins/privacy/tjnotification/tjnotification.xml
@@ -1,12 +1,12 @@
plg_privacy_tjnotification
- 2.0.0
- 17th Jun 2020
+ 2.1.0
+ 27th Jan 2021
Techjoomla
extensions@techjoomla.com
https://techjoomla.com
- Copyright (C) 2016 - 2020 Techjoomla. All rights reserved.
+ Copyright (C) 2016 - 2021 Techjoomla. All rights reserved.
http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
PLG_PRIVACY_TJNOTIFICATION_XML_DESCRIPTION
diff --git a/src/plugins/user/tjnotificationsmobilenumber/tjnotificationsmobilenumber.xml b/src/plugins/user/tjnotificationsmobilenumber/tjnotificationsmobilenumber.xml
index 8cca3963..b2a05938 100644
--- a/src/plugins/user/tjnotificationsmobilenumber/tjnotificationsmobilenumber.xml
+++ b/src/plugins/user/tjnotificationsmobilenumber/tjnotificationsmobilenumber.xml
@@ -3,12 +3,12 @@
plg_user_tjnotificationsmobilenumber
PLG_USER_TJNOTIFICATIONSMOBILENUMBER_XML_DESCRIPTION
Techjoomla
- contact@techjoomla.com
- https:/techjoomla.com
- 5 Oct 2020
- Copyright (C) 2009 - 2019 Techjoomla. All rights reserved.
- http:/www.gnu.org/licenses/gpl-2.0.html GNU/GPL
- 1.0.0
+ extensions@techjoomla.com
+ https://techjoomla.com
+ 27th Jan 2021
+ Copyright (C) 2016 - 2021 Techjoomla. All rights reserved.
+ http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
+ 2.1.0
tjnotificationsmobilenumber.php