From 8f592b3e3bb63109069075a56546e315d657c008 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Fri, 22 Oct 2021 10:11:18 +0100 Subject: [PATCH] MDL-72894 course: format name and summary data for download. The names and summaries of course elements (i.e. the course itself, plus sections and modules) included when downloading it's content are now passed through appropriate methods to format their values. --- .../exportable_items/exportable_textarea.php | 6 ++ .../export/exporters/course_exporter.php | 60 +++++++++++-------- lib/classes/content/export/zipwriter.php | 7 ++- 3 files changed, 46 insertions(+), 27 deletions(-) diff --git a/lib/classes/content/export/exportable_items/exportable_textarea.php b/lib/classes/content/export/exportable_items/exportable_textarea.php index 246d4786129..2e69d402962 100644 --- a/lib/classes/content/export/exportable_items/exportable_textarea.php +++ b/lib/classes/content/export/exportable_items/exportable_textarea.php @@ -141,6 +141,12 @@ class exportable_textarea extends exportable_item { $exporteditem->set_content($text); } + if (!empty($this->textformatfield)) { + $formattedcontent = format_text($exporteditem->get_content(), $record->{$this->textformatfield}, + ['context' => $this->get_context()]); + $exporteditem->set_content($formattedcontent); + } + $exporteditem->set_title($this->get_user_visible_name()); return $exporteditem; } diff --git a/lib/classes/content/export/exporters/course_exporter.php b/lib/classes/content/export/exporters/course_exporter.php index cc22730db42..7d9e9c085d2 100644 --- a/lib/classes/content/export/exporters/course_exporter.php +++ b/lib/classes/content/export/exporters/course_exporter.php @@ -118,7 +118,8 @@ class course_exporter extends component_exporter { if ($summarydata->has_any_data()) { $hascontent = true; - $templatedata->summary = $summarydata->get_content(); + $templatedata->summary = format_text($summarydata->get_content(), $this->course->summaryformat, + ['context' => $this->get_context()]); } } @@ -161,20 +162,28 @@ class course_exporter extends component_exporter { protected function get_course_section(array $exportedcontexts, section_info $section): stdClass { $sectiondata = (object) [ 'number' => $section->section, - 'title' => $section->name, + 'title' => format_string($section->name, true, ['context' => $this->get_context()]), 'summary' => '', 'activities' => [], ]; - $sectiondata->summary = $this->get_archive()->add_pluginfiles_for_content( - $this->get_context(), - "_course", - $section->summary, - 'course', - 'section', - $section->id, - $section->id - )->get_template_data()->content; + // Fetch the section summary content. + if ($section->summary) { + $summarydata = $this->get_archive()->add_pluginfiles_for_content( + $this->get_context(), + '_course', + $section->summary, + 'course', + 'section', + $section->id, + $section->id + ); + + if ($summarydata->has_any_data()) { + $sectiondata->summary = format_text($summarydata->get_content(), $section->summaryformat, + ['context' => $this->get_context()]); + } + } if (empty($this->modinfo->sections[$section->section])) { return $sectiondata; @@ -196,7 +205,7 @@ class course_exporter extends component_exporter { $url = $cm->url; } $sectiondata->activities[] = (object) [ - 'title' => $cm->name, + 'title' => $cm->get_formatted_name(), 'modname' => $cm->modfullname, 'link' => $url, ]; @@ -253,20 +262,23 @@ class course_exporter extends component_exporter { $cm = $this->modinfo->get_cm($modcontext->instanceid); $modname = $cm->modname; - $record = $DB->get_record($modname, ['id' => $cm->instance], 'intro'); + $record = $DB->get_record($modname, ['id' => $cm->instance], 'intro,introformat'); - $exporteditem = $this->get_archive()->add_pluginfiles_for_content( - $modcontext, - '', - $record->intro, - "mod_{$modname}", - 'intro', - 0, - null - ); + // Fetch the module intro content. + if ($record->intro) { + $exporteditem = $this->get_archive()->add_pluginfiles_for_content( + $modcontext, + '', + $record->intro, + "mod_{$modname}", + 'intro', + 0, + null + ); - if ($exporteditem->has_any_data()) { - return $exporteditem->get_content(); + if ($exporteditem->has_any_data()) { + return format_text($exporteditem->get_content(), $record->introformat, ['context' => $modcontext]); + } } return null; diff --git a/lib/classes/content/export/zipwriter.php b/lib/classes/content/export/zipwriter.php index 960fa8bf1bf..85d12510c83 100644 --- a/lib/classes/content/export/zipwriter.php +++ b/lib/classes/content/export/zipwriter.php @@ -249,6 +249,7 @@ class zipwriter { $exportedcourse = $this->get_course(); $courselink = (new moodle_url('/course/view.php', ['id' => $exportedcourse->id]))->out(false); + $coursename = format_string($exportedcourse->fullname, true, ['context' => $this->coursecontext]); $this->add_template_requirements(); @@ -260,16 +261,16 @@ class zipwriter { 'pathtotop' => $this->get_relative_context_path($context, $this->rootcontext, '/'), 'contentexportfooter' => get_string('contentexport_footersummary', 'core', (object) [ 'courselink' => $courselink, - 'coursename' => $exportedcourse->fullname, + 'coursename' => $coursename, 'userfullname' => fullname($USER), 'date' => userdate(time()), ]), 'contentexportsummary' => get_string('contentexport_coursesummary', 'core', (object) [ 'courselink' => $courselink, - 'coursename' => $exportedcourse->fullname, + 'coursename' => $coursename, 'date' => userdate(time()), ]), - 'coursename' => $exportedcourse->fullname, + 'coursename' => $coursename, 'courseshortname' => $exportedcourse->shortname, 'courselink' => $courselink, 'exportdate' => userdate(time()),