Skip to content

Commit

Permalink
Task techjoomla#369 feat: Add sort functionality using fields value o…
Browse files Browse the repository at this point in the history
…n to the list view
  • Loading branch information
ankush-maherwal committed Jul 24, 2020
1 parent 8d75474 commit fc4c35d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 242 deletions.
114 changes: 20 additions & 94 deletions src/components/com_tjucm/site/layouts/list/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
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'];
Expand Down Expand Up @@ -141,100 +137,29 @@
<?php
}

if (!empty($item->field_values))
if (!empty($item))
{
foreach ($item->field_values as $key => $fieldValue)
foreach ($item as $key => $fieldValue)
{
$tjFieldsFieldTable = $fieldsData[$key];

$canView = false;

if ($user->authorise('core.field.viewfieldvalue', 'com_tjfields.group.' . $tjFieldsFieldTable->group_id))
if (array_key_exists($key, $displayData['listcolumn']))
{
$canView = $user->authorise('core.field.viewfieldvalue', 'com_tjfields.field.' . $tjFieldsFieldTable->id);
}

$fieldXml = $formObject->getFieldXml($tjFieldsFieldTable->name);
?>
<td style="word-break: break-word;" width="<?php echo (85 - $displayData['statusColumnWidth']) / count($displayData['listcolumn']) . '%';?>">
<?php
if ($canView || ($item->created_by == $user->id))
{
$field = $formObject->getField($tjFieldsFieldTable->name);
$field->setValue($fieldValue);

if ($field->type == 'Ucmsubform' && $fieldValue)
{
$ucmSubFormData = json_decode($tjucmItemFormModel->getUcmSubFormFieldDataJson($item->id, $field));
$field->setValue($ucmSubFormData);
?>
<div>
<div class="col-xs-4"><?php echo $field->label; ?>:</div>
<div class="col-xs-8">
<?php
$count = 0;
$ucmSubFormXmlFieldSets = array();

// Call to extra fields
JLoader::import('components.com_tjucm.models.item', JPATH_SITE);
$tjucmItemModel = JModelLegacy::getInstance('Item', 'TjucmModel');

// Get Subform field data
$fieldData = $TjfieldsHelper->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;
$tjFieldsFieldTable = $fieldsData[$key];

if (!empty($ucmSubFormData))
{
$count = 0;
$canView = false;

foreach ($ucmSubFormData as $subFormData)
{
$count++;
$contentIdFieldname = str_replace('.', '_', $ucmSubFormClient) . '_contentid';
if ($user->authorise('core.field.viewfieldvalue', 'com_tjfields.group.' . $tjFieldsFieldTable->group_id))
{
$canView = $user->authorise('core.field.viewfieldvalue', 'com_tjfields.field.' . $tjFieldsFieldTable->id);
}

$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 "<hr>";
}
}
}
?>
</div>
</div>
<?php
}
else
$fieldXml = $formObject->getFieldXml($tjFieldsFieldTable->name);
?>
<td style="word-break: break-word;" width="<?php echo (85 - $displayData['statusColumnWidth']) / count($displayData['listcolumn']) . '%';?>">
<?php
if ($canView || ($item->created_by == $user->id))
{
$field = $formObject->getField($tjFieldsFieldTable->name);
$field->setValue($fieldValue);
$layoutToUse = (
array_key_exists(
ucfirst($tjFieldsFieldTable->type), $fieldLayout
Expand All @@ -244,9 +169,10 @@
$output = $layout->render(array('fieldXml' => $fieldXml, 'field' => $field));
echo $output;
}
}
?>
</td><?php
?>
</td>
<?php
}
}
}
?>
Expand Down
Loading

0 comments on commit fc4c35d

Please sign in to comment.