From df017048dece752b9ca5e5072048c670549a6657 Mon Sep 17 00:00:00 2001 From: Ankush Maherwal Date: Wed, 22 Jul 2020 17:40:04 +0530 Subject: [PATCH] Task #123 feat: Support subform fields on list view --- .../com_tjucm/site/layouts/list/list.php | 94 +++++++++++++++++-- .../com_tjucm/site/models/itemform.php | 11 +++ 2 files changed, 97 insertions(+), 8 deletions(-) diff --git a/src/components/com_tjucm/site/layouts/list/list.php b/src/components/com_tjucm/site/layouts/list/list.php index 1b8f2b58..56fd4708 100644 --- a/src/components/com_tjucm/site/layouts/list/list.php +++ b/src/components/com_tjucm/site/layouts/list/list.php @@ -43,6 +43,10 @@ JLoader::import('components.com_tjfields.helpers.tjfields', JPATH_SITE); $TjfieldsHelper = new TjfieldsHelper; +// Load itemForm model +JLoader::import('components.com_tjucm.models.itemform', JPATH_SITE); +$tjucmItemFormModel = JModelLegacy::getInstance('ItemForm', 'TjucmModel'); + // Get JLayout data $item = $displayData['itemsData']; $created_by = $displayData['created_by']; @@ -158,14 +162,88 @@ { $field = $formObject->getField($tjFieldsFieldTable->name); $field->setValue($fieldValue); - $layoutToUse = ( - array_key_exists( - ucfirst($tjFieldsFieldTable->type), $fieldLayout - ) - ) ? $fieldLayout[ucfirst($tjFieldsFieldTable->type)] : 'field'; - $layout = new JLayoutFile($layoutToUse, JPATH_ROOT . '/components/com_tjfields/layouts/fields'); - $output = $layout->render(array('fieldXml' => $fieldXml, 'field' => $field)); - echo $output; + + if ($field->type == 'Ucmsubform' && $fieldValue) + { + $ucmSubFormData = json_decode($tjucmItemFormModel->getUcmSubFormFieldDataJson($item->id, $field)); + $field->setValue($ucmSubFormData); + ?> +
+
label; ?>:
+
+ getFieldData($field->getAttribute('name')); + + $ucmSubFormFieldParams = json_decode($fieldData->params); + $ucmSubFormFormSource = explode('/', $ucmSubFormFieldParams->formsource); + $ucmSubFormClient = $ucmSubFormFormSource[1] . '.' . str_replace('form_extra.xml', '', $ucmSubFormFormSource[4]); + $view = explode('.', $ucmSubFormClient); + $ucmSubFormData = (array) $ucmSubFormData; + + if (!empty($ucmSubFormData)) + { + $count = 0; + + foreach ($ucmSubFormData as $subFormData) + { + $count++; + $contentIdFieldname = str_replace('.', '_', $ucmSubFormClient) . '_contentid'; + + $ucmSubformFormObject = $tjucmItemModel->getFormExtra( + array( + "clientComponent" => 'com_tjucm', + "client" => $ucmSubFormClient, + "view" => $view[1], + "layout" => 'default', + "content_id" => $subFormData->$contentIdFieldname) + ); + + $ucmSubFormFormXml = simplexml_load_file($field->formsource); + + $ucmSubFormCount = 0; + + foreach ($ucmSubFormFormXml as $ucmSubFormXmlFieldSet) + { + $ucmSubFormXmlFieldSets[$ucmSubFormCount] = $ucmSubFormXmlFieldSet; + $ucmSubFormCount++; + } + + $ucmSubFormRecordData = $tjucmItemModel->getData($subFormData->$contentIdFieldname); + + // Call the JLayout recursively to render fields of ucmsubform + $layout = new JLayoutFile('fields', JPATH_ROOT . '/components/com_tjucm/layouts/detail'); + echo $layout->render(array('xmlFormObject' => $ucmSubFormXmlFieldSets, 'formObject' => $ucmSubformFormObject, 'itemData' => $ucmSubFormRecordData, 'isSubForm' => 1)); + + if (count($ucmSubFormData) > $count) + { + echo "
"; + } + } + } + ?> +
+
+ type), $fieldLayout + ) + ) ? $fieldLayout[ucfirst($tjFieldsFieldTable->type)] : 'field'; + $layout = new JLayoutFile($layoutToUse, JPATH_ROOT . '/components/com_tjfields/layouts/fields'); + $output = $layout->render(array('fieldXml' => $fieldXml, 'field' => $field)); + echo $output; + } } ?> params); + // Check if UCM type is subform $isSubform = $ucmTypeParams->get('is_subform'); @@ -908,6 +909,16 @@ public function getUcmSubFormFieldDataJson($parentRecordId, $efd) $subFormData->$ucmSubformContentIdFieldName = $contentId; $concat = $efd->name . $key; + + // Check if any field has value for the subform entry and if there is no value in subform then dont show it + $subFormDataArray = (array) $subFormData; + unset($subFormDataArray[$ucmSubformContentIdFieldName]); + + if (empty($subFormDataArray)) + { + continue; + } + $ucmSubFormFieldData->$concat = $subFormData; }