From 30697cf3fe47e00d5eacf11f42dc2aefc3a8a2b2 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Thu, 20 Dec 2012 13:36:32 +0800 Subject: [PATCH] MDL-37062 Course: Show one 'Add new course' button Currently if there is no course and admin/course creator go to create course, he/she see two 'Add new course' buttons. --- course/index.php | 14 ++++++-------- course/lib.php | 6 +++++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/course/index.php b/course/index.php index a1a5e569957..645d4bd8190 100644 --- a/course/index.php +++ b/course/index.php @@ -67,12 +67,11 @@ $straction = get_string('action'); $strfulllistofcourses = get_string('fulllistofcourses'); -/// Unless it's an editing admin, just print the regular listing of courses/categories +// Unless it's an editing admin, just print the regular listing of courses/categories. if (!$adminediting) { - -/// Print form for creating new categories + $showaddcoursebutton = true; + // Print form for creating new categories. $countcategories = $DB->count_records('course_categories'); - if ($countcategories > 1 || ($countcategories == 1 && $DB->count_records('course') > 200)) { $strcourses = get_string('courses'); $strcategories = get_string('categories'); @@ -96,14 +95,13 @@ if (!$adminediting) { echo $OUTPUT->header(); echo $OUTPUT->skip_link_target(); echo $OUTPUT->box_start('courseboxes'); - print_courses(0); + $showaddcoursebutton = print_courses(0); echo $OUTPUT->box_end(); } echo $OUTPUT->container_start('buttons'); - if (has_capability('moodle/course:create', $systemcontext)) { - /// Print link to create a new course - /// Get the 1st available category + if (has_capability('moodle/course:create', $systemcontext) && $showaddcoursebutton) { + // Print link to create a new course, for the 1st available category. $options = array('category' => $CFG->defaultrequestcategory); echo $OUTPUT->single_button(new moodle_url('edit.php', $options), get_string('addnewcourse'), 'get'); } diff --git a/course/lib.php b/course/lib.php index a58b86ad3c9..d9c1cb8f8d1 100644 --- a/course/lib.php +++ b/course/lib.php @@ -2419,7 +2419,9 @@ function update_category_button($categoryid = 0) { } /** - * Category is 0 (for all courses) or an object + * Print courses in category. If category is 0 then all courses are printed. + * @param int|stdClass $category category object or id. + * @return bool true if courses found and printed, else false. */ function print_courses($category) { global $CFG, $OUTPUT; @@ -2467,8 +2469,10 @@ function print_courses($category) { echo html_writer::start_tag('div', array('class'=>'addcoursebutton')); echo $OUTPUT->single_button(new moodle_url('/course/edit.php', $options), get_string("addnewcourse")); echo html_writer::end_tag('div'); + return false; } } + return true; } /**