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

WIP: Merge Onsite notifications into release-3.1.0 #110

Open
wants to merge 9 commits into
base: release-3.1.0
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
12 changes: 8 additions & 4 deletions src/com_tjnotifications/admin/models/fields/backends.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
4 changes: 2 additions & 2 deletions src/com_tjnotifications/admin/models/fields/clients.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* Custom field to list all client of tjnotification
*
* @since __DEPLOY_VERSION__
* @since 2.1.0
*/
class JFormFieldClients extends JFormFieldList
{
Expand All @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @package Tjnotifications
* @subpackage component
* @since __DEPLOY_VERSION__
* @since 2.0.0
*/

class JFormFieldMobilenumberfields extends JFormFieldGroupedList
Expand All @@ -30,15 +30,15 @@ class JFormFieldMobilenumberfields extends JFormFieldGroupedList
* The form field type.
*
* @var string
* @since __DEPLOY_VERSION__
* @since 2.1.0
*/
protected $type = 'mobilenumberfields';

/**
* Fiedd to decide if options are being loaded externally and from xml
*
* @var integer
* @since __DEPLOY_VERSION__
* @since 2.0.0
*/
protected $loadExternally = 0;

Expand All @@ -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()
{
Expand Down
28 changes: 28 additions & 0 deletions src/com_tjnotifications/admin/models/forms/notification.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,34 @@
</fieldset>
</fields>

<fields name="onsite">
<fieldset name="onsite_fieldset">
<field
name="state"
type="radio"
default="0"
label="COM_TJNOTIFICATIONS_FIELD_ONSITE_STATUS_LABEL"
description="COM_TJNOTIFICATIONS_FIELD_ONSITE_STATUS_DESC"
class="btn-group btn-group-yesno"
>
<option value="1">JON</option>
<option value="0">JOFF</option>
</field>

<field
name="onsitefields"
description="COM_TJNOTIFICATIONS_ONSITE_FIELDS_DESC"
type="subform"
label="COM_TJNOTIFICATIONS_ONSITE_FIELDS"
min="1"
formsource="/administrator/components/com_tjnotifications/models/forms/onsitefields.xml"
multiple="true"
buttons="add,remove"
layout="joomla.form.field.subform.repeatable"
groupByFieldset="false" />
</fieldset>
</fields>

<fields name="push">
<fieldset name="push_fieldset">
<field
Expand Down
30 changes: 30 additions & 0 deletions src/com_tjnotifications/admin/models/forms/onsitefields.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<form>
<fieldset>
<field
name="id"
type="hidden" />

<field
name="language"
type="contentlanguage"
label="JFIELD_LANGUAGE_LABEL"
description="COM_TJNOTIFICATIONS_NOTIFICATION_LANGUAGE_DESC"
required="true"
>
<option value="*">JALL</option>
</field>

<field
name="body"
type="textarea"
label="COM_TJNOTIFICATIONS_FIELD_ONSITE_BODY_LABEL"
description="COM_TJNOTIFICATIONS_FIELD_ONSITE_BODY_DESC"
rows="10"
cols="150"
filter="JComponentHelper::filterText"
class="validate-json"
required="true"
/>
</fieldset>
</form>
10 changes: 5 additions & 5 deletions src/com_tjnotifications/admin/models/logs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/com_tjnotifications/admin/models/notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ public function deleteBackendConfigs($backendConfigIdsToBeDeleted)
*
* @return void
*
* @since __DEPLOY_VERSION__
* @since 2.0.0
*/
public function updateTemplates($template, $client)
{
Expand Down
1 change: 1 addition & 0 deletions src/com_tjnotifications/admin/models/subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function __construct($config = array())
'address', 'a.address',
'platform', 'a.platform',
'state', 'a.state',
'user_id', 'a.user_id',
);
}

Expand Down
21 changes: 21 additions & 0 deletions src/com_tjnotifications/admin/sql/install.mysql.utf8.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
20 changes: 20 additions & 0 deletions src/com_tjnotifications/admin/sql/updates/mysql/2.1.0.sql
Original file line number Diff line number Diff line change
@@ -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;

34 changes: 34 additions & 0 deletions src/com_tjnotifications/admin/tables/onsitenotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* @package Tjnotifications
* @subpackage tjnotifications
*
* @copyright Copyright (C) 2009 - 2021 Techjoomla. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/

// No direct access
defined('_JEXEC') or die('Restricted access');

use Joomla\CMS\Table\Table;

/**
* Table class for message
*
* @package Tjnotifications
*
* @since 2.1.0
*/
class TjnotificationsTableOnsiteNotification extends Table
{
/**
* Constructor
*
* @param \JDatabaseDriver &$db \JDatabaseDriver object.
*/
public function __construct(&$db)
{
parent::__construct('#__tjnotifications_notifications', 'id', $db);
$this->setColumnAlias('published', 'state');
}
}
3 changes: 2 additions & 1 deletion src/com_tjnotifications/admin/views/logs/tmpl/body.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@

<div class="col-xs-12">
<?php
if ($logTable->backend !== 'push')
// @TODO - detect of body is json insted of checking for backends
if ($logTable->backend !== 'push' && $logTable->backend !== 'onsite')
{
echo $logTable->body;
}
Expand Down
66 changes: 66 additions & 0 deletions src/com_tjnotifications/site/controllers/messageform.json.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* @package Tjnotifications
* @subpackage tjnotifications
*
* @copyright Copyright (C) 2009 - 2021 Techjoomla. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/

// No direct access
defined('_JEXEC') or die('Restricted access');

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\FormController;

/**
* Controller for form for message
*
* @package Tjnotifications
*
* @since 2.1.0
*/
class TjnotificationsControllerMessageform extends FormController
{
/**
* Method to remove data
*
* @return void
*
* @throws Exception
*
* @since 2.1.0
*/
public function markAsRead()
{
$app = Factory::getApplication();
$model = $this->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();
}
}
Loading