Function get_course_category_tree

Function get_course_category_tree

by Victor Bonnet -
Number of replies: 1

Hi everyone,

I am currently movi,g my Moodle from 2.4 to 3.0 and I get an error code saying that this function is deprecated.

The code deprecated is in renderers.php :

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

$branch = $menu->add(get_string('my', 'theme_enfa'), new moodle_url('/my'), null, 10000);
   
        $categorytree = get_course_category_tree();
   
        foreach ($categorytree as $category)
        {
            $branch = $menu->add($category->name, new moodle_url('/course/category.php', array('id' =>  $category->id)));
               
            if (!empty($category->categories))
            {
                foreach ($category->categories as $subcategory)
                {
                    $this->add_category_to_custommenu($branch, $subcategory);
                }
            }
   
            if (!empty($category->courses))
            {
                foreach ($category->courses as $course)
                {
                    $branch->add($course->shortname, new moodle_url('/course/view.php', array('id' => $course->id)), $course->shortname);
                }
            }
   
        } // End foreach ($categorytree as $category)

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

So I googled it and the only solution I found was : " Add $courses = get_course($categoryid) to your code"

But I'm not a PHP developper so I don't know how to use this function in my .php.


Have you a solution, a tip ?


Thank you for reading, and sorry if my English is not good.


Have a nice day !

Average of ratings: -
In reply to Victor Bonnet

Re: Function get_course_category_tree

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

There's only part of the story here. Almost certainly, this is caused by a plugin which is incompatible with 3.0. Make sure that all your optional plugins are up to date (and actually have versions that work with 3.0). 

There have been a lot of changes since 2.4 and you cannot just copy the plugins over. 

It's unlikely that there is a simple fix for this one.