Skip to content

Commit

Permalink
MDL-39794 - Course - Add 'Add a new course' button to front page when…
Browse files Browse the repository at this point in the history
… page editing is on
  • Loading branch information
jsnfwlr committed Jun 18, 2013
1 parent f192883 commit ee11f4a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
23 changes: 17 additions & 6 deletions course/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1878,17 +1878,28 @@ public function frontpage_available_courses() {
$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
*
Expand Down
4 changes: 3 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit ee11f4a

Please sign in to comment.