Skip to content

Commit

Permalink
MDL-34704 couse, accesslib: improve $CFG->courselistshortnames
Browse files Browse the repository at this point in the history
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'.
  • Loading branch information
timhunt committed Aug 3, 2012
1 parent 02814bf commit e071bc1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
16 changes: 0 additions & 16 deletions course/lib.php
Expand Up @@ -2255,22 +2255,6 @@ function make_categories_options() {
return $cats; 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 * Prints the category info in indented fashion
* This function is only used by print_whole_category_list() above * This function is only used by print_whole_category_list() above
Expand Down
4 changes: 2 additions & 2 deletions lang/en/admin.php
Expand Up @@ -352,8 +352,8 @@
$string['country'] = 'Default country'; $string['country'] = 'Default country';
$string['coursecontact'] = 'Course contacts'; $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['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'] = 'Display extended course names';
$string['courselistshortnames_desc'] = 'Show short name as well as full name when displaying lists of courses.'; $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['coursemgmt'] = 'Add/edit courses';
$string['courseoverview'] = 'Course overview'; $string['courseoverview'] = 'Course overview';
$string['courserequestnotify'] = 'Course request notification'; $string['courserequestnotify'] = 'Course request notification';
Expand Down
1 change: 1 addition & 0 deletions lang/en/moodle.php
Expand Up @@ -299,6 +299,7 @@
$string['coursedisplay_single'] = 'Show all sections on one page'; $string['coursedisplay_single'] = 'Show all sections on one page';
$string['coursedisplay_multi'] = 'Show one section per page'; $string['coursedisplay_multi'] = 'Show one section per page';
$string['coursedeleted'] = 'Deleted course {$a}'; $string['coursedeleted'] = 'Deleted course {$a}';
$string['courseextendednamedisplay'] = '{$a->shortname} {$a->fullname}';
$string['coursefiles'] = 'Legacy course files'; $string['coursefiles'] = 'Legacy course files';
$string['coursefilesedit'] = 'Edit legacy course files'; $string['coursefilesedit'] = 'Edit legacy course files';
$string['coursefileswarning'] = 'Course files are deprecated'; $string['coursefileswarning'] = 'Course files are deprecated';
Expand Down
2 changes: 1 addition & 1 deletion lib/accesslib.php
Expand Up @@ -6319,7 +6319,7 @@ public function get_context_name($withprefix = true, $short = false) {
if ($short){ if ($short){
$name .= format_string($course->shortname, true, array('context' => $this)); $name .= format_string($course->shortname, true, array('context' => $this));
} else { } else {
$name .= format_string($course->fullname); $name .= format_string(get_course_display_name_for_list($course));
} }
} }
} }
Expand Down
16 changes: 16 additions & 0 deletions lib/moodlelib.php
Expand Up @@ -10780,6 +10780,22 @@ function get_home_page() {
return HOMEPAGE_SITE; 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 * The lang_string class
* *
Expand Down

0 comments on commit e071bc1

Please sign in to comment.