diff --git a/src/components/com_tjucm/site/models/itemform.php b/src/components/com_tjucm/site/models/itemform.php index db7caf04..c6bceca5 100644 --- a/src/components/com_tjucm/site/models/itemform.php +++ b/src/components/com_tjucm/site/models/itemform.php @@ -610,7 +610,16 @@ public function saveFieldsData($fieldData) if (!empty($fieldData['fieldsvalue'][$ownerShipFieldName])) { - $ucmItemTable->created_by = $fieldData['fieldsvalue'][$ownerShipFieldName]; + JLoader::import('components.com_tjfields.tables.field', JPATH_ADMINISTRATOR); + $fieldTable = JTable::getInstance('Field', 'TjfieldsTable', array('dbo', JFactory::getDbo())); + $fieldTable->load(array('name' => $ownerShipFieldName)); + $fieldParams = new Registry($fieldTable->params); + + // If enabled then the selected user will be set as creator of the UCM type item + if ($fieldParams->get('ucmItemOwner')) + { + $ucmItemTable->created_by = $fieldData['fieldsvalue'][$ownerShipFieldName]; + } } if (!empty($fieldData['fieldsvalue'][$itemCategoryFieldName])) diff --git a/src/components/com_tjucm/site/models/items.php b/src/components/com_tjucm/site/models/items.php index c8d3d029..65ea3349 100644 --- a/src/components/com_tjucm/site/models/items.php +++ b/src/components/com_tjucm/site/models/items.php @@ -21,8 +21,6 @@ */ class TjucmModelItems extends JModelList { - private $client; - /** * Constructor. * @@ -69,34 +67,31 @@ protected function populateState($ordering = "a.id", $direction = "DESC") $user = JFactory::getUser(); $db = JFactory::getDbo(); - // Load the filter state. - $search = $app->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'STRING'); - $this->setState('filter.search', $search); - JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjucm/models'); $tjUcmModelType = JModelLegacy::getInstance('Type', 'TjucmModel'); - $typeId = $app->input->get('id', "", "INT"); + $typeId = $app->input->get('id', 0, "INT"); + $ucmType = $app->input->get('client', '', "STRING"); - JTable::addIncludePath(JPATH_ROOT . '/administrator/components/com_tjucm/tables'); - $typeTable = JTable::getInstance('Type', 'TjucmTable', array('dbo', $db)); - $typeTable->load(array('id' => $typeId)); - $ucmType = $typeTable->unique_identifier; + if (empty($typeId) || empty($ucmType)) + { + JTable::addIncludePath(JPATH_ROOT . '/administrator/components/com_tjucm/tables'); + $typeTable = JTable::getInstance('Type', 'TjucmTable', array('dbo', $db)); - // Set state for field filters - JLoader::import('components.com_tjfields.models.fields', JPATH_ADMINISTRATOR); - $fieldsModel = JModelLegacy::getInstance('Fields', 'TjfieldsModel', array('ignore_request' => true)); - $fieldsModel->setState('filter.client', $this->client); - $fieldsModel->setState('filter.filterable', 1); - $fields = $fieldsModel->getItems(); + if ($typeId && empty($ucmType)) + { + $typeTable->load(array('id' => $typeId)); + $ucmType = $typeTable->unique_identifier; + } - foreach ($fields as $field) - { - $filterValue = $app->getUserStateFromRequest($this->context . '.' . $field->name, $field->name, '', 'STRING'); - $this->setState('filter.field.' . $field->name, $filterValue); + if ($ucmType && empty($typeId)) + { + $typeTable->load(array('unique_identifier' => $ucmType)); + $typeId = $typeTable->id; + } } - if (empty($ucmType)) + if (empty($ucmType) && empty($typeId)) { // Get the active item $menuitem = $app->getMenu()->getActive(); @@ -106,34 +101,41 @@ protected function populateState($ordering = "a.id", $direction = "DESC") if (!empty($this->menuparams)) { - $this->ucm_type = $this->menuparams->get('ucm_type'); + $ucmTypeAlias = $this->menuparams->get('ucm_type'); - if (!empty($this->ucm_type)) + if (!empty($ucmTypeAlias)) { JLoader::import('components.com_tjfields.tables.type', JPATH_ADMINISTRATOR); $ucmTypeTable = JTable::getInstance('Type', 'TjucmTable', array('dbo', JFactory::getDbo())); - $ucmTypeTable->load(array('alias' => $this->ucm_type)); + $ucmTypeTable->load(array('alias' => $ucmTypeAlias)); $ucmType = $ucmTypeTable->unique_identifier; + $typeId = $ucmTypeTable->id; } } } - if (empty($ucmType)) - { - // Get UCM type id from uniquue identifier - $ucmType = $app->input->get('client', '', 'STRING'); - } + // Load the filter state. + $search = $app->getUserStateFromRequest($this->context . '.' . $ucmType . '.filter.search', 'filter_search', '', 'STRING'); + $this->setState($ucmType . '.filter.search', $search); - if (empty($typeId)) + // Set state for field filters + JLoader::import('components.com_tjfields.models.fields', JPATH_ADMINISTRATOR); + $fieldsModel = JModelLegacy::getInstance('Fields', 'TjfieldsModel', array('ignore_request' => true)); + $fieldsModel->setState('filter.client', $ucmType); + $fieldsModel->setState('filter.filterable', 1); + $fields = $fieldsModel->getItems(); + + foreach ($fields as $field) { - $typeId = $tjUcmModelType->getTypeId($ucmType); + $filterValue = $app->getUserStateFromRequest($this->context . '.' . $field->name, $field->name, '', 'STRING'); + $this->setState('filter.field.' . $field->name, $filterValue); } - $clusterId = $app->getUserStateFromRequest($this->context . '.cluster', 'cluster'); + $clusterId = $app->getUserStateFromRequest($this->context . '.' . $ucmType . '.cluster', 'cluster'); if ($clusterId) { - $this->setState('filter.cluster_id', $clusterId); + $this->setState($ucmType . '.filter.cluster_id', $clusterId); } $this->setState('ucm.client', $ucmType); @@ -149,14 +151,14 @@ protected function populateState($ordering = "a.id", $direction = "DESC") $this->setState("created_by", $createdBy); - if ($this->getUserStateFromRequest($this->context . '.filter.order', 'filter_order', '', 'string')) + if ($this->getUserStateFromRequest($this->context . $ucmType . '.filter.order', 'filter_order', '', 'string')) { - $ordering = $this->getUserStateFromRequest($this->context . '.filter.order', 'filter_order', '', 'string'); + $ordering = $this->getUserStateFromRequest($this->context . $ucmType . '.filter.order', 'filter_order', '', 'string'); } - if ($this->getUserStateFromRequest($this->context . '.filter.order_Dir', 'filter_order_Dir', '', 'string')) + if ($this->getUserStateFromRequest($this->context . $ucmType . '.filter.order_Dir', 'filter_order_Dir', '', 'string')) { - $direction = $this->getUserStateFromRequest($this->context . '.filter.order_Dir', 'filter_order_Dir', '', 'string'); + $direction = $this->getUserStateFromRequest($this->context . $ucmType . '.filter.order_Dir', 'filter_order_Dir', '', 'string'); } // List state information. @@ -196,18 +198,18 @@ protected function getListQuery() $query->select($db->quoteName('uc.name', 'uEditor')); $query->join("LEFT", $db->quoteName('#__users', 'uc') . ' ON (' . $db->quoteName('uc.id') . ' = ' . $db->quoteName('a.checked_out') . ')'); - $this->client = $this->getState('ucm.client'); + $client = $this->getState('ucm.client'); - if (!empty($this->client)) + if (!empty($client)) { - $query->where($db->quoteName('a.client') . ' = ' . $db->quote($db->escape($this->client))); + $query->where($db->quoteName('a.client') . ' = ' . $db->quote($db->escape($client))); } - $ucmType = $this->getState('ucmType.id', '', 'INT'); + $ucmTypeId = $this->getState('ucmType.id', '', 'INT'); - if (!empty($ucmType)) + if (!empty($ucmTypeId)) { - $query->where($db->quoteName('a.type_id') . ' = ' . (INT) $ucmType); + $query->where($db->quoteName('a.type_id') . ' = ' . (INT) $ucmTypeId); } $createdBy = $this->getState('created_by', '', 'INT'); @@ -232,7 +234,7 @@ protected function getListQuery() { JLoader::import('components.com_tjfields.tables.field', JPATH_ADMINISTRATOR); $fieldTable = JTable::getInstance('Field', 'TjfieldsTable', array('dbo', $db)); - $fieldTable->load(array('client' => $this->client, 'type' => 'cluster')); + $fieldTable->load(array('client' => $client, 'type' => 'cluster')); if ($fieldTable->id) { @@ -275,7 +277,7 @@ protected function getListQuery() } // Search by content id - $search = $this->getState('filter.search'); + $search = $this->getState($client . '.filter.search'); if (!empty($search)) { @@ -288,7 +290,7 @@ protected function getListQuery() } // Search on fields data - $filteredItemIds = $this->filterContent(); + $filteredItemIds = $this->filterContent($client); if (is_array($filteredItemIds)) { @@ -305,7 +307,7 @@ protected function getListQuery() } // Filter by cluster - $clusterId = (int) $this->getState('filter.cluster_id'); + $clusterId = (int) $this->getState($client . '.filter.cluster_id'); if ($clusterId) { @@ -331,7 +333,7 @@ protected function getListQuery() * * @since 1.2.1 */ - private function filterContent() + private function filterContent($client) { // Flag to mark if field specific search is done from the search box $filterFieldFound = 0; @@ -349,10 +351,10 @@ private function filterContent() $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($this->client)); + $query->where($db->quoteName('f.client') . ' = ' . $db->quote($client)); // Filter by field value - $search = $this->getState('filter.search'); + $search = $this->getState($client . '.filter.search'); if (!empty($this->fields) && (stripos($search, 'id:') !== 0)) { @@ -398,7 +400,7 @@ private function filterContent() // For filterable fields JLoader::import('components.com_tjfields.models.fields', JPATH_ADMINISTRATOR); $fieldsModel = JModelLegacy::getInstance('Fields', 'TjfieldsModel', array('ignore_request' => true)); - $fieldsModel->setState('filter.client', $this->client); + $fieldsModel->setState('filter.client', $client); $fieldsModel->setState('filter.filterable', 1); $fields = $fieldsModel->getItems(); @@ -450,11 +452,11 @@ public function getFields() $fieldsModel = JModelLegacy::getInstance('Fields', 'TjfieldsModel', array('ignore_request' => true)); $fieldsModel->setState('filter.showonlist', 1); $fieldsModel->setState('filter.state', 1); - $this->client = $this->getState('ucm.client'); + $client = $this->getState('ucm.client'); - if (!empty($this->client)) + if (!empty($client)) { - $fieldsModel->setState('filter.client', $this->client); + $fieldsModel->setState('filter.client', $client); } $items = $fieldsModel->getItems(); diff --git a/src/components/com_tjucm/site/views/items/tmpl/default_filters.php b/src/components/com_tjucm/site/views/items/tmpl/default_filters.php index 223b1ada..27e04593 100644 --- a/src/components/com_tjucm/site/views/items/tmpl/default_filters.php +++ b/src/components/com_tjucm/site/views/items/tmpl/default_filters.php @@ -20,7 +20,7 @@
@@ -47,7 +47,7 @@ ?>