From 32f6eaccefc3f973440f2b55eecf47d9ae68fe43 Mon Sep 17 00:00:00 2001 From: Nitesh Prakash Kesarkar Date: Fri, 10 Jan 2020 11:34:54 +0530 Subject: [PATCH] Issue #172 Fix: Notice: Undefined index in reports model & reports default view (#173) * Issue #172 Fix: Notice: Undefined index in reports model & reports default view * Issue #172 Fix: Notice: Undefined index in reports model & reports default view * Issue #172 Fix: Scrutinizer changes and namespaces * Issue #172 Fix: Scrutinizer changes --- tjreports/site/models/reports.php | 216 ++++++++++-------- tjreports/site/views/reports/tmpl/default.php | 82 ++++--- tjreports/site/views/reports/view.base.php | 81 ++++--- 3 files changed, 211 insertions(+), 168 deletions(-) diff --git a/tjreports/site/models/reports.php b/tjreports/site/models/reports.php index 2472f24..70728a6 100755 --- a/tjreports/site/models/reports.php +++ b/tjreports/site/models/reports.php @@ -10,6 +10,14 @@ // No direct access defined('_JEXEC') or die('Restricted access'); +Use Joomla\CMS\MVC\Model\ListModel; +use Joomla\CMS\Table\Table; +use Joomla\CMS\Factory; +Use Joomla\Registry\Registry; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Plugin\PluginHelper; +use Joomla\CMS\HTML\HTMLHelper; + jimport('joomla.application.component.modellist'); // Load TJReports db helper @@ -21,7 +29,7 @@ * * @since 1.0.0 */ -class TjreportsModelReports extends JModelList +class TjreportsModelReports extends ListModel { // Default ordering of Data protected $default_order = ''; @@ -114,14 +122,17 @@ public function __construct($config = array()) // Get email column $this->emailColumn = array_search( - 1, array_map( - function ($ar) { - if (!empty($ar['emailColumn'])) - { - return $ar['emailColumn']; - } - }, $this->columns - ) + 1, + array_map( + function ($ar) + { + if (!empty($ar['emailColumn'])) + { + return $ar['emailColumn']; + } + }, + $this->columns + ) ); // Check PII data permission @@ -154,7 +165,7 @@ protected function setCustomFieldsColumns() } // Get column name, type for custom fields index table - $db = JFactory::getDbo(); + $db = Factory::getDbo(); $columnsDetails = $db->getTableColumns($this->customFieldsTable); // If no columns, return @@ -179,9 +190,9 @@ protected function setCustomFieldsColumns() foreach ($columnNames as $columnName) { $customField = array ( - 'title' => ($columnLabels[$columnName]) ? $columnLabels[$columnName] : $columnName, - 'table_column' => $this->customFieldsTableAlias . '.' . $columnName, - 'not_show_hide' => false + 'title' => isset($columnLabels[$columnName]) ? $columnLabels[$columnName] : $columnName, + 'table_column' => $this->customFieldsTableAlias . '.' . $columnName, + 'not_show_hide' => false ); // Eg. tuf.dob @@ -214,7 +225,7 @@ protected function setCustomFieldsDisplayFilters(&$displayFilters) } // Get column name, type for custom fields index table - $db = JFactory::getDbo(); + $db = Factory::getDbo(); $columnsDetails = $db->getTableColumns($this->customFieldsTable); // If no columns, return @@ -275,13 +286,13 @@ protected function setCustomFieldsDisplayFilters(&$displayFilters) $this->customFieldsTableAlias . '.' . $key . '_from' => array ( 'attrib' => array ( 'placeholder' => 'YYYY-MM-DD', - 'onChange' => 'tjrContentUI.report.attachCalSubmit(this);' + 'onChange' => 'tjrContentUI.report.attachCalSubmit(this);' ) ), $this->customFieldsTableAlias . '.' . $key . '_to' => array ( 'attrib' => array ( 'placeholder' => 'YYYY-MM-DD', - 'onChange' => 'tjrContentUI.report.attachCalSubmit(this);' + 'onChange' => 'tjrContentUI.report.attachCalSubmit(this);' ) ) ); @@ -328,14 +339,14 @@ protected function setCustomFieldsDisplayFilters(&$displayFilters) */ protected function getCustomFieldsDisplayFilterOptions($column) { - $objArray = array(); - $obj = new stdClass; - $obj->text = JText::_('- Select ' . $column . ' -'); - $obj->value = ''; - $objArray[] = $obj; + $objArray = array(); + $obj = new stdClass; + $obj->text = Text::_('- Select ' . $column . ' -'); + $obj->value = ''; + $objArray[] = $obj; // Get column name, type for custom fields index table - $db = JFactory::getDbo(); + $db = Factory::getDbo(); // Get column labels from #__fields table for all indexed custom fields from this table $query = $db->getQuery(true); @@ -359,10 +370,11 @@ protected function getCustomFieldsDisplayFilterOptions($column) * */ private function initData() { - $columns = $this->columns; - $columnsKeys = array_keys($columns); + $columns = $this->columns; + $columnsKeys = array_keys($columns); + $this->sortableWoQuery = array(); + $this->defaultColToShow = $this->sortableColumns = $this->showhideCols = array_combine($columnsKeys, $columnsKeys); - $this->sortableWoQuery = array(); foreach ($columns as $key => $column) { @@ -430,9 +442,12 @@ public function getTJRMessages() public function getValidRequestVars() { $validVars = array( - 'colToshow' => 'ARRAY', 'filters' => 'ARRAY', - 'limit' => 'INT', 'limitstart' => 'INT', - 'filter_order' => 'STRING', 'filter_order_Dir' => 'STRING' + 'colToshow' => 'ARRAY', + 'filters' => 'ARRAY', + 'limit' => 'INT', + 'limitstart' => 'INT', + 'filter_order' => 'STRING', + 'filter_order_Dir' => 'STRING' ); return $validVars; @@ -524,8 +539,8 @@ protected function _getList($query, $limitstart = 0, $limit = 0) protected function populateState($ordering = '', $direction = 'ASC') { // List state information - $app = JFactory::getApplication(); - $input = JFactory::getApplication()->input; + $app = Factory::getApplication(); + $input = $app->input; if (!($reportId = $input->get('reportId', 0, 'uint'))) { @@ -542,13 +557,13 @@ protected function populateState($ordering = '', $direction = 'ASC') if (empty($colToshow)) { $reportParams = $this->getReportParams($reportId); - - $colToshow = $reportParams->get("colToshow"); - $piiColumns = array_flip($reportParams->get("piiColumns")); + $colToshow = (array) $reportParams->get("colToshow"); + $piiColumns = (array) $reportParams->get("piiColumns"); + $piiColumns = array_flip($piiColumns); if (!empty($piiColumns)) { - $colToshow = (object) array_diff_key((array) $colToshow, $piiColumns); + $colToshow = (object) array_diff_key($colToshow, $piiColumns); } } @@ -561,7 +576,7 @@ protected function populateState($ordering = '', $direction = 'ASC') $this->setState('colToshow', $colToshow); - $filters = $input->get('filters', array(), 'ARRAY'); + $filters = $input->get('filters', array(), 'ARRAY'); $this->setState('filters', $filters); // List state information @@ -620,7 +635,7 @@ protected function populateState($ordering = '', $direction = 'ASC') */ protected function getListQuery() { - $db = JFactory::getDBO(); + $db = Factory::getDBO(); $query = $db->getQuery(true); $filters = (array) $this->getState('filters'); $displayFilters = (array) $this->displayFilters(); @@ -762,9 +777,9 @@ protected function sortCustomColumns($items) if (!empty($items) && !empty($sortKey) && in_array($sortKey, $this->sortableWoQuery) && $limit) { - $orderDir = $this->getState('list.direction', $this->default_order_dir); + $orderDir = $this->getState('list.direction', $this->default_order_dir); $this->multi_d_sort($items, $sortKey, $orderDir); - $items = array_splice($items, $limitstart, $limit); + $items = array_splice($items, $limitstart, $limit); } return $items; @@ -809,7 +824,7 @@ private function multi_d_sort(&$array, $column, $order) * * @param INT $reportToBuild report to build * - * @return object + * @return Mixed * * @since 1.0 */ @@ -817,7 +832,7 @@ public function getSavedQueries($user_id, $reportToBuild) { if (!empty($reportToBuild) && !empty($user_id)) { - $db = JFactory::getDBO(); + $db = Factory::getDBO(); $query = $db->getQuery(true); $query->select('*'); $query->from('#__tj_reports'); @@ -843,7 +858,7 @@ public function getSavedQueries($user_id, $reportToBuild) */ public function getQueryData($queryId) { - $ol_user = JFactory::getUser()->id; + $ol_user = Factory::getUser()->id; $query = $this->_db->getQuery(true); $query->select('*'); $query->from('#__tj_reports'); @@ -859,23 +874,23 @@ public function getQueryData($queryId) /** * Get all plugins names * - * @return object + * @return Array * * @since 1.0 */ public function getenableReportPlugins() { - $user = JFactory::getUser(); - $input = JFactory::getApplication()->input; + $user = Factory::getUser(); + $input = Factory::getApplication()->input; $client = $input->get('client', '', 'STRING'); // Get all report plugin $dispatcher = JEventDispatcher::getInstance(); - $plugins = JPluginHelper::getPlugin('tjreports'); + $plugins = PluginHelper::getPlugin('tjreports'); $pluginExists = json_decode(json_encode($plugins), true); - $pluginNames = array_column($pluginExists, 'name'); + $pluginNames = array_column($pluginExists, 'name'); - $db = JFactory::getDBO(); + $db = Factory::getDBO(); $query = $db->getQuery(true); $query->select(array('id as reportId, title, plugin, ordering')); @@ -905,7 +920,10 @@ public function getenableReportPlugins() // In view layouts - reports[0] is used, and since array indexes are unset above, // Let's re-arrange index accordingly - $reports = array_values($reports); + if (is_array($reports)) + { + $reports = array_values($reports); + } return $reports; } @@ -919,7 +937,7 @@ public function getenableReportPlugins() */ public function getUserFilter() { - $db = JFactory::getDbo(); + $db = Factory::getDbo(); $query = $db->getQuery(true); $query->select('u.id,u.username'); @@ -929,13 +947,13 @@ public function getUserFilter() $db->setQuery($query); $users = $db->loadObjectList(); - $userFilter[] = JHTML::_('select.option', '', JText::_('COM_TJREPORTS_FILTER_SELECT_USER')); + $userFilter[] = HTMLHelper::_('select.option', '', Text::_('COM_TJREPORTS_FILTER_SELECT_USER')); if (!empty($users)) { foreach ($users as $eachUser) { - $userFilter[] = JHTML::_('select.option', $eachUser->id, $eachUser->username); + $userFilter[] = HTMLHelper::_('select.option', $eachUser->id, $eachUser->username); } } @@ -952,9 +970,9 @@ public function getUserFilter() public function getreportoptions() { // Initialize variables. - $db = JFactory::getDbo(); - $query = $db->getQuery(true); - $user_id = JFactory::getUser()->id; + $db = Factory::getDbo(); + $query = $db->getQuery(true); + $user_id = Factory::getUser()->id; $clients = $this->getState('client'); @@ -984,11 +1002,11 @@ public function getreportoptions() $db->setQuery($query); $reports = $db->loadObjectList(); - $options[] = JHTML::_('select.option', 0, JText::_('COM_TJREPORTS_SELONE_REPORTS')); + $options[] = HTMLHelper::_('select.option', 0, Text::_('COM_TJREPORTS_SELONE_REPORTS')); foreach ($reports as $repo) { - $options[] = JHtml::_('select.option', $repo->value, $repo->text); + $options[] = HTMLHelper::_('select.option', $repo->value, $repo->text); } return $options; @@ -1014,14 +1032,14 @@ public function canViewPiiData() * * @param INT $reportId report id * - * @return object + * @return Mixed * - * @since 1.0 + * @since 1.0 */ public function checkpermissions($reportId) { - $user = JFactory::getUser(); + $user = Factory::getUser(); if ($reportId) { @@ -1042,8 +1060,8 @@ public function checkpermissions($reportId) */ public function getUserGroupFilter($includeSuperAdmin = true) { - $groups = JHtml::_('user.groups', $includeSuperAdmin); - array_unshift($groups, JHtml::_('select.option', '', JText::_('JGLOBAL_FILTER_GROUPS_LABEL'))); + $groups = HTMLHelper::_('user.groups', $includeSuperAdmin); + array_unshift($groups, HTMLHelper::_('select.option', '', Text::_('JGLOBAL_FILTER_GROUPS_LABEL'))); return $groups; } @@ -1057,25 +1075,25 @@ public function getUserGroupFilter($includeSuperAdmin = true) */ public function datadenyset() { - $input = JFactory::getApplication()->input; + $input = Factory::getApplication()->input; $reportId = $input->get('reportId', '0', 'int'); if ($reportId) { $this->model = $this->getModel('reports'); - $reportData = $this->model->getReportNameById($reportId); - $reportName = $reportData->title; + $reportData = $this->model->getReportNameById($reportId); + $reportName = $reportData->title; } else { return false; } - $user_id = JFactory::getUser()->id; + $user_id = Factory::getUser()->id; if ($reportName && $user_id && $reportId) { - $db = JFactory::getDBO(); + $db = Factory::getDBO(); $query = $db->getQuery(true); $query->select(array('param')); $query->from($db->quoteName('#__tj_reports')); @@ -1113,7 +1131,7 @@ public function loadLanguage($name, $type = 'tjreports', $extension = '', $baseP } $extension = strtolower($extension); - $lang = JFactory::getLanguage(); + $lang = Factory::getLanguage(); // If language already loaded, don't load it again. if ($lang->getPaths($extension)) @@ -1210,12 +1228,12 @@ private function processSavedReportColumns($queryId, &$selColToshow) ->from('#__tj_reports') ->where('id=' . (int) $queryId); $this->_db->setQuery($query); - $queryData = $this->_db->loadObject(); - $i = $parent = 0; + $queryData = $this->_db->loadObject(); + $i = $parent = 0; if (!empty($queryData->param)) { - $param = json_decode($queryData->param, true); + $param = json_decode($queryData->param, true); if (isset($param['showHideColumns'])) { @@ -1270,9 +1288,8 @@ private function processSavedReportColumns($queryId, &$selColToshow) /* Checked the columns which are hide(false) in load params & if set them as piiColumns * then it only returns the columns which are not available in piiColumns. */ $this->filterDefaultColToHide = array_diff($this->filterDefaultColToHide, $param['piiColumns']); - - $this->filterParamColToshow = array_diff($this->filterParamColToshow, $param['piiColumns']); - $this->filterShowhideCols = array_diff($this->filterShowhideCols, $param['piiColumns']); + $this->filterParamColToshow = array_diff($this->filterParamColToshow, $param['piiColumns']); + $this->filterShowhideCols = array_diff($this->filterShowhideCols, $param['piiColumns']); } $parent = $queryData->parent; @@ -1283,7 +1300,7 @@ private function processSavedReportColumns($queryId, &$selColToshow) if (!empty($this->piiColumns) && !$this->piiPermission) { $this->defaultColToShow = array_diff($this->defaultColToShow, $this->piiColumns); - $this->showhideCols = array_diff($this->showhideCols, $this->piiColumns); + $this->showhideCols = array_diff($this->showhideCols, $this->piiColumns); } } @@ -1295,15 +1312,15 @@ private function processSavedReportColumns($queryId, &$selColToshow) * * @param INT $reportId Report Id * - * @return Object + * @return Mixed * * @since 3.0 */ public function getReportNameById($reportId) { - $db = JFactory::getDBO(); - JTable::addIncludePath(JPATH_ROOT . '/administrator/components/com_tjreports/tables'); - $reportTable = JTable::getInstance('Tjreport', 'TjreportsTable', array('dbo', $db)); + $db = Factory::getDBO(); + Table::addIncludePath(JPATH_ROOT . '/administrator/components/com_tjreports/tables'); + $reportTable = Table::getInstance('Tjreport', 'TjreportsTable', array('dbo', $db)); $reportTable->load(array('id' => $reportId)); return $reportTable; @@ -1321,9 +1338,8 @@ public function getReportNameById($reportId) */ public function getReportLink($reportToLink, $filters) { - $user = JFactory::getUser(); - - $reports = $this->getPluginReport($reportToLink); + $user = Factory::getUser(); + $reports = $this->getPluginReport($reportToLink); $filterLink = ''; foreach ($filters as $key => $value) @@ -1349,18 +1365,18 @@ public function getReportLink($reportToLink, $filters) * * @param STRING $reportId Report id * - * @return Integer + * @return Object * * @since 1.1.0 */ public function getReportParams($reportId) { - $db = JFactory::getDBO(); - JTable::addIncludePath(JPATH_ROOT . '/administrator/components/com_tjreports/tables'); - $reportTable = JTable::getInstance('Tjreport', 'TjreportsTable', array('dbo', $db)); + $db = Factory::getDBO(); + Table::addIncludePath(JPATH_ROOT . '/administrator/components/com_tjreports/tables'); + $reportTable = Table::getInstance('Tjreport', 'TjreportsTable', array('dbo', $db)); $reportTable->load($reportId); - return new JRegistry($reportTable->param); + return new Registry($reportTable->param); } /** @@ -1374,9 +1390,9 @@ public function getReportParams($reportId) */ public function getDefaultReport($pluginName) { - $db = JFactory::getDBO(); - JTable::addIncludePath(JPATH_ROOT . '/administrator/components/com_tjreports/tables'); - $reportTable = JTable::getInstance('Tjreport', 'TjreportsTable', array('dbo', $db)); + $db = Factory::getDBO(); + Table::addIncludePath(JPATH_ROOT . '/administrator/components/com_tjreports/tables'); + $reportTable = Table::getInstance('Tjreport', 'TjreportsTable', array('dbo', $db)); $reportTable->load(array('plugin' => $pluginName, 'default' => 1)); return $reportTable->id; @@ -1397,7 +1413,7 @@ public function getPluginReport($pluginName) if (!isset($reports[$pluginName])) { - $db = JFactory::getDBO(); + $db = Factory::getDBO(); $query = $db->getQuery(true); $query->select(array('id as reportId', 'client')); $query->from($db->quoteName('#__tj_reports')); @@ -1459,7 +1475,7 @@ public function getPluginInstallationDetail($pluginName) if ($pluginName && !isset($clients[$pluginName])) { $clients[$pluginName] = ''; - $model = $this->getPluginModel($pluginName); + $model = $this->getPluginModel($pluginName); if ($model) { @@ -1477,7 +1493,7 @@ public function getPluginInstallationDetail($pluginName) */ public function addTjReportsPlugins() { - $db = JFactory::getDbo(); + $db = Factory::getDbo(); $query = $db->getQuery(true) ->select( $db->quoteName( @@ -1509,21 +1525,21 @@ public function addTjReportsPlugins() foreach ($plugins as $plugin) { - $pluginName = $plugin->name; - JTable::addIncludePath(JPATH_ROOT . '/administrator/components/com_tjreports/tables'); - $reportTable = JTable::getInstance('Tjreport', 'TjreportsTable'); - $details = $this->getPluginInstallationDetail($pluginName); + $pluginName = $plugin->name; + Table::addIncludePath(JPATH_ROOT . '/administrator/components/com_tjreports/tables'); + $reportTable = Table::getInstance('Tjreport', 'TjreportsTable'); + $details = $this->getPluginInstallationDetail($pluginName); $reportTable->load(array('plugin' => $pluginName, 'userid' => 0)); if (!$reportTable->id) { - $data = array(); - $data['title'] = $details['title']; + $data = array(); + $data['title'] = $details['title']; $data['plugin'] = $pluginName; - $data['alias'] = $pluginName; + $data['alias'] = $pluginName; $data['client'] = $details['client']; $data['parent'] = 0; - $data['default'] = 1; + $data['default'] = 1; $reportTable->save($data); $count++; diff --git a/tjreports/site/views/reports/tmpl/default.php b/tjreports/site/views/reports/tmpl/default.php index b63d2b3..284e142 100644 --- a/tjreports/site/views/reports/tmpl/default.php +++ b/tjreports/site/views/reports/tmpl/default.php @@ -10,11 +10,18 @@ // no direct access defined('_JEXEC') or die; -JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); +use Joomla\CMS\Factory; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Router\Route; +use Joomla\CMS\Uri\Uri; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Filter\OutputFilter; + +HTMLHelper::addIncludePath(JPATH_COMPONENT . '/helpers/html'); $emailColmClass = 'td-sendemail'; -$app = JFactory::getApplication(); +$app = Factory::getApplication(); $headerLevel = $this->headerLevel; $this->listOrder = $this->state->get('list.ordering'); $this->listDirn = $this->state->get('list.direction'); @@ -32,25 +39,25 @@ } } -$input = JFactory::getApplication()->input; +$input = Factory::getApplication()->input; $displayFilters = $this->userFilters; $totalHeadRows = count($displayFilters); $reportId = $app->getUserStateFromRequest('reportId', 'reportId', ''); -$user = JFactory::getUser(); +$user = Factory::getUser(); $userAuthorisedExport = $user->authorise('core.export', 'com_tjreports.tjreport.' . $reportId); -if ($app->isSite()) +if ($app->isClient('site')) { - $siteUrl = JUri::root(); - $message = array(); - $message['success'] = JText::_("COM_TJREPORTS_EXPORT_FILE_SUCCESS"); - $message['error'] = JText::_("COM_TJREPORTS_EXPORT_FILE_ERROR"); - $message['inprogress'] = JText::_("COM_TJREPORTS_EXPORT_FILE_NOTICE"); - $message['text'] = JText::_("COM_TJREPORTS_CSV_EXPORT"); + $siteUrl = Uri::root(); + $message = array(); + $message['success'] = Text::_("COM_TJREPORTS_EXPORT_FILE_SUCCESS"); + $message['error'] = Text::_("COM_TJREPORTS_EXPORT_FILE_ERROR"); + $message['inprogress'] = Text::_("COM_TJREPORTS_EXPORT_FILE_NOTICE"); + $message['text'] = Text::_("COM_TJREPORTS_CSV_EXPORT"); - JHtml::script(JUri::base() . 'libraries/techjoomla/assets/js/tjexport.js'); - $document = JFactory::getDocument(); - $csv_url = 'index.php?option=' . $input->get('option') . '&view=' . $input->get('view') . '&format=csv'; + HTMLHelper::script(Uri::base() . 'libraries/techjoomla/assets/js/tjexport.js'); + $document = Factory::getDocument(); + $csv_url = 'index.php?option=' . $input->get('option') . '&view=' . $input->get('view') . '&format=csv'; $document->addScriptDeclaration("var csv_export_url='{$csv_url}';"); $document->addScriptDeclaration("var csv_export_success='{$message['success']}';"); @@ -75,14 +82,14 @@ isSite() && isset($this->reportData->title)) + if ($app->isClient('site') && isset($this->reportData->title)) { ?>

