diff --git a/README.md b/README.md index d96bc6a..55acbab 100644 --- a/README.md +++ b/README.md @@ -6,16 +6,17 @@ Here is a live example of how general and context specific hierarchy can be: Mark, Swapnil, Mary & Vaishali normally report to Vijay. However Mary and Vaishali have been asked to additionally report to Parth in the special context of a 'Project A' ## How to Install -Donwload the code. Package it as a Zip and install it using the Joomla extension manager. +Download the code. Package it as a Zip and install it using the Joomla extension manager. ## Configurtion -Integration Options : Core Joomla, EasySocial, JomSocial, EasyProfile, Community Builder +Integration Options: Core Joomla, EasySocial, JomSocial, EasyProfile, Community Builder ## Frontend Menus The Hierarchy management system supports the following menus on the frontend. ### My Team -Shows a list view of people directly reporting to the logged in user. List can be filtered by Context. Default (context ?) is None. +Shows a list view of people directly reporting to the logged in user. List can be filtered by Context. Default (context ?) is None. + From this view they can drill down to the user and see a short User information page and also the team that reports to that user. An Icon will let you switch to a visual representation that will show a chart view. The default layout to use can be set in menu parameters. 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..05fdaad 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,9 +32,12 @@ class HierarchyHelper */ public static function addSubmenu($vName = '') { - JHtmlSidebar::addEntry(JText::_('COM_HIERARCHY_TITLE_HIERARCHYS'), 'index.php?option=com_hierarchy&view=hierarchys', $vName == 'hierarchys'); + if (JVERSION < '4.0.0') + { + JHtmlSidebar::addEntry(Text::_('COM_HIERARCHY_TITLE_HIERARCHYS'), 'index.php?option=com_hierarchy&view=hierarchys', $vName == 'hierarchys'); + } } - + /** * Gets a list of the actions that can be performed. * @@ -41,8 +48,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 +72,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/language/en-GB/en-GB.com_hierarchy.ini b/administrator/language/en-GB/en-GB.com_hierarchy.ini index b12b03b..ab7e0a6 100755 --- a/administrator/language/en-GB/en-GB.com_hierarchy.ini +++ b/administrator/language/en-GB/en-GB.com_hierarchy.ini @@ -62,7 +62,7 @@ COM_HIERARCHY_IMPORT_CATEGORY_SUCCESSFULY="Successfully import categoryies." COM_HIERARCHY_IMPORT_SUBUSERS_CSV_DATA_WRONG="Please check CSV file, Data format is wrong." COM_HIERARCHY_HIERARCHYS_REPORT_TO="Reports to" CSV_EXPORT="Export CSV" -COM_HIERARCHY_USERS_CSV_SELECT_FILE="Select CSV File" +COM_HIERARCHY_USERS_CSV_SELECT_FILE="Select the CSV File" COM_HIERARCHY_USERS_BROWSE="Browse" COM_HIERARCHY_CSVHELP="Note: To import users from a CSV file, make sure you enter your data in the given CSV %s" COM_HIERARCHY_CSV_SAMPLE="Format" @@ -123,7 +123,7 @@ COM_HIERARCHY_GRAVATAR_INT_CONF="Fetch user profile pic from http://en.gravatar. COM_HIERARCHY_GRAVATAR_INT_CONF_DESC="If you enable this option then user profile pic will be taken from http://en.gravatar.com/, where most of the users profile pics available. This configuration is useful only while integration with the only Joomla." COM_HIERARCHY_INVALID_USER="Enter a valid user id" COM_HIERARCHY_INVALID_REPORTS_TO="Enter a valid reports to." -COM_HIERARCHY_SAVE_MSG="Hierarchy save successfully." +COM_HIERARCHY_SAVE_MSG="Hierarchy saved successfully." COM_HIERARCHY_FAIL_MSG="Failed to save hierarchy." COM_HIERARCHY_IMPORT_CSV_SUCCESS_MSG="Hierarchy imported successfully" COM_HIERARCHY_SET_MANAGER="Set" diff --git a/administrator/models/fields/contextlist.php b/administrator/models/fields/contextlist.php index 3de1105..6c04a2b 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'); @@ -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..e408943 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'); @@ -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..e04fe16 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("onBeforeHierarchySaveHierarchy", 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("onAfterHierarchySaveHierarchy", 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("onBeforeHierarchyDeleteHierarchy", 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("onAfterHierarchyDeleteHierarchy", 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("onBeforeHierarchyDeleteHierarchy", 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("onAfterHierarchyDeleteHierarchy", 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/sql/install.mysql.utf8.sql b/administrator/sql/install.mysql.utf8.sql index 5cb47c9..e8ba576 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 DEFAULT NULL, +`modified_date` datetime DEFAULT NULL, +`state` INT(11) NOT NULL DEFAULT 0, +`note` TEXT DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; diff --git a/administrator/sql/updates/mysql/1.1.2.sql b/administrator/sql/updates/mysql/1.1.2.sql index 3f23ae8..150f82b 100755 --- a/administrator/sql/updates/mysql/1.1.2.sql +++ b/administrator/sql/updates/mysql/1.1.2.sql @@ -2,7 +2,5 @@ ALTER TABLE `#__hierarchy_users` ENGINE = InnoDB; -- Change charset, collation -ALTER TABLE `#__hierarchy_users` CHANGE `note` `note` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL; -ALTER TABLE `#__hierarchy_users` CHANGE `context` `context` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL; - - +ALTER TABLE `#__hierarchy_users` CHANGE `note` `note` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL; +ALTER TABLE `#__hierarchy_users` CHANGE `context` `context` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''; diff --git a/administrator/sql/updates/mysql/1.1.sql b/administrator/sql/updates/mysql/1.1.sql index af95455..14622b4 100755 --- a/administrator/sql/updates/mysql/1.1.sql +++ b/administrator/sql/updates/mysql/1.1.sql @@ -4,25 +4,24 @@ -- 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 DEFAULT NULL, +`modified_date` datetime DEFAULT NULL, +`state` INT(11) NOT NULL DEFAULT 0, +`note` TEXT DEFAULT NULL, PRIMARY KEY (`id`) -) DEFAULT COLLATE=utf8_general_ci; - -ALTER TABLE `#__hierarchy_users` CHANGE `user_id` `reports_to` INT(11); -ALTER TABLE `#__hierarchy_users` CHANGE `subuser_id` `user_id` INT(11); -ALTER TABLE `#__hierarchy_users` CHANGE `client` `context` varchar(255); -ALTER TABLE `#__hierarchy_users` CHANGE `client_id` `context_id` varchar(255); -ALTER TABLE `#__hierarchy_users` add column `created_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00'; -ALTER TABLE `#__hierarchy_users` add column `created_by` int(11) NULL DEFAULT '0' AFTER `created_date`; -ALTER TABLE `#__hierarchy_users` add column `modified_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `created_by`; -ALTER TABLE `#__hierarchy_users` add column `modified_by` int(11) NULL DEFAULT '0' AFTER `modified_date`; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; +ALTER TABLE `#__hierarchy_users` CHANGE `user_id` `reports_to` INT(11) NOT NULL COMMENT 'This field is to select to whom all current user reports to' DEFAULT 0; +ALTER TABLE `#__hierarchy_users` CHANGE `subuser_id` `user_id` INT(11) NOT NULL COMMENT 'This field is to store user id of user' DEFAULT 0; +ALTER TABLE `#__hierarchy_users` CHANGE `client` `context` VARCHAR(255) NOT NULL DEFAULT ''; +ALTER TABLE `#__hierarchy_users` CHANGE `client_id` `context_id` INT(11) NOT NULL DEFAULT 0; +ALTER TABLE `#__hierarchy_users` add column `created_date` datetime DEFAULT NULL; +ALTER TABLE `#__hierarchy_users` add column `created_by` INT(11) NOT NULL DEFAULT 0; +ALTER TABLE `#__hierarchy_users` add column `modified_date` datetime DEFAULT NULL; +ALTER TABLE `#__hierarchy_users` add column `modified_by` INT(11) NOT NULL DEFAULT 0; diff --git a/administrator/sql/updates/mysql/2.0.0.sql b/administrator/sql/updates/mysql/2.0.0.sql new file mode 100644 index 0000000..5402d57 --- /dev/null +++ b/administrator/sql/updates/mysql/2.0.0.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 DEFAULT NULL; +ALTER TABLE `#__hierarchy_users` CHANGE `modified_date` `modified_date` datetime DEFAULT NULL; +ALTER TABLE `#__hierarchy_users` CHANGE `state` `state` INT(11) NOT NULL DEFAULT 0; +ALTER TABLE `#__hierarchy_users` CHANGE `note` `note` TEXT DEFAULT NULL; 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');