diff --git a/.upgradenotes/MDL-82349-2024111211161866.yml b/.upgradenotes/MDL-82349-2024111211161866.yml new file mode 100644 index 00000000000..4b68ee38048 --- /dev/null +++ b/.upgradenotes/MDL-82349-2024111211161866.yml @@ -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 diff --git a/course/format/classes/base.php b/course/format/classes/base.php index 663aba3a0c6..97810344112 100644 --- a/course/format/classes/base.php +++ b/course/format/classes/base.php @@ -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. * diff --git a/course/format/classes/output/local/content/bulkedittoggler.php b/course/format/classes/output/local/content/bulkedittoggler.php index e0975cd75a3..59450f5ac2b 100644 --- a/course/format/classes/output/local/content/bulkedittoggler.php +++ b/course/format/classes/output/local/content/bulkedittoggler.php @@ -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; diff --git a/course/format/tests/base_test.php b/course/format/tests/base_test.php index a0f9b2238e4..efd55c536eb 100644 --- a/course/format/tests/base_test.php +++ b/course/format/tests/base_test.php @@ -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() + ); + } } /** diff --git a/course/resources.php b/course/resources.php index 350c9bd65d7..43f053938f1 100644 --- a/course/resources.php +++ b/course/resources.php @@ -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 { diff --git a/course/section.php b/course/section.php index 0fe81a5b6e2..e1f6162acbd 100644 --- a/course/section.php +++ b/course/section.php @@ -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, diff --git a/course/view.php b/course/view.php index 900607f0112..ecf7fa4ed9b 100644 --- a/course/view.php +++ b/course/view.php @@ -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, diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 46588ccbd1f..cd05752a2e8 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -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); diff --git a/mod/bigbluebuttonbn/classes/output/index.php b/mod/bigbluebuttonbn/classes/output/index.php index 2bc8012bcbd..c57e6f875c9 100644 --- a/mod/bigbluebuttonbn/classes/output/index.php +++ b/mod/bigbluebuttonbn/classes/output/index.php @@ -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 = ''; } diff --git a/mod/book/index.php b/mod/book/index.php index 3c91e8ed892..6fc2867c5b1 100644 --- a/mod/book/index.php +++ b/mod/book/index.php @@ -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 { diff --git a/mod/chat/index.php b/mod/chat/index.php index be83bd57595..3c89547d889 100644 --- a/mod/chat/index.php +++ b/mod/chat/index.php @@ -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(); - diff --git a/mod/choice/index.php b/mod/choice/index.php index 5616a1c89fa..2ed8ea84621 100644 --- a/mod/choice/index.php +++ b/mod/choice/index.php @@ -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(); - - diff --git a/mod/data/index.php b/mod/data/index.php index b2c603c678e..8cbf07dad72 100644 --- a/mod/data/index.php +++ b/mod/data/index.php @@ -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 "
"; echo html_writer::tag('div', html_writer::table($table), array('class'=>'no-overflow')); echo $OUTPUT->footer(); - diff --git a/mod/feedback/index.php b/mod/feedback/index.php index 704b74a4e46..3f582171f81 100644 --- a/mod/feedback/index.php +++ b/mod/feedback/index.php @@ -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'); diff --git a/mod/folder/index.php b/mod/folder/index.php index 7bafe8c1987..f5e567fedf3 100644 --- a/mod/folder/index.php +++ b/mod/folder/index.php @@ -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 { diff --git a/mod/forum/index.php b/mod/forum/index.php index 0b2191c7c94..b16354094a6 100644 --- a/mod/forum/index.php +++ b/mod/forum/index.php @@ -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'); diff --git a/mod/glossary/index.php b/mod/glossary/index.php index 50245774733..fafb91eb1ec 100644 --- a/mod/glossary/index.php +++ b/mod/glossary/index.php @@ -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(); - diff --git a/mod/imscp/index.php b/mod/imscp/index.php index f2c7257ceb7..2c78249cf28 100644 --- a/mod/imscp/index.php +++ b/mod/imscp/index.php @@ -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 { diff --git a/mod/lesson/index.php b/mod/lesson/index.php index 3da15f96df3..10fed60a097 100644 --- a/mod/lesson/index.php +++ b/mod/lesson/index.php @@ -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 { diff --git a/mod/lti/index.php b/mod/lti/index.php index 1a0e97b6b62..f3582f41966 100644 --- a/mod/lti/index.php +++ b/mod/lti/index.php @@ -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 { diff --git a/mod/page/index.php b/mod/page/index.php index 53138b2b945..108aa86f8f2 100644 --- a/mod/page/index.php +++ b/mod/page/index.php @@ -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 { diff --git a/mod/quiz/index.php b/mod/quiz/index.php index 640bddaf3a9..766549c8933 100644 --- a/mod/quiz/index.php +++ b/mod/quiz/index.php @@ -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, ''); } diff --git a/mod/resource/index.php b/mod/resource/index.php index 17598411545..e176a103a5e 100644 --- a/mod/resource/index.php +++ b/mod/resource/index.php @@ -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'); diff --git a/mod/scorm/index.php b/mod/scorm/index.php index 95e9f9da295..cca951a4991 100644 --- a/mod/scorm/index.php +++ b/mod/scorm/index.php @@ -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(); \ No newline at end of file +echo $OUTPUT->footer(); diff --git a/mod/survey/index.php b/mod/survey/index.php index edbdf079d74..f979543b6c7 100644 --- a/mod/survey/index.php +++ b/mod/survey/index.php @@ -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 "
"; echo html_writer::table($table); echo $OUTPUT->footer(); - - diff --git a/mod/url/index.php b/mod/url/index.php index 869eed21a3e..e44411e55e2 100644 --- a/mod/url/index.php +++ b/mod/url/index.php @@ -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 { diff --git a/mod/wiki/index.php b/mod/wiki/index.php index b9039bb8aff..0bdcc8b4c69 100644 --- a/mod/wiki/index.php +++ b/mod/wiki/index.php @@ -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); diff --git a/mod/workshop/index.php b/mod/workshop/index.php index eba17ae1627..281a526ebf2 100644 --- a/mod/workshop/index.php +++ b/mod/workshop/index.php @@ -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 {