MDL-73549 Course: My course page menu improvement

- Introduce core_course_category::get_nearest_editable_subcategory()
 - This function will return the first creatable/manageable category
for current user
 - With this new function, we can fix the issue that the users with
course management or creation permision at category level cannot see
the manage menu on My courses page
This commit is contained in:
Huong Nguyen 2022-03-02 13:16:18 +07:00
parent 1d99ba19a2
commit 481cfdc3f0
6 changed files with 251 additions and 9 deletions

View file

@ -63,12 +63,18 @@ $PAGE->theme->addblockposition = BLOCK_ADDBLOCK_POSITION_CUSTOM;
// Add course management if the user has the capabilities for it.
$coursecat = core_course_category::user_top();
if ($coursecat->can_create_course() || $coursecat->has_manage_capability()) {
$data = [
'newcourseurl' => new moodle_url('/course/edit.php', ['category' => $coursecat->id]),
'manageurl' => new moodle_url('/course/management.php', ['categoryid' => $coursecat->id]),
];
$PAGE->add_header_action($OUTPUT->render_from_template('my/dropdown', $data));
$coursemanagemenu = [];
if ($category = core_course_category::get_nearest_editable_subcategory($coursecat, ['create'])) {
// The user has the capability to create course.
$coursemanagemenu['newcourseurl'] = new moodle_url('/course/edit.php', ['category' => $category->id]);
}
if ($category = core_course_category::get_nearest_editable_subcategory($coursecat, ['manage'])) {
// The user has the capability to manage the course category.
$coursemanagemenu['manageurl'] = new moodle_url('/course/management.php', ['categoryid' => $category->id]);
}
if (!empty($coursemanagemenu)) {
// Render the course management menu.
$PAGE->add_header_action($OUTPUT->render_from_template('my/dropdown', $coursemanagemenu));
}
echo $OUTPUT->header();