?
avatar berserkerx
berserkerx
27 Dec 2014

Steps to reproduce the issue

Create test site with 3 categories. Call JCategories::getInstance('Content')->get('root')->getChildren(true);

Expected result

Array of 3 categories.

Actual result

Array of single category item.

System information (as much as possible)

OpenServer, PHP 5.4, Joomla 3.3.6.

Additional comments

Votes

# of Users Experiencing Issue
1/1
Average Importance Score
5.00

avatar berserkerx berserkerx - open - 27 Dec 2014
avatar smz
smz - comment - 27 Dec 2014

Confirmed with Joomla 3.4.0-dev
I'm looking into this...

avatar smz
smz - comment - 27 Dec 2014

Actually, an array is returned containing a single element of type JCategoryNode for the Uncategorized category.

In this object you will find (amongst a lot of stuff...) a [_parent:protected] element pointing to the root node with all its children (the [_nodes:protected] array).

I'm unsure if this is the expected behavior... (probably not...)

avatar smz
smz - comment - 27 Dec 2014

I used this code to "dump" the object:

defined('_JEXEC') or die;

define('BR', '<br/>');

class SMZ_Tester {
    public static function executeTest() {
        $r = '';

        $r .= 'Date time is: ';
        $r .= strftime("%Y-%m-%d %H:%M:%S") . BR;

        $cats = JCategories::getInstance('Content')->get('root')->getChildren(true);
        $r .= BR . 'Categories:' . BR;
        $r .= print_r($cats, true);

        return $r;
    }
}
avatar berserkerx
berserkerx - comment - 27 Dec 2014

Thank you for the reply. I've also used var_dump and saw, that all categories can be accessed via private members, but it's definitely not an expected behaviour.

avatar berserkerx
berserkerx - comment - 27 Dec 2014

In my case, the single element returned was user-defined category, not uncategorized.

avatar smz
smz - comment - 27 Dec 2014

Ah... I thought the category with the lowest ID (normally Uncategorized) would always be returned, but this evidently is a "false assumption". I will look at the code...

I'm wondering what will happen if a "deeper" (2nd or 3rd level) category is returned: the _parent at that point would not be root...

avatar smz
smz - comment - 27 Dec 2014

hmmm... we are probably making some mistake or false assumption...
This is what the model for "List All Categories" does (guaranteed functioning!)

$categories = JCategories::getInstance('Content', $options);
$this->_parent = $categories->get($this->getState('filter.parentId', 'root'));

if (is_object($this->_parent))
{
    $this->_items = $this->_parent->getChildren($recursive);
}
else
{
    $this->_items = false;
}
avatar brianteeman brianteeman - change - 27 Dec 2014
Priority Urgent Medium
avatar berserkerx
berserkerx - comment - 27 Dec 2014

The code is roughly equivalent to the following:
$cat = JCategories::getInstance('Content', $options)->get('root');
$items = is_object($cat) ? $cat->getChildren($recursive) : false;
Probably options differ from the default, but it still gives no light on a problem.

avatar smz
smz - comment - 27 Dec 2014

I agree, but I tried your same code and... no way! :confused:

avatar brianteeman brianteeman - change - 3 Jan 2015
Status New Confirmed
avatar brianteeman brianteeman - change - 3 Jan 2015
Labels Added: ?
avatar zero-24
zero-24 - comment - 8 May 2015

Closing as we have a merged PR that should fix the issue see #6440

avatar zero-24 zero-24 - change - 8 May 2015
Status Confirmed Closed
Closed_Date 0000-00-00 00:00:00 2015-05-08 22:28:38
Closed_By zero-24
avatar zero-24 zero-24 - close - 8 May 2015

Add a Comment

Login with GitHub to post a comment