Skip to content

Commit db34a10

Browse files
Task techjoomla#369 feat: Add sort functionality using fields value on to the list view
1 parent 8d75474 commit db34a10

File tree

1 file changed

+93
-89
lines changed
  • src/components/com_tjucm/site/layouts/list

1 file changed

+93
-89
lines changed

src/components/com_tjucm/site/layouts/list/list.php

Lines changed: 93 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -141,112 +141,116 @@
141141
<?php
142142
}
143143

144-
if (!empty($item->field_values))
144+
if (!empty($item))
145145
{
146-
foreach ($item->field_values as $key => $fieldValue)
146+
foreach ($item as $key => $fieldValue)
147147
{
148-
$tjFieldsFieldTable = $fieldsData[$key];
149-
150-
$canView = false;
151-
152-
if ($user->authorise('core.field.viewfieldvalue', 'com_tjfields.group.' . $tjFieldsFieldTable->group_id))
148+
if (array_key_exists($key, $displayData['listcolumn']))
153149
{
154-
$canView = $user->authorise('core.field.viewfieldvalue', 'com_tjfields.field.' . $tjFieldsFieldTable->id);
155-
}
150+
$tjFieldsFieldTable = $fieldsData[$key];
156151

157-
$fieldXml = $formObject->getFieldXml($tjFieldsFieldTable->name);
158-
?>
159-
<td style="word-break: break-word;" width="<?php echo (85 - $displayData['statusColumnWidth']) / count($displayData['listcolumn']) . '%';?>">
160-
<?php
161-
if ($canView || ($item->created_by == $user->id))
162-
{
163-
$field = $formObject->getField($tjFieldsFieldTable->name);
164-
$field->setValue($fieldValue);
152+
$canView = false;
165153

166-
if ($field->type == 'Ucmsubform' && $fieldValue)
154+
if ($user->authorise('core.field.viewfieldvalue', 'com_tjfields.group.' . $tjFieldsFieldTable->group_id))
155+
{
156+
$canView = $user->authorise('core.field.viewfieldvalue', 'com_tjfields.field.' . $tjFieldsFieldTable->id);
157+
}
158+
159+
$fieldXml = $formObject->getFieldXml($tjFieldsFieldTable->name);
160+
?>
161+
<td style="word-break: break-word;" width="<?php echo (85 - $displayData['statusColumnWidth']) / count($displayData['listcolumn']) . '%';?>">
162+
<?php
163+
if ($canView || ($item->created_by == $user->id))
167164
{
168-
$ucmSubFormData = json_decode($tjucmItemFormModel->getUcmSubFormFieldDataJson($item->id, $field));
169-
$field->setValue($ucmSubFormData);
170-
?>
171-
<div>
172-
<div class="col-xs-4"><?php echo $field->label; ?>:</div>
173-
<div class="col-xs-8">
174-
<?php
175-
$count = 0;
176-
$ucmSubFormXmlFieldSets = array();
177-
178-
// Call to extra fields
179-
JLoader::import('components.com_tjucm.models.item', JPATH_SITE);
180-
$tjucmItemModel = JModelLegacy::getInstance('Item', 'TjucmModel');
181-
182-
// Get Subform field data
183-
$fieldData = $TjfieldsHelper->getFieldData($field->getAttribute('name'));
184-
185-
$ucmSubFormFieldParams = json_decode($fieldData->params);
186-
$ucmSubFormFormSource = explode('/', $ucmSubFormFieldParams->formsource);
187-
$ucmSubFormClient = $ucmSubFormFormSource[1] . '.' . str_replace('form_extra.xml', '', $ucmSubFormFormSource[4]);
188-
$view = explode('.', $ucmSubFormClient);
189-
$ucmSubFormData = (array) $ucmSubFormData;
190-
191-
if (!empty($ucmSubFormData))
192-
{
165+
$field = $formObject->getField($tjFieldsFieldTable->name);
166+
$field->setValue($fieldValue);
167+
168+
if ($field->type == 'Ucmsubform' && $fieldValue)
169+
{
170+
$ucmSubFormData = json_decode($tjucmItemFormModel->getUcmSubFormFieldDataJson($item->id, $field));
171+
$field->setValue($ucmSubFormData);
172+
?>
173+
<div>
174+
<div class="col-xs-4"><?php echo $field->label; ?>:</div>
175+
<div class="col-xs-8">
176+
<?php
193177
$count = 0;
178+
$ucmSubFormXmlFieldSets = array();
194179

195-
foreach ($ucmSubFormData as $subFormData)
196-
{
197-
$count++;
198-
$contentIdFieldname = str_replace('.', '_', $ucmSubFormClient) . '_contentid';
180+
// Call to extra fields
181+
JLoader::import('components.com_tjucm.models.item', JPATH_SITE);
182+
$tjucmItemModel = JModelLegacy::getInstance('Item', 'TjucmModel');
199183

200-
$ucmSubformFormObject = $tjucmItemModel->getFormExtra(
201-
array(
202-
"clientComponent" => 'com_tjucm',
203-
"client" => $ucmSubFormClient,
204-
"view" => $view[1],
205-
"layout" => 'default',
206-
"content_id" => $subFormData->$contentIdFieldname)
207-
);
184+
// Get Subform field data
185+
$fieldData = $TjfieldsHelper->getFieldData($field->getAttribute('name'));
208186

209-
$ucmSubFormFormXml = simplexml_load_file($field->formsource);
187+
$ucmSubFormFieldParams = json_decode($fieldData->params);
188+
$ucmSubFormFormSource = explode('/', $ucmSubFormFieldParams->formsource);
189+
$ucmSubFormClient = $ucmSubFormFormSource[1] . '.' . str_replace('form_extra.xml', '', $ucmSubFormFormSource[4]);
190+
$view = explode('.', $ucmSubFormClient);
191+
$ucmSubFormData = (array) $ucmSubFormData;
210192

211-
$ucmSubFormCount = 0;
212-
213-
foreach ($ucmSubFormFormXml as $ucmSubFormXmlFieldSet)
214-
{
215-
$ucmSubFormXmlFieldSets[$ucmSubFormCount] = $ucmSubFormXmlFieldSet;
216-
$ucmSubFormCount++;
217-
}
218-
219-
$ucmSubFormRecordData = $tjucmItemModel->getData($subFormData->$contentIdFieldname);
220-
221-
// Call the JLayout recursively to render fields of ucmsubform
222-
$layout = new JLayoutFile('fields', JPATH_ROOT . '/components/com_tjucm/layouts/detail');
223-
echo $layout->render(array('xmlFormObject' => $ucmSubFormXmlFieldSets, 'formObject' => $ucmSubformFormObject, 'itemData' => $ucmSubFormRecordData, 'isSubForm' => 1));
193+
if (!empty($ucmSubFormData))
194+
{
195+
$count = 0;
224196

225-
if (count($ucmSubFormData) > $count)
197+
foreach ($ucmSubFormData as $subFormData)
226198
{
227-
echo "<hr>";
199+
$count++;
200+
$contentIdFieldname = str_replace('.', '_', $ucmSubFormClient) . '_contentid';
201+
202+
$ucmSubformFormObject = $tjucmItemModel->getFormExtra(
203+
array(
204+
"clientComponent" => 'com_tjucm',
205+
"client" => $ucmSubFormClient,
206+
"view" => $view[1],
207+
"layout" => 'default',
208+
"content_id" => $subFormData->$contentIdFieldname)
209+
);
210+
211+
$ucmSubFormFormXml = simplexml_load_file($field->formsource);
212+
213+
$ucmSubFormCount = 0;
214+
215+
foreach ($ucmSubFormFormXml as $ucmSubFormXmlFieldSet)
216+
{
217+
$ucmSubFormXmlFieldSets[$ucmSubFormCount] = $ucmSubFormXmlFieldSet;
218+
$ucmSubFormCount++;
219+
}
220+
221+
$ucmSubFormRecordData = $tjucmItemModel->getData($subFormData->$contentIdFieldname);
222+
223+
// Call the JLayout recursively to render fields of ucmsubform
224+
$layout = new JLayoutFile('fields', JPATH_ROOT . '/components/com_tjucm/layouts/detail');
225+
echo $layout->render(array('xmlFormObject' => $ucmSubFormXmlFieldSets, 'formObject' => $ucmSubformFormObject, 'itemData' => $ucmSubFormRecordData, 'isSubForm' => 1));
226+
227+
if (count($ucmSubFormData) > $count)
228+
{
229+
echo "<hr>";
230+
}
228231
}
229232
}
230-
}
231-
?>
233+
?>
234+
</div>
232235
</div>
233-
</div>
234-
<?php
236+
<?php
237+
}
238+
else
239+
{
240+
$layoutToUse = (
241+
array_key_exists(
242+
ucfirst($tjFieldsFieldTable->type), $fieldLayout
243+
)
244+
) ? $fieldLayout[ucfirst($tjFieldsFieldTable->type)] : 'field';
245+
$layout = new JLayoutFile($layoutToUse, JPATH_ROOT . '/components/com_tjfields/layouts/fields');
246+
$output = $layout->render(array('fieldXml' => $fieldXml, 'field' => $field));
247+
echo $output;
248+
}
235249
}
236-
else
237-
{
238-
$layoutToUse = (
239-
array_key_exists(
240-
ucfirst($tjFieldsFieldTable->type), $fieldLayout
241-
)
242-
) ? $fieldLayout[ucfirst($tjFieldsFieldTable->type)] : 'field';
243-
$layout = new JLayoutFile($layoutToUse, JPATH_ROOT . '/components/com_tjfields/layouts/fields');
244-
$output = $layout->render(array('fieldXml' => $fieldXml, 'field' => $field));
245-
echo $output;
246-
}
247-
}
248-
?>
249-
</td><?php
250+
?>
251+
</td>
252+
<?php
253+
}
250254
}
251255
}
252256
?>

0 commit comments

Comments
 (0)