Merge branch 'MDL-29719-master' of git://github.com/sammarshallou/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2011-10-17 12:05:05 +02:00
commit a598a8d4b1
5 changed files with 49 additions and 4 deletions

View file

@ -314,7 +314,8 @@
$linkcss = $acourse->visible ? '' : ' class="dimmed" ';
echo '<tr>';
echo '<td><a '.$linkcss.' href="view.php?id='.$acourse->id.'">'. format_string($acourse->fullname) .'</a></td>';
$coursename = get_course_display_name_for_list($course);
echo '<td><a '.$linkcss.' href="view.php?id='.$acourse->id.'">'. format_string($coursename) .'</a></td>';
if ($editingon) {
echo '<td>';
if (has_capability('moodle/course:update', $coursecontext)) {

View file

@ -2173,6 +2173,22 @@ function make_categories_options() {
return $cats;
}
/**
* Gets the name of a course to be displayed when showing a list of courses.
* By default this is just $course->fullname but user can configure it. The
* result of this function should be passed through print_string.
* @param object $course Moodle course object
* @return string Display name of course (either fullname or short + fullname)
*/
function get_course_display_name_for_list($course) {
global $CFG;
if (!empty($CFG->courselistshortnames)) {
return $course->shortname . ' ' .$course->fullname;
} else {
return $course->fullname;
}
}
/**
* Prints the category info in indented fashion
* This function is only used by print_whole_category_list() above
@ -2231,7 +2247,8 @@ function print_category_info($category, $depth=0, $showcourses = false) {
$linkcss = array('class'=>'dimmed');
}
$courselink = html_writer::link(new moodle_url('/course/view.php', array('id'=>$course->id)), format_string($course->fullname), $linkcss);
$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 = '';
@ -2423,7 +2440,9 @@ function print_course($course, $highlightterms = '') {
echo html_writer::start_tag('h3', array('class'=>'name'));
$linkhref = new moodle_url('/course/view.php', array('id'=>$course->id));
$linktext = highlight($highlightterms, format_string($course->fullname));
$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';

View file

@ -113,4 +113,24 @@ class courselib_test extends UnitTestCase {
$this->assertEqual(25, next($newsections_flipped));
$this->assertEqual(21, next($newsections_flipped));
}
function test_get_course_display_name_for_list() {
global $CFG;
$course = (object)array('shortname' => 'FROG101',
'fullname' => 'Introduction to pond life');
// Store config value in case other tests rely on it
$oldcfg = $CFG->courselistshortnames;
$CFG->courselistshortnames = 0;
$this->assertEqual('Introduction to pond life',
get_course_display_name_for_list($course));
$CFG->courselistshortnames = 1;
$this->assertEqual('FROG101 Introduction to pond life',
get_course_display_name_for_list($course));
$CFG->courselistshortnames = $oldcfg;
}
}