Commit d3e9f5a8 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Use notified user's language for strings created by email,emaildigest notifications

parent a86a6d7d
......@@ -32,30 +32,32 @@ class PluginNotificationEmail extends PluginNotification {
public static function notify_user($user, $data) {
$lang = (empty($user->lang) || $user->lang == 'default') ? get_config('lang') : $user->lang;
$sitename = get_config('sitename');
$fulltype = get_string('type' . $data->activityname, 'activity');
$subject = get_string('emailsubject', 'notification.email', $sitename, $fulltype);
$fulltype = get_string_from_language($lang, 'type' . $data->activityname, 'activity');
$subject = get_string_from_language($lang, 'emailsubject', 'notification.email', $sitename, $fulltype);
if (!empty($data->subject)) {
$subject .= ': ' . $data->subject;
}
if (!empty($data->userfrom)) {
$userfrom = get_record('usr', 'id', $data->userfrom);
$messagebody = get_string('emailbody', 'notification.email', $sitename)
. get_string('subject') . ': ' . $data->subject . "\n\n"
$messagebody = get_string_from_language($lang, 'emailbody', 'notification.email', $sitename)
. get_string_from_language($lang, 'subject') . ': ' . $data->subject . "\n\n"
. $data->message;
}
else {
$userfrom = null;
$messagebody = get_string('emailbodynoreply', 'notification.email', $sitename)
. get_string('subject') . ': ' . $data->subject . "\n\n"
$messagebody = get_string_from_language($lang, 'emailbodynoreply', 'notification.email', $sitename)
. get_string_from_language($lang, 'subject') . ': ' . $data->subject . "\n\n"
. $data->message;
}
if (!empty($data->url)) {
$messagebody .= "\n\n" . get_string('referurl', 'notification.email', $data->url);
$messagebody .= "\n\n" . get_string_from_language($lang, 'referurl', 'notification.email', $data->url);
}
$prefurl = get_config('wwwroot') . 'account/activity/preferences/';
$messagebody .= "\n\n" . get_string('emailbodyending', 'notification.email', $prefurl);
$messagebody .= "\n\n" . get_string_from_language($lang, 'emailbodyending', 'notification.email', $prefurl);
email_user($user, $userfrom, $subject, $messagebody);
}
}
......
......@@ -55,10 +55,12 @@ class PluginNotificationEmaildigest extends PluginNotification {
$users = array();
$sitename = get_config('sitename');
$sql = 'SELECT q.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.admin, u.staff, q.*,' . db_format_tsfield('ctime').'
$sql = 'SELECT q.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.admin, u.staff,
p.value AS lang, q.*,' . db_format_tsfield('ctime').'
FROM {usr} u
JOIN {notification_emaildigest_queue} q
ON q.usr = u.id
LEFT OUTER JOIN {usr_account_preference} p ON (p.usr = u.id AND p.field = \'lang\')
ORDER BY usr,type,q.ctime';
if ($tosend = get_records_sql_array($sql, array())) {
......@@ -75,21 +77,24 @@ class PluginNotificationEmaildigest extends PluginNotification {
$users[$queue->usr]->user->admin = $queue->admin;
$users[$queue->usr]->user->staff = $queue->staff;
$users[$queue->usr]->user->id = $queue->usr;
$users[$queue->usr]->user->lang = (empty($queue->lang) || $queue->lang == 'default') ? get_config('lang') : $queue->lang;
$users[$queue->usr]->entries = array();
}
$queue->nicetype = get_string('type' . $queue->type, 'activity');
$queue->nicetype = get_string_from_language($users[$queue->usr]->user->lang,
'type' . $queue->type, 'activity');
$users[$queue->usr]->entries[$queue->id] = $queue;
}
}
foreach ($users as $user) {
$subject = get_string('emailsubject', 'notification.emaildigest', $sitename);
$body = get_string('emailbodynoreply', 'notification.emaildigest', $sitename);
$lang = $user->user->lang;
$subject = get_string_from_language($lang, 'emailsubject', 'notification.emaildigest', $sitename);
$body = get_string_from_language($lang, 'emailbodynoreply', 'notification.emaildigest', $sitename);
foreach ($user->entries as $entry) {
$body .= get_string('type', 'activity') . ': ' . $entry->nicetype
. ' ' . get_string('attime', 'activity') . ' ' . format_date($entry->ctime) . "\n";
$body .= get_string_from_language($lang, 'type', 'activity') . ': ' . $entry->nicetype
. ' ' . get_string_from_language($lang, 'attime', 'activity') . ' ' . format_date($entry->ctime) . "\n";
if (!empty($queue->subject)) {
$body .= get_string('subject') . $queue->subject ."\n";
$body .= get_string_from_language($lang, 'subject') . $queue->subject ."\n";
}
if (!empty($queue->message)) {
$body .= "\n" . $queue->message;
......@@ -100,7 +105,7 @@ class PluginNotificationEmaildigest extends PluginNotification {
$body .= "\n\n";
}
$prefurl = get_config('wwwroot') . 'account/activity/preferences/';
$body .= "\n\n" . get_string('emailbodyending', 'notification.emaildigest', $prefurl);
$body .= "\n\n" . get_string_from_language($lang, 'emailbodyending', 'notification.emaildigest', $prefurl);
try {
email_user($user->user, null, $subject, $body);
//only delete them if the email succeeded!
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment