From 157583b862487422881b2fa86818163cad81fd49 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 2 Aug 2012 17:21:32 +0100 Subject: [PATCH] MDL-34704 couse, accesslib: improve $CFG->courselistshortnames 1. get_context_name should respect the $CFG->courselistshortnames setting. 2. When $CFG->courselistshortnames is on, what to display should use a language string, rather than string concatenation. This makes it possible for people to configure the display. For example, they might want 'My first course [M101]' instead of 'M101 My first course'. --- course/lib.php | 16 ---------------- lang/en/admin.php | 4 ++-- lang/en/moodle.php | 1 + lib/accesslib.php | 2 +- lib/moodlelib.php | 16 ++++++++++++++++ 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/course/lib.php b/course/lib.php index 44255766160..06fb241774c 100644 --- a/course/lib.php +++ b/course/lib.php @@ -2256,22 +2256,6 @@ 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 diff --git a/lang/en/admin.php b/lang/en/admin.php index 9c143985d96..eb6f0e95ceb 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -351,8 +351,8 @@ $string['cookiesecure'] = 'Secure cookies only'; $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['courselistshortnames'] = 'Display extended course names'; +$string['courselistshortnames_desc'] = 'When showing lists of courses, or when referring to courses on administration screens, show the course short name as well as the full name. In fact, when you turn this setting on, the display uses the \'courseextendednamedisplay\' language string, so you can changewhat is displayed using Language customisation.'; $string['coursemgmt'] = 'Add/edit courses'; $string['courseoverview'] = 'Course overview'; $string['courserequestnotify'] = 'Course request notification'; diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 804df10d0b1..2b8eadbecb9 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -299,6 +299,7 @@ $string['coursedisplay_help'] = 'This setting determines whether the whole cours $string['coursedisplay_single'] = 'Show all sections on one page'; $string['coursedisplay_multi'] = 'Show one section per page'; $string['coursedeleted'] = 'Deleted course {$a}'; +$string['courseextendednamedisplay'] = '{$a->shortname} {$a->fullname}'; $string['coursefiles'] = 'Legacy course files'; $string['coursefilesedit'] = 'Edit legacy course files'; $string['coursefileswarning'] = 'Course files are deprecated'; diff --git a/lib/accesslib.php b/lib/accesslib.php index a75ce2f05fe..523086375fe 100644 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -6458,7 +6458,7 @@ class context_course extends context { if ($short){ $name .= format_string($course->shortname, true, array('context' => $this)); } else { - $name .= format_string($course->fullname); + $name .= format_string(get_course_display_name_for_list($course)); } } } diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 842efaceff3..1a36b518466 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -10799,6 +10799,22 @@ function get_home_page() { return HOMEPAGE_SITE; } +/** + * 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 get_string('courseextendednamedisplay', '', $course); + } else { + return $course->fullname; + } +} + /** * The lang_string class *