diff --git a/blocks/myoverview/classes/output/main.php b/blocks/myoverview/classes/output/main.php index abe98d9e20910..08ae029a492d9 100644 --- a/blocks/myoverview/classes/output/main.php +++ b/blocks/myoverview/classes/output/main.php @@ -522,10 +522,10 @@ public function export_for_zero_state_template(renderer_base $output) { } $totalcourses = $DB->count_records_select('course', 'category > 0'); - if (!$totalcourses && ($category = \core_course_category::get_nearest_editable_subcategory($coursecat, ['create']))) { - // Add Quickstart guide and Create course buttons. + if ($category = \core_course_category::get_nearest_editable_subcategory($coursecat, ['create'])) { + // Add Quickstart guide, Manage courses and Create course buttons. $quickstarturl = $CFG->coursecreationguide; - if ($quickstarturl) { + if (!$totalcourses && $quickstarturl) { $quickstartbutton = new \single_button( new \moodle_url($quickstarturl, ['lang' => current_language()]), get_string('viewquickstart', 'block_myoverview'), @@ -534,45 +534,29 @@ public function export_for_zero_state_template(renderer_base $output) { $buttons = [$quickstartbutton->export_for_template($output)]; } - $createbutton = new \single_button( - new \moodle_url('/course/edit.php', ['category' => $category->id]), - get_string('createcourse', 'block_myoverview'), - 'post', - \single_button::BUTTON_PRIMARY - ); - $buttons[] = $createbutton->export_for_template($output); - return $this->generate_zero_state_data( - $nocoursesimg, - $buttons, - ['title' => 'zero_nocourses_title', 'intro' => 'zero_nocourses_intro'] - ); - } - - if ($categorytocreate = \core_course_category::get_nearest_editable_subcategory($coursecat, ['create'])) { - $createbutton = new \single_button( - new \moodle_url('/course/edit.php', ['category' => $categorytocreate->id]), - get_string('createcourse', 'block_myoverview'), - 'post', - \single_button::BUTTON_PRIMARY - ); - $buttons = [$createbutton->export_for_template($output)]; if ($categorytomanage = \core_course_category::get_nearest_editable_subcategory($coursecat, ['manage'])) { // Add a Manage course button. $managebutton = new \single_button( new \moodle_url('/course/management.php', ['category' => $categorytomanage->id]), - get_string('managecourses') + get_string('managecourses'), ); $buttons[] = $managebutton->export_for_template($output); - return $this->generate_zero_state_data( - $nocoursesimg, - array_reverse($buttons), - ['title' => 'zero_default_title', 'intro' => 'zero_default_intro'] - ); } + + $createbutton = new \single_button( + new \moodle_url('/course/edit.php', ['category' => $category->id]), + get_string('createcourse', 'block_myoverview'), + 'post', + \single_button::BUTTON_PRIMARY, + ); + $buttons[] = $createbutton->export_for_template($output); + + $title = $totalcourses ? 'zero_default_title' : 'zero_nocourses_title'; + $intro = $totalcourses ? 'zero_default_intro' : 'zero_nocourses_intro'; return $this->generate_zero_state_data( $nocoursesimg, $buttons, - ['title' => 'zero_default_title', 'intro' => 'zero_default_intro'] + ['title' => $title, 'intro' => $intro], ); } } diff --git a/my/courses.php b/my/courses.php index 60489dc053306..4d41218e00ca5 100644 --- a/my/courses.php +++ b/my/courses.php @@ -71,19 +71,21 @@ // Add course management if the user has the capabilities for it. $coursecat = core_course_category::user_top(); $coursemanagemenu = []; -if ($coursecat && ($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 ($coursecat && ($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 ($coursecat) { - $category = core_course_category::get_nearest_editable_subcategory($coursecat, ['moodle/course:request']); - if ($category && $category->can_request_course()) { - $coursemanagemenu['courserequesturl'] = new moodle_url('/course/request.php', ['categoryid' => $category->id]); - +// Only display the action menu if the user has courses (otherwise, the buttons will be displayed in the zero state). +if (count(enrol_get_all_users_courses($USER->id, true)) > 0) { + if ($coursecat && ($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 ($coursecat && ($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 ($coursecat) { + $category = core_course_category::get_nearest_editable_subcategory($coursecat, ['moodle/course:request']); + if ($category && $category->can_request_course()) { + $coursemanagemenu['courserequesturl'] = new moodle_url('/course/request.php', ['categoryid' => $category->id]); + } } } if (!empty($coursemanagemenu)) { diff --git a/my/templates/dropdown.mustache b/my/templates/dropdown.mustache index 0ef5225855499..74975363d0bd3 100644 --- a/my/templates/dropdown.mustache +++ b/my/templates/dropdown.mustache @@ -27,19 +27,21 @@ } }}
- - - diff --git a/theme/boost/scss/moodle/core.scss b/theme/boost/scss/moodle/core.scss index 2bb620ebc9263..ac1784db64726 100644 --- a/theme/boost/scss/moodle/core.scss +++ b/theme/boost/scss/moodle/core.scss @@ -2944,6 +2944,13 @@ body.dragging { } } +#page-my-index .my-action-buttons { + display: flex; + justify-content: center; + align-items: center; + gap: 10px; +} + .dropdown-toggle::after { @extend .fa-solid; content: fa-content($fa-var-chevron-down); diff --git a/theme/boost/style/moodle.css b/theme/boost/style/moodle.css index ae6f748b20b83..08da4541cdbfa 100644 --- a/theme/boost/style/moodle.css +++ b/theme/boost/style/moodle.css @@ -25921,6 +25921,13 @@ body.dragging .dragging { padding-right: 0 !important; /* stylelint-disable-line declaration-no-important */ } +#page-my-index .my-action-buttons { + display: flex; + justify-content: center; + align-items: center; + gap: 10px; +} + .dropdown-toggle::after { content: "\f078"; margin-right: 0; diff --git a/theme/classic/style/moodle.css b/theme/classic/style/moodle.css index f02544c7eeef2..413d657a3b2c9 100644 --- a/theme/classic/style/moodle.css +++ b/theme/classic/style/moodle.css @@ -25921,6 +25921,13 @@ body.dragging .dragging { padding-right: 0 !important; /* stylelint-disable-line declaration-no-important */ } +#page-my-index .my-action-buttons { + display: flex; + justify-content: center; + align-items: center; + gap: 10px; +} + .dropdown-toggle::after { content: "\f078"; margin-right: 0;