Skip to content

Commit

Permalink
Email: add ##shortcourses## placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
justusdieckmann committed Jun 10, 2024
1 parent bd2aca6 commit ba23724
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 40 deletions.
2 changes: 2 additions & 0 deletions step/email/lang/de/lifecyclestep_email.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
. '<br>' . 'Nachname des Empfängers: ##lastname##'
. '<br>' . 'Link zur Antwortseite: ##link##'
. '<br>' . 'Betroffene Kurse: ##courses##'
. '<br>' . 'Kurznamen betroffener Kurse: ##shortcourses##'
. '</p>';
$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!)' . '<p>' . 'Sie können die folgenden Platzhalter benutzen:'
Expand All @@ -45,6 +46,7 @@
. '<br>' . 'Nachname des Empfängers: ##lastname##'
. '<br>' . 'Link zur Antwortseite: ##link##'
. '<br>' . 'Betroffene Kurse: ##courses##'
. '<br>' . 'Kurznamen betroffener Kurse: ##shortcourses-html##'
. '</p>';
$string['keep_course'] = 'Kurs behalten';
$string['pluginname'] = 'Email-Schritt';
Expand Down
2 changes: 2 additions & 0 deletions step/email/lang/en/lifecyclestep_email.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@
. '<br>' . 'Last name of recipient: ##lastname##'
. '<br>' . 'Link to response page: ##link##'
. '<br>' . 'Impacted courses: ##courses##'
. '<br>' . 'Short names of impacted courses: ##shortcourses##'
. '</p>';
$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!)' . '<p>' . 'You can use the following placeholders:'
. '<br>' . 'First name of recipient: ##firstname##'
. '<br>' . 'Last name of recipient: ##lastname##'
. '<br>' . 'Link to response page: ##link-html##'
. '<br>' . 'Impacted courses: ##courses-html##'
. '<br>' . 'Short names of impacted courses: ##shortcourses-html##'
. '</p>';
$string['email_responsetimeout'] = 'Time the user has for the response';
$string['email_subject'] = 'Subject template';
Expand Down
60 changes: 20 additions & 40 deletions step/email/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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("<br>", $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("<br>", $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
Expand Down

0 comments on commit ba23724

Please sign in to comment.