From 5a7babb77a85c2ae6986be70bcad5507eb8b20c5 Mon Sep 17 00:00:00 2001 From: Vijay Khollam Date: Fri, 4 Dec 2020 19:41:36 +0530 Subject: [PATCH 1/2] Task #166808 feat: Copy Multiple records to Multiple Organisation --- src/components/com_tjucm/media/js/ui/items.js | 21 +- .../com_tjucm/media/js/ui/items.min.js | 2 +- .../site/controllers/itemform.json.php | 362 +++++++++--------- .../views/items/tmpl/default_copyitems.php | 4 +- 4 files changed, 209 insertions(+), 180 deletions(-) diff --git a/src/components/com_tjucm/media/js/ui/items.js b/src/components/com_tjucm/media/js/ui/items.js index e852e282..0c0f9a5d 100644 --- a/src/components/com_tjucm/media/js/ui/items.js +++ b/src/components/com_tjucm/media/js/ui/items.js @@ -10,7 +10,7 @@ jQuery(window).load(function() if (response.data) { jQuery.each(response.data, function(key, value) { - jQuery('#target_ucm').append(jQuery('').attr('value',value.value).text(value.text)); + jQuery('#target_ucm').append(jQuery('').attr('value',value.value).text(value.text)); jQuery('#target_ucm').trigger('liszt:updated'); }); } @@ -19,7 +19,7 @@ jQuery(window).load(function() jQuery('.ucmListField').addClass('hide'); } }; - + // Code to check ucm type compatibility to copy item com_tjucm.Services.Items.chekCompatibility(currentUcmType, afterCheckCompatibilityOfUcmType); @@ -28,7 +28,7 @@ jQuery(window).load(function() if (response.data != null) { jQuery.each(response.data, function(key, value) { - jQuery('#cluster_list').append(jQuery('').attr('value',value.value).text(value.text)); + jQuery('#cluster_list').append(jQuery('').attr('value',value.value).text(value.text)); jQuery('#cluster_list').trigger('liszt:updated'); }); } @@ -37,7 +37,7 @@ jQuery(window).load(function() jQuery('.clusterListField').addClass('hide'); } }; - + // To get the cluster fields options com_tjucm.Services.Items.getClusterFieldOptions(currentUcmType, afterGetClusterField); }); @@ -51,7 +51,7 @@ var tjUcmItems = { jQuery("html, body").animate({scrollTop: jQuery("#item-form #tjucm_loader").position().top}, "slow"); response = JSON.parse(response); - + sessionStorage.setItem('message', response.message); if(response.data !== null) { @@ -63,7 +63,16 @@ var tjUcmItems = { } } - var copyItemData = jQuery('#adminForm').serialize(); + var copyItemData = jQuery('#adminForm').serializeArray(); + var clusterId = jQuery('.cluster_list').val(); + + // Update cluster Ids + copyItemData.push({ + name: "cluster_list", + value: clusterId + }); + + copyItemData = jQuery.param(copyItemData); // Code to copy item to ucm type com_tjucm.Services.Items.copyItem(copyItemData, afterCopyItem); diff --git a/src/components/com_tjucm/media/js/ui/items.min.js b/src/components/com_tjucm/media/js/ui/items.min.js index f93d7843..290ce0af 100644 --- a/src/components/com_tjucm/media/js/ui/items.min.js +++ b/src/components/com_tjucm/media/js/ui/items.min.js @@ -1 +1 @@ -jQuery(window).load(function(){var e=jQuery("#client").val(),t=new FormData;t.append("client",e);com_tjucm.Services.Items.chekCompatibility(t,function(e,t){(t=JSON.parse(t)).data?jQuery.each(t.data,function(e,t){jQuery("#target_ucm").append(jQuery("").attr("value",t.value).text(t.text)),jQuery("#target_ucm").trigger("liszt:updated")}):jQuery(".ucmListField").addClass("hide")});com_tjucm.Services.Items.getClusterFieldOptions(t,function(e,t){null!=(t=JSON.parse(t)).data?jQuery.each(t.data,function(e,t){jQuery("#cluster_list").append(jQuery("").attr("value",t.value).text(t.text)),jQuery("#cluster_list").trigger("liszt:updated")}):jQuery(".clusterListField").addClass("hide")})});var tjUcmItems={copyItem:function(){var e=jQuery("#adminForm").serialize();com_tjucm.Services.Items.copyItem(e,function(e,t){jQuery("#item-form #tjucm_loader").show(),jQuery("html, body").animate({scrollTop:jQuery("#item-form #tjucm_loader").position().top},"slow"),t=JSON.parse(t),sessionStorage.setItem("message",t.message),null!==t.data?sessionStorage.setItem("class","alert alert-success"):sessionStorage.setItem("class","alert alert-danger")})}}; +jQuery(window).load(function(){var a=jQuery("#client").val(),b=new FormData;b.append("client",a);com_tjucm.Services.Items.chekCompatibility(b,function(a,b){b=JSON.parse(b),b.data?jQuery.each(b.data,function(a,b){jQuery("#target_ucm").append(jQuery("").attr("value",b.value).text(b.text)),jQuery("#target_ucm").trigger("liszt:updated")}):jQuery(".ucmListField").addClass("hide")});com_tjucm.Services.Items.getClusterFieldOptions(b,function(a,b){b=JSON.parse(b),null==b.data?jQuery(".clusterListField").addClass("hide"):jQuery.each(b.data,function(a,b){jQuery("#cluster_list").append(jQuery("").attr("value",b.value).text(b.text)),jQuery("#cluster_list").trigger("liszt:updated")})})});var tjUcmItems={copyItem:function(){var a=jQuery("#adminForm").serializeArray(),b=jQuery(".cluster_list").val();a.push({name:"cluster_list",value:b}),a=jQuery.param(a),com_tjucm.Services.Items.copyItem(a,function(a,b){jQuery("#item-form #tjucm_loader").show(),jQuery("html, body").animate({scrollTop:jQuery("#item-form #tjucm_loader").position().top},"slow"),b=JSON.parse(b),sessionStorage.setItem("message",b.message),null===b.data?sessionStorage.setItem("class","alert alert-danger"):sessionStorage.setItem("class","alert alert-success")})}}; diff --git a/src/components/com_tjucm/site/controllers/itemform.json.php b/src/components/com_tjucm/site/controllers/itemform.json.php index e523cff3..36cb2f1d 100644 --- a/src/components/com_tjucm/site/controllers/itemform.json.php +++ b/src/components/com_tjucm/site/controllers/itemform.json.php @@ -550,11 +550,11 @@ public function copyItem() // Check for request forgeries. Session::checkToken() or jexit(Text::_('JINVALID_TOKEN')); - $app = Factory::getApplication(); + $app = Factory::getApplication(); $post = $app->input->post; $sourceClient = $app->input->get('client', '', 'string'); - $filter = $app->input->get('filter', '', 'ARRAY'); + $filter = $app->input->get('filter', '', 'ARRAY'); $targetClient = $filter['target_ucm']; if (!$targetClient) @@ -562,7 +562,19 @@ public function copyItem() $targetClient = $sourceClient; } - $clusterId = $filter['cluster_list']; + // Get Clusers list and conver to array + $clusterIds = $app->input->get('cluster_list', '', 'string'); + $clusterIds = explode(',', $clusterIds); + + $db = JFactory::getDbo(); + JTable::addIncludePath(JPATH_ROOT . '/administrator/components/com_tjucm/tables'); + $typeTable = JTable::getInstance('Type', 'TjucmTable', array('dbo', $db)); + + if ($targetClient) + { + $typeTable->load(array('unique_identifier' => $targetClient)); + $ucmTypeId = $typeTable->id; + } JLoader::import('components.com_tjucm.models.type', JPATH_ADMINISTRATOR); $typeModel = BaseDatabaseModel::getInstance('Type', 'TjucmModel'); @@ -580,221 +592,229 @@ public function copyItem() if ($result) { $copyIds = $app->input->get('cid'); + JLoader::import('components.com_tjfields.helpers.tjfields', JPATH_SITE); $tjFieldsHelper = new TjfieldsHelper; if (count($copyIds)) { - $model = $this->getModel('itemform'); + $model = $this->getModel('itemform'); $ucmConfigs = ComponentHelper::getParams('com_tjucm'); $useTjQueue = $ucmConfigs->get('tjqueue_copy_items'); if ($useTjQueue) { - foreach ($copyIds as $cid) + foreach ($clusterIds as $clusterId) { - $response = $model->queueItemCopy($cid, $sourceClient, $targetClient, Factory::getuser()->id, $clusterId); + foreach ($copyIds as $cid) + { + $response = $model->queueItemCopy($cid, $sourceClient, $targetClient, Factory::getuser()->id, $clusterId); - $msg = ($response) ? Text::_("COM_TJUCM_ITEM_COPY_TO_QUEUE_SUCCESSFULLY") : Text::_("COM_TJUCM_FORM_SAVE_FAILED"); + $msg = ($response) ? Text::_("COM_TJUCM_ITEM_COPY_TO_QUEUE_SUCCESSFULLY") : Text::_("COM_TJUCM_FORM_SAVE_FAILED"); + } } } else { $model->setClient($targetClient); - foreach ($copyIds as $cid) + foreach ($clusterIds as $clusterId) { - $ucmOldData = array(); - $ucmOldData['clientComponent'] = 'com_tjucm'; - $ucmOldData['content_id'] = $cid; - $ucmOldData['layout'] = 'edit'; - $ucmOldData['client'] = $sourceClient; - $fileFieldArray = array(); - - // Get the field values - $extraFieldsData = $model->loadFormDataExtra($ucmOldData); - - // Code to replace source field name with destination field name - foreach ($extraFieldsData as $fieldKey => $fieldValue) + foreach ($copyIds as $cid) { - $prefixSourceClient = str_replace(".", "_", $sourceClient); - $fieldName = explode($prefixSourceClient . "_", $fieldKey); - $prefixTargetClient = str_replace(".", "_", $targetClient); - $targetFieldName = $prefixTargetClient . '_' . $fieldName[1]; - $tjFieldsTable = $tjFieldsHelper->getFieldData($targetFieldName); - $fieldId = $tjFieldsTable->id; - $fieldType = $tjFieldsTable->type; - $fielParams = json_decode($tjFieldsTable->params); - $sourceTjFieldsTable = $tjFieldsHelper->getFieldData($fieldKey); - $sourceFieldParams = json_decode($sourceTjFieldsTable->params); - $subFormData = array(); - - if ($tjFieldsTable->type == 'ucmsubform' || $tjFieldsTable->type == 'subform') + $ucmOldData = array(); + $ucmOldData['clientComponent'] = 'com_tjucm'; + $ucmOldData['content_id'] = $cid; + $ucmOldData['layout'] = 'edit'; + $ucmOldData['client'] = $sourceClient; + $fileFieldArray = array(); + + // Get the field values + $extraFieldsData = $model->loadFormDataExtra($ucmOldData); + + // Code to replace source field name with destination field name + foreach ($extraFieldsData as $fieldKey => $fieldValue) { - $params = json_decode($tjFieldsTable->params)->formsource; - $subFormClient = explode('components/com_tjucm/models/forms/', $params); - $subFormClient = explode('form_extra.xml', $subFormClient[1]); - $subFormClient = 'com_tjucm.' . $subFormClient[0]; + $prefixSourceClient = str_replace(".", "_", $sourceClient); + $fieldName = explode($prefixSourceClient . "_", $fieldKey); + $prefixTargetClient = str_replace(".", "_", $targetClient); + $targetFieldName = $prefixTargetClient . '_' . $fieldName[1]; + $tjFieldsTable = $tjFieldsHelper->getFieldData($targetFieldName); + $fieldId = $tjFieldsTable->id; + $fieldType = $tjFieldsTable->type; + $fielParams = json_decode($tjFieldsTable->params); + $sourceTjFieldsTable = $tjFieldsHelper->getFieldData($fieldKey); + $sourceFieldParams = json_decode($sourceTjFieldsTable->params); + $subFormData = array(); + + if ($tjFieldsTable->type == 'ucmsubform' || $tjFieldsTable->type == 'subform') + { + $params = json_decode($tjFieldsTable->params)->formsource; + $subFormClient = explode('components/com_tjucm/models/forms/', $params); + $subFormClient = explode('form_extra.xml', $subFormClient[1]); + $subFormClient = 'com_tjucm.' . $subFormClient[0]; - $params = $sourceFieldParams->formsource; - $subFormSourceClient = explode('components/com_tjucm/models/forms/', $params); - $subFormSourceClient = explode('form_extra.xml', $subFormSourceClient[1]); - $subFormSourceClient = 'com_tjucm.' . $subFormSourceClient[0]; + $params = $sourceFieldParams->formsource; + $subFormSourceClient = explode('components/com_tjucm/models/forms/', $params); + $subFormSourceClient = explode('form_extra.xml', $subFormSourceClient[1]); + $subFormSourceClient = 'com_tjucm.' . $subFormSourceClient[0]; - $subFormData = (array) json_decode($fieldValue); - } + $subFormData = (array) json_decode($fieldValue); + } - if ($subFormData) - { - foreach ($subFormData as $keyData => $data) + if ($subFormData) { - $prefixSourceClient = str_replace(".", "_", $sourceClient); - $fieldName = explode($prefixSourceClient . "_", $keyData); - $prefixTargetClient = str_replace(".", "_", $targetClient); - $subTargetFieldName = $prefixTargetClient . '_' . $fieldName[1]; - $data = (array) $data; - - foreach ((array) $data as $key => $d) + foreach ($subFormData as $keyData => $data) { - $prefixSourceClient = str_replace(".", "_", $subFormSourceClient); - $fieldName = explode($prefixSourceClient . "_", $key); - $prefixTargetClient = str_replace(".", "_", $subFormClient); - $subFieldName = $prefixTargetClient . '_' . $fieldName[1]; + $prefixSourceClient = str_replace(".", "_", $sourceClient); + $fieldName = explode($prefixSourceClient . "_", $keyData); + $prefixTargetClient = str_replace(".", "_", $targetClient); + $subTargetFieldName = $prefixTargetClient . '_' . $fieldName[1]; + $data = (array) $data; - JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjfields/tables'); - $fieldTable = JTable::getInstance('field', 'TjfieldsTable'); + foreach ((array) $data as $key => $d) + { + $prefixSourceClient = str_replace(".", "_", $subFormSourceClient); + $fieldName = explode($prefixSourceClient . "_", $key); + $prefixTargetClient = str_replace(".", "_", $subFormClient); + $subFieldName = $prefixTargetClient . '_' . $fieldName[1]; - $fieldTable->load(array('name' => $key)); + JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjfields/tables'); + $fieldTable = JTable::getInstance('field', 'TjfieldsTable'); - if ($fieldName[1] == 'contentid') - { - $d = ''; - } + $fieldTable->load(array('name' => $key)); - $temp = array(); - unset($data[$key]); + if ($fieldName[1] == 'contentid') + { + $d = ''; + } - if (is_array($d)) - { - // TODO Temprary used switch case need to modify code - switch ($fieldTable->type) + $temp = array(); + unset($data[$key]); + + if (is_array($d)) { - case 'multi_select': - foreach ($d as $option) - { - $temp[] = $option->value; - } - - if (!empty($temp)) - { - $data[$subFieldName] = $temp; - } - break; - - case 'tjlist': - case 'related': - foreach ($d as $option) - { - $data[$subFieldName][] = $option; - } - break; - - default: - foreach ($d as $option) - { - $data[$subFieldName] = $option->value; - } - break; + // TODO Temprary used switch case need to modify code + switch ($fieldTable->type) + { + case 'multi_select': + foreach ($d as $option) + { + $temp[] = $option->value; + } + + if (!empty($temp)) + { + $data[$subFieldName] = $temp; + } + break; + + case 'tjlist': + case 'related': + + foreach ($d as $option) + { + $data[$subFieldName][] = $option; + } + break; + + default: + foreach ($d as $option) + { + $data[$subFieldName] = $option->value; + } + break; + } + } + elseif($fieldTable->type == 'file' || $fieldTable->type == 'image') + { + JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjfields/tables'); + $subDestionationFieldTable = JTable::getInstance('field', 'TjfieldsTable'); + + $subDestionationFieldTable->load(array('name' => $subFieldName)); + + $subformFileData = array(); + $subformFileData['value'] = $d; + $subformFileData['copy'] = true; + $subformFileData['type'] = $fieldTable->type; + $subformFileData['sourceClient'] = $subFormSourceClient; + $subformFileData['sourceFieldUploadPath'] = json_decode($fieldTable->params)->uploadpath; + $subformFileData['destFieldUploadPath'] = json_decode($subDestionationFieldTable->params)->uploadpath; + $subformFileData['user_id'] = Factory::getUser()->id; + $data[$subFieldName] = $subformFileData; + } + elseif ($fieldTable->type == 'cluster') + { + $data[$subFieldName] = $clusterId; + } + else + { + $data[$subFieldName] = $d; } } - elseif($fieldTable->type == 'file' || $fieldTable->type == 'image') - { - JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjfields/tables'); - $subDestionationFieldTable = JTable::getInstance('field', 'TjfieldsTable'); - - $subDestionationFieldTable->load(array('name' => $subFieldName)); - - $subformFileData = array(); - $subformFileData['value'] = $d; - $subformFileData['copy'] = true; - $subformFileData['type'] = $fieldTable->type; - $subformFileData['sourceClient'] = $subFormSourceClient; - $subformFileData['sourceFieldUploadPath'] = json_decode($fieldTable->params)->uploadpath; - $subformFileData['destFieldUploadPath'] = json_decode($subDestionationFieldTable->params)->uploadpath; - $subformFileData['user_id'] = Factory::getUser()->id; - $data[$subFieldName] = $subformFileData; - } - elseif ($fieldTable->type == 'cluster') - { - $data[$subFieldName] = $clusterId; - } - else - { - $data[$subFieldName] = $d; - } - } - - unset($subFormData[$keyData]); - $subFormData[$subTargetFieldName] = $data; - } - unset($extraFieldsData[$fieldKey]); - $extraFieldsData[$targetFieldName] = $subFormData; - } - else - { - unset($extraFieldsData[$fieldKey]); + unset($subFormData[$keyData]); + $subFormData[$subTargetFieldName] = $data; + } - if ($fieldType == 'file' || $fieldType == 'image') - { - $fileData = array(); - $fileData['value'] = $fieldValue; - $fileData['copy'] = true; - $fileData['type'] = $fieldType; - $fileData['sourceClient'] = $sourceClient; - $fileData['sourceFieldUploadPath'] = $sourceFieldParams->uploadpath; - $fileData['destFieldUploadPath'] = $fielParams->uploadpath; - $fileData['user_id'] = Factory::getUser()->id; - $extraFieldsData[$targetFieldName] = $fileData; - } - elseif($fieldType == 'cluster') - { - $extraFieldsData[$targetFieldName] = $clusterId; + unset($extraFieldsData[$fieldKey]); + $extraFieldsData[$targetFieldName] = $subFormData; } else { - $extraFieldsData[$targetFieldName] = $fieldValue; + unset($extraFieldsData[$fieldKey]); + + if ($fieldType == 'file' || $fieldType == 'image') + { + $fileData = array(); + $fileData['value'] = $fieldValue; + $fileData['copy'] = true; + $fileData['type'] = $fieldType; + $fileData['sourceClient'] = $sourceClient; + $fileData['sourceFieldUploadPath'] = $sourceFieldParams->uploadpath; + $fileData['destFieldUploadPath'] = $fielParams->uploadpath; + $fileData['user_id'] = Factory::getUser()->id; + $extraFieldsData[$targetFieldName] = $fileData; + } + elseif($fieldType == 'cluster') + { + $extraFieldsData[$targetFieldName] = $clusterId; + } + else + { + $extraFieldsData[$targetFieldName] = $fieldValue; + } } } - } - $ucmData = array(); - $ucmData['id'] = 0; - $ucmData['client'] = $targetClient; - $ucmData['parent_id'] = 0; - $ucmData['state'] = 0; - $ucmData['draft'] = 1; + $ucmData = array(); + $ucmData['id'] = 0; + $ucmData['client'] = $targetClient; + $ucmData['parent_id'] = 0; + $ucmData['state'] = 0; + $ucmData['draft'] = 1; - if ($clusterId) - { - $ucmData['cluster_id'] = $clusterId; - } + if ($clusterId) + { + $ucmData['cluster_id'] = $clusterId; + } - // Save data into UCM data table - $result = $model->save($ucmData); - $recordId = $model->getState($model->getName() . '.id'); + // Save data into UCM data table + $result = $model->save($ucmData); + $recordId = $model->getState($model->getName() . '.id'); - if ($recordId) - { - $formData = array(); - $formData['content_id'] = $recordId; - $formData['fieldsvalue'] = $extraFieldsData; - $formData['client'] = $targetClient; + if ($recordId) + { + $formData = array(); + $formData['content_id'] = $recordId; + $formData['fieldsvalue'] = $extraFieldsData; + $formData['client'] = $targetClient; - // If data is valid then save the data into DB - $response = $model->saveExtraFields($formData); + // If data is valid then save the data into DB + $response = $model->saveExtraFields($formData); - $msg = ($response) ? Text::_("COM_TJUCM_ITEM_COPY_SUCCESSFULLY") : Text::_("COM_TJUCM_FORM_SAVE_FAILED"); + $msg = ($response) ? Text::_("COM_TJUCM_ITEM_COPY_SUCCESSFULLY") : Text::_("COM_TJUCM_FORM_SAVE_FAILED"); + } } } } diff --git a/src/components/com_tjucm/site/views/items/tmpl/default_copyitems.php b/src/components/com_tjucm/site/views/items/tmpl/default_copyitems.php index 663ee83f..2fdb8819 100755 --- a/src/components/com_tjucm/site/views/items/tmpl/default_copyitems.php +++ b/src/components/com_tjucm/site/views/items/tmpl/default_copyitems.php @@ -1,7 +1,7 @@ * @copyright Copyright (c) 2009-2019 TechJoomla. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt @@ -23,7 +23,7 @@
- state->get('filter.cluster_list'), 'cluster_list' ); ?> + state->get('filter.cluster_list'), 'cluster_list' ); ?>
From da837038933c24f42d35a675d7d48e8095be2981 Mon Sep 17 00:00:00 2001 From: Vijay Khollam Date: Fri, 4 Dec 2020 19:45:29 +0530 Subject: [PATCH 2/2] Task #166808 feat: Copy Multiple records to Multiple Organisation --- .../com_tjucm/site/controllers/itemform.json.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/components/com_tjucm/site/controllers/itemform.json.php b/src/components/com_tjucm/site/controllers/itemform.json.php index 36cb2f1d..4f4f7de2 100644 --- a/src/components/com_tjucm/site/controllers/itemform.json.php +++ b/src/components/com_tjucm/site/controllers/itemform.json.php @@ -566,16 +566,6 @@ public function copyItem() $clusterIds = $app->input->get('cluster_list', '', 'string'); $clusterIds = explode(',', $clusterIds); - $db = JFactory::getDbo(); - JTable::addIncludePath(JPATH_ROOT . '/administrator/components/com_tjucm/tables'); - $typeTable = JTable::getInstance('Type', 'TjucmTable', array('dbo', $db)); - - if ($targetClient) - { - $typeTable->load(array('unique_identifier' => $targetClient)); - $ucmTypeId = $typeTable->id; - } - JLoader::import('components.com_tjucm.models.type', JPATH_ADMINISTRATOR); $typeModel = BaseDatabaseModel::getInstance('Type', 'TjucmModel');