Permalink
Browse files

MDL-29719 Option to display course shortname alongside fullname on co…

…urse lists
  • Loading branch information...
1 parent 6731a04 commit 7fb46992661e2eb1fb7bfd1a6d3f7f1ccf8fd306 @sammarshallou sammarshallou committed Oct 10, 2011
Showing with 49 additions and 4 deletions.
  1. +4 −1 admin/settings/appearance.php
  2. +2 −1 course/category.php
  3. +21 −2 course/lib.php
  4. +20 −0 course/simpletest/testcourselib.php
  5. +2 −0 lang/en/admin.php
View
5 admin/settings/appearance.php
@@ -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'));
View
3 course/category.php
@@ -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
23 course/lib.php
@@ -2174,6 +2174,22 @@ function make_categories_options() {
}
/**
+ * 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
20 course/simpletest/testcourselib.php
@@ -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;
+ }
}
View
2 lang/en/admin.php
@@ -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';

0 comments on commit 7fb4699

Please sign in to comment.