Skip to content

Commit

Permalink
Issue techjoomla#48 chore: Log Email details in DB table - Tj Notific…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
manojLondhe committed Jun 8, 2020
1 parent 1591458 commit 0eb4a46
Show file tree
Hide file tree
Showing 21 changed files with 807 additions and 14 deletions.
22 changes: 11 additions & 11 deletions src/com_tjnotifications/admin/access.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<access component="com_tjnotifications">
<section name="component">
<action name="core.admin" title="JACTION_ADMIN" description="JACTION_ADMIN_COMPONENT_DESC" />
<action name="core.options" title="JACTION_OPTIONS" description="JACTION_OPTIONS_COMPONENT_DESC" />
<action name="core.manage" title="JACTION_MANAGE" description="JACTION_MANAGE_COMPONENT_DESC" />
<action name="core.view" title="JACTION_VIEW" description="JACTION_VIEW_COMPONENT_DESC" />
<action name="core.export" title="JACTION_EXPORT" description="JACTION_EXPORT_COMPONENT_DESC" />
<action name="core.create" title="JACTION_CREATE" description="JACTION_CREATE_COMPONENT_DESC" />
<action name="core.delete" title="JACTION_DELETE" description="JACTION_DELETE_COMPONENT_DESC" />
<action name="core.edit" title="JACTION_EDIT" description="JACTION_EDIT_COMPONENT_DESC" />
<action name="core.edit.state" title="JACTION_EDITSTATE" description="JACTION_EDITSTATE_COMPONENT_DESC" />
<action name="core.edit.own" title="JACTION_EDITOWN" description="JACTION_EDITOWN_COMPONENT_DESC" />
<action name="core.viewlist" title="JACTION_VIEW_LIST" description="JACTION_VIEW_LIST_DESC" />
<action name="core.admin" title="JACTION_ADMIN" description="JACTION_ADMIN_COMPONENT_DESC" />
<action name="core.options" title="JACTION_OPTIONS" description="JACTION_OPTIONS_COMPONENT_DESC" />
<action name="core.manage" title="JACTION_MANAGE" description="JACTION_MANAGE_COMPONENT_DESC" />
<action name="core.create" title="JACTION_CREATE" description="JACTION_CREATE_COMPONENT_DESC" />
<action name="core.edit" title="JACTION_EDIT" description="JACTION_EDIT_COMPONENT_DESC" />
<action name="core.edit.state" title="JACTION_EDITSTATE" description="JACTION_EDITSTATE_COMPONENT_DESC" />
<action name="core.edit.own" title="JACTION_EDITOWN" description="JACTION_EDITOWN_COMPONENT_DESC" />
<action name="core.delete" title="JACTION_DELETE" description="JACTION_DELETE_COMPONENT_DESC" />
<action name="core.view" title="JACTION_VIEW" description="JACTION_VIEW_COMPONENT_DESC" />
<action name="core.viewlist" title="JACTION_VIEW_LIST" description="JACTION_VIEW_LIST_DESC" />
<action name="core.emailstatus" title="JACTION_EMAIL_STATUS" description="JACTION_EMAIL_STATUS_DESC" />
<action name="core.usercontrol" title="JACTION_USER_CONTROL" description="JACTION_USER_CONTROL_DESC" />
<action name="core.export" title="JACTION_EXPORT" description="JACTION_EXPORT_COMPONENT_DESC" />
</section>
</access>
3 changes: 3 additions & 0 deletions src/com_tjnotifications/admin/assets/css/tjnotifcations.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.minwidth-150px{min-width:150px}
.minwidth-100px{min-width:100px}
.table-responsive{width:100%;margin-bottom:15px;overflow-x:auto;overflow-y:hidden;-webkit-overflow-scrolling:touch;-ms-overflow-style:-ms-autohiding-scrollbar}
6 changes: 6 additions & 0 deletions src/com_tjnotifications/admin/config.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<config>
<fieldset label="COM_TJNOTIFICATION" name="Notifications">
<field name="enable_logs" type="radio" class="btn-group btn-group-yesno" default="0" label="COM_TJNOTIFICATIONS_ALLOW_SAVE_OPTION" description="COM_TJNOTIFICATIONS_APPLICATION_OPTION_DESC">
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
</fieldset>
<fieldset name="permissions" description="JCONFIG_PERMISSIONS_DESC" label="JCONFIG_PERMISSIONS_LABEL">
<field name="rules" type="rules" component="com_tjnotifications" class="inputbox" filter="rules" validate="rules" label="JCONFIG_PERMISSIONS_LABEL" section="component" />
</fieldset>
Expand Down
23 changes: 23 additions & 0 deletions src/com_tjnotifications/admin/controllers/log.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* @package TJNotifications
* @subpackage com_tjnotifications
*
* @author Techjoomla <[email protected]>
* @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/

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

