Skip to content

Commit

Permalink
Articles count in "List all categories". Fixes #5416
Browse files Browse the repository at this point in the history
  • Loading branch information
smz authored and wilsonge committed May 9, 2015
1 parent d5b9385 commit 497e2da
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
17 changes: 10 additions & 7 deletions libraries/legacy/categories/categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public function __construct($options)
$this->_statefield = (isset($options['statefield'])) ? $options['statefield'] : 'state';
$options['access'] = (isset($options['access'])) ? $options['access'] : 'true';
$options['published'] = (isset($options['published'])) ? $options['published'] : 1;
$options['countItems'] = (isset($options['countItems'])) ? $options['countItems'] : 0;
$options['currentlang'] = JLanguageMultilang::isEnabled() ? JFactory::getLanguage()->getTag() : 0;
$this->_options = $options;

return true;
Expand Down Expand Up @@ -259,20 +261,21 @@ protected function _load($id)
->where('badcats.id is null');

// Note: i for item
if (isset($this->_options['countItems']) && $this->_options['countItems'] == 1)
if ($this->_options['currentlang'] !== 0 || $this->_options['countItems'] == 1)
{
$queryjoin = $db->quoteName($this->_table) . ' AS i ON i.' . $db->quoteName($this->_field) . ' = c.id';

if ($this->_options['published'] == 1)
{
$query->join(
'LEFT',
$db->quoteName($this->_table) . ' AS i ON i.' . $db->quoteName($this->_field) . ' = c.id AND i.' . $this->_statefield . ' = 1'
);
$queryjoin .= ' AND i.' . $this->_statefield . ' = 1';
}
else

if ($this->_options['currentlang'] !== 0)
{
$query->join('LEFT', $db->quoteName($this->_table) . ' AS i ON i.' . $db->quoteName($this->_field) . ' = c.id');
$queryjoin .= ' AND (i.language = ' . $db->quote('*') . ' OR i.language = ' . $db->quote($this->_options['currentlang']) . ')';
}

$query->join('LEFT', $queryjoin);
$query->select('COUNT(i.' . $db->quoteName($this->_key) . ') AS numitems');
}

Expand Down
19 changes: 16 additions & 3 deletions tests/unit/suites/libraries/legacy/categories/JCategoriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,29 @@ class JCategoriesTest extends TestCaseDatabase
*
* @since 3.2
*/
protected function setUp()
public function setUp()
{
parent::setUp();

// Add JApplication and JLanguage dependencies
$this->saveFactoryState();
JFactory::$language = $this->getMockLanguage();
JFactory::$application = $this->getMockCmsApp();
}

/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
* Overrides the parent tearDown method.
*
* @return void
*
* @see PHPUnit_Framework_TestCase::tearDown()
* @since 3.2
*/
protected function tearDown()
{
$this->restoreFactoryState();

parent::tearDown();
}

/**
Expand Down

0 comments on commit 497e2da

Please sign in to comment.