Commit ea77fbdb authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Merge changes I0da8d834,I832a1877

* changes:
  Bug #1705162 Send institution invitations in correct language.
  Bug 1703608: Selecting the lang for inst membership confirmation messages
parents 503424a6 bf501442
......@@ -1137,22 +1137,41 @@ class ActivityTypeInstitutionmessage extends ActivityType {
}
}
private function get_language($user) {
$userlang = get_account_preference($user->id, 'lang');
if ($userlang === 'default') {
if (!isset($this->institution->language) || $this->institution->language === '' || $this->institution->language === 'default') {
return get_config('lang');
}
else {
return $this->institution->language;
}
}
else {
return $userlang;
}
}
public function get_subject($user) {
$lang = $this->get_language($user);
if ($this->messagetype == 'request') {
$userstring = $this->fullname . ' (' . $this->username . ')';
return get_string_from_language($user->lang, 'institutionrequestsubject', 'activity', $userstring,
$this->institution->displayname);
} else if ($this->messagetype == 'invite') {
return get_string_from_language($user->lang, 'institutioninvitesubject', 'activity',
$this->institution->displayname);
return get_string_from_language($lang, 'institutionrequestsubject', 'activity', $userstring,
$this->institution->displayname);
}
else if ($this->messagetype == 'invite') {
return get_string_from_language($lang, 'institutioninvitesubject', 'activity',
$this->institution->displayname);
}
}
public function get_message($user) {
$lang = $this->get_language($user);
if ($this->messagetype == 'request') {
return $this->get_subject($user) .' '. get_string_from_language($user->lang, 'institutionrequestmessage', 'activity', $this->url);
} else if ($this->messagetype == 'invite') {
return $this->get_subject($user) .' '. get_string_from_language($user->lang, 'institutioninvitemessage', 'activity', $this->url);
return $this->get_subject($user) .' '. get_string_from_language($lang, 'institutionrequestmessage', 'activity', $this->url);
}
else if ($this->messagetype == 'invite') {
return $this->get_subject($user) .' '. get_string_from_language($lang, 'institutioninvitemessage', 'activity', $this->url);
}
}
......
......@@ -299,16 +299,18 @@ class Institution {
$user = get_record('usr', 'id', $user);
}
if ($lang = get_account_preference($user->id, 'lang')) {
// The user has a preset lang preference so we will use this
}
else if ($this->lang != 'default') {
// The user hasn't been added yet, so we have to manually use this institution's lang
$lang = $this->lang;
}
else {
$lang = get_user_language($user->id);
$lang = get_account_preference($user->id, 'lang');
if ($lang == 'default') {
// The user does not have a preset lang preference so we will use the institution if it has one.
$institution_lang = !empty($this->configs['lang']) ? $this->configs['lang'] : 'default';
if ($institution_lang != 'default') {
$lang = $institution_lang;
}
else {
$lang = get_config('lang');
}
}
$userinst = new StdClass;
$userinst->institution = $this->name;
$studentid = get_field('usr_institution_request', 'studentid', 'usr', $user->id,
......@@ -420,7 +422,7 @@ class Institution {
'messagetype' => 'request',
'username' => $user->username,
'fullname' => $user->firstname . ' ' . $user->lastname,
'institution' => (object)array('name' => $this->name, 'displayname' => $this->displayname),
'institution' => (object)array('name' => $this->name, 'displayname' => $this->displayname, 'language' => $this->lang),
);
db_begin();
if (!get_config('usersallowedmultipleinstitutions')) {
......@@ -506,7 +508,7 @@ class Institution {
activity_occurred('institutionmessage', (object) array(
'messagetype' => 'invite',
'users' => array($userid),
'institution' => (object)array('name' => $this->name, 'displayname' => $this->displayname),
'institution' => (object)array('name' => $this->name, 'displayname' => $this->displayname, 'language' => $this->lang),
));
handle_event('updateuser', $userid);
db_commit();
......
Markdown is supported
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