From bc085442a407dfae685c4acf73bc08f6dd08b028 Mon Sep 17 00:00:00 2001 From: divyachaudhari <58217051+divyachaudhari@users.noreply.github.com> Date: Fri, 27 Aug 2021 11:37:12 +0530 Subject: [PATCH 01/16] Task #173952 Fix: Joomla 4 compatibility (#55) * Task #173952 Fix: Hierarchy compatibility * Task #173952 Fix: Hierarchy compatibility * Task #173952 Fix: com_hierarchy compatibility * Task #173952 Fix: com_hierarchy compatibility * Task #173544 Chore: Resolving comment * Task #173544 Chore: Resolving comment * Task #173544 Chore: Resolving comment --- .../assets/elements/integrations.php | 31 +++--- administrator/controller.php | 8 +- administrator/controllers/hierarchy.php | 42 ++++---- administrator/controllers/hierarchys.php | 43 ++++---- administrator/helpers/hierarchy.php | 16 +-- administrator/hierarchy.php | 17 +-- administrator/models/fields/contextlist.php | 12 ++- administrator/models/fields/users.php | 10 +- administrator/models/hierarchy.php | 100 +++++++++--------- administrator/models/hierarchys.php | 16 +-- administrator/tables/hierarchy.php | 3 +- administrator/views/hierarchy/tmpl/edit.php | 30 +++--- administrator/views/hierarchy/view.html.php | 17 +-- .../views/hierarchys/tmpl/default.php | 62 ++++++----- administrator/views/hierarchys/view.csv.php | 16 ++- administrator/views/hierarchys/view.html.php | 37 ++++--- media/js/hierarchy.js | 4 +- plugins/privacy/hierarchy/hierarchy.php | 13 +-- script.hierarchy.php | 26 ++--- site/controller.php | 8 +- site/controllers/hierarchys.php | 5 +- site/helpers/hierarchy.php | 16 +-- site/hierarchy.php | 17 +-- site/models/hierarchys.php | 16 +-- site/views/hierarchys/tmpl/chart.php | 28 ++--- site/views/hierarchys/tmpl/default.php | 17 +-- site/views/hierarchys/tmpl/list.php | 33 +++--- site/views/hierarchys/view.html.php | 31 ++++-- 28 files changed, 380 insertions(+), 294 deletions(-) diff --git a/administrator/assets/elements/integrations.php b/administrator/assets/elements/integrations.php index 0fd9831..b9e2e71 100644 --- a/administrator/assets/elements/integrations.php +++ b/administrator/assets/elements/integrations.php @@ -8,7 +8,10 @@ */ defined('_JEXEC') or die('Restricted access'); -jimport('joomla.form.formfield'); +use Joomla\CMS\Form\FormField; +use Joomla\CMS\Language\Text; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Filesystem\File; /** * JFormFieldIntegrations class @@ -17,7 +20,7 @@ * @subpackage component * @since 1.0 */ -class JFormFieldIntegrations extends JFormField +class FormFieldIntegrations extends FormField { /** *Function to construct a hierarchy view @@ -63,37 +66,37 @@ public function fetchElement ($name, $value, $controlName) if ($name == 'jform[integration]') { $options = array(); - $options[] = JHtml::_('select.option', '2', JText::_('COM_HIERARCHY_NATIVE')); + $options[] = HTMLHelper::_('select.option', '2', Text::_('COM_HIERARCHY_NATIVE')); - if (JFile::exists($this->communityMainFile)) + if (File::exists($this->communityMainFile)) { - $options[] = JHtml::_('select.option', '1', JText::_('COM_HIERARCHY_JOMSOCIAL')); + $options[] = HTMLHelper::_('select.option', '1', Text::_('COM_HIERARCHY_JOMSOCIAL')); } - if (JFile::exists($this->jeventsMainFile)) + if (File::exists($this->jeventsMainFile)) { - $options[] = JHtml::_('select.option', '3', JText::_('COM_HIERARCHY_JEVENT')); + $options[] = HTMLHelper::_('select.option', '3', Text::_('COM_HIERARCHY_JEVENT')); } - if (JFile::exists($this->esMainFile)) + if (File::exists($this->esMainFile)) { - $options[] = JHtml::_('select.option', '4', JText::_('COM_HIERARCHY_EASYSOCIAL')); + $options[] = HTMLHelper::_('select.option', '4', Text::_('COM_HIERARCHY_EASYSOCIAL')); } - if (JFile::exists($this->easyProMainFile)) + if (File::exists($this->easyProMainFile)) { - $options[] = JHtml::_('select.option', '5', JText::_('COM_HIERARCHY_EASYPROFILE')); + $options[] = HTMLHelper::_('select.option', '5', Text::_('COM_HIERARCHY_EASYPROFILE')); } - if (JFile::exists($this->cbMainFile)) + if (File::exists($this->cbMainFile)) { - $options[] = JHtml::_('select.option', '6', JText::_('COM_HIERARCHY_COMMUNITY_BUILDER')); + $options[] = HTMLHelper::_('select.option', '6', Text::_('COM_HIERARCHY_COMMUNITY_BUILDER')); } $fieldName = $name; } - $html = JHtml::_('select.genericlist', $options, $fieldName, 'class="inputbox"', 'value', 'text', $value, $controlName . $name); + $html = HTMLHelper::_('select.genericlist', $options, $fieldName, 'class="inputbox"', 'value', 'text', $value, $controlName . $name); return $html; } diff --git a/administrator/controller.php b/administrator/controller.php index 331b1d7..546e44d 100755 --- a/administrator/controller.php +++ b/administrator/controller.php @@ -9,13 +9,15 @@ // No direct access defined('_JEXEC') or die; +use Joomla\CMS\MVC\Controller\BaseController; +use Joomla\CMS\Factory; /** * Hierarchy view class for the hierarchy package. * * @since 1.6 */ -class HierarchyController extends JControllerLegacy +class HierarchyController extends BaseController { /** * Method to display a view. @@ -31,8 +33,8 @@ public function display($cachable = false, $urlparams = false) { require_once JPATH_COMPONENT . '/helpers/hierarchy.php'; - $view = JFactory::getApplication()->input->getCmd('view', 'hierarchys'); - JFactory::getApplication()->input->set('view', $view); + $view = Factory::getApplication()->input->getCmd('view', 'hierarchys'); + Factory::getApplication()->input->set('view', $view); parent::display($cachable, $urlparams); diff --git a/administrator/controllers/hierarchy.php b/administrator/controllers/hierarchy.php index 8681709..af5c69d 100755 --- a/administrator/controllers/hierarchy.php +++ b/administrator/controllers/hierarchy.php @@ -9,15 +9,19 @@ // No direct access defined('_JEXEC') or die; - -jimport('joomla.application.component.controllerform'); +use Joomla\CMS\MVC\Controller\FormController; +use Joomla\CMS\Factory; +use Joomla\CMS\Table\Table; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Session\Session; +use Joomla\CMS\Router\Route; /** * The Hierarchy Controller * * @since 1.6 */ -class HierarchyControllerHierarchy extends JControllerForm +class HierarchyControllerHierarchy extends FormController { /** * Constructor. @@ -30,11 +34,11 @@ public function __construct() { $this->view_list = 'hierarchys'; - $this->db = JFactory::getDbo(); - JTable::addIncludePath(JPATH_ROOT . '/administrator/components/com_hierarchy/tables'); - $this->hierarchyTableObj = JTable::getInstance('Hierarchy', 'HierarchyTable', array('dbo', $this->db)); + $this->db = Factory::getDbo(); + Table::addIncludePath(JPATH_ROOT . '/administrator/components/com_hierarchy/tables'); + $this->hierarchyTableObj = Table::getInstance('Hierarchy', 'HierarchyTable', array('dbo', $this->db)); - $this->msg = JText::_('COM_HIERARCHY_REPORTEES_SAVE_MSG'); + $this->msg = Text::_('COM_HIERARCHY_REPORTEES_SAVE_MSG'); parent::__construct(); } @@ -51,21 +55,21 @@ public function __construct() public function save($key = null, $urlVar = null) { // Check for request forgeries. - JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); + Session::checkToken() or jexit(Text::_('JINVALID_TOKEN')); // Initialise variables. - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $model = $this->getModel('hierarchy', 'HierarchyModel'); // Get the user data. - $data = JFactory::getApplication()->input->get('jform', array(), 'array'); + $data = Factory::getApplication()->input->get('jform', array(), 'array'); // Validate the posted data. $form = $model->getForm(); if (!$form) { - JError::raiseError(500, $model->getError()); + $app->enqueueMessage($model->getError(), 'error'); return false; } @@ -76,7 +80,7 @@ public function save($key = null, $urlVar = null) $data = $model->validate($form, $data); } - $jinput = JFactory::getApplication()->input; + $jinput = Factory::getApplication()->input; $data['user_id'] = $jinput->get('user_id', '', 'int'); $data['created_by'] = $jinput->get('created_by', '', 'int'); $data['modified_by'] = $jinput->get('modified_by', '', 'int'); @@ -112,7 +116,7 @@ public function save($key = null, $urlVar = null) $return = $model->save($data); } - $input = JFactory::getApplication()->input; + $input = Factory::getApplication()->input; $id = $input->get('id'); if (empty($id)) @@ -124,8 +128,9 @@ public function save($key = null, $urlVar = null) if ($task == 'apply') { - $redirect = JRoute::_('index.php?option=com_hierarchy&view=hierarchy&layout=edit&id=' . $id, false); - $app->redirect($redirect, $this->msg); + $redirect = Route::_('index.php?option=com_hierarchy&view=hierarchy&layout=edit&id=' . $id, false); + $app->enqueueMessage($this->msg); + $app->redirect($redirect); } // Clear the profile id from the session. @@ -138,8 +143,9 @@ public function save($key = null, $urlVar = null) } // Redirect to the list screen. - $redirect = JRoute::_('index.php?option=com_hierarchy&view=hierarchys', false); - $app->redirect($redirect, $this->msg); + $redirect = Route::_('index.php?option=com_hierarchy&view=hierarchys', false); + $app->enqueueMessage($this->msg); + $app->redirect($redirect); // Flush the data from the session. $app->setUserState('com_hierarchy.edit.hierarchy.data', null); @@ -154,7 +160,7 @@ public function save($key = null, $urlVar = null) */ public function getAutoSuggestUsers() { - $jinput = JFactory::getApplication()->input; + $jinput = Factory::getApplication()->input; $userId = $jinput->get('user_id', '', 'int'); // Get the model. diff --git a/administrator/controllers/hierarchys.php b/administrator/controllers/hierarchys.php index 364d59f..81f3061 100755 --- a/administrator/controllers/hierarchys.php +++ b/administrator/controllers/hierarchys.php @@ -9,16 +9,18 @@ // No direct access. defined('_JEXEC') or die; - -jimport('joomla.application.component.controlleradmin'); -jimport('joomla.filesystem.file'); +use Joomla\CMS\MVC\Controller\AdminController; +use Joomla\CMS\Factory; +use Joomla\CMS\Filesystem\File; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Router\Route; /** * The Hierarchys List Controller * * @since 1.6 */ -class HierarchyControllerHierarchys extends JControllerAdmin +class HierarchyControllerHierarchys extends AdminController { /** * Proxy for getModel @@ -47,23 +49,22 @@ public function getModel($name = 'hierarchy', $prefix = 'HierarchyModel', $confi */ public function csvImport() { - jimport('joomla.filesystem.file'); - $app = JFactory::getApplication(); + $app = Factory::getApplication(); // Start file heandling functionality $fname = $_FILES['csvfile']['name']; $rowNum = 0; - $uploadsDir = JFactory::getApplication()->getCfg('tmp_path') . '/' . $fname; - JFile::upload($_FILES['csvfile']['tmp_name'], $uploadsDir); + $uploadsDir = Factory::getApplication()->get('tmp_path') . '/' . $fname; + File::upload($_FILES['csvfile']['tmp_name'], $uploadsDir); if ($file = fopen($uploadsDir, "r")) { - $ext = JFile::getExt($uploadsDir); + $ext = File::getExt($uploadsDir); if ($ext != 'csv') { - $app->enqueueMessage(JText::_('COM_HIERARCHY_CSV_FORMAT_ERROR'), 'Message'); - $app->redirect(JRoute::_('index.php?option=com_hierarchy&view=hierarchys', false)); + $app->enqueueMessage(Text::_('COM_HIERARCHY_CSV_FORMAT_ERROR'), 'Message'); + $app->redirect(Route::_('index.php?option=com_hierarchy&view=hierarchys', false)); return; } @@ -100,14 +101,14 @@ public function csvImport() } else { - $app->enqueueMessage(JText::_('COM_HIERARCHY_IMPORT_CSV_ERROR'), 'error'); - $app->redirect(JRoute::_('index.php?option=com_hierarchy&view=hierarchys', false)); + $app->enqueueMessage(Text::_('COM_HIERARCHY_IMPORT_CSV_ERROR'), 'error'); + $app->redirect(Route::_('index.php?option=com_hierarchy&view=hierarchys', false)); return; } $model = $this->getModel(); - $userID = JFactory::getUser()->id; + $userID = Factory::getUser()->id; $data = array(); @@ -123,8 +124,10 @@ public function csvImport() $result = $model->save($data); } - $msg = JText::_('COM_HIERARCHY_IMPORT_CSV_SUCCESS_MSG'); - $app->redirect(JRoute::_('index.php?option=com_hierarchy&view=hierarchys', false), $msg); + $msg = Text::_('COM_HIERARCHY_IMPORT_CSV_SUCCESS_MSG'); + + $app->enqueueMessage($msg, 'success'); + $app->redirect(Route::_('index.php?option=com_hierarchy&view=hierarchys', false)); return; } @@ -140,7 +143,7 @@ public function csvImport() */ public function getUserId($email) { - $db = JFactory::getDbo(); + $db = Factory::getDbo(); $query = $db->getQuery(true) ->select($db->quoteName('id')) ->from($db->quoteName('#__users')) @@ -160,7 +163,7 @@ public function getUserId($email) public function remove() { $model = $this->getModel(); - $input = JFactory::getApplication()->input; + $input = Factory::getApplication()->input; $post = $input->post; $userIds = $post->get('cid', '', 'ARRAY'); @@ -181,11 +184,11 @@ public function remove() if ($model->delete($hierarchyIds)) { - $msg = JText::_('COM_HIERARCHY_HIERARCHY_DELETED_SCUSS'); + $msg = Text::_('COM_HIERARCHY_HIERARCHY_DELETED_SCUSS'); } else { - $msg = JText::_('COM_HIERARCHY_HIERARCHY_DELETED_ERROR'); + $msg = Text::_('COM_HIERARCHY_HIERARCHY_DELETED_ERROR'); } $this->setRedirect("index.php?option=com_hierarchy&view=hierarchys", $msg); diff --git a/administrator/helpers/hierarchy.php b/administrator/helpers/hierarchy.php index ced585a..1297e53 100755 --- a/administrator/helpers/hierarchy.php +++ b/administrator/helpers/hierarchy.php @@ -9,6 +9,10 @@ // No direct access defined('_JEXEC') or die; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Factory; +use Joomla\CMS\Object\CMSObject; /** * Hierarchys helper. @@ -28,7 +32,7 @@ class HierarchyHelper */ public static function addSubmenu($vName = '') { - JHtmlSidebar::addEntry(JText::_('COM_HIERARCHY_TITLE_HIERARCHYS'), 'index.php?option=com_hierarchy&view=hierarchys', $vName == 'hierarchys'); + JHtmlSidebar::addEntry(Text::_('COM_HIERARCHY_TITLE_HIERARCHYS'), 'index.php?option=com_hierarchy&view=hierarchys', $vName == 'hierarchys'); } /** @@ -41,8 +45,8 @@ public static function addSubmenu($vName = '') */ public static function getActions() { - $user = JFactory::getUser(); - $result = new JObject; + $user = Factory::getUser(); + $result = new CMSObject; $assetName = 'com_hierarchy'; @@ -65,8 +69,8 @@ public static function getActions() */ public static function getLanguageConstant() { - JText::script('JGLOBAL_VALIDATION_FORM_FAILED'); - JText::script('COM_HIERARCHY_HIERARCHY_DELETE_CONF'); - JText::script('COM_HIERARCHY_USERNAMES_DESC'); + Text::script('JGLOBAL_VALIDATION_FORM_FAILED'); + Text::script('COM_HIERARCHY_HIERARCHY_DELETE_CONF'); + Text::script('COM_HIERARCHY_USERNAMES_DESC'); } } diff --git a/administrator/hierarchy.php b/administrator/hierarchy.php index 1c0e4cf..c10d076 100755 --- a/administrator/hierarchy.php +++ b/administrator/hierarchy.php @@ -9,20 +9,25 @@ // No direct access defined('_JEXEC') or die; +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Uri\Uri; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\MVC\Controller\BaseController; // Access check. -if (!JFactory::getUser()->authorise('core.manage', 'com_hierarchy')) +if (!Factory::getUser()->authorise('core.manage', 'com_hierarchy')) { - throw new Exception(JText::_('JERROR_ALERTNOAUTHOR')); + throw new Exception(Text::_('JERROR_ALERTNOAUTHOR')); } // Include dependancies jimport('joomla.application.component.controller'); // Initialize hierarchy js -$document = JFactory::getDocument(); -$document->addScript(JUri::root(true) . '/media/com_hierarchy/js/hierarchy.js'); +$document = Factory::getDocument(); +HTMLHelper::_('script', '/media/com_hierarchy/js/hierarchy.js'); -$controller = JControllerLegacy::getInstance('Hierarchy'); -$controller->execute(JFactory::getApplication()->input->get('task')); +$controller = BaseController::getInstance('Hierarchy'); +$controller->execute(Factory::getApplication()->input->get('task')); $controller->redirect(); diff --git a/administrator/models/fields/contextlist.php b/administrator/models/fields/contextlist.php index 3de1105..ff111b7 100644 --- a/administrator/models/fields/contextlist.php +++ b/administrator/models/fields/contextlist.php @@ -9,6 +9,10 @@ // No direct access. defined('_JEXEC') or die(); +use Joomla\CMS\Form\FormHelper; +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\HTML\HTMLHelper; JFormHelper::loadFieldClass('list'); @@ -17,7 +21,7 @@ * * @since 1.0.0 */ -class JFormFieldContextList extends JFormFieldList +class JFormFieldContextList extends FormFieldList { /** * The form field type. @@ -44,7 +48,7 @@ class JFormFieldContextList extends JFormFieldList */ protected function getOptions() { - $db = JFactory::getDbo(); + $db = Factory::getDbo(); $query = $db->getQuery(true); // Select the required fields from the table. @@ -57,14 +61,14 @@ protected function getOptions() $contextList = $db->loadObjectList(); $options = array(); - $options[] = JHtml::_('select.option', '0', JText::_('COM_HIERARCHY_SELECT_CONTEXT')); + $options[] = HTMLHelper::_('select.option', '0', Text::_('COM_HIERARCHY_SELECT_CONTEXT')); if (!empty($contextList)) { foreach ($contextList as $context) { $context = $context->context; - $options[] = JHtml::_('select.option', $context, $context); + $options[] = HTMLHelper::_('select.option', $context, $context); } } diff --git a/administrator/models/fields/users.php b/administrator/models/fields/users.php index 4deb8b2..cf4d148 100644 --- a/administrator/models/fields/users.php +++ b/administrator/models/fields/users.php @@ -9,6 +9,10 @@ // No direct access. defined('_JEXEC') or die(); +use Joomla\CMS\Form\FormHelper; +use Joomla\CMS\Form\Field\UserField; +use Joomla\CMS\Factory; +use Joomla\CMS\HTML\HTMLHelper; JFormHelper::loadFieldClass('list'); @@ -17,7 +21,7 @@ * * @since 1.0.0 */ -class JFormFieldUsers extends JFormFieldList +class JFormFieldUsers extends FormFieldList { /** * The form field type. @@ -44,7 +48,7 @@ class JFormFieldUsers extends JFormFieldList */ protected function getOptions() { - $db = JFactory::getDbo(); + $db = Factory::getDbo(); $query = $db->getQuery(true); // Select the required fields from the table. @@ -61,7 +65,7 @@ protected function getOptions() foreach ($allUsers as $u) { - $options[] = JHtml::_('select.option', $u->id, $u->name); + $options[] = HTMLHelper::_('select.option', $u->id, $u->name); } if (!$this->loadExternally) diff --git a/administrator/models/hierarchy.php b/administrator/models/hierarchy.php index e478383..ae0f328 100755 --- a/administrator/models/hierarchy.php +++ b/administrator/models/hierarchy.php @@ -9,16 +9,18 @@ // No direct access. defined('_JEXEC') or die; - -jimport('joomla.application.component.modeladmin'); -jimport('joomla.database.table'); +use Joomla\CMS\MVC\Model\AdminModel; +use Joomla\CMS\Table\Table; +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Plugin\PluginHelper; /** * Methods supporting a list of Hierarchy records. * * @since 1.6 */ -class HierarchyModelHierarchy extends JModelAdmin +class HierarchyModelHierarchy extends AdminModel { /** * @var string The prefix to use with controller messages. @@ -38,9 +40,9 @@ class HierarchyModelHierarchy extends JModelAdmin */ public function getTable($type = 'hierarchy', $prefix = 'HierarchyTable', $config = array()) { - JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_hierarchy/tables'); + Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_hierarchy/tables'); - return JTable::getInstance($type, $prefix, $config); + return Table::getInstance($type, $prefix, $config); } /** @@ -56,7 +58,7 @@ public function getTable($type = 'hierarchy', $prefix = 'HierarchyTable', $confi public function getForm($data = array(), $loadData = true) { // Initialise variables. - $app = JFactory::getApplication(); + $app = Factory::getApplication(); // Get the form. $form = $this->loadForm('com_hierarchy.hierarchy', 'hierarchy', array('control' => 'jform', 'load_data' => $loadData)); @@ -79,7 +81,7 @@ public function getForm($data = array(), $loadData = true) protected function loadFormData() { // Check the session for previously entered form data. - $data = JFactory::getApplication()->getUserState('com_hierarchy.edit.hierarchy.data', array()); + $data = Factory::getApplication()->getUserState('com_hierarchy.edit.hierarchy.data', array()); if (empty($data)) { @@ -101,7 +103,7 @@ public function getItem($pk = null) $item = parent::getItem($pk); // Get client and client_id from URL - $jinput = JFactory::getApplication()->input; + $jinput = Factory::getApplication()->input; if (empty($item->context) && $jinput->get('client')) { @@ -142,7 +144,7 @@ public function save($data) // Validate if user_id is not specified if (!$data['user_id'] || !$data['reports_to']) { - $this->setError(JText::_('COM_HIERARCHY_INVALID_USER')); + $this->setError(Text::_('COM_HIERARCHY_INVALID_USER')); return false; } @@ -155,7 +157,7 @@ public function save($data) // Check hierarchy is already exist or not. $hierarchyId = $this->checkIfHierarchyExist($data); - $date = JFactory::getDate(); + $date = Factory::getDate(); if ($hierarchyId) { @@ -172,25 +174,23 @@ public function save($data) $isNew = empty($data['id']) ? true : false; // On before assigning manager - $dispatcher = JDispatcher::getInstance(); - JPluginHelper::importPlugin("system"); - JPluginHelper::importPlugin("actionlog"); - $dispatcher->trigger("hierarchyOnBeforeSaveHierarchy", array($data, $isNew)); + PluginHelper::importPlugin("system"); + PluginHelper::importPlugin("actionlog"); + Factory::getApplication()->triggerEvent("hierarchyOnBeforeSaveHierarchy", array($data, $isNew)); if (parent::save($data)) { $id = (int) $this->getState($this->getName() . '.id'); // On after assigning manager - $dispatcher = JDispatcher::getInstance(); - JPluginHelper::importPlugin("system"); - JPluginHelper::importPlugin("actionlog"); - $dispatcher->trigger("hierarchyOnAfterSaveHierarchy", array($data, $isNew)); + PluginHelper::importPlugin("system"); + PluginHelper::importPlugin("actionlog"); + Factory::getApplication()->triggerEvent("hierarchyOnAfterSaveHierarchy", array($data, $isNew)); return $id; } - $this->setError(JText::_('COM_HIERARCHY_SAVE_FAIL')); + $this->setError(Text::_('COM_HIERARCHY_SAVE_FAIL')); return false; } @@ -233,16 +233,16 @@ public function checkIfHierarchyExist($data) */ public function getSubUsers($id, $onlyIds = false) { - $user = JFactory::getuser($id); + $user = Factory::getuser($id); if (!$user->id) { - $this->setError(JText::_("COM_HIERARCHY_INVALID_USER")); + $this->setError(Text::_("COM_HIERARCHY_INVALID_USER")); return false; } - $db = JFactory::getDBO(); + $db = Factory::getDBO(); $query = $db->getQuery(true); if ($onlyIds) @@ -284,16 +284,16 @@ public function getSubUsers($id, $onlyIds = false) */ public function getManagers($id) { - $user = JFactory::getuser($id); + $user = Factory::getuser($id); if (!$user->id) { - $this->setError(JText::_("COM_HIERARCHY_INVALID_USER")); + $this->setError(Text::_("COM_HIERARCHY_INVALID_USER")); return false; } - $db = JFactory::getDBO(); + $db = Factory::getDBO(); $query = $db->getQuery(true); $query->select('*'); $query->from($db->quoteName('#__hierarchy_users')); @@ -318,16 +318,16 @@ public function getManagers($id) */ public function getReportsTo($reportsTo) { - $user = JFactory::getuser($reportsTo); + $user = Factory::getuser($reportsTo); if (!$user->id) { - $this->setError(JText::_("COM_HIERARCHY_INVALID_USER")); + $this->setError(Text::_("COM_HIERARCHY_INVALID_USER")); return false; } - $db = JFactory::getDbo(); + $db = Factory::getDbo(); $query = $db->getQuery(true); $query->select($db->quoteName(array('hu.id', 'user_id','reports_to','name','username','email'))); $query->from($db->quoteName('#__hierarchy_users', 'hu')); @@ -350,12 +350,12 @@ public function getReportsTo($reportsTo) */ public function getAutoSuggestUsers($userId) { - $app = JFactory::getApplication(); + $app = Factory::getApplication(); // Get search term $searchTerm = $app->input->get('search', '', 'STRING'); - $db = JFactory::getDbo(); + $db = Factory::getDbo(); $query = $db->getQuery(true); // Select the required fields from the table. @@ -387,33 +387,31 @@ public function getAutoSuggestUsers($userId) */ public function delete(&$pks) { - $user = JFactory::getUser(); - $db = JFactory::getDbo(); + $user = Factory::getUser(); + $db = Factory::getDbo(); - JTable::addIncludePath(JPATH_ROOT . '/administrator/components/com_hierarchy/tables'); + Table::addIncludePath(JPATH_ROOT . '/administrator/components/com_hierarchy/tables'); if (is_array($pks)) { foreach ($pks as $id) { - $hierarchyTable = JTable::getInstance('Hierarchy', 'HierarchyTable', array('dbo', $db)); + $hierarchyTable = Table::getInstance('Hierarchy', 'HierarchyTable', array('dbo', $db)); $hierarchyTable->load(array('id' => $id)); $data = $hierarchyTable->getProperties(); // On before removing manager - JPluginHelper::importPlugin("system"); - JPluginHelper::importPlugin("actionlog"); - $dispatcher = JDispatcher::getInstance(); - $dispatcher->trigger("hierarchyOnBeforeDeleteHierarchy", array($data)); + PluginHelper::importPlugin("system"); + PluginHelper::importPlugin("actionlog"); + Factory::getApplication()->triggerEvent("hierarchyOnBeforeDeleteHierarchy", array($data)); if ($hierarchyTable->delete($data['id'])) { // On after removing manager - JPluginHelper::importPlugin("system"); - JPluginHelper::importPlugin("actionlog"); - $dispatcher = JDispatcher::getInstance(); - $dispatcher->trigger("hierarchyOnAfterDeleteHierarchy", array($data)); + PluginHelper::importPlugin("system"); + PluginHelper::importPlugin("actionlog"); + Factory::getApplication()->triggerEvent("hierarchyOnAfterDeleteHierarchy", array($data)); } else { @@ -423,24 +421,22 @@ public function delete(&$pks) } else { - $hierarchyTable = JTable::getInstance('Hierarchy', 'HierarchyTable', array('dbo', $db)); + $hierarchyTable = Table::getInstance('Hierarchy', 'HierarchyTable', array('dbo', $db)); $hierarchyTable->load(array('id' => $pks)); $data = $hierarchyTable->getProperties(); // On before removing manager - $dispatcher = JDispatcher::getInstance(); - JPluginHelper::importPlugin("system"); - JPluginHelper::importPlugin("actionlog"); - $dispatcher->trigger("hierarchyOnBeforeDeleteHierarchy", array($data)); + PluginHelper::importPlugin("system"); + PluginHelper::importPlugin("actionlog"); + Factory::getApplication()->triggerEvent("hierarchyOnBeforeDeleteHierarchy", array($data)); if ($hierarchyTable->delete($data['id'])) { // On after removing manager - $dispatcher = JDispatcher::getInstance(); - JPluginHelper::importPlugin("system"); - JPluginHelper::importPlugin("actionlog"); - $dispatcher->trigger("hierarchyOnAfterDeleteHierarchy", array($data)); + PluginHelper::importPlugin("system"); + PluginHelper::importPlugin("actionlog"); + Factory::getApplication()->triggerEvent("hierarchyOnAfterDeleteHierarchy", array($data)); } else { diff --git a/administrator/models/hierarchys.php b/administrator/models/hierarchys.php index e3e38fb..29181d9 100644 --- a/administrator/models/hierarchys.php +++ b/administrator/models/hierarchys.php @@ -8,15 +8,17 @@ */ defined('_JEXEC') or die; - -jimport('joomla.application.component.modellist'); +use Joomla\CMS\MVC\Model\ListModel; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; +use Joomla\CMS\Factory; +use Joomla\CMS\Component\ComponentHelper; /** * Methods supporting a list of Hierarchy records. * * @since 1.6 */ -class HierarchyModelHierarchys extends JModelList +class HierarchyModelHierarchys extends ListModel { /** * Constructor. @@ -37,8 +39,8 @@ public function __construct($config = array()) ); } - JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_hierarchy/models'); - $this->hierarchyModel = JModelLegacy::getInstance('Hierarchy', 'HierarchyModel'); + BaseDatabaseModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_hierarchy/models'); + $this->hierarchyModel = BaseDatabaseModel::getInstance('Hierarchy', 'HierarchyModel'); parent::__construct($config); } @@ -58,7 +60,7 @@ public function __construct($config = array()) protected function populateState($ordering = null, $direction = null) { // Initialise variables. - $app = JFactory::getApplication('administrator'); + $app = Factory::getApplication('administrator'); // Load the filter state. $search = $app->getUserStateFromRequest($this->context . '.filter.search', 'filter_search'); @@ -71,7 +73,7 @@ protected function populateState($ordering = null, $direction = null) $this->setState('filter.context', $contextName); // Load the parameters. - $params = JComponentHelper::getParams('com_hierarchy'); + $params = ComponentHelper::getParams('com_hierarchy'); $this->setState('params', $params); // List state information. diff --git a/administrator/tables/hierarchy.php b/administrator/tables/hierarchy.php index e866302..0c2aae9 100644 --- a/administrator/tables/hierarchy.php +++ b/administrator/tables/hierarchy.php @@ -9,13 +9,14 @@ // No direct access defined('_JEXEC') or die; +use Joomla\CMS\Table\Table; /** * hierarchy Table class * * @since 1.0.4 */ -class HierarchyTableHierarchy extends JTable +class HierarchyTableHierarchy extends Table { /** * Constructor diff --git a/administrator/views/hierarchy/tmpl/edit.php b/administrator/views/hierarchy/tmpl/edit.php index 2223e7d..0e356c1 100755 --- a/administrator/views/hierarchy/tmpl/edit.php +++ b/administrator/views/hierarchy/tmpl/edit.php @@ -9,24 +9,28 @@ // No direct access defined('_JEXEC') or die; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Factory; +use Joomla\CMS\Uri\Uri; +use Joomla\CMS\Router\Route; -JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); -JHtml::_('behavior.tooltip'); -JHtml::_('behavior.formvalidation'); -JHtml::_('behavior.keepalive'); -$input = JFactory::getApplication()->input; +HTMLHelper::addIncludePath(JPATH_COMPONENT . '/helpers/html'); +HTMLHelper::_('behavior.tooltip'); +HTMLHelper::_('behavior.formvalidation'); +HTMLHelper::_('behavior.keepalive'); +$input = Factory::getApplication()->input; $userId = $input->get('user_id', 0); -$JUriRoot = JUri::root(true) . '/administrator/'; +$UriRoot = Uri::root(true) . '/administrator/'; // Tokenize -$document = JFactory::getDocument(); -$document->addScript(JUri::root(true) . '/media/com_hierarchy/vendors/tokenize/jquery.tokenize.js'); -$document->addStylesheet(JUri::root(true) . '/media/com_hierarchy/vendors/tokenize/jquery.tokenize.css'); +$document = Factory::getDocument(); +HTMLHelper::_('script', '/media/com_hierarchy/vendors/tokenize/jquery.tokenize.js'); +HTMLHelper::_('stylesheet','/media/com_hierarchy/vendors/tokenize/jquery.tokenize.css'); // Call helper function HierarchyHelper::getLanguageConstant(); ?> -
diff --git a/site/views/hierarchys/view.html.php b/site/views/hierarchys/view.html.php index ebd18a4..7de9c23 100755 --- a/site/views/hierarchys/view.html.php +++ b/site/views/hierarchys/view.html.php @@ -7,8 +7,15 @@ * @license GNU General Public License version 2 or later. */ defined('_JEXEC') or die; +use Joomla\CMS\MVC\View\HtmlView; +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Uri\Uri; +use Joomla\CMS\Router\Route; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; +use Joomla\CMS\Component\ComponentHelper; -jimport('joomla.application.component.view'); JLoader::import('components.com_hierarchy.models.hierarchys', JPATH_SITE); /** @@ -16,7 +23,7 @@ * * @since 1.6 */ -class HierarchyViewHierarchys extends JViewLegacy +class HierarchyViewHierarchys extends HtmlView { protected $items; @@ -37,18 +44,20 @@ class HierarchyViewHierarchys extends JViewLegacy */ public function display($tpl = null) { - $app = JFactory::getApplication(); - $user = JFactory::getUser(); + $app = Factory::getApplication(); + $user = Factory::getUser(); // Validate user login. if (empty($user->id)) { - $msg = JText::_('COM_HIERARCHY_MESSAGE_LOGIN_FIRST'); + $msg = Text::_('COM_HIERARCHY_MESSAGE_LOGIN_FIRST'); // Get current url. - $current = JUri::getInstance()->toString(); + $current = Uri::getInstance()->toString(); $url = base64_encode($current); - $app->redirect(JRoute::_('index.php?option=com_users&view=login&return=' . $url, false), $msg); + + $app->enqueueMessage($msg, 'notice'); + $app->redirect(Route::_('index.php?option=com_users&view=login&return=' . $url, false)); } $this->state = $this->get('State'); @@ -59,14 +68,14 @@ public function display($tpl = null) $contextName = $this->state->get('filter_context'); $contextList = array(); - $contextList[] = JHtml::_('select.option', '0', JText::_('COM_HIERARCHY_SELECT_CONTEXT')); + $contextList[] = HTMLHelper::_('select.option', '0', Text::_('COM_HIERARCHY_SELECT_CONTEXT')); if (!empty($this->items)) { foreach ($this->items as $item) { // Get list of people who is managers of logged in user. - $this->hierarchysModel = JModelLegacy::getInstance('Hierarchys', 'HierarchyModel'); + $this->hierarchysModel = BaseDatabaseModel::getInstance('Hierarchys', 'HierarchyModel'); $this->reportingsTo = $this->hierarchysModel->getReportingTo($item->reports_to); // Get avatar @@ -75,7 +84,7 @@ public function display($tpl = null) // Context filter $context = $item->context; - $contextList[] = JHtml::_('select.option', $context, $context); + $contextList[] = HTMLHelper::_('select.option', $context, $context); } } @@ -90,7 +99,7 @@ public function display($tpl = null) $this->HierarchyFrontendHelper = new HierarchyFrontendHelper; // Get component params - $this->params = JComponentHelper::getParams('com_hierarchy'); + $this->params = ComponentHelper::getParams('com_hierarchy'); // Get permissions $this->canCreate = $user->authorise('core.create', 'com_hierarchy'); From e8eebecf6de0533dd03884062e228c7ec660d823 Mon Sep 17 00:00:00 2001 From: divyachaudhari <58217051+divyachaudhari@users.noreply.github.com> Date: Thu, 7 Oct 2021 13:54:43 +0530 Subject: [PATCH 02/16] Task #173952 Chore: Script changes (#56) --- script.hierarchy.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/script.hierarchy.php b/script.hierarchy.php index 840880f..5a02719 100755 --- a/script.hierarchy.php +++ b/script.hierarchy.php @@ -16,6 +16,7 @@ use Joomla\CMS\Installer\InstallerHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\Object\CMSObject; +use Joomla\CMS\Installer\Installer; /** * Hierarchy Installer @@ -110,7 +111,7 @@ public function installSqlFiles($parent) if ($buffer !== false) { - $queries = \JDatabaseDriver::splitSql($buffer) + $queries = \JDatabaseDriver::splitSql($buffer); if (count($queries) != 0) { @@ -122,7 +123,7 @@ public function installSqlFiles($parent) { $db->setQuery($query); - if (!$db->query()) + if (!$db->execute()) { $this->setMessage(Text::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $db->stderr(true)), 'error'); From 68789025b3087abefe593a42c2fdd3d43bb36a31 Mon Sep 17 00:00:00 2001 From: divyachaudhari <58217051+divyachaudhari@users.noreply.github.com> Date: Thu, 7 Oct 2021 17:35:43 +0530 Subject: [PATCH 03/16] Task #173952 Chore: Table changes - changing default values for changes (#57) --- administrator/sql/install.mysql.utf8.sql | 20 ++++++++++---------- administrator/sql/updates/mysql/1.1.4.sql | 10 ++++++++++ changelog.md | 5 +++++ 3 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 administrator/sql/updates/mysql/1.1.4.sql diff --git a/administrator/sql/install.mysql.utf8.sql b/administrator/sql/install.mysql.utf8.sql index 5cb47c9..d7b2909 100755 --- a/administrator/sql/install.mysql.utf8.sql +++ b/administrator/sql/install.mysql.utf8.sql @@ -4,15 +4,15 @@ -- CREATE TABLE IF NOT EXISTS `#__hierarchy_users` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, -`user_id` INT(11) NOT NULL COMMENT 'This field is to store user id of user', -`reports_to` INT(11) NOT NULL COMMENT 'This field is to select to whom all current user reports to', -`context` VARCHAR(255) NOT NULL , -`context_id` INT(11) NOT NULL, -`created_by` INT(11) NOT NULL, -`modified_by` INT(11) NOT NULL, -`created_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', -`modified_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', -`state` INT(11) NOT NULL, -`note` TEXT NOT NULL, +`user_id` INT(11) NOT NULL COMMENT 'This field is to store user id of user' DEFAULT 0, +`reports_to` INT(11) NOT NULL COMMENT 'This field is to select to whom all current user reports to' DEFAULT 0, +`context` VARCHAR(255) NOT NULL DEFAULT '', +`context_id` INT(11) NOT NULL DEFAULT 0, +`created_by` INT(11) NOT NULL DEFAULT 0, +`modified_by` INT(11) NOT NULL DEFAULT 0, +`created_date` datetime NULL DEFAULT NULL, +`modified_date` datetime NULL DEFAULT NULL, +`state` INT(11) NOT NULL DEFAULT 0, +`note` TEXT NOT NULL DEFAULT '', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; diff --git a/administrator/sql/updates/mysql/1.1.4.sql b/administrator/sql/updates/mysql/1.1.4.sql new file mode 100644 index 0000000..ef1269b --- /dev/null +++ b/administrator/sql/updates/mysql/1.1.4.sql @@ -0,0 +1,10 @@ +-- Adding default value for all the columns + +ALTER TABLE `#__hierarchy_users` CHANGE `context` `context` VARCHAR(255) NOT NULL DEFAULT ''; +ALTER TABLE `#__hierarchy_users` CHANGE `context_id` `context_id` INT(11) NOT NULL DEFAULT 0; +ALTER TABLE `#__hierarchy_users` CHANGE `created_by` `created_by` INT(11) NOT NULL DEFAULT 0; +ALTER TABLE `#__hierarchy_users` CHANGE `modified_by` `modified_by` INT(11) NOT NULL DEFAULT 0; +ALTER TABLE `#__hierarchy_users` CHANGE `created_date` `created_date` datetime NULL DEFAULT NULL, +ALTER TABLE `#__hierarchy_users` CHANGE `modified_date` `modified_date` datetime NULL DEFAULT NULL, +ALTER TABLE `#__hierarchy_users` CHANGE `state` `state` INT(11) NOT NULL DEFAULT 0; +ALTER TABLE `#__hierarchy_users` CHANGE `note` `note` TEXT NOT NULL DEFAULT ''; diff --git a/changelog.md b/changelog.md index a09ac8c..30a0bbc 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,11 @@ - Feature Addition (+) - Improvement (^) +## com_hierarchy v1.1.4 + +##### ^ Improvements: +- #173952 Adding default values to the Tables for Joomla 4 Compatibility + ## com_hierarchy v1.1.3 ##### - Bug Fixes: From 8616a5a5e5504bec0c0bb249478cd7bedb6b1ccb Mon Sep 17 00:00:00 2001 From: kokbira