Skip to content
Browse files

MDL-34635 support multilang in self enrol course welcome message

Includes also new help string for the custom multilang placeholders by Helen Foster.
  • Loading branch information...
1 parent 02814bf commit 56eda1f10a2c4ee481dd7a1717e8ec5307342e4d @skodak skodak committed
Showing with 27 additions and 10 deletions.
  1. +2 −1 enrol/self/edit_form.php
  2. +6 −0 enrol/self/lang/en/enrol_self.php
  3. +19 −9 enrol/self/lib.php
View
3 enrol/self/edit_form.php
@@ -105,6 +105,7 @@ function definition() {
$mform->addHelpButton('customint4', 'sendcoursewelcomemessage', 'enrol_self');
$mform->addElement('textarea', 'customtext1', get_string('customwelcomemessage', 'enrol_self'), array('cols'=>'60', 'rows'=>'8'));
+ $mform->addHelpButton('customtext1', 'customwelcomemessage', 'enrol_self');
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
@@ -176,4 +177,4 @@ function extend_assignable_roles($context, $defaultrole) {
}
return $roles;
}
-}
+}
View
6 enrol/self/lang/en/enrol_self.php
@@ -25,6 +25,12 @@
*/
$string['customwelcomemessage'] = 'Custom welcome message';
+$string['customwelcomemessage_help'] = 'A custom welcome message may be added as plain text or Moodle-auto format, including HTML tags and multi-lang tags.
+
+The following placeholders may be included in the message:
+
+* Course name {$a->coursename}
+* Link to user\'s profile page {$a->profileurl}';
$string['defaultrole'] = 'Default role assignment';
$string['defaultrole_desc'] = 'Select role which should be assigned to users during self enrolment';
$string['editenrolment'] = 'Edit enrolment';
View
28 enrol/self/lib.php
@@ -74,7 +74,7 @@ public function get_instance_name($instance) {
if (empty($instance->name)) {
if (!empty($instance->roleid) and $role = $DB->get_record('role', array('id'=>$instance->roleid))) {
- $role = ' (' . role_get_name($role, get_context_instance(CONTEXT_COURSE, $instance->courseid)) . ')';
+ $role = ' (' . role_get_name($role, context_course::instance($instance->courseid, IGNORE_MISSING)) . ')';
} else {
$role = '';
}
@@ -115,7 +115,7 @@ public function add_course_navigation($instancesnode, stdClass $instance) {
throw new coding_exception('Invalid enrol instance type!');
}
- $context = get_context_instance(CONTEXT_COURSE, $instance->courseid);
+ $context = context_course::instance($instance->courseid);
if (has_capability('enrol/self:config', $context)) {
$managelink = new moodle_url('/enrol/self/edit.php', array('courseid'=>$instance->courseid, 'id'=>$instance->id));
$instancesnode->add($this->get_instance_name($instance), $managelink, navigation_node::TYPE_SETTING);
@@ -133,7 +133,7 @@ public function get_action_icons(stdClass $instance) {
if ($instance->enrol !== 'self') {
throw new coding_exception('invalid enrol instance!');
}
- $context = get_context_instance(CONTEXT_COURSE, $instance->courseid);
+ $context = context_course::instance($instance->courseid);
$icons = array();
@@ -151,7 +151,7 @@ public function get_action_icons(stdClass $instance) {
* @return moodle_url page url
*/
public function get_newinstance_link($courseid) {
- $context = get_context_instance(CONTEXT_COURSE, $courseid, MUST_EXIST);
+ $context = context_course::instance($courseid, MUST_EXIST);
if (!has_capability('moodle/course:enrolconfig', $context) or !has_capability('enrol/self:config', $context)) {
return NULL;
@@ -267,22 +267,32 @@ protected function email_welcome_message($instance, $user) {
global $CFG, $DB;
$course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST);
+ $context = context_course::instance($course->id);
$a = new stdClass();
- $a->coursename = format_string($course->fullname);
+ $a->coursename = format_string($course->fullname, true, array('context'=>$context));
$a->profileurl = "$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id";
if (trim($instance->customtext1) !== '') {
$message = $instance->customtext1;
$message = str_replace('{$a->coursename}', $a->coursename, $message);
$message = str_replace('{$a->profileurl}', $a->profileurl, $message);
+ if (strpos($message, '<') === false) {
+ // Plain text only.
+ $messagetext = $message;
+ $messagehtml = text_to_html($messagetext, null, false, true);
+ } else {
+ // This is most probably the tag/newline soup known as FORMAT_MOODLE.
+ $messagehtml = format_text($message, FORMAT_MOODLE, array('context'=>$context, 'para'=>false, 'newlines'=>true, 'filter'=>true));
+ $messagetext = html_to_text($messagehtml);
+ }
} else {
- $message = get_string('welcometocoursetext', 'enrol_self', $a);
+ $messagetext = get_string('welcometocoursetext', 'enrol_self', $a);
+ $messagehtml = text_to_html($messagetext, null, false, true);
}
- $subject = get_string('welcometocourse', 'enrol_self', format_string($course->fullname));
+ $subject = get_string('welcometocourse', 'enrol_self', format_string($course->fullname, true, array('context'=>$context)));
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
$rusers = array();
if (!empty($CFG->coursecontact)) {
$croles = explode(',', $CFG->coursecontact);
@@ -295,7 +305,7 @@ protected function email_welcome_message($instance, $user) {
}
//directly emailing welcome message rather than using messaging
- email_to_user($user, $contact, $subject, $message);
+ email_to_user($user, $contact, $subject, $messagetext, $messagehtml);
}
/**

0 comments on commit 56eda1f

Please sign in to comment.
Something went wrong with that request. Please try again.