diff --git a/step/email/lang/de/lifecyclestep_email.php b/step/email/lang/de/lifecyclestep_email.php index b0fab933..f2710d1d 100644 --- a/step/email/lang/de/lifecyclestep_email.php +++ b/step/email/lang/de/lifecyclestep_email.php @@ -30,6 +30,7 @@ . '
' . 'Nachname des Empfängers: ##lastname##' . '
' . 'Link zur Antwortseite: ##link##' . '
' . 'Betroffene Kurse: ##courses##' + . '
' . 'Kurznamen betroffener Kurse: ##shortcourses##' . '

'; $string['email_content_html'] = 'HTML-Vorlage für Emails'; $string['email_content_html_help'] = 'Stellen sie die HTML-Vorlage für Emails ein. (in HTML-Format; falls gesetzt, wird es an Stelle der Klartext-Vorlage benutzt!)' . '

' . 'Sie können die folgenden Platzhalter benutzen:' @@ -45,6 +46,7 @@ . '
' . 'Nachname des Empfängers: ##lastname##' . '
' . 'Link zur Antwortseite: ##link##' . '
' . 'Betroffene Kurse: ##courses##' + . '
' . 'Kurznamen betroffener Kurse: ##shortcourses-html##' . '

'; $string['keep_course'] = 'Kurs behalten'; $string['pluginname'] = 'Email-Schritt'; diff --git a/step/email/lang/en/lifecyclestep_email.php b/step/email/lang/en/lifecyclestep_email.php index a0fd8ec4..e593339f 100644 --- a/step/email/lang/en/lifecyclestep_email.php +++ b/step/email/lang/en/lifecyclestep_email.php @@ -30,6 +30,7 @@ . '
' . 'Last name of recipient: ##lastname##' . '
' . 'Link to response page: ##link##' . '
' . 'Impacted courses: ##courses##' + . '
' . 'Short names of impacted courses: ##shortcourses##' . '

'; $string['email_content_html'] = 'Content HTML Template'; $string['email_content_html_help'] = 'Set the html template for the content of the email (HTML email, will be used instead of plaintext field if not empty!)' . '

' . 'You can use the following placeholders:' @@ -37,6 +38,7 @@ . '
' . 'Last name of recipient: ##lastname##' . '
' . 'Link to response page: ##link-html##' . '
' . 'Impacted courses: ##courses-html##' + . '
' . 'Short names of impacted courses: ##shortcourses-html##' . '

'; $string['email_responsetimeout'] = 'Time the user has for the response'; $string['email_subject'] = 'Subject template'; diff --git a/step/email/lib.php b/step/email/lib.php index f25b78bb..1dfcbbc2 100644 --- a/step/email/lib.php +++ b/step/email/lib.php @@ -27,7 +27,6 @@ use tool_lifecycle\local\manager\settings_manager; use tool_lifecycle\local\response\step_response; use tool_lifecycle\local\manager\step_manager; -use tool_lifecycle\local\manager\process_data_manager; use tool_lifecycle\settings_type; defined('MOODLE_INTERNAL') || die(); @@ -169,53 +168,34 @@ private function replace_placeholders($strings, $user, $stepid, $mailentries) { $patterns[] = '##link-html##'; $replacements[] = \html_writer::link($url, $url); - // Replace courses list. - $patterns[] = '##courses##'; - $courses = $mailentries; - $coursesstring = ''; - $coursesstring .= $this->parse_course(array_pop($courses)->courseid); - foreach ($courses as $entry) { - $coursesstring .= "\n" . $this->parse_course($entry->courseid); + $courses = []; + foreach ($mailentries as $entry) { + $courses[] = get_course($entry->courseid); } - $replacements[] = $coursesstring; - // Replace courses html. + // Replace courses list. + $coursesstrings = []; + foreach ($courses as $course) { + $coursesstrings[] = $course->fullname; + } + $patterns[] = '##courses##'; + $replacements[] = join("\n", $coursesstrings); $patterns[] = '##courses-html##'; - $courses = $mailentries; - $coursestabledata = []; - foreach ($courses as $entry) { - $coursestabledata[$entry->courseid] = $this->parse_course_row_data($entry->courseid); + $replacements[] = join("
", $coursesstrings); + + // Replace short courses list. + $coursesstrings = []; + foreach ($courses as $course) { + $coursesstrings[] = $course->shortname; } - $coursestable = new \html_table(); - $coursestable->data = $coursestabledata; - $replacements[] = \html_writer::table($coursestable); + $patterns[] = '##shortcourses##'; + $replacements[] = join("\n", $coursesstrings); + $patterns[] = '##shortcourses-html##'; + $replacements[] = join("
", $coursesstrings); return str_ireplace($patterns, $replacements, $strings); } - /** - * Parses a course for the non html format. - * @param int $courseid id of the course - * @return string - * @throws \dml_exception - */ - private function parse_course($courseid) { - $course = get_course($courseid); - $result = $course->fullname; - return $result; - } - - /** - * Parses a course for the html format. - * @param int $courseid id of the course - * @return array column of a course - * @throws \dml_exception - */ - private function parse_course_row_data($courseid) { - $course = get_course($courseid); - return [$course->fullname]; - } - /** * Defines which settings each instance of the subplugin offers for the user to define. * @return instance_setting[] containing settings keys and PARAM_TYPES