private function get_all_category_branches() {

        $categories = data_registry::get_site_categories();

        $categoriesbranch = [];
        while (count($categories) > 0) {
            foreach ($categories as $key => $category) {

                $context = \context_coursecat::instance($category->id);
                $newnode = [
                    'text' => shorten_text(format_string($category->name, true, ['context' => $context])),
                    'categoryid' => $category->id,
                    'contextid' => $context->id,
                ];
                if ($category->coursecount > 0) {
                    $newnode['branches'] = [
                        [
                            'text' => get_string('courses'),
                            'expandcontextid' => $context->id,
                            'expandelement' => 'course',
                            'expanded' => 0,
                        ]
                    ];
                }

                $added = false;
                if ($category->parent == 0) {
                    // New categories root-level node.
                    $categoriesbranch[] = $newnode;
                    $added = true;

                } else {
                    // Add the new node under the appropriate parent.
                    if ($this->add_to_parent_category_branch($category, $newnode, $categoriesbranch)) {
                        $added = true;
                    }
                }

                if ($added) {
                    unset($categories[$key]);
                }
            }
        }

        return $categoriesbranch;
    }
private function get_all_category_branches() {

        $categories = data_registry::get_site_categories();

        $categoriesbranch = [];
        while (count($categories) > 0) {
            foreach ($categories as $key => $category) {

                $context = \context_coursecat::instance($category->id);
                $newnode = [
                    'text' => shorten_text(format_string($category->name, true, ['context' => $context])),
                    'categoryid' => $category->id,
                    'contextid' => $context->id,
                ];
                if ($category->coursecount > 0) {
                    $newnode['branches'] = [
                        [
                            'text' => get_string('courses'),
                            'expandcontextid' => $context->id,
                            'expandelement' => 'course',
                            'expanded' => 0,
                        ]
                    ];
                }

                $added = false;
                if ($category->parent == 0) {
                    // New categories root-level node.
                    $categoriesbranch[] = $newnode;
                    $added = true;

                } else {
                    // Add the new node under the appropriate parent.
                    if ($this->add_to_parent_category_branch($category, $newnode, $categoriesbranch)) {
                        $added = true;
                    }
                }

                if ($added) {
                    unset($categories[$key]);
                }
            }
        }

        return $categoriesbranch;
    }
private function get_all_category_branches ( ) { $ categories = data_registry :: get_site_categories ( ) ; $ categoriesbranch = [ ] ; while ( count ( $ categories ) > 0 ) { foreach ( $ categories as $ key => $ category ) { $ context = \ context_coursecat :: instance ( $ category -> id ) ; $ newnode = [ 'text' => shorten_text ( format_string ( $ category -> name , true , [ 'context' => $ context ] ) ) , 'categoryid' => $ category -> id , 'contextid' => $ context -> id , ] ; if ( $ category -> coursecount > 0 ) { $ newnode [ 'branches' ] = [ [ 'text' => get_string ( 'courses' ) , 'expandcontextid' => $ context -> id , 'expandelement' => 'course' , 'expanded' => 0 , ] ] ; } $ added = false ; if ( $ category -> parent == 0 ) { // New categories root-level node. $ categoriesbranch [ ] = $ newnode ; $ added = true ; } else { // Add the new node under the appropriate parent. if ( $ this -> add_to_parent_category_branch ( $ category , $ newnode , $ categoriesbranch ) ) { $ added = true ; } } if ( $ added ) { unset ( $ categories [ $ key ] ) ; } } } return $ categoriesbranch ; }
Returns the hierarchy of system course categories.

@return array
Returns the hierarchy of system course categories .