Skip to content
Browse files

MDL-36259 course short names: ensure it displays when enabled in admin

Fixed 5 Moodle pages that does not display the course short name even if "Display extended course names" setting is on.  In fixing this, search.php also included related minor code to change to minimise DB calls to improve performance.
  • Loading branch information...
1 parent 7d2c5cd commit defbd5dd2c59f953b0efed1f7cb38472566f1dbf @dtle dtle committed with timhunt Nov 20, 2012
Showing with 35 additions and 33 deletions.
  1. +17 −20 course/search.php
  2. +6 −3 enrol/meta/addinstance_form.php
  3. +6 −6 report/log/locallib.php
  4. +3 −2 user/profile.php
  5. +3 −2 user/view.php
View
37 course/search.php
@@ -175,13 +175,11 @@
if (!empty($blocklist) and confirm_sesskey()) {
$blockname = $DB->get_field('block', 'name', array('id' => $blocklist));
$courses = array();
- $courses = $DB->get_records_sql("
- SELECT * FROM {course} WHERE id IN (
- SELECT DISTINCT ctx.instanceid
- FROM {context} ctx
- JOIN {block_instances} bi ON bi.parentcontextid = ctx.id
- WHERE ctx.contextlevel = " . CONTEXT_COURSE . " AND bi.blockname = ?)",
- array($blockname));
+ list($select, $join) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
+ $sql = "SELECT C.* $select FROM {course} c
+ $join JOIN {block_instances} bi ON bi.parentcontextid = ctx.id
+ WHERE bi.blockname = ?";
+ $courses = $DB->get_records_sql($sql, array($blockname));
$totalcount = count($courses);
// Keep only chunk of array which you want to display
if ($totalcount > $perpage) {
@@ -193,26 +191,24 @@
}
} elseif (!empty($modulelist) and confirm_sesskey()) { // get list of courses containing modules
$modulename = $modulelist;
- $sql = "SELECT DISTINCT c.id FROM {".$modulelist."} module, {course} c"
- ." WHERE module.course=c.id";
-
- $courseids = $DB->get_records_sql($sql);
+ list($select, $join) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
+ $sql = "SELECT c.* $select FROM {course} c $join
+ WHERE c.id IN (SELECT DISTINCT cc.id FROM {".$modulelist."} module, {course} cc
+ WHERE module.course = cc.id)";
+ $courselist = $DB->get_records_sql($sql);
$courses = array();
- if (!empty($courseids)) {
+ if (!empty($courselist)) {
$firstcourse = $page*$perpage;
$lastcourse = $page*$perpage + $perpage -1;
$i = 0;
- foreach ($courseids as $courseid) {
+ foreach ($courselist as $course) {
if ($i >= $firstcourse && $i <= $lastcourse) {
- $courses[$courseid->id] = $DB->get_record('course', array('id'=> $courseid->id));
+ $courses[$course->id] = $course;
}
$i++;
}
- $totalcount = count($courseids);
- }
- else {
- $totalcount = 0;
}
+ $totalcount = count($courselist);
} else if (!empty($searchterm)) {
// Donot do search for empty search request.
$courses = get_courses_search($searchterms, "fullname ASC", $page, $perpage, $totalcount);
@@ -294,6 +290,7 @@
foreach ($courses as $course) {
+ context_helper::preload_from_record($course);
$coursecontext = context_course::instance($course->id);
$linkcss = $course->visible ? "" : " class=\"dimmed\" ";
@@ -313,7 +310,7 @@
echo "<tr>\n";
echo "<td><a $linkcss href=\"view.php?id=$course->id\">"
- . highlight($search, format_string($course->fullname)) . "</a></td>\n";
+ . highlight($search, $coursecontext->get_context_name(false)) . "</a></td>\n";
echo "<td>".$displaylist[$course->category]."</td>\n";
echo "<td>\n";
@@ -432,4 +429,4 @@ function print_navigation_bar($totalcount, $page, $perpage, $encodedsearch, $mod
echo "<a href=\"search.php?search=$encodedsearch".$modulelink."&amp;perpage=".$defaultperpage."\">".get_string("showperpage", "", $defaultperpage)."</a>";
echo "</p></center>";
}
-}
+}
View
9 enrol/meta/addinstance_form.php
@@ -41,19 +41,22 @@ function definition() {
// TODO: this has to be done via ajax or else it will fail very badly on large sites!
$courses = array('' => get_string('choosedots'));
- $rs = $DB->get_recordset('course', array(), 'sortorder ASC', 'id, fullname, shortname, visible');
+ list ($select, $join) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
+ $sql = "SELECT c.id, c.fullname, c.shortname, c.visible $select FROM {course} c $join ORDER BY c.sortorder ASC";
+ $rs = $DB->get_recordset_sql($sql);
foreach ($rs as $c) {
if ($c->id == SITEID or $c->id == $course->id or isset($existing[$c->id])) {
continue;
}
- $coursecontext = get_context_instance(CONTEXT_COURSE, $c->id);
+ context_helper::preload_from_record($c);
+ $coursecontext = context_course::instance($c->id);
if (!$c->visible and !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
continue;
}
if (!has_capability('enrol/meta:selectaslinked', $coursecontext)) {
continue;
}
- $courses[$c->id] = format_string($c->fullname). ' ['.format_string($c->shortname, true, array('context' => $coursecontext)).']';
+ $courses[$c->id] = $coursecontext->get_context_name(false);
}
$rs->close();
View
12 report/log/locallib.php
@@ -190,12 +190,12 @@ function report_log_print_mnet_selector_form($hostid, $course, $selecteduser=0,
$sites = array();
if ($CFG->mnet_localhost_id == $hostid) {
if (has_capability('report/log:view', $sitecontext) && $showcourses) {
- if ($ccc = $DB->get_records("course", null, "fullname","id,fullname,category")) {
+ if ($ccc = $DB->get_records("course", null, "fullname","id,shortname,fullname,category")) {
foreach ($ccc as $cc) {
if ($cc->id == SITEID) {
$sites["$hostid/$cc->id"] = format_string($cc->fullname).' ('.get_string('site').')';
} else {
- $courses["$hostid/$cc->id"] = format_string($cc->fullname);
+ $courses["$hostid/$cc->id"] = format_string(get_course_display_name_for_list($cc));
}
}
}
@@ -313,7 +313,7 @@ function report_log_print_mnet_selector_form($hostid, $course, $selecteduser=0,
echo html_writer::select($dropdown, "host_course", $hostid.'/'.$cid);
} else {
$courses = array();
- $courses[$course->id] = $course->fullname . ((empty($course->category)) ? ' ('.get_string('site').') ' : '');
+ $courses[$course->id] = get_course_display_name_for_list($course) . ((empty($course->category)) ? ' ('.get_string('site').') ' : '');
echo html_writer::label(get_string('selectacourse'), 'menuid', false, array('class' => 'accesshide'));
echo html_writer::select($courses,"id",$course->id, false);
if (has_capability('report/log:view', $sitecontext)) {
@@ -461,10 +461,10 @@ function report_log_print_selector_form($course, $selecteduser=0, $selecteddate=
}
if (has_capability('report/log:view', $sitecontext) && $showcourses) {
- if ($ccc = $DB->get_records("course", null, "fullname", "id,fullname,category")) {
+ if ($ccc = $DB->get_records("course", null, "fullname", "id,shortname,fullname,category")) {
foreach ($ccc as $cc) {
if ($cc->category) {
- $courses["$cc->id"] = format_string($cc->fullname);
+ $courses["$cc->id"] = format_string(get_course_display_name_for_list($cc));
} else {
$courses["$cc->id"] = format_string($cc->fullname) . ' (Site)';
}
@@ -563,7 +563,7 @@ function report_log_print_selector_form($course, $selecteduser=0, $selecteddate=
} else {
// echo '<input type="hidden" name="id" value="'.$course->id.'" />';
$courses = array();
- $courses[$course->id] = $course->fullname . (($course->id == SITEID) ? ' ('.get_string('site').') ' : '');
+ $courses[$course->id] = get_course_display_name_for_list($course) . (($course->id == SITEID) ? ' ('.get_string('site').') ' : '');
echo html_writer::label(get_string('selectacourse'), 'menuid', false, array('class' => 'accesshide'));
echo html_writer::select($courses,"id",$course->id, false);
if (has_capability('report/log:view', $sitecontext)) {
View
5 user/profile.php
@@ -321,15 +321,16 @@
$courselisting = '';
foreach ($mycourses as $mycourse) {
if ($mycourse->category) {
+ context_helper::preload_from_record($mycourse);
+ $ccontext = context_course::instance($mycourse->id);
$class = '';
if ($mycourse->visible == 0) {
- $ccontext = get_context_instance(CONTEXT_COURSE, $mycourse->id);
if (!has_capability('moodle/course:viewhiddencourses', $ccontext)) {
continue;
}
$class = 'class="dimmed"';
}
- $courselisting .= "<a href=\"{$CFG->wwwroot}/user/view.php?id={$user->id}&amp;course={$mycourse->id}\" $class >" . format_string($mycourse->fullname) . "</a>, ";
+ $courselisting .= "<a href=\"{$CFG->wwwroot}/user/view.php?id={$user->id}&amp;course={$mycourse->id}\" $class >" . $ccontext->get_context_name(false) . "</a>, ";
}
$shown++;
if($shown==20) {
View
5 user/view.php
@@ -288,8 +288,9 @@
$courselisting = '';
foreach ($mycourses as $mycourse) {
if ($mycourse->category) {
- $ccontext = get_context_instance(CONTEXT_COURSE, $mycourse->id);;
- $cfullname = format_string($mycourse->fullname, true, array('context' => $ccontext));
+ context_helper::preload_from_record($mycourse);
+ $ccontext = context_course::instance($mycourse->id);
+ $cfullname = $ccontext->get_context_name(false);
if ($mycourse->id != $course->id){
$class = '';
if ($mycourse->visible == 0) {

0 comments on commit defbd5d

Please sign in to comment.
Something went wrong with that request. Please try again.