diff --git a/course/renderer.php b/course/renderer.php index 9bc279d7a21..94f0006d91b 100644 --- a/course/renderer.php +++ b/course/renderer.php @@ -1878,17 +1878,28 @@ class core_course_renderer extends plugin_renderer_base { $chelper->set_attributes(array('class' => 'frontpage-course-list-all')); $courses = coursecat::get(0)->get_courses($chelper->get_courses_display_options()); $totalcount = coursecat::get(0)->get_courses_count($chelper->get_courses_display_options()); - if (!$totalcount && has_capability('moodle/course:create', context_system::instance())) { + if (!$totalcount && !$this->page->user_is_editing() && has_capability('moodle/course:create', context_system::instance())) { // Print link to create a new course, for the 1st available category. - $output = $this->container_start('buttons'); - $url = new moodle_url('/course/edit.php', array('category' => $CFG->defaultrequestcategory, 'returnto' => 'topcat')); - $output .= $this->single_button($url, get_string('addnewcourse'), 'get'); - $output .= $this->container_end('buttons'); - return $output; + return $this->add_new_course_button(); } return $this->coursecat_courses($chelper, $courses, $totalcount); } + /** + * Returns HTML to the "add new course" button for the page + * + * @return string + */ + public function add_new_course_button() { + global $CFG; + // Print link to create a new course, for the 1st available category. + $output = $this->container_start('buttons'); + $url = new moodle_url('/course/edit.php', array('category' => $CFG->defaultrequestcategory, 'returnto' => 'topcat')); + $output .= $this->single_button($url, get_string('addnewcourse'), 'get'); + $output .= $this->container_end('buttons'); + return $output; + } + /** * Returns HTML to print tree with course categories and courses for the frontpage * diff --git a/index.php b/index.php index ce56de5cf6a..b5dc3218dd4 100644 --- a/index.php +++ b/index.php @@ -281,5 +281,7 @@ } echo '
'; } - + if ($editing && has_capability('moodle/course:create', context_system::instance())) { + echo $courserenderer->add_new_course_button(); + } echo $OUTPUT->footer();