MDL-39794 - Course - Add 'Add a new course' button to front page when page editing is on

This commit is contained in:
Jason Fowler
2013-06-18 09:26:55 +08:00
parent f192883305
commit ee11f4a759
2 changed files with 20 additions and 7 deletions
+17 -6
View File
@@ -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
*
+3 -1
View File
@@ -281,5 +281,7 @@
}
echo '<br />';
}
if ($editing && has_capability('moodle/course:create', context_system::instance())) {
echo $courserenderer->add_new_course_button();
}
echo $OUTPUT->footer();