From a08972cd1ab71caf35894b59ccda946cd00b3dd0 Mon Sep 17 00:00:00 2001 From: kamalakanta Date: Thu, 11 May 2023 15:16:40 +0530 Subject: [PATCH] Task #198104 chore: comaptibleand code to joomla4 --- src/plugins/actionlog/tjucm/tjucm.php | 15 +++++++++------ src/plugins/api/tjucm/tjucm.php | 16 +++++++++------- src/plugins/api/tjucm/tjucm/item.php | 19 +++++++++++-------- src/plugins/api/tjucm/tjucm/type.php | 22 +++++++++++++--------- 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/src/plugins/actionlog/tjucm/tjucm.php b/src/plugins/actionlog/tjucm/tjucm.php index cd422570..7683b387 100644 --- a/src/plugins/actionlog/tjucm/tjucm.php +++ b/src/plugins/actionlog/tjucm/tjucm.php @@ -10,13 +10,16 @@ // No direct access. defined('_JEXEC') or die(); +use Joomla\CMS\Application\CMSApplication; +use Joomla\Data\DataObject; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; +use Joomla\CMS\Router\Route; JLoader::register('ActionlogsHelper', JPATH_ADMINISTRATOR . '/components/com_actionlogs/helpers/actionlogs.php'); use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Plugin\CMSPlugin; use Joomla\CMS\Factory; -use Joomla\CMS\MVC\Model\BaseDatabaseModel; use Joomla\CMS\Table\Table; /** @@ -29,7 +32,7 @@ class PlgActionlogTjUcm extends CMSPlugin /** * Application object. * - * @var JApplicationCms + * @var CMSApplication * @since __DEPLOY__VERSION__ */ protected $app; @@ -37,7 +40,7 @@ class PlgActionlogTjUcm extends CMSPlugin /** * Database object. * - * @var JDatabaseDriver + * @var DataObjectbaseDriver * @since __DEPLOY__VERSION__ */ protected $db; @@ -317,7 +320,7 @@ public function tjucmOnBeforeSaveItemData($recordId, $client, $data) $clusterField = str_replace(".", "_", $client) . '_clusterclusterid'; JLoader::import('components.com_cluster.models.clusteruser', JPATH_ADMINISTRATOR); - $clusterUserModel = JModelLegacy::getInstance('ClusterUser', 'ClusterModel'); + $clusterUserModel = BaseDatabaseModel::getInstance('ClusterUser', 'ClusterModel'); $usersClusters = $clusterUserModel->getUsersClusters($user->id); if ($data[$clusterField]) @@ -370,7 +373,7 @@ public function tjucmOnBeforeSaveItemData($recordId, $client, $data) $tjUcmFrontendHelper = new TjucmHelpersTjucm; $link = 'index.php?option=com_tjucm&view=item&client=' . $client . '&id=' . $recordId; $itemId = $tjUcmFrontendHelper->getItemId($link); - $link = JRoute::_($link . '&Itemid=' . $itemId, false); + $link = Route::_($link . '&Itemid=' . $itemId, false); $message = array( 'action' => 'add', @@ -428,7 +431,7 @@ public function tjUcmOnBeforeDeleteItem($item, $client) $tjucmTableItem->load($item); JLoader::import('components.com_cluster.models.clusteruser', JPATH_ADMINISTRATOR); - $clusterUserModel = JModelLegacy::getInstance('ClusterUser', 'ClusterModel'); + $clusterUserModel = BaseDatabaseModel::getInstance('ClusterUser', 'ClusterModel'); $usersClusters = $clusterUserModel->getUsersClusters($user->id); $deletingRecordOfOtherCluster = true; diff --git a/src/plugins/api/tjucm/tjucm.php b/src/plugins/api/tjucm/tjucm.php index 1f59a2a8..3ec10da2 100644 --- a/src/plugins/api/tjucm/tjucm.php +++ b/src/plugins/api/tjucm/tjucm.php @@ -9,10 +9,12 @@ */ defined('_JEXEC') or die('Restricted access'); +use Joomla\CMS\Factory; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; +use Joomla\CMS\Table\Table; jimport('joomla.plugin.plugin'); -jimport('joomla.application.component.model'); -$lang = JFactory::getLanguage(); +$lang = Factory::getLanguage(); $lang->load('com_tjucm', JPATH_ADMINISTRATOR); /** @@ -46,13 +48,13 @@ public function __construct($subject, $config = array()) } // Load component models - JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjucm/models'); - JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjfields/models'); - JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_tjucm/models'); + BaseDatabaseModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjucm/models'); + BaseDatabaseModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjfields/models'); + BaseDatabaseModel::addIncludePath(JPATH_SITE . '/components/com_tjucm/models'); // Load component tables - JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjucm/tables'); - JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjfields/tables'); + Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjucm/tables'); + Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjfields/tables'); ApiResource::addIncludePath(dirname(__FILE__) . '/tjucm'); } diff --git a/src/plugins/api/tjucm/tjucm/item.php b/src/plugins/api/tjucm/tjucm/item.php index 2e4e9230..5dfb57ac 100644 --- a/src/plugins/api/tjucm/tjucm/item.php +++ b/src/plugins/api/tjucm/tjucm/item.php @@ -9,6 +9,9 @@ */ defined('_JEXEC') or die; +use Joomla\CMS\Factory; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; +use Joomla\CMS\Language\Text; jimport('joomla.plugin.plugin'); /** @@ -29,9 +32,9 @@ class TjucmApiResourceItem extends ApiResource */ public function get() { - $jInput = JFactory::getApplication()->input; + $jInput = Factory::getApplication()->input; $id = $jInput->get('id'); - $tjUcmModelItem = JModelLegacy::getInstance('Item', 'TjucmModel'); + $tjUcmModelItem = BaseDatabaseModel::getInstance('Item', 'TjucmModel'); // Setting Client ID $item = $tjUcmModelItem->getItem($id); @@ -48,11 +51,11 @@ public function get() */ public function post() { - $jInput = JFactory::getApplication()->input; + $jInput = Factory::getApplication()->input; $client = $jInput->get('client'); // Getting the request Body Data - $jinput = JFactory::getApplication()->input->json; + $jinput = Factory::getApplication()->input->json; // Setting Item details $data = array(); @@ -65,7 +68,7 @@ public function post() $extra_jform_data = array(); // Addding Extra item field values - $tjFieldsModelFields = JModelLegacy::getInstance('Fields', 'TjfieldsModel'); + $tjFieldsModelFields = BaseDatabaseModel::getInstance('Fields', 'TjfieldsModel'); $tjFieldsModelFields->setState("filter.client", $client); // Variable to store Fields of FieldGroup @@ -87,7 +90,7 @@ public function post() $extra_jform_data[$fieldsAssoc[(int) $field["id"]]] = $field["value"]; } - $tjUcmModelItemForm = JModelLegacy::getInstance('ItemForm', 'TjucmModel'); + $tjUcmModelItemForm = BaseDatabaseModel::getInstance('ItemForm', 'TjucmModel'); // Setting Client ID $tjUcmModelItemForm->setClient($client); @@ -99,13 +102,13 @@ public function post() if ($itemId) { $return_arr['success'] = true; - $return_arr['message'] = JText::_("COM_TJUCM_ITEM_ADDED"); + $return_arr['message'] = Text::_("COM_TJUCM_ITEM_ADDED"); $return_arr['id'] = $itemId; } else { $return_arr['success'] = false; - $return_arr['message'] = JText::_("COM_TJUCM_ITEM_NOT_ADDED"); + $return_arr['message'] = Text::_("COM_TJUCM_ITEM_NOT_ADDED"); } $this->plugin->setResponse($return_arr); diff --git a/src/plugins/api/tjucm/tjucm/type.php b/src/plugins/api/tjucm/tjucm/type.php index 0e3ed031..7fbdec0a 100644 --- a/src/plugins/api/tjucm/tjucm/type.php +++ b/src/plugins/api/tjucm/tjucm/type.php @@ -9,6 +9,10 @@ */ defined('_JEXEC') or die; +use Joomla\CMS\Factory; +use Joomla\CMS\Table\Table; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; +use Joomla\CMS\Language\Text; jimport('joomla.plugin.plugin'); /** @@ -29,26 +33,26 @@ class TjucmApiResourceType extends ApiResource */ public function get() { - $jInput = JFactory::getApplication()->input; + $jInput = Factory::getApplication()->input; $client = $jInput->get('client'); - $table = JTable::getInstance('Type', 'TjucmTable'); + $table = Table::getInstance('Type', 'TjucmTable'); $table->load(["unique_identifier" => $client]); - $tjUcmModelType = JModelLegacy::getInstance('Type', 'TjucmModel'); + $tjUcmModelType = BaseDatabaseModel::getInstance('Type', 'TjucmModel'); $tjUcmModelType->setState("filter.client", $client); // Variable to store UCM Type $ucmType = $tjUcmModelType->getItem($table->id); // Variable to store creator name and id - $created_by = JFactory::getUser($ucmType->created_by); + $created_by = Factory::getUser($ucmType->created_by); $ucmType->created_by = array("id" => $created_by->id, "name" => $created_by->name); // Variable to store modifier name and id - $modified_by = JFactory::getUser($ucmType->modified_by); + $modified_by = Factory::getUser($ucmType->modified_by); $ucmType->modified_by = array("id" => $modified_by->id, "name" => $modified_by->name); - $tjFieldsModelGroups = JModelLegacy::getInstance('Groups', 'TjfieldsModel', array('ignore_request' => true)); + $tjFieldsModelGroups = BaseDatabaseModel::getInstance('Groups', 'TjfieldsModel', array('ignore_request' => true)); $tjFieldsModelGroups->setState('list.ordering', 'a.ordering'); $tjFieldsModelGroups->setState('list.direction', 'asc'); @@ -58,7 +62,7 @@ public function get() // Getting fields of fieldgroups foreach ($fieldgroups as $groupKey => $groupValue) { - $tjFieldsModelFields = JModelLegacy::getInstance('Fields', 'TjfieldsModel', array('ignore_request' => true)); + $tjFieldsModelFields = BaseDatabaseModel::getInstance('Fields', 'TjfieldsModel', array('ignore_request' => true)); $tjFieldsModelFields->setState("filter.group_id", $fieldgroups[$groupKey]->id); $tjFieldsModelFields->setState('list.ordering', 'a.ordering'); $tjFieldsModelFields->setState('list.direction', 'asc'); @@ -69,7 +73,7 @@ public function get() // Getting options of field foreach ($fields as $fieldKey => $fieldValue) { - $tjFieldsModelOptions = JModelLegacy::getInstance('Options', 'TjfieldsModel'); + $tjFieldsModelOptions = BaseDatabaseModel::getInstance('Options', 'TjfieldsModel'); $tjFieldsModelOptions->setState("filter.field_id", $fields[$fieldKey]->id); // Variable to store Options of Field @@ -93,7 +97,7 @@ public function get() if (empty($ucmType)) { $return_arr['success'] = false; - $return_arr['message'] = JText::_("COM_TJUCM_NO_TYPE"); + $return_arr['message'] = Text::_("COM_TJUCM_NO_TYPE"); } else {