From 30142c1905401aa20a2e1641558c37cf4e8b1156 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Tue, 9 Apr 2013 12:21:05 +1000 Subject: [PATCH] MDL-38593 Merge code from /course/category.php into /course/index.php --- blocks/course_list/block_course_list.php | 2 +- .../yui/src/navigation/js/navigation.js | 2 +- course/category.php | 51 +------------ course/delete.php | 2 +- course/edit.php | 2 +- course/index.php | 31 +++++--- course/manage.php | 4 +- course/renderer.php | 74 ++++++++++--------- lib/accesslib.php | 2 +- lib/navigationlib.php | 4 +- user/index.php | 2 +- 11 files changed, 71 insertions(+), 105 deletions(-) diff --git a/blocks/course_list/block_course_list.php b/blocks/course_list/block_course_list.php index a9aeb45cd64..de356447914 100644 --- a/blocks/course_list/block_course_list.php +++ b/blocks/course_list/block_course_list.php @@ -60,7 +60,7 @@ class block_course_list extends block_list { foreach ($categories as $category) { $categoryname = $category->get_formatted_name(); $linkcss = $category->visible ? "" : " class=\"dimmed\" "; - $this->content->items[]="wwwroot/course/category.php?id=$category->id\">".$icon . $categoryname . ""; + $this->content->items[]="wwwroot/course/index.php?categoryid=$category->id\">".$icon . $categoryname . ""; } /// If we can update any course of the view all isn't hidden, show the view all courses link if (has_capability('moodle/course:update', context_system::instance()) || empty($CFG->block_course_list_hideallcourseslink)) { diff --git a/blocks/navigation/yui/src/navigation/js/navigation.js b/blocks/navigation/yui/src/navigation/js/navigation.js index eee568f1707..71f21670ce6 100644 --- a/blocks/navigation/yui/src/navigation/js/navigation.js +++ b/blocks/navigation/yui/src/navigation/js/navigation.js @@ -527,7 +527,7 @@ BRANCH.prototype = { url = M.cfg.wwwroot + '/course/index.php'; } } else { - url = M.cfg.wwwroot+'/course/category.php?id=' + branch.get('key'); + url = M.cfg.wwwroot+'/course/index.php?categoryid=' + branch.get('key'); } branch.addChild({ name : M.str.moodle.viewallcourses, diff --git a/course/category.php b/course/category.php index e82ab47525e..df2a35241cf 100644 --- a/course/category.php +++ b/course/category.php @@ -24,54 +24,9 @@ */ require_once("../config.php"); -require_once($CFG->dirroot.'/course/lib.php'); -require_once($CFG->libdir.'/textlib.class.php'); -require_once($CFG->libdir. '/coursecatlib.php'); -$id = required_param('id', PARAM_INT); // Category id -$page = optional_param('page', 0, PARAM_INT); // which page to show +$categoryid = required_param('id', PARAM_INT); // Category id -$perpage = optional_param('perpage', $CFG->coursesperpage, PARAM_INT); // how many per page +debugging('Please use URL /course/index.php?categoryid=XXX instead of /course/category.php?id=XXX', DEBUG_DEVELOPER); -if (empty($id)) { - print_error("unknowcategory"); -} - -$PAGE->set_category_by_id($id); -$PAGE->set_url(new moodle_url('/course/category.php', array('id' => $id))); -// This is sure to be the category context -$context = $PAGE->context; -// And the object has been loaded for us no need for another DB call -$category = $PAGE->category; - -if ($CFG->forcelogin) { - require_login(); -} - -if (!$category->visible) { - require_capability('moodle/category:viewhiddencategories', $context); -} - -// Prepare the standard URL params for this page. We'll need them later. -$urlparams = array('id' => $id); -if ($page) { - $urlparams['page'] = $page; -} -if ($perpage) { - $urlparams['perpage'] = $perpage; -} - -// Begin output -$PAGE->set_pagelayout('coursecategory'); -$courserenderer = $PAGE->get_renderer('core', 'course'); -$site = get_site(); -$PAGE->set_title("$site->shortname: $category->name"); -$PAGE->set_heading($site->fullname); - -$content = $courserenderer->course_category($id); -echo $OUTPUT->header(); - - -echo $content; - -echo $OUTPUT->footer(); +redirect(new moodle_url('/course/index.php', array('categoryid' => $categoryid))); \ No newline at end of file diff --git a/course/delete.php b/course/delete.php index bc550c30523..757092fd9c2 100644 --- a/course/delete.php +++ b/course/delete.php @@ -37,7 +37,7 @@ $PAGE->navbar->add($stradministration, new moodle_url('/admin/index.php/')); $PAGE->navbar->add($strcategories, new moodle_url('/course/index.php')); - $PAGE->navbar->add($categoryname, new moodle_url('/course/category.php', array('id'=>$course->category))); + $PAGE->navbar->add($categoryname, new moodle_url('/course/index.php', array('categoryid' => $course->category))); if (! $delete) { $strdeletecheck = get_string("deletecheck", "", $courseshortname); $strdeletecoursecheck = get_string("deletecoursecheck"); diff --git a/course/edit.php b/course/edit.php index 6d1150a0cc5..842e62c5a5e 100644 --- a/course/edit.php +++ b/course/edit.php @@ -95,7 +95,7 @@ $editform = new course_edit_form(NULL, array('course'=>$course, 'category'=>$cat if ($editform->is_cancelled()) { switch ($returnto) { case 'category': - $url = new moodle_url($CFG->wwwroot.'/course/category.php', array('id'=>$categoryid)); + $url = new moodle_url($CFG->wwwroot.'/course/index.php', array('categoryid' => $categoryid)); break; case 'catmanage': $url = new moodle_url($CFG->wwwroot.'/course/manage.php', array('id'=>$categoryid)); diff --git a/course/index.php b/course/index.php index 8a21209bf43..e3291719c55 100644 --- a/course/index.php +++ b/course/index.php @@ -24,29 +24,36 @@ */ require_once("../config.php"); -require_once("lib.php"); +require_once($CFG->dirroot. '/course/lib.php'); +require_once($CFG->libdir. '/coursecatlib.php'); +$categoryid = optional_param('categoryid', 0, PARAM_INT); // Category id $site = get_site(); -$systemcontext = context_system::instance(); +if ($categoryid) { + $PAGE->set_category_by_id($categoryid); + $PAGE->set_url(new moodle_url('/course/index.php', array('categoryid' => $categoryid))); + // And the object has been loaded for us no need for another DB call + $category = $PAGE->category; +} else { + $categoryid = 0; + $PAGE->set_url('/course/index.php'); + $PAGE->set_context(context_system::instance()); +} -$PAGE->set_url('/course/index.php'); -$PAGE->set_context($systemcontext); -$PAGE->set_pagelayout('admin'); +$PAGE->set_pagelayout('coursecategory'); $courserenderer = $PAGE->get_renderer('core', 'course'); if ($CFG->forcelogin) { require_login(); } -$countcategories = $DB->count_records('course_categories'); -if (can_edit_in_category()) { - $managebutton = $OUTPUT->single_button(new moodle_url('/course/manage.php'), - get_string('managecourses'), 'get'); - $PAGE->set_button($managebutton); +if ($categoryid && !$category->visible && !has_capability('moodle/category:viewhiddencategories', $PAGE->context)) { + throw new moodle_exception('unknowncategory'); } -$PAGE->set_heading($COURSE->fullname); -$content = $courserenderer->course_category(0); + +$PAGE->set_heading($site->fullname); +$content = $courserenderer->course_category($categoryid); echo $OUTPUT->header(); echo $OUTPUT->skip_link_target(); diff --git a/course/manage.php b/course/manage.php index c7d4073b800..bfd2dcbfe0a 100644 --- a/course/manage.php +++ b/course/manage.php @@ -75,7 +75,7 @@ if ($id) { // This is sure to be the category context. $context = $PAGE->context; if (!can_edit_in_category($coursecat->id)) { - redirect(new moodle_url('/course/category.php', array('id' => $coursecat->id))); + redirect(new moodle_url('/course/index.php', array('categoryid' => $coursecat->id))); } } else { $context = context_system::instance(); @@ -298,7 +298,7 @@ if (can_edit_in_category()) { // otherwise the admin block does not appear to this user, and you get an error. require_once($CFG->libdir . '/adminlib.php'); if ($id) { - navigation_node::override_active_url(new moodle_url('/course/category.php', array('id' => $id))); + navigation_node::override_active_url(new moodle_url('/course/index.php', array('categoryid' => $id))); } admin_externalpage_setup('coursemgmt', '', $urlparams, $CFG->wwwroot . '/course/manage.php'); $settingsnode = $PAGE->settingsnav->find_active_node(); diff --git a/course/renderer.php b/course/renderer.php index 671ff8f71e2..7290aca64a7 100644 --- a/course/renderer.php +++ b/course/renderer.php @@ -1161,7 +1161,7 @@ class core_course_renderer extends plugin_renderer_base { && ($cat = coursecat::get($course->category, IGNORE_MISSING))) { $content .= html_writer::start_tag('div', array('class' => 'coursecat')); $content .= get_string('category').': '. - html_writer::link(new moodle_url('/course/category.php', array('id' => $cat->id)), + html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $cat->id)), $cat->get_formatted_name(), array('class' => $cat->visible ? '' : 'dimmed')); $content .= html_writer::end_tag('div'); // .coursecat } @@ -1300,12 +1300,8 @@ class core_course_renderer extends plugin_renderer_base { } } else if ($viewmoreurl = $chelper->get_categories_display_option('viewmoreurl')) { // the option 'viewmoreurl' was specified, display more link (if it is link to category view page, add category id) - if ($viewmoreurl->compare(new moodle_url('/course/category.php'), URL_MATCH_BASE)) { - if ($coursecat->id) { - $viewmoreurl->param('id', $coursecat->id); - } else { - $viewmoreurl = new moodle_url('/course/index.php', $viewmoreurl->params()); - } + if ($viewmoreurl->compare(new moodle_url('/course/index.php'), URL_MATCH_BASE)) { + $viewmoreurl->param('categoryid', $coursecat->id); } $viewmoretext = $chelper->get_categories_display_option('viewmoretext', new lang_string('viewmore')); $morelink = html_writer::tag('div', html_writer::link($viewmoreurl, $viewmoretext), @@ -1367,8 +1363,8 @@ class core_course_renderer extends plugin_renderer_base { $courses = $coursecat->get_courses($chelper->get_courses_display_options()); if ($viewmoreurl = $chelper->get_courses_display_option('viewmoreurl')) { // the option for 'View more' link was specified, display more link (if it is link to category view page, add category id) - if ($viewmoreurl->compare(new moodle_url('/course/category.php'), URL_MATCH_BASE)) { - $chelper->set_courses_display_option('viewmoreurl', new moodle_url($viewmoreurl, array('id' => $coursecat->id))); + if ($viewmoreurl->compare(new moodle_url('/course/index.php'), URL_MATCH_BASE)) { + $chelper->set_courses_display_option('viewmoreurl', new moodle_url($viewmoreurl, array('categoryid' => $coursecat->id))); } } $content .= $this->coursecat_courses($chelper, $courses, $coursecat->get_courses_count()); @@ -1422,8 +1418,8 @@ class core_course_renderer extends plugin_renderer_base { // category name $categoryname = $coursecat->get_formatted_name(); - $categoryname = html_writer::link(new moodle_url('/course/category.php', - array('id' => $coursecat->id)), + $categoryname = html_writer::link(new moodle_url('/course/index.php', + array('categoryid' => $coursecat->id)), $categoryname); if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_COUNT && ($coursescount = $coursecat->get_courses_count())) { @@ -1498,21 +1494,29 @@ class core_course_renderer extends plugin_renderer_base { $site = get_site(); $output = ''; - if (!$coursecat->id && coursecat::count_all() == 1) { - // There exists only one category in the system, do not display link to it - $coursecat = coursecat::get_default(); - $strfulllistofcourses = get_string('fulllistofcourses'); - $this->page->set_title("$site->shortname: $strfulllistofcourses"); - } else if (!$coursecat->id) { - $strcategories = get_string('categories'); - $this->page->set_title("$site->shortname: $strcategories"); + $this->page->set_button($this->course_search_form('', 'navbar')); + if (!$coursecat->id) { + if (can_edit_in_category()) { + // add 'Manage' button instead of course search form + $managebutton = $this->single_button(new moodle_url('/course/manage.php'), + get_string('managecourses'), 'get'); + $this->page->set_button($managebutton); + } + if (coursecat::count_all() == 1) { + // There exists only one category in the system, do not display link to it + $coursecat = coursecat::get_default(); + $strfulllistofcourses = get_string('fulllistofcourses'); + $this->page->set_title("$site->shortname: $strfulllistofcourses"); + } else { + $strcategories = get_string('categories'); + $this->page->set_title("$site->shortname: $strcategories"); + } } else { $this->page->set_title("$site->shortname: ". $coursecat->get_formatted_name()); - $this->page->set_button($this->course_search_form('', 'navbar')); // Print the category selector $output .= html_writer::start_tag('div', array('class' => 'categorypicker')); - $select = new single_select(new moodle_url('/course/category.php'), 'id', + $select = new single_select(new moodle_url('/course/index.php'), 'categoryid', coursecat::make_categories_list(), $coursecat->id, null, 'switchcategory'); $select->set_label(get_string('categories').':'); $output .= $this->render($select); @@ -1534,29 +1538,29 @@ class core_course_renderer extends plugin_renderer_base { $browse = optional_param('browse', null, PARAM_ALPHA); $perpage = optional_param('perpage', $CFG->coursesperpage, PARAM_INT); $page = optional_param('page', 0, PARAM_INT); + $baseurl = new moodle_url('/course/index.php'); if ($coursecat->id) { - $baseurl = new moodle_url('/course/category.php', array('id' => $coursecat->id)); - } else { - $baseurl = new moodle_url('/course/index.php'); + $baseurl->param('categoryid', $coursecat->id); } + if ($perpage != $CFG->coursesperpage) { + $baseurl->param('perpage', $perpage); + } + $coursedisplayoptions['limit'] = $perpage; + $catdisplayoptions['limit'] = $perpage; if ($browse === 'courses' || !$coursecat->has_children()) { - $coursedisplayoptions['limit'] = $perpage; $coursedisplayoptions['offset'] = $page * $perpage; - $coursedisplayoptions['paginationurl'] = new moodle_url($baseurl, array('browse' => 'courses', 'perpage' => $perpage)); + $coursedisplayoptions['paginationurl'] = new moodle_url($baseurl, array('browse' => 'courses')); $catdisplayoptions['nodisplay'] = true; - $catdisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'categories', 'page' => 0)); + $catdisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'categories')); $catdisplayoptions['viewmoretext'] = new lang_string('viewallsubcategories'); } else if ($browse === 'categories' || !$coursecat->has_courses()) { $coursedisplayoptions['nodisplay'] = true; - $catdisplayoptions['limit'] = $perpage; $catdisplayoptions['offset'] = $page * $perpage; - $catdisplayoptions['paginationurl'] = new moodle_url($baseurl, array('browse' => 'categories', 'perpage' => $perpage)); - $coursedisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'courses', 'page' => 0)); + $catdisplayoptions['paginationurl'] = new moodle_url($baseurl, array('browse' => 'categories')); + $coursedisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'courses')); $coursedisplayoptions['viewmoretext'] = new lang_string('viewallcourses'); } else { // we have a category that has both subcategories and courses, display pagination separately - $coursedisplayoptions['limit'] = $CFG->coursesperpage; - $catdisplayoptions['limit'] = $CFG->coursesperpage; $coursedisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'courses', 'page' => 1)); $catdisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'categories', 'page' => 1)); } @@ -1849,12 +1853,12 @@ class core_course_renderer extends plugin_renderer_base { $chelper->set_subcat_depth($CFG->maxcategorydepth)-> set_categories_display_options(array( 'limit' => $CFG->coursesperpage, - 'viewmoreurl' => new moodle_url('/course/category.php', + 'viewmoreurl' => new moodle_url('/course/index.php', array('browse' => 'categories', 'page' => 1)) ))-> set_courses_display_options(array( 'limit' => $CFG->coursesperpage, - 'viewmoreurl' => new moodle_url('/course/category.php', + 'viewmoreurl' => new moodle_url('/course/index.php', array('browse' => 'courses', 'page' => 1)) ))-> set_attributes(array('class' => 'frontpage-category-combo')); @@ -1874,7 +1878,7 @@ class core_course_renderer extends plugin_renderer_base { set_show_courses(self::COURSECAT_SHOW_COURSES_COUNT)-> set_categories_display_options(array( 'limit' => $CFG->coursesperpage, - 'viewmoreurl' => new moodle_url('/course/category.php', + 'viewmoreurl' => new moodle_url('/course/index.php', array('browse' => 'categories', 'page' => 1)) ))-> set_attributes(array('class' => 'frontpage-category-names')); diff --git a/lib/accesslib.php b/lib/accesslib.php index 7d179745e57..6d21365b1f9 100644 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -6281,7 +6281,7 @@ class context_coursecat extends context { * @return moodle_url */ public function get_url() { - return new moodle_url('/course/category.php', array('id'=>$this->_instanceid)); + return new moodle_url('/course/index.php', array('categoryid' => $this->_instanceid)); } /** diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 61331f0816f..fe1b2555b21 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -1693,7 +1693,7 @@ class global_navigation extends navigation_node { $excessivecategories = $DB->get_records_sql($sql, $params); foreach ($categories as &$category) { if (array_key_exists($category->key, $excessivecategories) && !$this->can_add_more_courses_to_category($category)) { - $url = new moodle_url('/course/category.php', array('id'=>$category->key)); + $url = new moodle_url('/course/index.php', array('categoryid' => $category->key)); $category->add(get_string('viewallcourses'), $url, self::TYPE_SETTING); } } @@ -1713,7 +1713,7 @@ class global_navigation extends navigation_node { if (array_key_exists($category->id, $this->addedcategories)) { return; } - $url = new moodle_url('/course/category.php', array('id' => $category->id)); + $url = new moodle_url('/course/index.php', array('categoryid' => $category->id)); $context = context_coursecat::instance($category->id); $categoryname = format_string($category->name, true, array('context' => $context)); $categorynode = $parent->add($categoryname, $url, $nodetype, $categoryname, $category->id); diff --git a/user/index.php b/user/index.php index 06af50dfdcb..39ea25f6641 100644 --- a/user/index.php +++ b/user/index.php @@ -765,7 +765,7 @@ foreach ($ras AS $key=>$ra) { $rolename = $allrolenames[$ra['roleid']] ; if ($ra['ctxlevel'] == CONTEXT_COURSECAT) { - $rastring .= $rolename. ' @ ' . ''.s($ra['ccname']).''; + $rastring .= $rolename. ' @ ' . ''.s($ra['ccname']).''; } elseif ($ra['ctxlevel'] == CONTEXT_SYSTEM) { $rastring .= $rolename. ' - ' . get_string('globalrole','role'); } else {