use Joomla\CMS\MVC\Controller\FormController;

/**
* Log Controller
*
* @since 1.1.0
*/
class TjnotificationsControllerLog extends FormController
{
}
40 changes: 40 additions & 0 deletions src/com_tjnotifications/admin/controllers/logs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* @package TJNotifications
* @subpackage com_tjnotifications
*
* @author Techjoomla <[email protected]>
* @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/

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

use Joomla\CMS\MVC\Controller\AdminController;

/**
* Logs controller class.
*
* @since 1.1.0
*/
class TjnotificationsControllerLogs extends AdminController
{
/**
* Proxy for getModel.
*
* @param string $name The name of the model.
* @param string $prefix The prefix for the PHP class name.
* @param array $config Array of configuration parameters.
*
* @return JModelLegacy
*
* @since 1.1.0
*/
public function getModel($name = 'log', $prefix = 'TjnotificationsModel', $config = array('ignore_request' => true))
{
$model = parent::getModel($name, $prefix, $config);

return $model;
}
}
14 changes: 13 additions & 1 deletion src/com_tjnotifications/admin/helpers/tjnotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @subpackage com_tjnotifications
* @since 2.2
*/
class TjnotificationsHelper
class TjnotificationsHelper extends JHelperContent
{
/**
* Configure the Linkbar.
Expand Down Expand Up @@ -66,5 +66,17 @@ public static function addSubmenu($view = '')
}
}
}

/*JHtmlSidebar::addEntry(
JText::_('COM_TJNOTIFICATIONS_TITLE_NOTIFICATIONS'),
'index.php?option=com_tjnotifications&view=notifications',
$view == 'notifications'
);
JHtmlSidebar::addEntry(
JText::_('COM_TJNOTIFICATIONS_TITLE_NOTIFICATIONLOGS'),
'index.php?option=com_tjnotifications&view=logs',
$view == 'logs'
);*/
}
}
23 changes: 23 additions & 0 deletions src/com_tjnotifications/admin/models/forms/filter_logs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<form>
<fields name="filter">
<field name="search" type="text" label="search" hint="search" class="js-stools-search-string" />
<field name="client" label="COM_TJNOTIFICATIONS_FIELD_CLIENT_LABEL" description="COM_TJNOTIFICATIONS_FIELD_CLIENT_DESC" onchange="this.form.submit();" type="sql" class="inputbox" query="SELECT DISTINCT(client) FROM `#__tj_notification_templates`" key_field="client" value_field="client">
<option value=''>COM_TJNOTIFICATIONS_FIELD_CLIENT_OPTION</option>
</field>
<field name="provider" type="list" class="inputbox" label="COM_TJNOTIFICATIONS_FIELD_PROVIDER_LABEL" default="email" description="COM_TJNOTIFICATIONS_FIELD_PROVIDER_DESC" onchange="this.form.submit();" key_field="provider" value_field="provider">
<option value="email">COM_TJNOTIFICATIONS_PROVIDER_EMAIL</option>
<option value="sms">COM_TJNOTIFICATIONS_PROVIDER_SMS</option>
<option value="push">COM_TJNOTIFICATIONS_PROVIDER_PUSH</option>
<option value="web">COM_TJNOTIFICATIONS_PROVIDER_WEB</option>
</field>
<field name="key" label="COM_TJNOTIFICATIONS_FIELD_KEY_LABEL" description="COM_TJNOTIFICATIONS_FIELD_KEY_DESC" onchange="this.form.submit();" type="sql" class="inputbox" query="SELECT DISTINCT(`key`) AS `tmpkey` FROM `#__tj_notification_templates`" key_field="tmpkey" value_field="tmpkey">
<option value=''>COM_TJNOTIFICATIONS_FIELD_KEY_OPTION</option>
</field>
<field name="state" type="list" class="inputbox" label="COM_TJNOTIFICATIONS_FIELD_STATE_LABEL" description="COM_TJNOTIFICATIONS_FIELD_STATE_DESC" onchange="this.form.submit();" key_field="provider" value_field="provider">
<option value="">COM_TJNOTIFICATIONS_FIELD_STATE_OPTION</option>
<option value="1">COM_TJNOTIFICATIONS_STATE_SENT</option>
<option value="0">COM_TJNOTIFICATIONS_STATE_FAILED</option>
</field>
</fields>
</form>
62 changes: 62 additions & 0 deletions src/com_tjnotifications/admin/models/log.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* @package TJNotifications
* @subpackage com_tjnotifications
*
* @author Techjoomla <[email protected]>
* @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/

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

