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 bf4af7d6..19810d2e 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,7 @@ 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_WHATSAPP="Whatsapp" COM_TJNOTIFICATIONS_PLATFORM_LIST_CHOOSE="Choose platform" COM_TJNOTIFICATIONS_PLATFORM_ANDROID="Android" @@ -286,3 +286,15 @@ COM_TJNOTIFICATIONS_NOTIFICATION_SMS_REMAINING_EXCEEDED="characters exceeded" ; Notification - SMS provider template ID COM_TJNOTIFICATIONS_FIELD_SMS_TEMPLATE_ID_LABEL="SMS template ID" COM_TJNOTIFICATIONS_FIELD_SMS_TEMPLATE_ID_DESC="Set template ID which is proided by SMS provider" + +; Since v2.1.0 +; Onsite notifications +COM_TJNOTIFICATIONS_BACKEND_ONSITE="Onsite" +COM_TJNOTIFICATIONS_VIEW_NOTIFICATION_TAB_ONSITE="Onsite Notification" +COM_TJNOTIFICATIONS_FIELD_ONSITE_STATUS_LABEL="Onsite Notification Status" +COM_TJNOTIFICATIONS_FIELD_ONSITE_STATUS_DESC="Turn on this after filling the body to send an Onsite notification" +COM_TJNOTIFICATIONS_ONSITE_FIELDS="Onsite Notification Fields" +COM_TJNOTIFICATIONS_ONSITE_FIELDS_DESC="Set onsite notification fields" +COM_TJNOTIFICATIONS_FIELD_ONSITE_BODY_LABEL="Onsite Notification Body" +COM_TJNOTIFICATIONS_FIELD_ONSITE_BODY_DESC="Enter body for your Onsite notification" +COM_TJNOTIFICATIONS_VIEW_NOTIFICATIONS_DEFAULT_ONSITE_TITLE="Onsite Notification" diff --git a/src/com_tjnotifications/admin/models/fields/backends.php b/src/com_tjnotifications/admin/models/fields/backends.php index 213c57a4..fa6bcb5b 100644 --- a/src/com_tjnotifications/admin/models/fields/backends.php +++ b/src/com_tjnotifications/admin/models/fields/backends.php @@ -41,10 +41,14 @@ protected function getOptions() $options = array(); $options[] = JHtml::_('select.option', '', Text::_('COM_TJNOTIFICATIONS_BACKEND_LIST_CHOOSE')); - $options[] = JHtml::_('select.option', 'email', Text::_('COM_TJNOTIFICATIONS_BACKEND_EMAIL')); - $options[] = JHtml::_('select.option', 'push', Text::_('COM_TJNOTIFICATIONS_BACKEND_PUSH')); - $options[] = JHtml::_('select.option', 'sms', Text::_('COM_TJNOTIFICATIONS_BACKEND_SMS')); - $options[] = JHtml::_('select.option', 'whatsapp', Text::_('COM_TJNOTIFICATIONS_BACKEND_WHATSAPP')); + + require_once JPATH_ADMINISTRATOR . '/components/com_tjnotifications/defines.php'; + $backendsArray = explode(',', TJNOTIFICATIONS_CONST_BACKENDS_ARRAY); + + foreach ($backendsArray as $backend) + { + $options[] = JHtml::_('select.option', $backend, Text::_('COM_TJNOTIFICATIONS_BACKEND_' . strtoupper($backend))); + } return array_merge(parent::getOptions(), array_values($options)); } diff --git a/src/com_tjnotifications/admin/models/fields/clients.php b/src/com_tjnotifications/admin/models/fields/clients.php index 069ea3ed..7b506168 100644 --- a/src/com_tjnotifications/admin/models/fields/clients.php +++ b/src/com_tjnotifications/admin/models/fields/clients.php @@ -17,7 +17,7 @@ /** * Custom field to list all client of tjnotification * - * @since __DEPLOY_VERSION__ + * @since 2.1.0 */ class JFormFieldClients extends JFormFieldList { @@ -26,7 +26,7 @@ class JFormFieldClients extends JFormFieldList * * @return array An array of JHtml options. * - * @since __DEPLOY_VERSION__ + * @since 2.1.0 */ protected function getOptions() { diff --git a/src/com_tjnotifications/admin/models/fields/mobilenumberfields.php b/src/com_tjnotifications/admin/models/fields/mobilenumberfields.php index 8ed3d313..35bcea91 100644 --- a/src/com_tjnotifications/admin/models/fields/mobilenumberfields.php +++ b/src/com_tjnotifications/admin/models/fields/mobilenumberfields.php @@ -21,7 +21,7 @@ * * @package Tjnotifications * @subpackage component - * @since __DEPLOY_VERSION__ + * @since 2.0.0 */ class JFormFieldMobilenumberfields extends JFormFieldGroupedList @@ -30,7 +30,7 @@ class JFormFieldMobilenumberfields extends JFormFieldGroupedList * The form field type. * * @var string - * @since __DEPLOY_VERSION__ + * @since 2.1.0 */ protected $type = 'mobilenumberfields'; @@ -38,7 +38,7 @@ class JFormFieldMobilenumberfields extends JFormFieldGroupedList * Fiedd to decide if options are being loaded externally and from xml * * @var integer - * @since __DEPLOY_VERSION__ + * @since 2.0.0 */ protected $loadExternally = 0; @@ -47,7 +47,7 @@ class JFormFieldMobilenumberfields extends JFormFieldGroupedList * * @return array An array of HTMLHelper options. * - * @since __DEPLOY_VERSION__ + * @since 2.0.0 */ protected function getGroups() { diff --git a/src/com_tjnotifications/admin/models/forms/notification.xml b/src/com_tjnotifications/admin/models/forms/notification.xml index 35ad0195..75849295 100644 --- a/src/com_tjnotifications/admin/models/forms/notification.xml +++ b/src/com_tjnotifications/admin/models/forms/notification.xml @@ -139,6 +139,34 @@ + +
+ + + + + + +
+
+
+
+
+ + + + + + + +
+
diff --git a/src/com_tjnotifications/admin/models/logs.php b/src/com_tjnotifications/admin/models/logs.php index 7ff76190..12c0e036 100644 --- a/src/com_tjnotifications/admin/models/logs.php +++ b/src/com_tjnotifications/admin/models/logs.php @@ -61,14 +61,14 @@ public function __construct($config = array()) */ protected function populateState($ordering = 'tjl.id', $direction = 'desc') { - $app = Factory::getApplication(); + parent::populateState($ordering, $direction); + + $app = Factory::getApplication(); // Load the filter search $search = $app->getUserStateFromRequest($this->context . 'filter.search', 'filter_search'); $this->setState('filter.search', $search); - parent::populateState($ordering, $direction); - // Get pagination request variables $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->get('list_limit'), 'int'); $limitstart = Factory::getApplication()->input->post->get('limitstart'); @@ -141,8 +141,8 @@ protected function getListQuery() ); } - $orderCol = $this->getState('list.ordering'); - $orderDirn = $this->getState('list.direction'); + $orderCol = $this->state->get('list.ordering', 'tjl.id'); + $orderDirn = $this->state->get('list.direction', 'desc'); if ($orderCol && $orderDirn) { diff --git a/src/com_tjnotifications/admin/models/notification.php b/src/com_tjnotifications/admin/models/notification.php index f0283822..33dc49e8 100644 --- a/src/com_tjnotifications/admin/models/notification.php +++ b/src/com_tjnotifications/admin/models/notification.php @@ -636,7 +636,7 @@ public function deleteBackendConfigs($backendConfigIdsToBeDeleted) * * @return void * - * @since __DEPLOY_VERSION__ + * @since 2.0.0 */ public function updateTemplates($template, $client) { diff --git a/src/com_tjnotifications/admin/models/subscriptions.php b/src/com_tjnotifications/admin/models/subscriptions.php index 85bfb807..ce0a4bd8 100644 --- a/src/com_tjnotifications/admin/models/subscriptions.php +++ b/src/com_tjnotifications/admin/models/subscriptions.php @@ -41,6 +41,7 @@ public function __construct($config = array()) 'address', 'a.address', 'platform', 'a.platform', 'state', 'a.state', + 'user_id', 'a.user_id', ); } diff --git a/src/com_tjnotifications/admin/sql/install.mysql.utf8.sql b/src/com_tjnotifications/admin/sql/install.mysql.utf8.sql index 0949f8ae..3623c058 100644 --- a/src/com_tjnotifications/admin/sql/install.mysql.utf8.sql +++ b/src/com_tjnotifications/admin/sql/install.mysql.utf8.sql @@ -90,3 +90,24 @@ CREATE TABLE IF NOT EXISTS `#__tjnotifications_subscriptions` ( PRIMARY KEY (`id`), KEY `user_id_idx` (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT=1; + +--- Since v2.1.0 +CREATE TABLE IF NOT EXISTS `#__tjnotifications_notifications` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `key` varchar(100) NOT NULL, + `client` varchar(100) NOT NULL, + `title` varchar(255) NOT NULL, + `body` text NOT NULL, + `icon` text NOT NULL, + `link` text NOT NULL, + `recepient` int(11) NOT NULL, + `created_by` int(11) NOT NULL, + `created_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `type` varchar(255) NOT NULL, + `format` varchar(255) NOT NULL, + `delivered` tinyint(1) NOT NULL, + `read` tinyint(1) NOT NULL, + PRIMARY KEY (`id`), + KEY `key_idx` (`key`), + KEY `client_idx` (`client`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT=1; diff --git a/src/com_tjnotifications/admin/sql/updates/mysql/2.1.0.sql b/src/com_tjnotifications/admin/sql/updates/mysql/2.1.0.sql new file mode 100644 index 00000000..840cc1a9 --- /dev/null +++ b/src/com_tjnotifications/admin/sql/updates/mysql/2.1.0.sql @@ -0,0 +1,20 @@ +CREATE TABLE IF NOT EXISTS `#__tjnotifications_notifications` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `key` varchar(100) NOT NULL, + `client` varchar(100) NOT NULL, + `title` varchar(255) NOT NULL, + `body` text NOT NULL, + `icon` text NOT NULL, + `link` text NOT NULL, + `recepient` int(11) NOT NULL, + `created_by` int(11) NOT NULL, + `created_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `type` varchar(255) NOT NULL, + `format` varchar(255) NOT NULL, + `delivered` tinyint(1) NOT NULL, + `read` tinyint(1) NOT NULL, + PRIMARY KEY (`id`), + KEY `key_idx` (`key`), + KEY `client_idx` (`client`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT=1; + diff --git a/src/com_tjnotifications/admin/tables/onsitenotification.php b/src/com_tjnotifications/admin/tables/onsitenotification.php new file mode 100644 index 00000000..97c2026f --- /dev/null +++ b/src/com_tjnotifications/admin/tables/onsitenotification.php @@ -0,0 +1,34 @@ +setColumnAlias('published', 'state'); + } +} diff --git a/src/com_tjnotifications/admin/views/logs/tmpl/body.php b/src/com_tjnotifications/admin/views/logs/tmpl/body.php index 9e0cd198..827560ca 100644 --- a/src/com_tjnotifications/admin/views/logs/tmpl/body.php +++ b/src/com_tjnotifications/admin/views/logs/tmpl/body.php @@ -36,7 +36,8 @@
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