MDL-82349 core_courseformat: new get_generic_section_name method
The string "sectionname" was an unnecessary coupling between formats and other plugins. Now the generic name for a section should be obtained using $format->get_generic_section_name. This allow formats to use an alternative string for nameing sections. This is especially important for rare formats like the frontpage one that does not have a plugin lang file.
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
issueNumber: MDL-82349
|
||||
notes:
|
||||
core_courseformat:
|
||||
- message: >-
|
||||
A new core_courseformat\base::get_generic_section_name method is
|
||||
created to know how a specific format name the sections.
|
||||
This method is also used by plugins to know how to name the sections
|
||||
instead of using using a direct get_string on "sectionnamer" that
|
||||
may not exists.
|
||||
type: improved
|
||||
@@ -551,6 +551,18 @@ abstract class base {
|
||||
return self::get_section_name($section);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the generic name for sections in this course format.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_generic_section_name() {
|
||||
if (get_string_manager()->string_exists('sectionname', 'format_' . $this->format)) {
|
||||
return get_string('sectionname', 'format_' . $this->format);
|
||||
}
|
||||
return get_string('section');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name for the highlighted section.
|
||||
*
|
||||
|
||||
@@ -60,8 +60,8 @@ class bulkedittoggler implements named_templatable, renderable {
|
||||
];
|
||||
|
||||
if ($section) {
|
||||
$data->sectionname = get_string('sectionname', "format_$course->format");
|
||||
$data->sectiontitle = get_section_name($course, $section);
|
||||
$data->sectionname = $format->get_generic_section_name();
|
||||
$data->sectiontitle = $format->get_section_name($section);
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
@@ -996,6 +996,31 @@ class base_test extends advanced_testcase {
|
||||
$this->assertFalse($format->is_section_visible($modinfostudent->get_section_info(1)));
|
||||
$this->assertFalse($format->is_section_visible($modinfostudent->get_section_info(2)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for the get_generic_section_name method.
|
||||
*
|
||||
* @covers ::get_generic_section_name
|
||||
*/
|
||||
public function test_get_generic_section_name(): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$generator = $this->getDataGenerator();
|
||||
$course1 = $generator->create_course(['format' => 'topics']);
|
||||
$course2 = $generator->create_course(['format' => 'theunittest']);
|
||||
|
||||
$format = course_get_format($course1);
|
||||
$this->assertEquals(
|
||||
get_string('sectionname', 'format_topics'),
|
||||
$format->get_generic_section_name()
|
||||
);
|
||||
|
||||
$format = course_get_format($course2);
|
||||
$this->assertEquals(
|
||||
get_string('section'),
|
||||
$format->get_generic_section_name()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -99,7 +99,8 @@ $table = new html_table();
|
||||
$table->attributes['class'] = 'generaltable mod_index';
|
||||
|
||||
if ($usesections) {
|
||||
$strsectionname = get_string('sectionname', 'format_'.$course->format);
|
||||
|
||||
$strsectionname = course_get_format($course)->get_generic_section_name();
|
||||
$table->head = array ($strsectionname, $strname, $strintro);
|
||||
$table->align = array ('center', 'left', 'left');
|
||||
} else {
|
||||
|
||||
+2
-2
@@ -148,8 +148,8 @@ $editingtitle = '';
|
||||
if ($PAGE->user_is_editing()) {
|
||||
$editingtitle = 'editing';
|
||||
}
|
||||
$sectionname = get_string('sectionname', "format_$course->format");
|
||||
$sectiontitle = get_section_name($course, $section);
|
||||
$sectionname = $format->get_generic_section_name();
|
||||
$sectiontitle = $format->get_section_name($section);
|
||||
$PAGE->set_title(
|
||||
get_string(
|
||||
'coursesectiontitle' . $editingtitle,
|
||||
|
||||
+2
-2
@@ -284,8 +284,8 @@ if ($PAGE->user_is_editing()) {
|
||||
|
||||
// If viewing a section, make the title more specific.
|
||||
if ($section && $section > 0 && course_format_uses_sections($course->format)) {
|
||||
$sectionname = get_string('sectionname', "format_$course->format");
|
||||
$sectiontitle = get_section_name($course, $section);
|
||||
$sectionname = $format->get_generic_section_name();
|
||||
$sectiontitle = $format->get_section_name($section);
|
||||
$PAGE->set_title(
|
||||
get_string(
|
||||
'coursesectiontitle' . $editingtitle,
|
||||
|
||||
@@ -3280,7 +3280,7 @@ class assign {
|
||||
$modinfo = get_fast_modinfo($course);
|
||||
|
||||
if ($usesections) {
|
||||
$strsectionname = get_string('sectionname', 'format_'.$course->format);
|
||||
$strsectionname = course_get_format($course)->get_generic_section_name();
|
||||
$sections = $modinfo->get_section_info_all();
|
||||
}
|
||||
$courseindexsummary = new assign_course_index_summary($usesections, $strsectionname);
|
||||
|
||||
@@ -61,7 +61,7 @@ class index implements renderable {
|
||||
$table = new html_table();
|
||||
|
||||
if (course_format_uses_sections($this->course->format)) {
|
||||
$sectionheading = get_string('sectionname', "format_{$this->course->format}");
|
||||
$sectionheading = course_get_format($this->course)->get_generic_section_name();
|
||||
} else {
|
||||
$sectionheading = '';
|
||||
}
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ $table = new html_table();
|
||||
$table->attributes['class'] = 'generaltable mod_index';
|
||||
|
||||
if ($usesections) {
|
||||
$strsectionname = get_string('sectionname', 'format_'.$course->format);
|
||||
$strsectionname = course_get_format($course)->get_generic_section_name();
|
||||
$table->head = array ($strsectionname, $strname, $strintro);
|
||||
$table->align = array ('center', 'left', 'left');
|
||||
} else {
|
||||
|
||||
+1
-2
@@ -62,7 +62,7 @@ $strname = get_string('name');
|
||||
$table = new html_table();
|
||||
|
||||
if ($usesections) {
|
||||
$strsectionname = get_string('sectionname', 'format_'.$course->format);
|
||||
$strsectionname = course_get_format($course)->get_generic_section_name();
|
||||
$table->head = array ($strsectionname, $strname);
|
||||
$table->align = array ('center', 'left');
|
||||
} else {
|
||||
@@ -103,4 +103,3 @@ echo html_writer::table($table);
|
||||
// Finish the page.
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
$table = new html_table();
|
||||
|
||||
if ($usesections) {
|
||||
$strsectionname = get_string('sectionname', 'format_'.$course->format);
|
||||
$strsectionname = course_get_format($course)->get_generic_section_name();
|
||||
$table->head = array ($strsectionname, get_string("question"), get_string("answer"));
|
||||
$table->align = array ("center", "left", "left");
|
||||
} else {
|
||||
@@ -103,5 +103,3 @@
|
||||
echo html_writer::table($table);
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
|
||||
|
||||
+1
-2
@@ -75,7 +75,7 @@ $strnumnotapproved = get_string('numnotapproved', 'data');
|
||||
$table = new html_table();
|
||||
|
||||
if ($usesections) {
|
||||
$strsectionname = get_string('sectionname', 'format_'.$course->format);
|
||||
$strsectionname = course_get_format($course)->get_generic_section_name();
|
||||
$table->head = array ($strsectionname, $strname, $strdescription, $strentries, $strnumnotapproved);
|
||||
$table->align = array ('center', 'center', 'center', 'center', 'center');
|
||||
} else {
|
||||
@@ -149,4 +149,3 @@ foreach ($datas as $data) {
|
||||
echo "<br />";
|
||||
echo html_writer::tag('div', html_writer::table($table), array('class'=>'no-overflow'));
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ $strresponses = get_string('responses', 'feedback');
|
||||
$table = new html_table();
|
||||
|
||||
if ($usesections) {
|
||||
$strsectionname = get_string('sectionname', 'format_'.$course->format);
|
||||
$strsectionname = course_get_format($course)->get_generic_section_name();
|
||||
if (has_capability('mod/feedback:viewreports', $context)) {
|
||||
$table->head = array ($strsectionname, $strname, $strresponses);
|
||||
$table->align = array ("center", "left", 'center');
|
||||
|
||||
@@ -66,7 +66,7 @@ $table = new html_table();
|
||||
$table->attributes['class'] = 'generaltable mod_index';
|
||||
|
||||
if ($usesections) {
|
||||
$strsectionname = get_string('sectionname', 'format_'.$course->format);
|
||||
$strsectionname = course_get_format($course)->get_generic_section_name();
|
||||
$table->head = array ($strsectionname, $strname, $strintro);
|
||||
$table->align = array ('center', 'left', 'left');
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -349,7 +349,7 @@ if ($show_rss = (($showsubscriptioncolumns || $course->id == SITEID) &&
|
||||
// Now let's process the learning forums.
|
||||
if ($course->id != SITEID) { // Only real courses have learning forums
|
||||
// 'format_.'$course->format only applicable when not SITEID (format_site is not a format)
|
||||
$strsectionname = get_string('sectionname', 'format_'.$course->format);
|
||||
$strsectionname = course_get_format($course)->get_generic_section_name();
|
||||
// Add extra field for section number, at the front
|
||||
array_unshift($learningtable->head, $strsectionname);
|
||||
array_unshift($learningtable->align, 'center');
|
||||
|
||||
@@ -58,7 +58,7 @@ $strentries = get_string("entries", "glossary");
|
||||
$table = new html_table();
|
||||
|
||||
if ($usesections) {
|
||||
$strsectionname = get_string('sectionname', 'format_'.$course->format);
|
||||
$strsectionname = course_get_format($course)->get_generic_section_name();
|
||||
$table->head = array ($strsectionname, $strname, $strentries);
|
||||
$table->align = array ('center', 'left', 'center');
|
||||
} else {
|
||||
@@ -139,4 +139,3 @@ echo html_writer::table($table);
|
||||
/// Finish the page
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ $table = new html_table();
|
||||
$table->attributes['class'] = 'generaltable mod_index';
|
||||
|
||||
if ($usesections) {
|
||||
$strsectionname = get_string('sectionname', 'format_'.$course->format);
|
||||
$strsectionname = course_get_format($course)->get_generic_section_name();
|
||||
$table->head = array ($strsectionname, $strname, $strintro);
|
||||
$table->align = array ('center', 'left', 'left');
|
||||
} else {
|
||||
|
||||
@@ -78,7 +78,7 @@ $strnodeadline = get_string("nodeadline", "lesson");
|
||||
$table = new html_table();
|
||||
|
||||
if ($usesections) {
|
||||
$strsectionname = get_string('sectionname', 'format_'.$course->format);
|
||||
$strsectionname = course_get_format($course)->get_generic_section_name();
|
||||
$table->head = array ($strsectionname, $strname, $strgrade, $strdeadline);
|
||||
$table->align = array ("center", "left", "center", "center");
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ $table = new html_table();
|
||||
$table->attributes['class'] = 'generaltable mod_index';
|
||||
|
||||
if ($usesections) {
|
||||
$strsectionname = get_string('sectionname', 'format_'.$course->format);
|
||||
$strsectionname = course_get_format($course)->get_generic_section_name();
|
||||
$table->head = array ($strsectionname, $strname);
|
||||
$table->align = array ("center", "left");
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ $table = new html_table();
|
||||
$table->attributes['class'] = 'generaltable mod_index';
|
||||
|
||||
if ($usesections) {
|
||||
$strsectionname = get_string('sectionname', 'format_'.$course->format);
|
||||
$strsectionname = course_get_format($course)->get_generic_section_name();
|
||||
$table->head = array ($strsectionname, $strname, $strintro);
|
||||
$table->align = array ('center', 'left', 'left');
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ array_push($headings, get_string('quizcloses', 'quiz'));
|
||||
array_push($align, 'left');
|
||||
|
||||
if (course_format_uses_sections($course->format)) {
|
||||
array_unshift($headings, get_string('sectionname', 'format_'.$course->format));
|
||||
array_unshift($headings, course_get_format($course)->get_generic_section_name());
|
||||
} else {
|
||||
array_unshift($headings, '');
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ $event->trigger();
|
||||
|
||||
$strresource = get_string('modulename', 'resource');
|
||||
$strresources = get_string('modulenameplural', 'resource');
|
||||
$strsectionname = get_string('sectionname', 'format_'.$course->format);
|
||||
$strsectionname = course_get_format($course)->get_generic_section_name();
|
||||
$strname = get_string('name');
|
||||
$strintro = get_string('moduleintro');
|
||||
$strlastmodified = get_string('lastmodified');
|
||||
|
||||
+2
-2
@@ -65,7 +65,7 @@ if (! $scorms = get_all_instances_in_course("scorm", $course)) {
|
||||
$table = new html_table();
|
||||
|
||||
if ($usesections) {
|
||||
$strsectionname = get_string('sectionname', 'format_'.$course->format);
|
||||
$strsectionname = course_get_format($course)->get_generic_section_name();
|
||||
$table->head = array ($strsectionname, $strname, $strsummary, $strreport);
|
||||
$table->align = array ("center", "left", "left", "left");
|
||||
} else {
|
||||
@@ -116,4 +116,4 @@ echo html_writer::empty_tag('br');
|
||||
|
||||
echo html_writer::table($table);
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
$table = new html_table();
|
||||
|
||||
if ($usesections) {
|
||||
$strsectionname = get_string('sectionname', 'format_'.$course->format);
|
||||
$strsectionname = course_get_format($course)->get_generic_section_name();
|
||||
$table->head = array ($strsectionname, $strname, $strstatus);
|
||||
} else {
|
||||
$table->head = array ($strname, $strstatus);
|
||||
@@ -89,5 +89,3 @@
|
||||
echo "<br />";
|
||||
echo html_writer::table($table);
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ $table = new html_table();
|
||||
$table->attributes['class'] = 'generaltable mod_index';
|
||||
|
||||
if ($usesections) {
|
||||
$strsectionname = get_string('sectionname', 'format_'.$course->format);
|
||||
$strsectionname = course_get_format($course)->get_generic_section_name();
|
||||
$table->head = array ($strsectionname, $strname, $strintro);
|
||||
$table->align = array ('center', 'left', 'left');
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -75,7 +75,7 @@ $strname = get_string("name");
|
||||
$table = new html_table();
|
||||
|
||||
if ($usesections) {
|
||||
$strsectionname = get_string('sectionname', 'format_' . $course->format);
|
||||
$strsectionname = course_get_format($course)->get_generic_section_name();
|
||||
$table->head = array($strsectionname, $strname);
|
||||
} else {
|
||||
$table->head = array($strname);
|
||||
|
||||
@@ -63,7 +63,7 @@ $strname = get_string('name');
|
||||
$table = new html_table();
|
||||
|
||||
if ($usesections) {
|
||||
$strsectionname = get_string('sectionname', 'format_'.$course->format);
|
||||
$strsectionname = course_get_format($course)->get_generic_section_name();
|
||||
$table->head = array ($strsectionname, $strname);
|
||||
$table->align = array ('center', 'left');
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user