カテゴリ テーブルからカテゴリとサブカテゴリを取得する再帰に問題があり、html メソッドが間違った出力を生成します。サブカテゴリが親カテゴリとして 2 回追加されています

public function getCategories() {
    $refs = array();
    $list = array();
    // Get a db connection.
    $db = JFactory::getDbo();
    // Create a new query object.
    $query = $db->getQuery(true);
    $query->select('*');
    $query->from('#__immobilien_cat');
    $db->setQuery($query);
    $datas = $db->loadAssocList();
    $categories = array();
    foreach ($datas as $data) {
        $thisref = &$refs[$data['id']];
        $thisref['parent'] = $data['parent'];
        $thisref['cat_name'] = $data['cat_name'];
        $thisref['id'] = $data['id'];
        if ($data['parent'] == 0) {
            $list[$data['id']] = &$thisref;
        } else {
            $refs[$data['parent']]['children'][$data['id']] = &$thisref;
        }
    }
    return $this->toHTMl($refs);
}
function toHTML(array $array) {
    $html = '<ol class="dd-list">' ;
    foreach ($array as $value) {
        $html .= '<li data-id="'.$value['id'].'" class="dd-item dd3-item">';
        $html .= '<div class="dd-handle dd3-handle"></div>';
        $html .= '<div class="dd3-content">'.$value['cat_name'].'</div>';
        if (!empty($value['children'])) {
            $html .= $this->toUL($value['children']);
        }
        $html .= '</li>';
    }
    $html .= '</ol  >' ;
    return $html;
}
    id  cat_name     parent  translation  status  
------  -----------  ------  -----------  --------
     1  Villa             0  (NULL)         (NULL)
     2  Büro              0  (NULL)         (NULL)
     3  Apartment         0  (NULL)         (NULL)
     4  Luxus Villa       1  (NULL)         (NULL)