← Back to team overview

mahara-contributors team mailing list archive

[Bug 1705162] Re: Send institution messages for new users in the correct language

 

I'll propose something like:

class ActivityTypeInstitutionmessage extends ActivityType {

    protected $messagetype;
    protected $institution;
    protected $username;
    protected $fullname;

    public function __construct($data, $cron=false) {
        parent::__construct($data, $cron);
        if ($this->messagetype == 'request') {
            $this->url = 'admin/users/institutionusers.php';
            $this->users = activity_get_users($this->get_id(), null, null, null,
                                              array($this->institution->name));
            $this->add_urltext(array('key' => 'institutionmembers', 'section' => 'admin'));
        } else if ($this->messagetype == 'invite') {
            $this->url = 'account/institutions.php';
            $this->users = activity_get_users($this->get_id(), $this->users);
            $this->add_urltext(array('key' => 'institutionmembership', 'section' => 'mahara'));
        }
        $this->institution = new Institution($this->institution->name);
    }

    private function get_language($user, $institution) {
        if (!isset($user->lang) || $user->lang === '' || $user->lang === 'default') {
            if (!isset($institution->lang) || $institution->lang === '' || $institution->lang === 'default') {
                return get_config('lang') ? get_config('lang') : '';
            }
            else return $institution->lang;
        }
        else return $user->lang;
    }

    public function get_subject($user) {
        $lang = $this->get_language($user, $this->institution);
        if ($this->messagetype == 'request') {
            $userstring = $this->fullname . ' (' . $this->username . ')';
            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, $this->institution);
        if ($this->messagetype == 'request') {
            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);
        }
    }

    public function get_required_parameters() {
        return array('messagetype', 'institution');
    }
}

-- 
You received this bug notification because you are a member of Mahara
Contributors, which is subscribed to Mahara.
Matching subscriptions: Subscription for all Mahara Contributors -- please ask on #mahara-dev or mahara.org forum before editing or unsubscribing it!
https://bugs.launchpad.net/bugs/1705162

Title:
  Send institution messages for new users in the correct language

Status in Mahara:
  Confirmed

Bug description:
  1. When a site admin registers a new user, the account information
  message, i.e. the one that contains the username and password, is sent
  in the language of the admin but should be sent in the institution's
  language (as the user doesn't yet exist and therefore doesn't yet have
  a language preference).

  2. When a site admin or institution admin invites a user to another
  institution, that message should be sent in the language of the user
  that is being invited rather than the admin's language or the site
  language.

  If the user hasn't set a language specifically, the new institution's
  language should be used (See bug 1703608).

To manage notifications about this bug go to:
https://bugs.launchpad.net/mahara/+bug/1705162/+subscriptions


References