reportData->title, ENT_COMPAT, 'UTF-8'); ?>

-
+
@@ -115,7 +122,7 @@
isAdmin()) + if (!$app->isClient('administrator')) { echo $this->pagination->getPaginationLinks('joomla.pagination.links', array('showPagesLinks' => false,'showLimitStart' => false)); } @@ -136,7 +143,7 @@ { ?>
- savedQueries, "queryId", 'class="" size="1" onchange="tjrContentUI.report.getQueryResult(this.value);" name="filter_saveQuery"', "value", "text", $this->queryId); + savedQueries, "queryId", 'class="" size="1" onchange="tjrContentUI.report.getQueryResult(this.value);" name="filter_saveQuery"', "value", "text", $this->queryId); ?> queryId) @@ -153,7 +160,7 @@ isSite()) + if ($app->isClient('site')) { if ($this->isExport) { @@ -165,7 +172,7 @@ - +
@@ -183,7 +190,7 @@ ?>
@@ -192,7 +199,7 @@ ?>
- +
    showHideColumns as $colKey) @@ -210,13 +217,13 @@ if (in_array($colKey, $this->colToshow)) { - $checked = 'checked="checked"'; + $checked = 'checked="checked"'; } ?>
  • isAdmin() && $userAuthorisedExport && $user) + if (!$app->isClient('administrator') && $userAuthorisedExport && $user) { ?> srButton !== -1) { ?> - -
@@ -323,15 +330,15 @@ echo ''; - $colTitle = JText::sprintf($subTextTitle, $keyDetails[1]) ; + $colTitle = Text::sprintf($subTextTitle, $keyDetails[1]) ; if (in_array($subKey, $this->sortable)) { - echo $sortHtml = JHtml::_('grid.sort', $colTitle, $subKey, $this->listDirn, $this->listOrder); + echo $sortHtml = HTMLHelper::_('grid.sort', $colTitle, $subKey, $this->listDirn, $this->listOrder); } else { - echo '
' . JText::_($colTitle) . '
'; + echo '
' . Text::_($colTitle) . '
'; } echo ''; @@ -340,7 +347,7 @@ else { $colKey = $detail; - $colKeyClass = JFilterOutput::stringURLSafe($colKey); + $colKeyClass = OutputFilter::stringURLSafe($colKey); if (!isset($this->columns[$colKey]['title'])) { $colTitle = 'PLG_TJREPORTS_' . strtoupper($this->pluginName . '_' . $colKey . '_TITLE'); @@ -359,11 +366,11 @@ if (in_array($colKey, $this->sortable)) { - echo $sortHtml = JHtml::_('grid.sort', $colTitle, $colKey, $this->listDirn, $this->listOrder); + echo $sortHtml = HTMLHelper::_('grid.sort', $colTitle, $colKey, $this->listDirn, $this->listOrder); } else { - echo '
' . JText::_($colTitle) . '
'; + echo '
' . Text::_($colTitle) . '
'; } if ($hasFilter) { @@ -434,7 +441,8 @@ else { $isSendEmailClass = ($key == $this->emailColumn) ? $emailColmClass : ''; - echo "{$item[$key]}"; + $value = isset($item[$key]) ? $item[$key] : ''; + echo "{$value}"; } } @@ -463,7 +471,7 @@
isAdmin()) + if (!$app->isClient('administrator')) { echo $this->pagination->getPaginationLinks('joomla.pagination.links', array('showLimitBox' => false)); } @@ -483,7 +491,7 @@ - +
diff --git a/tjreports/site/views/reports/view.base.php b/tjreports/site/views/reports/view.base.php index 9e14e42..a355165 100644 --- a/tjreports/site/views/reports/view.base.php +++ b/tjreports/site/views/reports/view.base.php @@ -13,6 +13,9 @@ // No direct access defined('_JEXEC') or die; +use Joomla\CMS\Factory; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; + jimport('joomla.application.component.view'); JLoader::import('components.com_tjreports.helpers.tjreports', JPATH_ADMINISTRATOR); JLoader::import('components.com_tjreports.models.tjreports', JPATH_SITE); @@ -38,12 +41,28 @@ class ReportsViewBase extends JViewLegacy protected $reportData; - protected $savedQueries = array(); + protected $headerLevel; protected $reportId = 0; protected $queryId = 0; + protected $savedQueries = array(); + + protected $defaultColToHide; + + protected $columns; + + protected $showhideCols; + + protected $filterParamColToshow; + + protected $defaultColToShow; + + protected $sortableColumns; + + protected $showSearchResetButton; + /** * Execute and display a template script. * @@ -53,15 +72,14 @@ class ReportsViewBase extends JViewLegacy */ public function processData($type = 'html') { - $app = JFactory::getApplication(); - $canDo = TjreportsHelper::getActions(); - $input = JFactory::getApplication()->input; - $user = JFactory::getUser(); + $canDo = TjreportsHelper::getActions(); + $input = Factory::getApplication()->input; + $user = Factory::getUser(); $this->reportId = $input->get('reportId', 0, 'INT'); - $this->model = $this->getModel('reports'); + $this->model = $this->getModel('reports'); - $reports = $this->model->getenableReportPlugins(); + $reports = $this->model->getenableReportPlugins(); $this->reportId = $this->reportId ? $this->reportId : (isset($reports['0']['reportId']) ? $reports['0']['reportId'] : ''); $this->reportData = $this->model->getReportNameById($this->reportId); @@ -81,7 +99,11 @@ public function processData($type = 'html') } $this->model = $this->getModel($this->pluginName); - $this->setModel($this->model, true); + + if ($this->model) + { + $this->setModel($this->model, true); + } if ($this->reportId) { @@ -131,8 +153,8 @@ public function processData($type = 'html') if (!empty($savedQueries)) { - $qOptions = array(); - $qOptions[] = JHTML::_('select.option', '', JText::_('COM_TJREPORTS_SELONE_QUERY')); + $qOptions = array(); + $qOptions[] = JHTML::_('select.option', '', JText::_('COM_TJREPORTS_SELONE_QUERY')); foreach ($savedQueries as $savedQuery) { @@ -154,15 +176,15 @@ public function processData($type = 'html') } $this->model->loadLanguage($this->pluginName); - $this->state = $this->get('State'); - $this->items = $this->model->getItems(); - $this->pagination = $this->get('pagination'); - - $this->headerLevel = $this->model->headerLevel; + $this->state = $this->get('State'); + $this->items = $this->model->getItems(); + $this->pagination = $this->get('pagination'); + $this->headerLevel = $this->model->headerLevel; // Array_key - defaultColToHide column are present then get the key as value. - $this->defaultColToHide = array_keys($this->model->getState('defaultColToHide')); - $this->columns = $this->model->columns; + $defaultColToHide = (array) $this->model->getState('defaultColToHide'); + $this->defaultColToHide = array_keys($defaultColToHide); + $this->columns = $this->model->columns; /* Array_merge - here colToshow means get all true value array so want to mearg defaultColToHide column and then using * array_intersect - only remove those column which is force fully added in load param in showhideCols config @@ -184,19 +206,16 @@ public function processData($type = 'html') $this->showHideColumns = array_intersect($this->model->showhideCols, array_merge($this->defaultColToshow, $this->defaultColToHide)); } - $this->sortable = $this->model->sortableColumns; - $this->emailColumn = $this->model->getState('emailColumn'); - $this->srButton = $this->model->showSearchResetButton; - - $this->colToshow = $this->model->getState('colToshow'); - - $this->filterValues = $this->model->getState('filters'); - - $this->userFilters = $this->model->displayFilters(); - $this->messages = $this->model->getTJRMessages(); + $this->sortable = $this->model->sortableColumns; + $this->emailColumn = $this->model->getState('emailColumn'); + $this->srButton = $this->model->showSearchResetButton; + $this->colToshow = $this->model->getState('colToshow'); + $this->filterValues = $this->model->getState('filters'); + $this->userFilters = $this->model->displayFilters(); + $this->messages = $this->model->getTJRMessages(); $this->enableReportPlugins = $this->model->getenableReportPlugins($this->client); - $this->isExport = $user->authorise('core.export', 'com_tjreports.tjreport.' . $this->reportId); + $this->isExport = $user->authorise('core.export', 'com_tjreports.tjreport.' . $this->reportId); return true; } @@ -208,14 +227,14 @@ public function processData($type = 'html') * @param string $prefix The class prefix. Optional. * @param array $config Configuration array for model. Optional. * - * @return JModelLegacy|boolean Model object on success; otherwise false on failure. + * @return BaseDatabaseModel|boolean Model object on success; otherwise false on failure. * * @since 3.0 */ public function getModel($name = '', $prefix = '', $config = array()) { - JModelLegacy::addIncludePath(JPATH_SITE . '/plugins/tjreports/' . $name); + BaseDatabaseModel::addIncludePath(JPATH_SITE . '/plugins/tjreports/' . $name); - return JModelLegacy::getInstance($name, 'TjreportsModel', $config); + return BaseDatabaseModel::getInstance($name, 'TjreportsModel', $config); } }