diff --git a/src/components/com_tjucm/site/layouts/list/list.php b/src/components/com_tjucm/site/layouts/list/list.php index 56fd4708..909861bb 100644 --- a/src/components/com_tjucm/site/layouts/list/list.php +++ b/src/components/com_tjucm/site/layouts/list/list.php @@ -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']; @@ -141,100 +137,29 @@ 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); - ?> - - 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); - ?> -
-
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; + $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 "
"; - } - } - } - ?> -
-
- getFieldXml($tjFieldsFieldTable->name); + ?> + + created_by == $user->id)) { + $field = $formObject->getField($tjFieldsFieldTable->name); + $field->setValue($fieldValue); $layoutToUse = ( array_key_exists( ucfirst($tjFieldsFieldTable->type), $fieldLayout @@ -244,9 +169,10 @@ $output = $layout->render(array('fieldXml' => $fieldXml, 'field' => $field)); echo $output; } - } - ?> - + + diff --git a/src/components/com_tjucm/site/models/items.php b/src/components/com_tjucm/site/models/items.php index 03b24d34..3e3f2f15 100644 --- a/src/components/com_tjucm/site/models/items.php +++ b/src/components/com_tjucm/site/models/items.php @@ -197,22 +197,17 @@ protected function getListQuery() $query = $db->getQuery(true); // Select the required fields from the table. - $query->select( - $this->getState( - 'list.select', 'DISTINCT ' . $db->quoteName('a.id') . ', ' - . $db->quoteName('a.state') . ', ' - . $db->quoteName('a.cluster_id') . ', ' - . $db->quoteName('a.draft') . ', ' - . $db->quoteName('a.created_date') . ', ' - . $db->quoteName('a.created_by') - ) - ); + $query->select('a.*'); + + foreach ($this->fields as $fieldId => $field) + { + $query->select('MAX(CASE WHEN fv.field_id=' . $fieldId . ' THEN value END) `' . $fieldId . '`'); + } $query->from($db->quoteName('#__tj_ucm_data', 'a')); // Join over the users for the checked out user - $query->select($db->quoteName('uc.name', 'uEditor')); - $query->join("LEFT", $db->quoteName('#__users', 'uc') . ' ON (' . $db->quoteName('uc.id') . ' = ' . $db->quoteName('a.checked_out') . ')'); + $query->join("LEFT", $db->quoteName('#__tjfields_fields_value', 'fv') . ' ON (' . $db->quoteName('fv.content_id') . ' = ' . $db->quoteName('a.id') . ')'); $client = $this->getState('ucm.client'); @@ -325,21 +320,7 @@ protected function getListQuery() } // Search on fields data - $filteredItemIds = $this->filterContent($client); - - if ($filteredItemIds) - { - if (!empty($filteredItemIds) && is_array($filteredItemIds)) - { - $filteredItemIds = implode(',', $filteredItemIds); - $query->where($db->quoteName('a.id') . ' IN (' . $filteredItemIds . ')'); - } - else - { - // If no search results found then do not return any record - $query->where($db->quoteName('a.id') . '=0'); - } - } + $this->filterContent($client, $query); // Filter by cluster $clusterId = (int) $this->getState($client . '.filter.cluster_id'); @@ -353,9 +334,11 @@ protected function getListQuery() $orderCol = $this->state->get('list.ordering'); $orderDirn = $this->state->get('list.direction'); + $query->group($db->quoteName('a.id')); + if ($orderCol && $orderDirn) { - $query->order($db->escape($orderCol . ' ' . $orderDirn)); + $query->order($db->escape($db->qn($orderCol) . ' ' . $orderDirn)); } return $query; @@ -365,31 +348,26 @@ protected function getListQuery() * Function to filter content as per field values * * @param string $client Client + * + * @param OBJECT &$query query object * * @return Array Content Ids * * @since 1.2.1 */ - private function filterContent($client) + private function filterContent($client, &$query) { + $db = $this->getDbo(); + $subQuery = $db->getQuery(true); + $subQuery->select(1); + $subQuery->from($db->quoteName('#__tjfields_fields_value', 'v')); + // Flag to mark if field specific search is done from the search box $filterFieldFound = 0; - // Flag to mark if any filter is applied or not - $filterApplied = 0; - // Variable to store count of the self joins on the fields_value table $filterFieldsCount = 0; - // Apply search filter - $db = JFactory::getDbo(); - $query = $db->getQuery(true); - $query->select('fv1.content_id'); - $query->from($db->quoteName('#__tjfields_fields_value', 'fv1')); - $query->join('INNER', $db->qn('#__tjfields_fields', 'f') . ' ON (' . $db->qn('fv1.field_id') . ' = ' . $db->qn('f.id') . ')'); - $query->where($db->quoteName('f.state') . ' =1'); - $query->where($db->quoteName('f.client') . ' = ' . $db->quote($client)); - // Filter by field value $search = $this->getState($client . '.filter.search'); @@ -402,17 +380,13 @@ private function filterContent($client) { $filterFieldsCount++; - if ($filterFieldsCount > 1) - { - $query->join('LEFT', $db->qn('#__tjfields_fields_value', 'fv' . $filterFieldsCount) . ' ON (' . $db->qn('fv' . - ($filterFieldsCount - 1) . '.content_id') . ' = ' . $db->qn('fv' . $filterFieldsCount . '.content_id') . ')'); - } + $subQuery->join('LEFT', $db->qn('#__tjfields_fields_value', 'v' . $filterFieldsCount) . ' ON (' . $db->qn('v' . + '.content_id') . ' = ' . $db->qn('v' . $filterFieldsCount . '.content_id') . ')'); $search = trim(str_replace($field . ':', '', $search)); - $query->where($db->qn('fv' . $filterFieldsCount . '.field_id') . ' = ' . $fieldId); - $query->where($db->qn('fv' . $filterFieldsCount . '.value') . ' LIKE ' . $db->q('%' . $search . '%')); + $subQuery->where($db->qn('v' . $filterFieldsCount . '.field_id') . ' = ' . $fieldId); + $subQuery->where($db->qn('v' . $filterFieldsCount . '.value') . ' LIKE ' . $db->q('%' . $search . '%')); $filterFieldFound = 1; - $filterApplied = 1; break; } @@ -424,14 +398,9 @@ private function filterContent($client) { $filterFieldsCount++; - if ($filterFieldsCount > 1) - { - $query->join('LEFT', $db->qn('#__tjfields_fields_value', 'fv' . $filterFieldsCount) . ' ON (' . $db->qn('fv' . - ($filterFieldsCount - 1) . '.content_id') . ' = ' . $db->qn('fv' . $filterFieldsCount . '.content_id') . ')'); - } - - $query->where($db->quoteName('fv' . $filterFieldsCount . '.value') . ' LIKE ' . $db->q('%' . $search . '%')); - $filterApplied = 1; + $subQuery->join('LEFT', $db->qn('#__tjfields_fields_value', 'v' . $filterFieldsCount) . ' ON (' . $db->qn('v' . + '.content_id') . ' = ' . $db->qn('v' . $filterFieldsCount . '.content_id') . ')'); + $subQuery->where($db->quoteName('v' . $filterFieldsCount . '.value') . ' LIKE ' . $db->q('%' . $search . '%')); } // For filterable fields @@ -450,51 +419,34 @@ private function filterContent($client) { $filterFieldsCount++; - if ($filterFieldsCount > 1) - { - $query->join('LEFT', $db->qn('#__tjfields_fields_value', 'fv' . $filterFieldsCount) . ' ON (' . $db->qn('fv' . - ($filterFieldsCount - 1) . '.content_id') . ' = ' . $db->qn('fv' . $filterFieldsCount . '.content_id') . ')'); - } - - $query->where($db->qn('fv' . $filterFieldsCount . '.field_id') . ' = ' . $field->id); + $subQuery->join('LEFT', $db->qn('#__tjfields_fields_value', 'v' . $filterFieldsCount) . ' ON (' . $db->qn('v' . + '.content_id') . ' = ' . $db->qn('v' . $filterFieldsCount . '.content_id') . ')'); + $subQuery->where($db->qn('v' . $filterFieldsCount . '.field_id') . ' = ' . $field->id); if ($filteroptionId) { // Check option id blank or null if ($filteroptionId == 'other') { - $query->where('(' . $db->qn('fv' . $filterFieldsCount . '.option_id') . - ' is null OR ' . $db->qn('fv' . $filterFieldsCount . '.option_id') . ' = 0 )'); + $subQuery->where('(' . $db->qn('v' . $filterFieldsCount . '.option_id') . + ' is null OR ' . $db->qn('v' . $filterFieldsCount . '.option_id') . ' = 0 )'); } else { - $query->where($db->qn('fv' . $filterFieldsCount . '.option_id') . ' = ' . $db->q($filteroptionId)); + $subQuery->where($db->qn('v' . $filterFieldsCount . '.option_id') . ' = ' . $db->q($filteroptionId)); } } else { - $query->where($db->qn('fv' . $filterFieldsCount . '.value') . ' = ' . $db->q($filterValue)); + $subQuery->where($db->qn('v' . $filterFieldsCount . '.value') . ' = ' . $db->q($filterValue)); } - - $filterApplied = 1; } } - $query->order('fv1.content_id DESC'); - $query->group('fv1.content_id'); - - // If there is any filter applied then only execute the query - if ($filterApplied) - { - $db->setQuery($query); - - $filteredRecord = $db->loadColumn(); - - return empty($filteredRecord)? true : $filteredRecord; - } - else + if ($filterFieldsCount > 0) { - return false; + $subQuery->where($db->qn('v.content_id') . '=' . $db->qn('a.id')); + $query->where("EXISTS (" . $subQuery . ")"); } } @@ -531,69 +483,6 @@ public function getFields() return $data; } - /** - * Get an array of data items - * - * @return mixed Array of data items on success, false on failure. - */ - public function getItems() - { - $items = parent::getItems(); - $itemsArray = (array) $items; - $contentIds = array_column($itemsArray, 'id'); - $fieldValues = $this->getFieldsData($contentIds); - - foreach ($items as &$item) - { - $item->field_values = array(); - - foreach ($fieldValues as $key => &$fieldValue) - { - if ($item->id == $fieldValue->content_id) - { - if (isset($item->field_values[$fieldValue->field_id])) - { - if (is_array($item->field_values[$fieldValue->field_id])) - { - $item->field_values[$fieldValue->field_id] = array_merge($item->field_values[$fieldValue->field_id], array($fieldValue->value)); - } - else - { - $item->field_values[$fieldValue->field_id] = array_merge(array($item->field_values[$fieldValue->field_id]), array($fieldValue->value)); - } - } - else - { - $item->field_values[$fieldValue->field_id] = $fieldValue->value; - } - - unset($fieldValues[$key]); - } - } - } - - foreach ($items as &$item) - { - $fieldValues = array(); - - foreach ($this->fields as $fieldId => $fieldValue) - { - if (!array_key_exists($fieldId, $item->field_values)) - { - $fieldValues[$fieldId] = ""; - } - else - { - $fieldValues[$fieldId] = $item->field_values[$fieldId]; - } - } - - $item->field_values = $fieldValues; - } - - return $items; - } - /** * Method to fields data for given content Ids * diff --git a/src/components/com_tjucm/site/views/items/tmpl/default.php b/src/components/com_tjucm/site/views/items/tmpl/default.php index e9b5df0a..f4d9cd24 100644 --- a/src/components/com_tjucm/site/views/items/tmpl/default.php +++ b/src/components/com_tjucm/site/views/items/tmpl/default.php @@ -192,7 +192,7 @@ function copyItem() ?> - +