From 09ae7ee03133ea125cd5f70bd0b577c54b47ec16 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Tue, 26 Mar 2013 16:20:22 +1100 Subject: [PATCH] MDL-37009 Deprecated all courses display functions that are not used any more print_my_moodle(), print_remote_course(), print_remote_host(), print_whole_category_list(), print_category_info(), get_course_category_tree(), print_courses(), print_course(), get_category_courses_array(), get_category_courses_array_recursively() --- course/lib.php | 541 ---------------------------------------- course/renderer.php | 105 ++------ lib/datalib.php | 220 ---------------- lib/deprecatedlib.php | 568 ++++++++++++++++++++++++++++++++++++++++++ lib/upgrade.txt | 9 +- theme/upgrade.txt | 8 + 6 files changed, 598 insertions(+), 853 deletions(-) diff --git a/course/lib.php b/course/lib.php index f7d23e47e2a..c461ebc9f2d 100644 --- a/course/lib.php +++ b/course/lib.php @@ -1219,154 +1219,6 @@ function get_category_or_system_context($categoryid) { } } -/** - * This function generates a structured array of courses and categories. - * - * The depth of categories is limited by $CFG->maxcategorydepth however there - * is no limit on the number of courses! - * - * Suitable for use with the course renderers course_category_tree method: - * $renderer = $PAGE->get_renderer('core','course'); - * echo $renderer->course_category_tree(get_course_category_tree()); - * - * @global moodle_database $DB - * @param int $id - * @param int $depth - */ -function get_course_category_tree($id = 0, $depth = 0) { - global $DB, $CFG; - require_once($CFG->libdir. '/coursecatlib.php'); - if (!$coursecat = coursecat::get($id, IGNORE_MISSING)) { - return array(); - } - $categories = array(); - $categoryids = array(); - foreach ($coursecat->get_children() as $child) { - $categories[] = $category = (object)convert_to_array($child); - $categoryids[$category->id] = $category; - if (empty($CFG->maxcategorydepth) || $depth <= $CFG->maxcategorydepth) { - list($category->categories, $subcategories) = get_course_category_tree($category->id, $depth+1); - foreach ($subcategories as $subid=>$subcat) { - $categoryids[$subid] = $subcat; - } - $category->courses = array(); - } - } - - if ($depth > 0) { - // This is a recursive call so return the required array - return array($categories, $categoryids); - } - - if (empty($categoryids)) { - // No categories available (probably all hidden). - return array(); - } - - // The depth is 0 this function has just been called so we can finish it off - - list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx'); - list($catsql, $catparams) = $DB->get_in_or_equal(array_keys($categoryids)); - $sql = "SELECT - c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.summary,c.category - $ccselect - FROM {course} c - $ccjoin - WHERE c.category $catsql ORDER BY c.sortorder ASC"; - if ($courses = $DB->get_records_sql($sql, $catparams)) { - // loop throught them - foreach ($courses as $course) { - if ($course->id == SITEID) { - continue; - } - context_instance_preload($course); - if (!empty($course->visible) || has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) { - $categoryids[$course->category]->courses[$course->id] = $course; - } - } - } - return $categories; -} - -/** - * Recursive function to print out all the categories in a nice format - * with or without courses included - */ -function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1, $showcourses = true, $categorycourses=NULL) { - global $CFG; - require_once($CFG->libdir. '/coursecatlib.php'); - - // maxcategorydepth == 0 meant no limit - if (!empty($CFG->maxcategorydepth) && $depth >= $CFG->maxcategorydepth) { - return; - } - - // make sure category is visible to the current user - if ($category) { - if (!$coursecat = coursecat::get($category->id, IGNORE_MISSING)) { - return; - } - } else { - $coursecat = coursecat::get(0); - } - - if (!$categorycourses) { - $categorycourses = get_category_courses_array($coursecat->id); - } - - if ($coursecat->id) { - print_category_info($category, $depth, $showcourses, $categorycourses[$category->id]); - } - - if ($categories = $coursecat->get_children()) { // Print all the children recursively - $countcats = count($categories); - $count = 0; - $first = true; - $last = false; - foreach ($categories as $cat) { - $count++; - if ($count == $countcats) { - $last = true; - } - $up = $first ? false : true; - $down = $last ? false : true; - $first = false; - - print_whole_category_list($cat, $displaylist, $parentslist, $depth + 1, $showcourses, $categorycourses); - } - } -} - -/** - * Gets an array whose keys are category ids and whose values are arrays of courses in the corresponding category. - * - * @param int $categoryid - * @return array - */ -function get_category_courses_array($categoryid = 0) { - $tree = get_course_category_tree($categoryid); - $flattened = array(); - foreach ($tree as $category) { - get_category_courses_array_recursively($flattened, $category); - } - return $flattened; -} - -/** - * Recursive function to help flatten the course category tree. - * - * Do not call this function directly, instead calll its parent function {@link get_category_courses_array} - * - * @param array &$flattened An array passed by reference in which to store courses for each category. - * @param stdClass $category The category to get courses for. - */ -function get_category_courses_array_recursively(array &$flattened, $category) { - $flattened[$category->id] = $category->courses; - foreach ($category->categories as $childcategory) { - get_category_courses_array_recursively($flattened, $childcategory); - } -} - /** * Returns full course categories trees to be used in html_writer::select() * @@ -1385,126 +1237,6 @@ function make_categories_options() { return $cats; } -/** - * Prints the category information. - * - * This function is only used by print_whole_category_list() above - * - * @param stdClass $category - * @param int $depth The depth of the category. - * @param bool $showcourses If set to true course information will also be printed. - * @param array|null $courses An array of courses belonging to the category, or null if you don't have it yet. - */ -function print_category_info($category, $depth = 0, $showcourses = false, array $courses = null) { - global $CFG, $DB, $OUTPUT; - - $strsummary = get_string('summary'); - - $catlinkcss = null; - if (!$category->visible) { - $catlinkcss = array('class'=>'dimmed'); - } - static $coursecount = null; - if (null === $coursecount) { - // only need to check this once - $coursecount = $DB->count_records('course') <= FRONTPAGECOURSELIMIT; - } - - if ($showcourses and $coursecount) { - $catimage = ''; - } else { - $catimage = " "; - } - - if (is_null($courses)) { - $courses = get_courses($category->id, 'c.sortorder ASC', 'c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.summary'); - } - $context = context_coursecat::instance($category->id); - $fullname = format_string($category->name, true, array('context' => $context)); - - if ($showcourses and $coursecount) { - echo '
'; - $cat = ''; - $cat .= html_writer::tag('div', $catimage, array('class'=>'image')); - $catlink = html_writer::link(new moodle_url('/course/category.php', array('id'=>$category->id)), $fullname, $catlinkcss); - $cat .= html_writer::tag('div', $catlink, array('class'=>'name')); - - $html = ''; - if ($depth > 0) { - for ($i=0; $i< $depth; $i++) { - $html = html_writer::tag('div', $html . $cat, array('class'=>'indentation')); - $cat = ''; - } - } else { - $html = $cat; - } - echo html_writer::tag('div', $html, array('class'=>'category')); - echo html_writer::tag('div', '', array('class'=>'clearfloat')); - - // does the depth exceed maxcategorydepth - // maxcategorydepth == 0 or unset meant no limit - $limit = !(isset($CFG->maxcategorydepth) && ($depth >= $CFG->maxcategorydepth-1)); - if ($courses && ($limit || $CFG->maxcategorydepth == 0)) { - foreach ($courses as $course) { - $linkcss = null; - if (!$course->visible) { - $linkcss = array('class'=>'dimmed'); - } - - $coursename = get_course_display_name_for_list($course); - $courselink = html_writer::link(new moodle_url('/course/view.php', array('id'=>$course->id)), format_string($coursename), $linkcss); - - // print enrol info - $courseicon = ''; - if ($icons = enrol_get_course_info_icons($course)) { - foreach ($icons as $pix_icon) { - $courseicon = $OUTPUT->render($pix_icon); - } - } - - $coursecontent = html_writer::tag('div', $courseicon.$courselink, array('class'=>'name')); - - if ($course->summary) { - $link = new moodle_url('/course/info.php?id='.$course->id); - $actionlink = $OUTPUT->action_link($link, ''.$strsummary.'', - new popup_action('click', $link, 'courseinfo', array('height' => 400, 'width' => 500)), - array('title'=>$strsummary)); - - $coursecontent .= html_writer::tag('div', $actionlink, array('class'=>'info')); - } - - $html = ''; - for ($i=0; $i <= $depth; $i++) { - $html = html_writer::tag('div', $html . $coursecontent , array('class'=>'indentation')); - $coursecontent = ''; - } - echo html_writer::tag('div', $html, array('class'=>'course clearfloat')); - } - } - echo '
'; - } else { - echo '
'; - $html = ''; - $cat = html_writer::link(new moodle_url('/course/category.php', array('id'=>$category->id)), $fullname, $catlinkcss); - if (count($courses) > 0) { - $cat .= html_writer::tag('span', ' ('.count($courses).')', array('title'=>get_string('numberofcourses'), 'class'=>'numberofcourse')); - } - - if ($depth > 0) { - for ($i=0; $i< $depth; $i++) { - $html = html_writer::tag('div', $html .$cat, array('class'=>'indentation')); - $cat = ''; - } - } else { - $html = $cat; - } - - echo html_writer::tag('div', $html, array('class'=>'category')); - echo html_writer::tag('div', '', array('class'=>'clearfloat')); - echo '
'; - } -} - /** * Print the buttons relating to course requests. * @@ -1537,279 +1269,6 @@ function can_edit_in_category($categoryid = 0) { return has_any_capability(array('moodle/category:manage', 'moodle/course:create'), $context); } -/** - * 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; - require_once($CFG->libdir. '/coursecatlib.php'); - - if (!is_object($category) && $category==0) { - $categories = coursecat::get(0)->get_children(); // Parent = 0 ie top-level categories only - if (is_array($categories) && count($categories) == 1) { - $category = array_shift($categories); - $courses = get_courses_wmanagers($category->id, - 'c.sortorder ASC', - array('summary','summaryformat')); - } else { - $courses = get_courses_wmanagers('all', - 'c.sortorder ASC', - array('summary','summaryformat')); - } - unset($categories); - } else { - $courses = get_courses_wmanagers($category->id, - 'c.sortorder ASC', - array('summary','summaryformat')); - } - - if ($courses) { - echo html_writer::start_tag('ul', array('class'=>'unlist')); - foreach ($courses as $course) { - $coursecontext = context_course::instance($course->id); - if ($course->visible == 1 || has_capability('moodle/course:viewhiddencourses', $coursecontext)) { - echo html_writer::start_tag('li'); - print_course($course); - echo html_writer::end_tag('li'); - } - } - echo html_writer::end_tag('ul'); - } else { - echo $OUTPUT->heading(get_string("nocoursesyet")); - $context = context_system::instance(); - if (has_capability('moodle/course:create', $context)) { - $options = array(); - if (!empty($category->id)) { - $options['category'] = $category->id; - } else { - $options['category'] = $CFG->defaultrequestcategory; - } - 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; -} - -/** - * Print a description of a course, suitable for browsing in a list. - * - * @param object $course the course object. - * @param string $highlightterms (optional) some search terms that should be highlighted in the display. - */ -function print_course($course, $highlightterms = '') { - global $CFG, $USER, $DB, $OUTPUT; - - $context = context_course::instance($course->id); - - // Rewrite file URLs so that they are correct - $course->summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course', 'summary', NULL); - - echo html_writer::start_tag('div', array('class'=>'coursebox clearfix')); - echo html_writer::start_tag('div', array('class'=>'info')); - echo html_writer::start_tag('h3', array('class'=>'name')); - - $linkhref = new moodle_url('/course/view.php', array('id'=>$course->id)); - - $coursename = get_course_display_name_for_list($course); - $linktext = highlight($highlightterms, format_string($coursename)); - $linkparams = array('title'=>get_string('entercourse')); - if (empty($course->visible)) { - $linkparams['class'] = 'dimmed'; - } - echo html_writer::link($linkhref, $linktext, $linkparams); - echo html_writer::end_tag('h3'); - - /// first find all roles that are supposed to be displayed - if (!empty($CFG->coursecontact)) { - $managerroles = explode(',', $CFG->coursecontact); - $rusers = array(); - - if (!isset($course->managers)) { - list($sort, $sortparams) = users_order_by_sql('u'); - $rusers = get_role_users($managerroles, $context, true, - 'ra.id AS raid, u.id, u.username, u.firstname, u.lastname, rn.name AS rolecoursealias, - r.name AS rolename, r.sortorder, r.id AS roleid, r.shortname AS roleshortname', - 'r.sortorder ASC, ' . $sort, null, '', '', '', '', $sortparams); - } else { - // use the managers array if we have it for perf reasosn - // populate the datastructure like output of get_role_users(); - foreach ($course->managers as $manager) { - $user = clone($manager->user); - $user->roleid = $manager->roleid; - $user->rolename = $manager->rolename; - $user->roleshortname = $manager->roleshortname; - $user->rolecoursealias = $manager->rolecoursealias; - $rusers[$user->id] = $user; - } - } - - $namesarray = array(); - $canviewfullnames = has_capability('moodle/site:viewfullnames', $context); - foreach ($rusers as $ra) { - if (isset($namesarray[$ra->id])) { - // only display a user once with the higest sortorder role - continue; - } - - $role = new stdClass(); - $role->id = $ra->roleid; - $role->name = $ra->rolename; - $role->shortname = $ra->roleshortname; - $role->coursealias = $ra->rolecoursealias; - $rolename = role_get_name($role, $context, ROLENAME_ALIAS); - - $fullname = fullname($ra, $canviewfullnames); - $namesarray[$ra->id] = $rolename.': '. - html_writer::link(new moodle_url('/user/view.php', array('id'=>$ra->id, 'course'=>SITEID)), $fullname); - } - - if (!empty($namesarray)) { - echo html_writer::start_tag('ul', array('class'=>'teachers')); - foreach ($namesarray as $name) { - echo html_writer::tag('li', $name); - } - echo html_writer::end_tag('ul'); - } - } - echo html_writer::end_tag('div'); // End of info div - - echo html_writer::start_tag('div', array('class'=>'summary')); - $options = new stdClass(); - $options->noclean = true; - $options->para = false; - $options->overflowdiv = true; - if (!isset($course->summaryformat)) { - $course->summaryformat = FORMAT_MOODLE; - } - echo highlight($highlightterms, format_text($course->summary, $course->summaryformat, $options, $course->id)); - if ($icons = enrol_get_course_info_icons($course)) { - echo html_writer::start_tag('div', array('class'=>'enrolmenticons')); - foreach ($icons as $icon) { - $icon->attributes["alt"] .= ": ". format_string($coursename, true, array('context'=>$context)); - echo $OUTPUT->render($icon); - } - echo html_writer::end_tag('div'); // End of enrolmenticons div - } - echo html_writer::end_tag('div'); // End of summary div - echo html_writer::end_tag('div'); // End of coursebox div -} - -/** - * Prints custom user information on the home page. - * Over time this can include all sorts of information - */ -function print_my_moodle() { - global $USER, $CFG, $DB, $OUTPUT; - - if (!isloggedin() or isguestuser()) { - print_error('nopermissions', '', '', 'See My Moodle'); - } - - $courses = enrol_get_my_courses('summary', 'visible DESC,sortorder ASC'); - $rhosts = array(); - $rcourses = array(); - if (!empty($CFG->mnet_dispatcher_mode) && $CFG->mnet_dispatcher_mode==='strict') { - $rcourses = get_my_remotecourses($USER->id); - $rhosts = get_my_remotehosts(); - } - - if (!empty($courses) || !empty($rcourses) || !empty($rhosts)) { - - if (!empty($courses)) { - echo '\n"; - } - - // MNET - if (!empty($rcourses)) { - // at the IDP, we know of all the remote courses - foreach ($rcourses as $course) { - print_remote_course($course, "100%"); - } - } elseif (!empty($rhosts)) { - // non-IDP, we know of all the remote servers, but not courses - foreach ($rhosts as $host) { - print_remote_host($host, "100%"); - } - } - unset($course); - unset($host); - - if ($DB->count_records("course") > (count($courses) + 1) ) { // Some courses not being displayed - echo "
"; - print_course_search("", false, "short"); - echo ""; - echo $OUTPUT->single_button("$CFG->wwwroot/course/index.php", get_string("fulllistofcourses"), "get"); - echo "
\n"; - } - - } else { - if ($DB->count_records("course_categories") > 1) { - echo $OUTPUT->box_start("categorybox"); - print_whole_category_list(); - echo $OUTPUT->box_end(); - } else { - print_courses(0); - } - } -} - -function print_remote_course($course, $width="100%") { - global $CFG, $USER; - - $linkcss = ''; - - $url = "{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&wantsurl=/course/view.php?id={$course->remoteid}"; - - echo '
'; - echo '
'; - echo '
' - . format_string($course->fullname) .'
' - . format_string($course->hostname) . ' : ' - . format_string($course->cat_name) . ' : ' - . format_string($course->shortname). '
'; - echo '
'; - $options = new stdClass(); - $options->noclean = true; - $options->para = false; - $options->overflowdiv = true; - echo format_text($course->summary, $course->summaryformat, $options); - echo '
'; - echo '
'; -} - -function print_remote_host($host, $width="100%") { - global $OUTPUT; - - $linkcss = ''; - - echo '
'; - echo '
'; - echo '
'; - echo ''.get_string('course').''; - echo '' - . s($host['name']).' - '; - echo $host['count'] . ' ' . get_string('courses'); - echo '
'; - echo '
'; - echo '
'; -} - - /// MODULE FUNCTIONS ///////////////////////////////////////////////////////////////// function add_course_module($mod) { diff --git a/course/renderer.php b/course/renderer.php index b613e590d87..56318fe3a62 100644 --- a/course/renderer.php +++ b/course/renderer.php @@ -121,109 +121,34 @@ class core_course_renderer extends plugin_renderer_base { } /** - * Renderers a structured array of courses and categories into a nice - * XHTML tree structure. + * Renderers a structured array of courses and categories into a nice XHTML tree structure. * - * This method was designed initially to display the front page course/category - * combo view. The structure can be retrieved by get_course_category_tree() + * @deprecated since 2.5 * - * @param array $structure + * Please see http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5 + * + * @param array $ignored argument ignored * @return string */ - public function course_category_tree(array $structure) { - $this->strings->summary = get_string('summary'); - - // Generate an id and the required JS call to make this a nice widget - $id = html_writer::random_id('course_category_tree'); - $this->page->requires->js_init_call('M.util.init_toggle_class_on_click', array($id, '.category.with_children .category_label', 'collapsed', '.category.with_children')); - - // Start content generation - $content = html_writer::start_tag('div', array('class'=>'course_category_tree', 'id'=>$id)); - foreach ($structure as $category) { - $content .= $this->course_category_tree_category($category); - } - $content .= html_writer::start_tag('div', array('class'=>'controls')); - $content .= html_writer::tag('div', get_string('collapseall'), array('class'=>'addtoall expandall')); - $content .= html_writer::tag('div', get_string('expandall'), array('class'=>'removefromall collapseall')); - $content .= html_writer::end_tag('div'); - $content .= html_writer::end_tag('div'); - - // Return the course category tree HTML - return $content; + public final function course_category_tree(array $ignored) { + debugging('Function core_course_renderer::course_category_tree() is deprecated, please use frontpage_combo_list()', DEBUG_DEVELOPER); + return $this->frontpage_combo_list(); } /** * Renderers a category for use with course_category_tree * + * @deprecated since 2.5 + * + * Please see http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5 + * * @param array $category * @param int $depth * @return string */ - protected function course_category_tree_category(stdClass $category, $depth=1) { - $content = ''; - $hassubcategories = (isset($category->categories) && count($category->categories)>0); - $hascourses = (isset($category->courses) && count($category->courses)>0); - $classes = array('category'); - if ($category->parent != 0) { - $classes[] = 'subcategory'; - } - if (empty($category->visible)) { - $classes[] = 'dimmed_category'; - } - if ($hassubcategories || $hascourses) { - $classes[] = 'with_children'; - if ($depth > 1) { - $classes[] = 'collapsed'; - } - } - $categoryname = format_string($category->name, true, array('context' => context_coursecat::instance($category->id))); - - $content .= html_writer::start_tag('div', array('class'=>join(' ', $classes))); - $content .= html_writer::start_tag('div', array('class'=>'category_label')); - $content .= html_writer::link(new moodle_url('/course/category.php', array('id'=>$category->id)), $categoryname, array('class'=>'category_link')); - $content .= html_writer::end_tag('div'); - if ($hassubcategories) { - $content .= html_writer::start_tag('div', array('class'=>'subcategories')); - foreach ($category->categories as $subcategory) { - $content .= $this->course_category_tree_category($subcategory, $depth+1); - } - $content .= html_writer::end_tag('div'); - } - if ($hascourses) { - $content .= html_writer::start_tag('div', array('class'=>'courses')); - $coursecount = 0; - $strinfo = new lang_string('info'); - foreach ($category->courses as $course) { - $classes = array('course'); - $linkclass = 'course_link'; - if (!$course->visible) { - $linkclass .= ' dimmed'; - } - $coursecount ++; - $classes[] = ($coursecount%2)?'odd':'even'; - $content .= html_writer::start_tag('div', array('class'=>join(' ', $classes))); - $content .= html_writer::link(new moodle_url('/course/view.php', array('id'=>$course->id)), format_string($course->fullname), array('class'=>$linkclass)); - $content .= html_writer::start_tag('div', array('class'=>'course_info clearfix')); - - // print enrol info - if ($icons = enrol_get_course_info_icons($course)) { - foreach ($icons as $pix_icon) { - $content .= $this->render($pix_icon); - } - } - - if ($course->summary) { - $url = new moodle_url('/course/info.php', array('id' => $course->id)); - $image = html_writer::empty_tag('img', array('src'=>$this->output->pix_url('i/info'), 'alt'=>$this->strings->summary)); - $content .= $this->action_link($url, $image, new popup_action('click', $url, 'courseinfo'), array('title' => $this->strings->summary)); - } - $content .= html_writer::end_tag('div'); - $content .= html_writer::end_tag('div'); - } - $content .= html_writer::end_tag('div'); - } - $content .= html_writer::end_tag('div'); - return $content; + protected final function course_category_tree_category(stdClass $category, $depth=1) { + debugging('Function core_course_renderer::course_category_tree_category() is deprecated', DEBUG_DEVELOPER); + return ''; } /** diff --git a/lib/datalib.php b/lib/datalib.php index 9d257480060..8151f69a37b 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -605,226 +605,6 @@ function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c return $visiblecourses; } -/** - * Retrieve course records with the course managers and other related records - * that we need for print_course(). This allows print_courses() to do its job - * in a constant number of DB queries, regardless of the number of courses, - * role assignments, etc. - * - * The returned array is indexed on c.id, and each course will have - * - $course->managers - array containing RA objects that include a $user obj - * with the minimal fields needed for fullname() - * - * @global object - * @global object - * @global object - * @uses CONTEXT_COURSE - * @uses CONTEXT_SYSTEM - * @uses CONTEXT_COURSECAT - * @uses SITEID - * @param int|string $categoryid Either the categoryid for the courses or 'all' - * @param string $sort A SQL sort field and direction - * @param array $fields An array of additional fields to fetch - * @return array - */ -function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=array()) { - /* - * The plan is to - * - * - Grab the courses JOINed w/context - * - * - Grab the interesting course-manager RAs - * JOINed with a base user obj and add them to each course - * - * So as to do all the work in 2 DB queries. The RA+user JOIN - * ends up being pretty expensive if it happens over _all_ - * courses on a large site. (Are we surprised!?) - * - * So this should _never_ get called with 'all' on a large site. - * - */ - global $USER, $CFG, $DB; - - $params = array(); - $allcats = false; // bool flag - if ($categoryid === 'all') { - $categoryclause = ''; - $allcats = true; - } elseif (is_numeric($categoryid)) { - $categoryclause = "c.category = :catid"; - $params['catid'] = $categoryid; - } else { - debugging("Could not recognise categoryid = $categoryid"); - $categoryclause = ''; - } - - $basefields = array('id', 'category', 'sortorder', - 'shortname', 'fullname', 'idnumber', - 'startdate', 'visible', - 'newsitems', 'groupmode', 'groupmodeforce'); - - if (!is_null($fields) && is_string($fields)) { - if (empty($fields)) { - $fields = $basefields; - } else { - // turn the fields from a string to an array that - // get_user_courses_bycap() will like... - $fields = explode(',',$fields); - $fields = array_map('trim', $fields); - $fields = array_unique(array_merge($basefields, $fields)); - } - } elseif (is_array($fields)) { - $fields = array_merge($basefields,$fields); - } - $coursefields = 'c.' .join(',c.', $fields); - - if (empty($sort)) { - $sortstatement = ""; - } else { - $sortstatement = "ORDER BY $sort"; - } - - $where = 'WHERE c.id != ' . SITEID; - if ($categoryclause !== ''){ - $where = "$where AND $categoryclause"; - } - - // pull out all courses matching the cat - list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx'); - $sql = "SELECT $coursefields $ccselect - FROM {course} c - $ccjoin - $where - $sortstatement"; - - $catpaths = array(); - $catpath = NULL; - if ($courses = $DB->get_records_sql($sql, $params)) { - // loop on courses materialising - // the context, and prepping data to fetch the - // managers efficiently later... - foreach ($courses as $k => $course) { - context_instance_preload($course); - $coursecontext = context_course::instance($course->id); - $courses[$k] = $course; - $courses[$k]->managers = array(); - if ($allcats === false) { - // single cat, so take just the first one... - if ($catpath === NULL) { - $catpath = preg_replace(':/\d+$:', '', $coursecontext->path); - } - } else { - // chop off the contextid of the course itself - // like dirname() does... - $catpaths[] = preg_replace(':/\d+$:', '', $coursecontext->path); - } - } - } else { - return array(); // no courses! - } - - $CFG->coursecontact = trim($CFG->coursecontact); - if (empty($CFG->coursecontact)) { - return $courses; - } - - $managerroles = explode(',', $CFG->coursecontact); - $catctxids = ''; - if (count($managerroles)) { - if ($allcats === true) { - $catpaths = array_unique($catpaths); - $ctxids = array(); - foreach ($catpaths as $cpath) { - $ctxids = array_merge($ctxids, explode('/',substr($cpath,1))); - } - $ctxids = array_unique($ctxids); - $catctxids = implode( ',' , $ctxids); - unset($catpaths); - unset($cpath); - } else { - // take the ctx path from the first course - // as all categories will be the same... - $catpath = substr($catpath,1); - $catpath = preg_replace(':/\d+$:','',$catpath); - $catctxids = str_replace('/',',',$catpath); - } - if ($categoryclause !== '') { - $categoryclause = "AND $categoryclause"; - } - /* - * Note: Here we use a LEFT OUTER JOIN that can - * "optionally" match to avoid passing a ton of context - * ids in an IN() clause. Perhaps a subselect is faster. - * - * In any case, this SQL is not-so-nice over large sets of - * courses with no $categoryclause. - * - */ - $sql = "SELECT ctx.path, ctx.instanceid, ctx.contextlevel, - r.id AS roleid, r.name AS rolename, r.shortname AS roleshortname, - rn.name AS rolecoursealias, u.id AS userid, u.firstname, u.lastname - FROM {role_assignments} ra - JOIN {context} ctx ON ra.contextid = ctx.id - JOIN {user} u ON ra.userid = u.id - JOIN {role} r ON ra.roleid = r.id - LEFT JOIN {role_names} rn ON (rn.contextid = ctx.id AND rn.roleid = r.id) - LEFT OUTER JOIN {course} c - ON (ctx.instanceid=c.id AND ctx.contextlevel=".CONTEXT_COURSE.") - WHERE ( c.id IS NOT NULL"; - // under certain conditions, $catctxids is NULL - if($catctxids == NULL){ - $sql .= ") "; - }else{ - $sql .= " OR ra.contextid IN ($catctxids) )"; - } - - $sql .= "AND ra.roleid IN ({$CFG->coursecontact}) - $categoryclause - ORDER BY r.sortorder ASC, ctx.contextlevel ASC, ra.sortorder ASC"; - $rs = $DB->get_recordset_sql($sql, $params); - - // This loop is fairly stupid as it stands - might get better - // results doing an initial pass clustering RAs by path. - foreach($rs as $ra) { - $user = new stdClass; - $user->id = $ra->userid; unset($ra->userid); - $user->firstname = $ra->firstname; unset($ra->firstname); - $user->lastname = $ra->lastname; unset($ra->lastname); - $ra->user = $user; - if ($ra->contextlevel == CONTEXT_SYSTEM) { - foreach ($courses as $k => $course) { - $courses[$k]->managers[] = $ra; - } - } else if ($ra->contextlevel == CONTEXT_COURSECAT) { - if ($allcats === false) { - // It always applies - foreach ($courses as $k => $course) { - $courses[$k]->managers[] = $ra; - } - } else { - foreach ($courses as $k => $course) { - $coursecontext = context_course::instance($course->id); - // Note that strpos() returns 0 as "matched at pos 0" - if (strpos($coursecontext->path, $ra->path.'/') === 0) { - // Only add it to subpaths - $courses[$k]->managers[] = $ra; - } - } - } - } else { // course-level - if (!array_key_exists($ra->instanceid, $courses)) { - //this course is not in a list, probably a frontpage course - continue; - } - $courses[$ra->instanceid]->managers[] = $ra; - } - } - $rs->close(); - } - - return $courses; -} - /** * A list of courses that match a search * diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index eabfa035095..8022c44df6f 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -3947,3 +3947,571 @@ function print_course_search($value="", $return=false, $format="plain") { echo $renderer->course_search_form($value, $format); } } + +/** + * Prints custom user information on the home page + * + * This function is deprecated, please use: + * $renderer = $PAGE->get_renderer('core', 'course'); + * echo $renderer->frontpage_my_courses() + * + * @deprecated since 2.5 + */ +function print_my_moodle() { + global $PAGE; + debugging('Function print_my_moodle() is deprecated, please use course renderer function frontpage_my_courses()', DEBUG_DEVELOPER); + + $renderer = $PAGE->get_renderer('core', 'course'); + echo $renderer->frontpage_my_courses(); +} + +/** + * Prints information about one remote course + * + * This function is deprecated, it is replaced with protected function + * {@link core_course_renderer::frontpage_remote_course()} + * It is only used from function {@link core_course_renderer::frontpage_my_courses()} + * + * @deprecated since 2.5 + */ +function print_remote_course($course, $width="100%") { + global $CFG, $USER; + debugging('Function print_remote_course() is deprecated, please use course renderer', DEBUG_DEVELOPER); + + $linkcss = ''; + + $url = "{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&wantsurl=/course/view.php?id={$course->remoteid}"; + + echo '
'; + echo '
'; + echo '
' + . format_string($course->fullname) .'
' + . format_string($course->hostname) . ' : ' + . format_string($course->cat_name) . ' : ' + . format_string($course->shortname). '
'; + echo '
'; + $options = new stdClass(); + $options->noclean = true; + $options->para = false; + $options->overflowdiv = true; + echo format_text($course->summary, $course->summaryformat, $options); + echo '
'; + echo '
'; +} + +/** + * Prints information about one remote host + * + * This function is deprecated, it is replaced with protected function + * {@link core_course_renderer::frontpage_remote_host()} + * It is only used from function {@link core_course_renderer::frontpage_my_courses()} + * + * @deprecated since 2.5 + */ +function print_remote_host($host, $width="100%") { + global $OUTPUT; + debugging('Function print_remote_host() is deprecated, please use course renderer', DEBUG_DEVELOPER); + + $linkcss = ''; + + echo '
'; + echo '
'; + echo '
'; + echo ''.get_string('course').''; + echo '' + . s($host['name']).' - '; + echo $host['count'] . ' ' . get_string('courses'); + echo '
'; + echo '
'; + echo '
'; +} + +/** + * Recursive function to print out all the categories in a nice format + * with or without courses included + * + * @deprecated since 2.5 + * + * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5 + */ +function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1, $showcourses = true, $categorycourses=NULL) { + global $PAGE; + debugging('Function print_whole_category_list() is deprecated, please use course renderer', DEBUG_DEVELOPER); + + $renderer = $PAGE->get_renderer('core', 'course'); + if ($showcourses && $category) { + echo $renderer->course_category($category); + } else if ($showcourses) { + echo $renderer->frontpage_combo_list(); + } else { + echo $renderer->frontpage_categories_list(); + } +} + +/** + * Prints the category information. + * + * @deprecated since 2.5 + * + * This function was only used by {@link print_whole_category_list()} but now + * all course category rendering is moved to core_course_renderer. + * + * @param stdClass $category + * @param int $depth The depth of the category. + * @param bool $showcourses If set to true course information will also be printed. + * @param array|null $courses An array of courses belonging to the category, or null if you don't have it yet. + */ +function print_category_info($category, $depth = 0, $showcourses = false, array $courses = null) { + global $PAGE; + debugging('Function print_category_info() is deprecated, please use course renderer', DEBUG_DEVELOPER); + + $renderer = $PAGE->get_renderer('core', 'course'); + echo $renderer->course_category($category); +} + +/** + * This function generates a structured array of courses and categories. + * + * @deprecated since 2.5 + * + * This function is not used any more in moodle core and course renderer does not have render function for it. + * Combo list on the front page is displayed as: + * $renderer = $PAGE->get_renderer('core', 'course'); + * echo $renderer->frontpage_combo_list() + * + * The new class {@link coursecat} stores the information about course category tree + * To get children categories use: + * coursecat::get($id)->get_children() + * To get list of courses use: + * coursecat::get($id)->get_courses() + * + * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5 + * + * @param int $id + * @param int $depth + */ +function get_course_category_tree($id = 0, $depth = 0) { + global $DB, $CFG; + if (!$depth) { + debugging('Function get_course_category_tree() is deprecated, please use course renderer or coursecat class, see function phpdocs for more info', DEBUG_DEVELOPER); + } + + $categories = array(); + $categoryids = array(); + $sql = context_helper::get_preload_record_columns_sql('ctx'); + $records = $DB->get_records_sql("SELECT c.*, $sql FROM {course_categories} c ". + "JOIN {context} ctx on ctx.instanceid = c.id AND ctx.contextlevel = ? WHERE c.parent = ? ORDER BY c.sortorder", + array(CONTEXT_COURSECAT, $id)); + foreach ($records as $category) { + context_helper::preload_from_record($category); + if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->id))) { + continue; + } + $categories[] = $category; + $categoryids[$category->id] = $category; + if (empty($CFG->maxcategorydepth) || $depth <= $CFG->maxcategorydepth) { + list($category->categories, $subcategories) = get_course_category_tree($category->id, $depth+1); + foreach ($subcategories as $subid=>$subcat) { + $categoryids[$subid] = $subcat; + } + $category->courses = array(); + } + } + + if ($depth > 0) { + // This is a recursive call so return the required array + return array($categories, $categoryids); + } + + if (empty($categoryids)) { + // No categories available (probably all hidden). + return array(); + } + + // The depth is 0 this function has just been called so we can finish it off + + list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx'); + list($catsql, $catparams) = $DB->get_in_or_equal(array_keys($categoryids)); + $sql = "SELECT + c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.summary,c.category + $ccselect + FROM {course} c + $ccjoin + WHERE c.category $catsql ORDER BY c.sortorder ASC"; + if ($courses = $DB->get_records_sql($sql, $catparams)) { + // loop throught them + foreach ($courses as $course) { + if ($course->id == SITEID) { + continue; + } + context_instance_preload($course); + if (!empty($course->visible) || has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) { + $categoryids[$course->category]->courses[$course->id] = $course; + } + } + } + return $categories; +} + +/** + * Print courses in category. If category is 0 then all courses are printed. + * + * @deprecated since 2.5 + * + * To print a generic list of courses use: + * $renderer = $PAGE->get_renderer('core', 'course'); + * echo $renderer->courses_list($courses); + * + * To print list of all courses: + * $renderer = $PAGE->get_renderer('core', 'course'); + * echo $renderer->frontpage_available_courses(); + * + * To print list of courses inside category: + * $renderer = $PAGE->get_renderer('core', 'course'); + * echo $renderer->course_category($category); // this will also print subcategories + * + * @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, $PAGE; + require_once($CFG->libdir. '/coursecatlib.php'); + debugging('Function print_courses() is deprecated, please use course renderer', DEBUG_DEVELOPER); + + if (!is_object($category) && $category==0) { + $courses = coursecat::get(0)->get_courses(array('recursive' => true, 'summary' => true, 'coursecontacts' => true)); + } else { + $courses = coursecat::get($category->id)->get_courses(array('summary' => true, 'coursecontacts' => true)); + } + + if ($courses) { + $renderer = $PAGE->get_renderer('core', 'course'); + echo $renderer->courses_list($courses); + } else { + echo $OUTPUT->heading(get_string("nocoursesyet")); + $context = context_system::instance(); + if (has_capability('moodle/course:create', $context)) { + $options = array(); + if (!empty($category->id)) { + $options['category'] = $category->id; + } else { + $options['category'] = $CFG->defaultrequestcategory; + } + 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; +} + +/** + * Print a description of a course, suitable for browsing in a list. + * + * @deprecated since 2.5 + * + * Please use course renderer to display a course information box. + * $renderer = $PAGE->get_renderer('core', 'course'); + * echo $renderer->courses_list($courses); // will print list of courses + * echo $renderer->course_info_box($course); // will print one course wrapped in div.generalbox + * + * @param object $course the course object. + * @param string $highlightterms Ignored in this deprecated function! + */ +function print_course($course, $highlightterms = '') { + global $PAGE; + + debugging('Function print_course() is deprecated, please use course renderer', DEBUG_DEVELOPER); + $renderer = $PAGE->get_renderer('core', 'course'); + // Please note, correct would be to use $renderer->coursecat_coursebox() but this function is protected. + // To print list of courses use $renderer->courses_list(); + echo $renderer->course_info_box($course); +} + +/** + * Gets an array whose keys are category ids and whose values are arrays of courses in the corresponding category. + * + * @deprecated since 2.5 + * + * This function is not used any more in moodle core and course renderer does not have render function for it. + * Combo list on the front page is displayed as: + * $renderer = $PAGE->get_renderer('core', 'course'); + * echo $renderer->frontpage_combo_list() + * + * The new class {@link coursecat} stores the information about course category tree + * To get children categories use: + * coursecat::get($id)->get_children() + * To get list of courses use: + * coursecat::get($id)->get_courses() + * + * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5 + * + * @param int $categoryid + * @return array + */ +function get_category_courses_array($categoryid = 0) { + debugging('Function get_category_courses_array() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER); + $tree = get_course_category_tree($categoryid); + $flattened = array(); + foreach ($tree as $category) { + get_category_courses_array_recursively($flattened, $category); + } + return $flattened; +} + +/** + * Recursive function to help flatten the course category tree. + * + * @deprecated since 2.5 + * + * Was intended to be called from {@link get_category_courses_array()} + * + * @param array &$flattened An array passed by reference in which to store courses for each category. + * @param stdClass $category The category to get courses for. + */ +function get_category_courses_array_recursively(array &$flattened, $category) { + debugging('Function get_category_courses_array_recursively() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER); + $flattened[$category->id] = $category->courses; + foreach ($category->categories as $childcategory) { + get_category_courses_array_recursively($flattened, $childcategory); + } +} + +/** + * Retrieve course records with the course managers and other related records + * that we need for print_course(). This allows print_courses() to do its job + * in a constant number of DB queries, regardless of the number of courses, + * role assignments, etc. + * + * The returned array is indexed on c.id, and each course will have + * - $course->managers - array containing RA objects that include a $user obj + * with the minimal fields needed for fullname() + * + * @deprecated since 2.5 + * + * To get list of all courses with course contacts ('managers') use + * coursecat::get(0)->get_courses(array('recursive' => true, 'coursecontacts' => true)); + * + * To get list of courses inside particular category use + * coursecat::get($id)->get_courses(array('coursecontacts' => true)); + * + * Additionally you can specify sort order, offset and maximum number of courses, + * see {@link coursecat::get_courses()} + * + * Please note that code of this function is not changed to use coursecat class because + * coursecat::get_courses() returns result in slightly different format. Also note that + * get_courses_wmanagers() DOES NOT check that users are enrolled in the course and + * coursecat::get_courses() does. + * + * @global object + * @global object + * @global object + * @uses CONTEXT_COURSE + * @uses CONTEXT_SYSTEM + * @uses CONTEXT_COURSECAT + * @uses SITEID + * @param int|string $categoryid Either the categoryid for the courses or 'all' + * @param string $sort A SQL sort field and direction + * @param array $fields An array of additional fields to fetch + * @return array + */ +function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=array()) { + /* + * The plan is to + * + * - Grab the courses JOINed w/context + * + * - Grab the interesting course-manager RAs + * JOINed with a base user obj and add them to each course + * + * So as to do all the work in 2 DB queries. The RA+user JOIN + * ends up being pretty expensive if it happens over _all_ + * courses on a large site. (Are we surprised!?) + * + * So this should _never_ get called with 'all' on a large site. + * + */ + global $USER, $CFG, $DB; + debugging('Function get_courses_wmanagers() is deprecated, please use coursecat::get_courses()', DEBUG_DEVELOPER); + + $params = array(); + $allcats = false; // bool flag + if ($categoryid === 'all') { + $categoryclause = ''; + $allcats = true; + } elseif (is_numeric($categoryid)) { + $categoryclause = "c.category = :catid"; + $params['catid'] = $categoryid; + } else { + debugging("Could not recognise categoryid = $categoryid"); + $categoryclause = ''; + } + + $basefields = array('id', 'category', 'sortorder', + 'shortname', 'fullname', 'idnumber', + 'startdate', 'visible', + 'newsitems', 'groupmode', 'groupmodeforce'); + + if (!is_null($fields) && is_string($fields)) { + if (empty($fields)) { + $fields = $basefields; + } else { + // turn the fields from a string to an array that + // get_user_courses_bycap() will like... + $fields = explode(',',$fields); + $fields = array_map('trim', $fields); + $fields = array_unique(array_merge($basefields, $fields)); + } + } elseif (is_array($fields)) { + $fields = array_merge($basefields,$fields); + } + $coursefields = 'c.' .join(',c.', $fields); + + if (empty($sort)) { + $sortstatement = ""; + } else { + $sortstatement = "ORDER BY $sort"; + } + + $where = 'WHERE c.id != ' . SITEID; + if ($categoryclause !== ''){ + $where = "$where AND $categoryclause"; + } + + // pull out all courses matching the cat + list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx'); + $sql = "SELECT $coursefields $ccselect + FROM {course} c + $ccjoin + $where + $sortstatement"; + + $catpaths = array(); + $catpath = NULL; + if ($courses = $DB->get_records_sql($sql, $params)) { + // loop on courses materialising + // the context, and prepping data to fetch the + // managers efficiently later... + foreach ($courses as $k => $course) { + context_instance_preload($course); + $coursecontext = context_course::instance($course->id); + $courses[$k] = $course; + $courses[$k]->managers = array(); + if ($allcats === false) { + // single cat, so take just the first one... + if ($catpath === NULL) { + $catpath = preg_replace(':/\d+$:', '', $coursecontext->path); + } + } else { + // chop off the contextid of the course itself + // like dirname() does... + $catpaths[] = preg_replace(':/\d+$:', '', $coursecontext->path); + } + } + } else { + return array(); // no courses! + } + + $CFG->coursecontact = trim($CFG->coursecontact); + if (empty($CFG->coursecontact)) { + return $courses; + } + + $managerroles = explode(',', $CFG->coursecontact); + $catctxids = ''; + if (count($managerroles)) { + if ($allcats === true) { + $catpaths = array_unique($catpaths); + $ctxids = array(); + foreach ($catpaths as $cpath) { + $ctxids = array_merge($ctxids, explode('/',substr($cpath,1))); + } + $ctxids = array_unique($ctxids); + $catctxids = implode( ',' , $ctxids); + unset($catpaths); + unset($cpath); + } else { + // take the ctx path from the first course + // as all categories will be the same... + $catpath = substr($catpath,1); + $catpath = preg_replace(':/\d+$:','',$catpath); + $catctxids = str_replace('/',',',$catpath); + } + if ($categoryclause !== '') { + $categoryclause = "AND $categoryclause"; + } + /* + * Note: Here we use a LEFT OUTER JOIN that can + * "optionally" match to avoid passing a ton of context + * ids in an IN() clause. Perhaps a subselect is faster. + * + * In any case, this SQL is not-so-nice over large sets of + * courses with no $categoryclause. + * + */ + $sql = "SELECT ctx.path, ctx.instanceid, ctx.contextlevel, + r.id AS roleid, r.name AS rolename, r.shortname AS roleshortname, + rn.name AS rolecoursealias, u.id AS userid, u.firstname, u.lastname + FROM {role_assignments} ra + JOIN {context} ctx ON ra.contextid = ctx.id + JOIN {user} u ON ra.userid = u.id + JOIN {role} r ON ra.roleid = r.id + LEFT JOIN {role_names} rn ON (rn.contextid = ctx.id AND rn.roleid = r.id) + LEFT OUTER JOIN {course} c + ON (ctx.instanceid=c.id AND ctx.contextlevel=".CONTEXT_COURSE.") + WHERE ( c.id IS NOT NULL"; + // under certain conditions, $catctxids is NULL + if($catctxids == NULL){ + $sql .= ") "; + }else{ + $sql .= " OR ra.contextid IN ($catctxids) )"; + } + + $sql .= "AND ra.roleid IN ({$CFG->coursecontact}) + $categoryclause + ORDER BY r.sortorder ASC, ctx.contextlevel ASC, ra.sortorder ASC"; + $rs = $DB->get_recordset_sql($sql, $params); + + // This loop is fairly stupid as it stands - might get better + // results doing an initial pass clustering RAs by path. + foreach($rs as $ra) { + $user = new stdClass; + $user->id = $ra->userid; unset($ra->userid); + $user->firstname = $ra->firstname; unset($ra->firstname); + $user->lastname = $ra->lastname; unset($ra->lastname); + $ra->user = $user; + if ($ra->contextlevel == CONTEXT_SYSTEM) { + foreach ($courses as $k => $course) { + $courses[$k]->managers[] = $ra; + } + } else if ($ra->contextlevel == CONTEXT_COURSECAT) { + if ($allcats === false) { + // It always applies + foreach ($courses as $k => $course) { + $courses[$k]->managers[] = $ra; + } + } else { + foreach ($courses as $k => $course) { + $coursecontext = context_course::instance($course->id); + // Note that strpos() returns 0 as "matched at pos 0" + if (strpos($coursecontext->path, $ra->path.'/') === 0) { + // Only add it to subpaths + $courses[$k]->managers[] = $ra; + } + } + } + } else { // course-level + if (!array_key_exists($ra->instanceid, $courses)) { + //this course is not in a list, probably a frontpage course + continue; + } + $courses[$ra->instanceid]->managers[] = $ra; + } + } + $rs->close(); + } + + return $courses; +} diff --git a/lib/upgrade.txt b/lib/upgrade.txt index a55865326bb..5e9677cc5ea 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -38,10 +38,15 @@ information provided here is intended especially for developers. * Formslib will now throw a developer warning if a PARAM_ type hasn't been set for elements which need it. Please set PARAM_RAW explicitly if you do not want any cleaning. * Functions responsible for managing and accessing course categories are moved to class coursecat - in lib/coursecatlib.php. The following global functions are deprecated: make_categories_list(), + in lib/coursecatlib.php, functions responsible for rendering courses and categories lists are + moved to course/renderer.php. The following global functions are deprecated: make_categories_list(), category_delete_move(), category_delete_full(), move_category(), course_category_hide(), course_category_show(), get_course_category(), create_course_category(), get_all_subcategories(), - get_child_categories(), get_categories() + get_child_categories(), get_categories(), print_my_moodle(), print_remote_course(), + print_remote_host(), print_whole_category_list(), print_category_info(), get_course_category_tree(), + print_courses(), print_course(), get_category_courses_array(), get_category_courses_array_recursively(), + get_courses_wmanagers() + See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5 * $core_renderer->block_move_target() changed to support more verbose move-block-here descriptions. Database (DML) layer: diff --git a/theme/upgrade.txt b/theme/upgrade.txt index 56688c5998c..59e5b94a4d6 100644 --- a/theme/upgrade.txt +++ b/theme/upgrade.txt @@ -3,6 +3,14 @@ information provided here is intended especially for theme designer. === 2.5 === +required changes: +* Functions core_course_renderer::course_category_tree() and course_category_tree_category() + are deprecated +* Significant changes in rendering of courses and categories listings, lots of CSS classes changed, + several functions such as print_courses(), print_whole_category_list(), print_category_info() + are moved to course renderer. + See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5 + DOM changes: * changed the h1 title in the help popup to a h2. * new setting $THEME->yuicssmodules = array('cssreset', 'cssfonts', 'cssgrids', 'cssbase'); which