Skip to content
Snippets Groups Projects
Unverified Commit 67cdd305 authored by Tobias Reischmann's avatar Tobias Reischmann
Browse files

Added email placeholder for courses

parent 37e1e6bf
No related branches found
No related tags found
No related merge requests found
...@@ -107,7 +107,7 @@ class email extends libbase { ...@@ -107,7 +107,7 @@ class email extends libbase {
array('instanceid' => $step->id, array('instanceid' => $step->id,
'touser' => $user->id)); 'touser' => $user->id));
$parsedsettings = $this->replace_placeholders($settings, $user, $step->id); $parsedsettings = $this->replace_placeholders($settings, $user, $step->id, $mailentries);
$subject = $parsedsettings['subject']; $subject = $parsedsettings['subject'];
$content = $parsedsettings['content']; $content = $parsedsettings['content'];
...@@ -129,29 +129,72 @@ class email extends libbase { ...@@ -129,29 +129,72 @@ class email extends libbase {
* @param mixed $user user object * @param mixed $user user object
* @return string[] array of mail text. * @return string[] array of mail text.
*/ */
private function replace_placeholders($strings, $user, $stepid) { private function replace_placeholders($strings, $user, $stepid, $mailentries) {
global $CFG; global $CFG;
$patterns = array(); $patterns = array();
$replacements = array(); $replacements = array();
// Replaces firstname of the user.
$patterns [] = '##firstname##'; $patterns [] = '##firstname##';
$replacements [] = $user->firstname; $replacements [] = $user->firstname;
// Replaces lastname of the user.
$patterns [] = '##lastname##'; $patterns [] = '##lastname##';
$replacements [] = $user->lastname; $replacements [] = $user->lastname;
// Replace link to interaction page.
$url = $CFG->wwwroot . '/' . $this->get_interaction_link($stepid)->out(); $url = $CFG->wwwroot . '/' . $this->get_interaction_link($stepid)->out();
$patterns [] = '##link##'; $patterns [] = '##link##';
$replacements [] = $url; $replacements [] = $url;
// Replace html link to interaction page.
$patterns [] = '##link-html##'; $patterns [] = '##link-html##';
$replacements [] = \html_writer::link($url, $url); $replacements [] = \html_writer::link($url, $url);
// Replace courses list.
$patterns [] = '##courses##';
$coursesstring = '';
$coursesstring .= $this->parse_course(array_pop($mailentries)->courseid);
foreach ($mailentries as $entry) {
$coursesstring .= "\n" . $this->parse_course($entry->courseid);
}
$replacements [] = $coursesstring;
// Replace courses html.
$patterns [] = '##courses-html##';
$coursestabledata = array();
foreach ($mailentries as $entry) {
$coursestabledata[$entry->courseid] = $this->parse_course_row_data($entry->courseid);
}
$coursestable = new \html_table();
$coursestable->data = $coursestabledata;
$replacements [] = \html_writer::table($coursestable);
return str_ireplace($patterns, $replacements, $strings); return str_ireplace($patterns, $replacements, $strings);
} }
/**
* Parses a course for the non html format.
* @param int $courseid id of the course
* @return string
*/
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
*/
private function parse_course_row_data($courseid) {
$course = get_course($courseid);
return array($course->fullname);
}
public function instance_settings() { public function instance_settings() {
return array( return array(
new instance_setting('responsetimeout', PARAM_INT), new instance_setting('responsetimeout', PARAM_INT),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment