Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Joomla\CMS\Language\Associations;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Database\DatabaseQuery;
use Joomla\Database\ParameterType;
use Joomla\Utilities\ArrayHelper;

Expand Down Expand Up @@ -490,30 +491,22 @@ public function countItems(&$items, $extension)
}

/**
* Is this an empty state, I.e: no items of this type regardless of the searched for states.
* Manipulate the query to be used to evaluate if this is an Empty State to provide specific conditions for this extension.
*
* @return boolean
* @return DatabaseQuery
*
* @since __DEPLOY_VERSION__
*/
public function getisEmptyState()
protected function getEmptyStateQuery()
{
$extension = $this->getState('filter.extension');
$query = parent::getEmptyStateQuery();

$sql = $this->query
->clear('select')
->clear('values')
->clear('bounded')
->clear('limit')
->clear('order')
->clear('where')
->select('count(*)');
// Get the extension from the filter
$extension = $this->getState('filter.extension');

$sql->where($this->_db->quoteName('extension') . ' = :extension')
$query->where($this->_db->quoteName('extension') . ' = :extension')
->bind(':extension', $extension);

$this->_db->setQuery($sql);

return !($this->_db->loadResult() > 0);
return $query;
}
}
22 changes: 7 additions & 15 deletions administrator/components/com_tags/src/Model/TagsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\CMS\Tag\TagServiceInterface;
use Joomla\Database\DatabaseQuery;
use Joomla\Database\ParameterType;

/**
Expand Down Expand Up @@ -327,27 +328,18 @@ public function countItems(&$items, $extension)
}

/**
* Is this an empty state, I.e: no items of this type regardless of the searched for states.
* Manipulate the query to be used to evaluate if this is an Empty State to provide specific conditions for this extension.
*
* @return boolean
* @return DatabaseQuery
*
* @since __DEPLOY_VERSION__
*/
public function getisEmptyState()
protected function getEmptyStateQuery()
{
$sql = $this->query
->clear('select')
->clear('values')
->clear('bounded')
->clear('limit')
->clear('order')
->clear('where')
->select('count(*)');
$query = parent::getEmptyStateQuery();

$sql->where($this->_db->quoteName('alias') . ' != ' . $this->_db->quote('root'));
$query->where($this->_db->quoteName('alias') . ' != ' . $this->_db->quote('root'));

$this->_db->setQuery($sql);

return !($this->_db->loadResult() > 0);
return $query;
}
}
44 changes: 30 additions & 14 deletions libraries/src/MVC/Model/ListModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

\defined('JPATH_PLATFORM') or die;

use Exception;
use Joomla\CMS\Factory;
use Joomla\CMS\Filter\InputFilter;
use Joomla\CMS\Form\Form;
Expand Down Expand Up @@ -118,7 +119,7 @@ class ListModel extends BaseDatabaseModel implements ListModelInterface
* @param MVCFactoryInterface $factory The factory.
*
* @since 1.6
* @throws \Exception
* @throws Exception
*/
public function __construct($config = array(), MVCFactoryInterface $factory = null)
{
Expand Down Expand Up @@ -149,27 +150,42 @@ public function __construct($config = array(), MVCFactoryInterface $factory = nu
}
}

/**
* Provide a query to be used to evaluate if this is an Empty State, can be overridden in the model to provide granular control.
*
* @return DatabaseQuery
*
* @since __DEPLOY_VERSION__
*/
protected function getEmptyStateQuery()
{
$query = clone $this->_getListQuery();

if ($query instanceof DatabaseQuery)
{
$query->clear('bounded')
->clear('group')
->clear('having')
->clear('join')
->clear('values')
->clear('where');
}

return $query;
}

/**
* Is this an empty state, I.e: no items of this type regardless of the searched for states.
*
* @return boolean
*
* @throws Exception
*
* @since __DEPLOY_VERSION__
*/
public function getIsEmptyState()
public function getIsEmptyState(): bool
{
$sql = $this->query
->clear('select')
->clear('values')
->clear('bounded')
->clear('limit')
->clear('order')
->clear('where')
->select('count(*)');

$this->_db->setQuery($sql);

return !($this->_db->loadResult() > 0);
return $this->_getListCount($this->getEmptyStateQuery()) === 0;
}

/**
Expand Down