General developer forum

Get user's assigned categories

 
Picture of Ionuț Vîlsan
Get user's assigned categories
 

Hi, 


I am trying to read user's categories but I did not have any success. 

This is my code, but I only get all the courses .


protected function render_custom_menu(custom_menu $menu) { 

  $mycourses = $this->page->navigation->get('mycourses');

 // my courses

 if (isloggedin() ) { 

 $branchlabel = get_string('mycourses');

 $branchurl = new moodle_url('/course/index.php');

 $branchtitle = $branchlabel;

 $branch = $menu->add($branchlabel, $branchurl, $branchtitle, -1);

 foreach ($mycourses->children as $coursenode) {

 $branch->add($coursenode->get_content(), $coursenode->action, $coursenode->get_title()); 

         }

 }



How can I edit my code to get user's categories ?

 
Average of ratings: -
Picture of Darko Miletić
Re: Get user's assigned categories
Core developersParticularly helpful Moodlers

Can you be a bit more specific? Users are never assigned to categories. They get assigned to courses while in turn courses are inside some category.

 
Average of ratings: -
Picture of Ionuț Vîlsan
Re: Get user's assigned categories
 

Can I get the categories of the courses that a user is enrolled in ? For example a user is enrolled in the English course and the English course is in the Languages category. How can I get the categories for the enrolled course ?

The code above is used for a drop-down menu in the custom menu items navbar .

In the navbar I want to have the categories not the courses assigned to student.

Thank you

 
Average of ratings: -