Skip to content

Commit

Permalink
Merge pull request #293 from ankush-maherwal/10023
Browse files Browse the repository at this point in the history
10023
  • Loading branch information
ankush-maherwal authored Dec 11, 2019
2 parents 2a136d6 + ba5a42d commit 3338753
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
50 changes: 24 additions & 26 deletions src/components/com_tjucm/site/models/items.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
*/
class TjucmModelItems extends JModelList
{
private $client;

/**
* Constructor.
*
Expand Down Expand Up @@ -103,22 +101,22 @@ 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;
}
}
}

// Load the filter state.
$search = $app->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'STRING');
$this->setState('filter.search', $search);
$search = $app->getUserStateFromRequest($this->context . '.' . $ucmType . '.filter.search', 'filter_search', '', 'STRING');
$this->setState($ucmType . '.filter.search', $search);

// Set state for field filters
JLoader::import('components.com_tjfields.models.fields', JPATH_ADMINISTRATOR);
Expand All @@ -133,11 +131,11 @@ protected function populateState($ordering = "a.id", $direction = "DESC")
$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);
Expand Down Expand Up @@ -200,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');
Expand All @@ -236,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)
{
Expand Down Expand Up @@ -279,7 +277,7 @@ protected function getListQuery()
}

// Search by content id
$search = $this->getState('filter.search');
$search = $this->getState($client . '.filter.search');

if (!empty($search))
{
Expand All @@ -292,7 +290,7 @@ protected function getListQuery()
}

// Search on fields data
$filteredItemIds = $this->filterContent();
$filteredItemIds = $this->filterContent($client);

if (is_array($filteredItemIds))
{
Expand All @@ -309,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)
{
Expand All @@ -335,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;
Expand All @@ -353,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))
{
Expand Down Expand Up @@ -402,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();

Expand Down Expand Up @@ -454,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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<div class="pull-left">
<input type="text" name="filter_search" id="filter_search"
title="<?php echo empty($firstListColumn) ? JText::_('JSEARCH_FILTER') : JText::sprintf('COM_TJUCM_ITEMS_SEARCH_TITLE', $this->listcolumn[$firstListColumn]); ?>"
value="<?php echo $this->escape($this->state->get('filter.search')); ?>"
value="<?php echo $this->escape($this->state->get($this->client . '.filter.search')); ?>"
placeholder="<?php echo JText::_('JSEARCH_FILTER'); ?>"/>
</div>
<div class="pull-left">
Expand All @@ -47,7 +47,7 @@
?>
<div class="btn-group pull-right hidden-xs">
<?php
echo JHtml::_('select.genericlist', $this->clusterList, "cluster", 'class="input-medium" size="1" onchange="this.form.submit();"', "value", "text", $this->state->get('filter.cluster_id', '', 'INT'));
echo JHtml::_('select.genericlist', $this->clusterList, "cluster", 'class="input-medium" size="1" onchange="this.form.submit();"', "value", "text", $this->state->get($this->client . '.filter.cluster_id', '', 'INT'));
?>
</div>
<?php
Expand Down

0 comments on commit 3338753

Please sign in to comment.