diff --git a/src/components/com_tjucm/administrator/assets/css/tjucm.css b/src/components/com_tjucm/administrator/assets/css/tjucm.css index 7ae82a71..c323376d 100644 --- a/src/components/com_tjucm/administrator/assets/css/tjucm.css +++ b/src/components/com_tjucm/administrator/assets/css/tjucm.css @@ -1,33 +1,3 @@ -.icon-48-types { -background-image: url(../images/l_types.png); -padding-left:60px!important; -} - -.icon-48-type { -background-image: url(../images/l_types.png); -padding-left:60px!important; -} - -.color-box-types { -float: left;width: 15px;height: 15px;margin-right: 5px;border: 1px solid rgba(0, 0, 0, .2);} - -.icon-48-items { -background-image: url(../images/l_items.png); -padding-left:60px!important; -} - -.icon-48-item { -background-image: url(../images/l_items.png); -padding-left:60px!important; -} - -.color-box-items { -float: left;width: 15px;height: 15px;margin-right: 5px;border: 1px solid rgba(0, 0, 0, .2);} - -.other-filters{ - padding: 0 14px; -} - /* CSS for frontend*/ #item-form .radio input{ margin-left:5px !important; diff --git a/src/components/com_tjucm/administrator/assets/js/tjucm_type.js b/src/components/com_tjucm/administrator/assets/js/tjucm_type.js deleted file mode 100644 index 442914a5..00000000 --- a/src/components/com_tjucm/administrator/assets/js/tjucm_type.js +++ /dev/null @@ -1,3 +0,0 @@ -js = jQuery.noConflict(); -js(document).ready(function () { -}); diff --git a/src/components/com_tjucm/administrator/classes/funlist.php b/src/components/com_tjucm/administrator/classes/funlist.php deleted file mode 100644 index 33c7ffe4..00000000 --- a/src/components/com_tjucm/administrator/classes/funlist.php +++ /dev/null @@ -1,62 +0,0 @@ - - * @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved. - * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL - */ - -defined('_JEXEC') or die('Restricted access'); -jimport('joomla.form.form'); - -/** - * Extra function list. - * - * @package Joomla.site - * @subpackage com_tjucm - * - * @since 1.0 - */ -class TjucmFunList -{ - /** - * Function to get data - * - * @param STRING $table Name of database table - * @param STRING $selectList Selected value colume name - * @param STRING $where Query where condition - * @param STRING $returnObject Selecting data using JDatabase - link https://docs.joomla.org/Selecting_data_using_JDatabase - * @param STRING $joinType LEFT, RIGHT etc - * @param STRING $joinTable Name of database table - * - * @return true - * - * @since 1.0.0 - */ - public function getDataValues($table, $selectList = "*", $where = "", $returnObject = "", $joinType = "", $joinTable = "") - { - // Ref - link https://docs.joomla.org/Selecting_data_using_JDatabase - - $db = JFactory::getDbo(); - $query = $db->getQuery(true); - - $query->select($selectList); - $query->from($table); - - if ($joinTable) - { - $query->join($joinType, $joinTable); - } - - if ($where) - { - $query->where($where); - } - - $db->setQuery($query); - - return $db->$returnObject(); - } -} diff --git a/src/components/com_tjucm/administrator/houseKeeping/1.1.0/ucmSubformData.php b/src/components/com_tjucm/administrator/houseKeeping/1.1.0/ucmSubformData.php index dcdc6725..28a9cc9b 100644 --- a/src/components/com_tjucm/administrator/houseKeeping/1.1.0/ucmSubformData.php +++ b/src/components/com_tjucm/administrator/houseKeeping/1.1.0/ucmSubformData.php @@ -128,14 +128,11 @@ public function migrate() // Save ucmSubForm records if (!empty($ucmSubFormDataSet)) { - $itemFormModel = BaseDatabaseModel::getInstance('ItemForm', 'TjucmModel', array('ignore_request' => true)); - // Set ucm type id to check permission in Item form model save() for logged-in user $ucmTypeId = $tjUcmModelType->getTypeId($ucmSubFormClient); - $itemFormModel->setState('ucmType.id', $ucmTypeId); // Call method to save ucmsubform data into new UCM data - $subFormContentIds = $itemFormModel->saveUcmSubFormRecords($validData, $ucmSubFormDataSet); + $subFormContentIds = $this->saveUcmSubFormRecords($validData, $ucmSubFormDataSet, $ucmTypeId); // To update existing ucm subform field value from JSON to subform ucm type name if ($subFormContentIds) @@ -163,4 +160,104 @@ public function migrate() return $result; } + + /** + * Function to save ucmSubForm records + * + * @param ARRAY &$validData Parent record data + * @param ARRAY $ucmSubFormDataSet ucmSubForm records data + * @param ARRAY $ucmTypeId UCM Type Id + * + * @return ARRAY + */ + public function saveUcmSubFormRecords(&$validData, $ucmSubFormDataSet, $ucmTypeId) + { + $db = JFactory::getDbo(); + $subFormContentIds = array(); + $isNew = empty($validData['id']) ? 1 : 0; + + // Delete removed subform details + if (!$isNew) + { + $query = $db->getQuery(true); + $query->select('id'); + $query->from($db->quoteName('#__tj_ucm_data')); + $query->where($db->quoteName('parent_id') . '=' . $validData['id']); + $db->setQuery($query); + $oldSubFormContentIds = $db->loadColumn(); + } + + JLoader::import('components.com_tjfields.tables.fieldsvalue', JPATH_ADMINISTRATOR); + JLoader::import('components.com_tjfields.tables.field', JPATH_ADMINISTRATOR); + JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjucm/models'); + $tjUcmModelType = JModelLegacy::getInstance('Type', 'TjucmModel'); + $itemFormModel = BaseDatabaseModel::getInstance('ItemForm', 'TjucmModel', array('ignore_request' => true)); + $itemFormModel->setState('ucmType.id', $ucmTypeId); + + if (!empty($ucmSubFormDataSet)) + { + foreach ($ucmSubFormDataSet as $client => $ucmSubFormTypeData) + { + $validData['client'] = $client; + $validData['type_id'] = $tjUcmModelType->getTypeId($client); + $clientDetail = explode('.', $client); + + // This is an extra field which is used to render the reference of the ucmsubform field on the form (used in case of edit) + $ucmSubformContentIdFieldName = $clientDetail[0] . '_' . $clientDetail[1] . '_' . 'contentid'; + $count = 0; + + foreach ($ucmSubFormTypeData as $ucmSubFormData) + { + $validData['id'] = isset($ucmSubFormData[$ucmSubformContentIdFieldName]) ? (int) $ucmSubFormData[$ucmSubformContentIdFieldName] : 0; + + // Unset extra data + $sfFieldName = $ucmSubFormData['ucmSubformFieldName']; + unset($ucmSubFormData['ucmSubformFieldName']); + $ucmSubformContentFieldElementId = 'jform[' . $sfFieldName . '][' . $sfFieldName . $count . '][' . $ucmSubformContentIdFieldName . ']'; + $count++; + + if ($insertedId = $itemFormModel->save($validData, $ucmSubFormData)) + { + $validData['id'] = $insertedId; + $subFormContentIds[] = array('elementName' => $ucmSubformContentFieldElementId, 'content_id' => $insertedId); + $ucmSubFormData[$ucmSubformContentIdFieldName] = $insertedId; + + // Get field id of contentid field + $fieldTable = JTable::getInstance('Field', 'TjfieldsTable', array('dbo', $db)); + $fieldTable->load(array('name' => $ucmSubformContentIdFieldName)); + + // Add-Update the value of content id field in the fields value table - start + $fieldsValueTable = JTable::getInstance('Fieldsvalue', 'TjfieldsTable', array('dbo', $db)); + $fieldsValueTable->load(array('field_id' => $fieldTable->id, 'content_id' => $insertedId, 'client' => $validData['client'])); + + if (empty($fieldsValueTable->id)) + { + $fieldsValueTable->field_id = $fieldTable->id; + $fieldsValueTable->value = $fieldsValueTable->content_id = $insertedId; + $fieldsValueTable->client = $validData['client']; + } + + $fieldsValueTable->user_id = JFactory::getUser()->id; + $fieldsValueTable->store(); + + // Add-Update the value of content id field in the fields value table - end + } + } + } + } + + // Delete removed ucmSubForm record from the form + if (!empty($oldSubFormContentIds)) + { + foreach ($oldSubFormContentIds as $oldSubFormContentId) + { + if (array_search($oldSubFormContentId, array_column($subFormContentIds, 'content_id')) === false) + { + $itemFormModel->delete($oldSubFormContentId); + } + } + } + + return $subFormContentIds; + } } diff --git a/src/components/com_tjucm/administrator/houseKeeping/1.2.3/updateClientName.php b/src/components/com_tjucm/administrator/houseKeeping/1.2.3/updateClientName.php new file mode 100644 index 00000000..b3c17650 --- /dev/null +++ b/src/components/com_tjucm/administrator/houseKeeping/1.2.3/updateClientName.php @@ -0,0 +1,264 @@ + + * @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved. + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL + */ + +// No direct access +defined('_JEXEC') or die('Restricted access'); + +use Joomla\Registry\Registry; +use Joomla\CMS\Factory; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; +use Joomla\CMS\Filesystem\File; + +/** + * Migration file for TJ-UCM + * + * @since 1.0 + */ +class TjHouseKeepingUpdateClientName extends TjModelHouseKeeping +{ + public $title = "Update Types Name"; + + public $description = 'Update UCM Types name and name of fields in each Type'; + + /** + * Subform migration script + * + * @return void + * + * @since 1.0 + */ + public function migrate() + { + JTable::addIncludePath(JPATH_ROOT . '/administrator/components/com_tjucm/tables'); + JTable::addIncludePath(JPATH_ROOT . '/administrator/components/com_tjfields/tables'); + JLoader::import('components.com_tjfields.helpers.tjfields', JPATH_ADMINISTRATOR); + + // TJ-Fields helper object + $tjfieldsHelper = new TjfieldsHelper; + + $result = array(); + $ucmSubFormFieldsConfig = array(); + + try + { + // Get all the UCM types + $db = JFactory::getDbo(); + $query = $db->getQuery(true); + $query->select('*'); + $query->from($db->qn('#__tj_ucm_types')); + $db->setQuery($query); + $ucmTypes = $db->loadObjectlist(); + + $session = JFactory::getSession(); + $updatedTypes = (empty($session->get('updatedTypes'))) ? array() : $session->get('updatedTypes'); + + if (!empty($ucmTypes)) + { + foreach ($ucmTypes as $ucmType) + { + if (in_array($ucmType->id, $updatedTypes)) + { + continue; + } + + $ucmTypeTable = JTable::getInstance('Type', 'TjucmTable', array('dbo', $db)); + $ucmTypeTable->load($ucmType->id); + $updatedUniqueIdentifier = 'com_tjucm.' . preg_replace("/[^a-zA-Z0-9]/", "", str_replace('com_tjucm.', '', $ucmTypeTable->unique_identifier)); + $ucmTypeParams = new Registry($ucmType->params); + + // Variable to store the old client of the UCM Type + $oldClientName = $ucmTypeTable->unique_identifier; + $ucmTypeTable->unique_identifier = $updatedUniqueIdentifier; + + if ($ucmTypeTable->store()) + { + // Get all the field groups of the UCM Type + $query = $db->getQuery(true); + $query->select('*'); + $query->from($db->qn('#__tjfields_groups')); + $query->where($db->quoteName('client') . '=' . $db->quote($oldClientName)); + $db->setQuery($query); + $fieldGroups = $db->loadObjectlist(); + + foreach ($fieldGroups as $fieldGroup) + { + $tjfieldsGroupTable = JTable::getInstance('Group', 'TjfieldsTable', array('dbo', $db)); + $tjfieldsGroupTable->load($fieldGroup->id); + $tjfieldsGroupTable->client = $updatedUniqueIdentifier; + + // Update the client of field group in the given UCM Type + if ($tjfieldsGroupTable->store()) + { + $query = $db->getQuery(true); + $query->select('*'); + $query->from($db->qn('#__tjfields_fields')); + $query->where($db->quoteName('client') . '=' . $db->quote($oldClientName)); + $query->where($db->quoteName('group_id') . '=' . $fieldGroup->id); + $db->setQuery($query); + $fields = $db->loadObjectlist(); + + foreach ($fields as $field) + { + $tjfieldsFieldTable = JTable::getInstance('Field', 'TjfieldsTable', array('dbo', $db)); + $tjfieldsFieldTable->load($field->id); + $tjfieldsFieldTable->client = $updatedUniqueIdentifier; + + if ($tjfieldsFieldTable->type == 'cluster') + { + $tjfieldsFieldTable->name = str_replace('.', '_', $updatedUniqueIdentifier) . '_clusterclusterid'; + } + elseif ($tjfieldsFieldTable->type == 'ownership') + { + $tjfieldsFieldTable->name = str_replace('.', '_', $updatedUniqueIdentifier) . '_ownershipcreatedby'; + } + elseif ($tjfieldsFieldTable->type == 'itemcategory') + { + $tjfieldsFieldTable->name = str_replace('.', '_', $updatedUniqueIdentifier) . '_itemcategoryitemcategory'; + } + else + { + $tjfieldsFieldTable->name = str_replace('.', '_', $updatedUniqueIdentifier) . '_' . strtolower(preg_replace("/[^a-zA-Z0-9]/", "", $field->label)); + } + + $tjfieldsFieldTable->store(); + + // Check if field name is unique + $isUnique = $tjfieldsHelper->checkIfUniqueName($tjfieldsFieldTable->name); + + // If the name of the field is not unique then update the name by appending count to it + if ($isUnique > 1) + { + $count = 0; + + while ($tjfieldsHelper->checkIfUniqueName($tjfieldsFieldTable->name) > 1) + { + $count++; + $tjfieldsFieldTable->name = $tjfieldsFieldTable->name . $count; + } + + $tjfieldsFieldTable->store(); + } + } + } + } + + // Update client in ucm_data table + $query = $db->getQuery(true); + $fields = array($db->quoteName('client') . ' = ' . $db->quote($updatedUniqueIdentifier)); + $conditions = array($db->quoteName('client') . ' = ' . $db->quote($oldClientName)); + $query->update($db->quoteName('#__tj_ucm_data'))->set($fields)->where($conditions); + $db->setQuery($query); + $db->execute(); + + // Update client in fields_value table + $query = $db->getQuery(true); + $query->update($db->quoteName('#__tjfields_fields_value'))->set($fields)->where($conditions); + $db->setQuery($query); + $db->execute(); + + // Update value of ucmsubform fields in fields_value table + $query = $db->getQuery(true); + $fields = array($db->quoteName('value') . ' = ' . $db->quote($updatedUniqueIdentifier)); + $conditions = array($db->quoteName('value') . ' = ' . $db->quote($oldClientName)); + $query->update($db->quoteName('#__tjfields_fields_value'))->set($fields)->where($conditions); + $db->setQuery($query); + $db->execute(); + + $oldClientParts = explode('.', $oldClientName); + $newClientParts = explode('.', $updatedUniqueIdentifier); + $oldFileName = $oldClientParts[1] . 'form_extra.xml'; + $newFileName = $newClientParts[1] . 'form_extra.xml'; + $oldFileNameAdmin = $oldClientParts[1] . '_extra.xml'; + + // If the UCM type is of subform type then update the link in the respective field + if ($ucmTypeParams->get('is_subform')) + { + $query = $db->getQuery(true); + $query->select('*'); + $query->from($db->qn('#__tjfields_fields')); + $query->where($db->quoteName('params') . ' LIKE ' . $db->quote('%' . $oldFileName . '%')); + $db->setQuery($query); + $ucmSubFormFields = $db->loadObjectlist(); + + foreach ($ucmSubFormFields as $ucmSubFormField) + { + $tjfieldsFieldTable = JTable::getInstance('Field', 'TjfieldsTable', array('dbo', $db)); + $tjfieldsFieldTable->load($ucmSubFormField->id); + $tjfieldsFieldTable->params = str_replace($oldFileName, $newFileName, $tjfieldsFieldTable->params); + $tjfieldsFieldTable->store(); + } + } + + // If the UCM type is used as data source in related field the we need to update the UCM name in the field params + if ($ucmTypeParams->get('is_subform')) + { + $query = $db->getQuery(true); + $query->select('*'); + $query->from($db->qn('#__tjfields_fields')); + $query->where($db->quoteName('params') . ' LIKE ' . $db->quote('%' . $oldClientName . '%')); + $db->setQuery($query); + $formFields = $db->loadObjectlist(); + + foreach ($formFields as $formField) + { + $tjfieldsFieldTable = JTable::getInstance('Field', 'TjfieldsTable', array('dbo', $db)); + $tjfieldsFieldTable->load($formField->id); + $fieldParams = new Registry($tjfieldsFieldTable->params); + + if ($fieldParams->get('client') == $oldClientName) + { + $fieldParams->set('client', $updatedUniqueIdentifier); + } + + $tjfieldsFieldTable->params = json_encode($fieldParams); + $tjfieldsFieldTable->store(); + } + } + + // Delete the old XML files for the UCM type + if (File::exists(JPATH_SITE . '/components/com_tjucm/models/forms/' . $oldFileName)) + { + File::delete(JPATH_SITE . '/components/com_tjucm/models/forms/' . $oldFileName); + } + + if (File::exists(JPATH_SITE . '/' . 'administrator/components/com_tjucm/models/forms/' . $oldFileNameAdmin)) + { + File::delete(JPATH_SITE . '/' . 'administrator/components/com_tjucm/models/forms/' . $oldFileNameAdmin); + } + + // Regenerate the XML files + $tjfieldsHelper->generateXml(array('client' => $updatedUniqueIdentifier, 'client_type' => $newClientParts[1])); + } + + $updatedTypes[] = $ucmType->id; + $session->set('updatedTypes', $updatedTypes); + + $result['status'] = ''; + $result['message'] = "Migration in progress"; + + return $result; + } + } + + $session->set('updatedTypes', ''); + + $result['status'] = true; + $result['message'] = "Migration successful"; + } + catch (Exception $e) + { + $result['err_code'] = ''; + $result['status'] = false; + $result['message'] = $e->getMessage(); + } + + return $result; + } +} diff --git a/src/components/com_tjucm/administrator/models/forms/type.xml b/src/components/com_tjucm/administrator/models/forms/type.xml index 3497a681..7aca87fc 100644 --- a/src/components/com_tjucm/administrator/models/forms/type.xml +++ b/src/components/com_tjucm/administrator/models/forms/type.xml @@ -1,36 +1,18 @@ - +