Skip to content

Commit

Permalink
MDL-29719 Option to display course shortname alongside fullname on co…
Browse files Browse the repository at this point in the history
…urse lists
  • Loading branch information
sammarshallou committed Oct 17, 2011
1 parent 6731a04 commit 7fb4699
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
5 changes: 4 additions & 1 deletion admin/settings/appearance.php
Expand Up @@ -118,8 +118,11 @@
$ADMIN->add('appearance', $temp);

// coursecontact is the person responsible for course - usually manages enrolments, receives notification, etc.
$temp = new admin_settingpage('coursecontact', get_string('coursecontact', 'admin'));
$temp = new admin_settingpage('coursecontact', get_string('courses'));
$temp->add(new admin_setting_special_coursecontact());
$temp->add(new admin_setting_configcheckbox('courselistshortnames',
get_string('courselistshortnames', 'admin'),
get_string('courselistshortnames_desc', 'admin'), 0));
$ADMIN->add('appearance', $temp);

$temp = new admin_settingpage('ajax', get_string('ajaxuse'));
Expand Down
3 changes: 2 additions & 1 deletion course/category.php
Expand Up @@ -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)) {
Expand Down
23 changes: 21 additions & 2 deletions course/lib.php
Expand Up @@ -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
Expand Down Expand Up @@ -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 = '';
Expand Down Expand Up @@ -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';
Expand Down
20 changes: 20 additions & 0 deletions course/simpletest/testcourselib.php
Expand Up @@ -113,4 +113,24 @@ function testReorderSections() {
$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;
}
}
2 changes: 2 additions & 0 deletions lang/en/admin.php
Expand Up @@ -352,6 +352,8 @@
$string['country'] = 'Default country';
$string['coursecontact'] = 'Course contacts';
$string['coursecontact_desc'] = 'This setting allows you to control who appears on the course description. Users need to have at least one of these roles in a course to be shown on the course description for that course.';
$string['courselistshortnames'] = 'Display short names';
$string['courselistshortnames_desc'] = 'Show short name as well as full name when displaying lists of courses.';
$string['coursemgmt'] = 'Add/edit courses';
$string['courseoverview'] = 'Course overview';
$string['courserequestnotify'] = 'Course request notification';
Expand Down

0 comments on commit 7fb4699

Please sign in to comment.