In our old 2.7 custom theme we created a section to show some roles which people are managing a specific course section:
$user_string = "";
$list_container = [];
$list_con_counter = 0;
$chelper = new coursecat_helper();
$set_flag = FALSE;
$userroles = Array();
if ($category != null || $category != 0) {
$coursecontext = context_coursecat::instance($category); //aktueller context
if (has_capability('moodle/course:create', $coursecontext)) {
$category_information = $DB->get_records('course_categories', array('id' => $category)); //informationen aus dem aktuellen context
if ($category_information[$category]->parent != 0) {
$userroles_current = $DB->get_records('role_assignments', array('contextid' => $coursecontext->id));
if (empty($userroles_current) != true){ array_push($userroles, $userroles_current); }
$_category = $category;
do {
$course_context_parent = context_coursecat::instance($category_information[$_category]->parent);
$userroles_parent = $DB->get_records('role_assignments', array('contextid' => $course_context_parent->id));
if (empty($userroles_parent) != true) { array_push($userroles, $userroles_parent); }
$_category = $category_information[$_category]->parent;
$category_information = $DB->get_records('course_categories', array('id' => $_category));
} while ($category_information[$_category]->parent != 0);
if ($userroles != NULL) {
$set_flag = TRUE;
$user_string .= "<div class='cate_info_wrapper'><h2>Kursverwalter/-innen:</h2><div class='cate_info_content'><ul>";
foreach ($userroles as $user1) {
foreach ($user1 as $user) {
$user_query = $DB->get_record('user', array('id'=> $user->userid));
$user_string .= '<li>' . get_string('name') . ': '. $user_query->firstname . ' '. $user_query->lastname . ' -- '. get_string('username') .
': ' . $user_query->username . ' -- '. get_string('email') . ": <a href='mailto:" . $user_query->email . "'>" . $user_query->email . '</a></li>';
}
}
$user_string .= "</ul></div></div>";
}
}
else {
$userroles = $DB->get_records('role_assignments', array('contextid' => $coursecontext->id));
if ($userroles != NULL) {
$set_flag = TRUE;
$user_string .= "<div class='cate_info_wrapper'><h2>Kursverwalter/-innen:</h2><div class='cate_info_content'><ul>";
foreach ($userroles as $user) {
$user_query = $DB->get_record('user', array('id'=> $user->userid));
$user_string .= '<li>' . get_string('name') . ': '. $user_query->firstname . ' '. $user_query->lastname . ' -- '. get_string('username') .
': ' . $user_query->username . ' -- '. get_string('email') . ": <a href='mailto:" . $user_query->email . "'>" . $user_query->email . '</a></li>';
}
$user_string .= "</ul></div></div>";
}
}
}
if ($chelper->get_category_formatted_description($coursecat)) {
$description = $chelper->get_category_formatted_description($coursecat);
if ($set_flag == TRUE) {
$description .= $user_string;
}
$output .= $this->box($description, array('class' => 'generalbox info '));
}
else {
if ($set_flag == TRUE) {
$description = $chelper->get_category_formatted_description($coursecat);
$description .= $user_string;
$output .= $this->box($description, array('class' => 'generalbox info '));
}
}
}
I now try to port this code into 3.3 and boost, but if you have any ideas to improve this feature, please write a comment.