jimport('joomla.application.component.model');

use Joomla\CMS\MVC\Model\AdminModel;
use Joomla\CMS\Table\Table;

/**
* Log model.
*
* @since 1.1.0
*/
class TjnotificationsModelLog extends AdminModel
{
/**
* Method to get the record form.
*
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
*
* @return JForm|boolean A JForm object on success, false on failure
*
* @since 1.1.0
*/
public function getForm($data = array(), $loadData = true)
{
// Get the form.
$form = $this->loadForm('com_tjnotifications.log', 'log', array('control' => 'jform', 'load_data' => $loadData));

if (empty($form))
{
return false;
}

return $form;
}

/**
* Returns a Table object, always creating it.
*
* @param string $type The table type to instantiate
* @param string $prefix A prefix for the table class name. Optional.
* @param array $config Configuration array for model. Optional.
*
* @return JTable A database object
*/
public function getTable($type = 'Log', $prefix = 'TjnotificationsTable', $config = array())
{
return Table::getInstance($type, $prefix, $config);
}
}
157 changes: 157 additions & 0 deletions src/com_tjnotifications/admin/models/logs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?php
/**
* @package TJNotifications
* @subpackage com_tjnotifications
*
* @author Techjoomla <[email protected]>
* @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/

// No direct access to this file
defined('_JEXEC') or die;

jimport('joomla.application.component.model');

use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Model\ListModel;

/**
* notifications model.
*
* @since 1.1.0
*/
class TjnotificationsModelLogs extends ListModel
{
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
*
* @see JController
* @since 1.1.0
*/
public function __construct($config = array())
{
if (empty($config['filter_fields']))
{
$config['filter_fields'] = array(
'id', 'tjl.id',
'to', 'tjl.to',
'key', 'tjl.key',
'from', 'tjl.from',
'cc', 'tjl.cc',
'state', 'tjl.state',
'subject', 'tjl.subject',
'search'
);
}

parent::__construct($config);
}

/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
*
* @return void
*
* @since 1.1.0
*/
protected function populateState($ordering = 'tjl.id', $direction = 'desc')
{
$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->getCfg('list_limit'), 'int');
$limitstart = Factory::getApplication()->input->post->get('limitstart');

// In case limit has been changed, adjust it
$limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);

$this->setState('list.limit', $limit);
$this->setState('list.start', $limitstart);
}

/**
* Build an SQL query to load the list data.
*
* @return JDatabaseQuery
*
* @since 1.1.0
*/
protected function getListQuery()
{
// Initialize variables.
$db = Factory::getDbo();
$query = $db->getQuery(true);

// Create the base select statement.
$query->select('*')
->from($db->quoteName('#__tj_notification_logs', 'tjl'));

$search = $this->getState('filter.search');

// Filter by client
$client = $this->getState('filter.client');

if ($client)
{
$query->where($db->quoteName('tjl.client') . ' = ' . $db->quote($client));
}

// Filter by provider
$provider = $this->getState('filter.provider');

if ($provider)
{
$query->where($db->quoteName('tjl.provider') . ' = ' . $db->quote($provider));
}

// Filter by key
$key = $this->getState('filter.key');

if ($key)
{
$query->where($db->quoteName('tjl.key') . ' = ' . $db->quote($key));
}

// Filter by client
$state = $this->getState('filter.state');

if (is_numeric($state))
{
$query->where($db->quoteName('tjl.state') . ' = ' . $db->quote($state));
}

if (!empty($search))
{
$like = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%'));
$query->where(
$db->quoteName('tjl.subject') . ' LIKE ' . $like . '
OR ' . $db->quoteName('tjl.from') . ' LIKE ' . $like . '
OR ' . $db->quoteName('tjl.to') . ' LIKE ' . $like
);
}

$orderCol = $this->getState('list.ordering');
$orderDirn = $this->getState('list.direction');

if ($orderCol && $orderDirn)
{
$query->order($db->quoteName($orderCol) . ' ' . $db->escape($orderDirn));
}

return $query;
}
}
Loading

0 comments on commit 0eb4a46

Please sign in to comment.