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.
This commit is contained in:
Thanh Le 2012-11-20 10:07:06 +00:00 committed by Tim Hunt
parent 20751863e3
commit 31f4086460
5 changed files with 33 additions and 31 deletions

View File

@ -175,13 +175,11 @@ if (!empty($moveto) and $data = data_submitted() and confirm_sesskey()) { // S
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 @@ if (!empty($blocklist) and confirm_sesskey()) {
}
} 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 @@ if ($courses) {
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 @@ if ($courses) {
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";

View File

@ -41,11 +41,14 @@ class enrol_meta_addinstance_form extends moodleform {
// 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;
}
context_helper::preload_from_record($c);
$coursecontext = context_course::instance($c->id);
if (!$c->visible and !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
continue;
@ -53,7 +56,7 @@ class enrol_meta_addinstance_form extends moodleform {
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 File

@ -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));
}
}
}
@ -312,7 +312,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)) {
@ -460,10 +460,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)';
}
@ -561,7 +561,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 File

@ -321,15 +321,16 @@ if (!isset($hiddenfields['mycourses'])) {
$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 = context_course::instance($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 File

@ -288,8 +288,9 @@ if (!isset($hiddenfields['mycourses'])) {
$courselisting = '';
foreach ($mycourses as $mycourse) {
if ($mycourse->category) {
$ccontext = context_course::instance($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) {