Commit 27086dbf authored by Richard Mansfield's avatar Richard Mansfield
Browse files
parents ba8da71f 823385fe
......@@ -70,7 +70,7 @@ class Session {
'admin' => false,
'firstname' => '',
'lastname' => '',
'prefname' => '',
'preferredname' => '',
'email' => '',
'accountprefs' => array(),
'activityprefs' => array(),
......
......@@ -50,7 +50,6 @@ $offset = param_integer('offset', 0);
$data = search_user($query, $limit, $offset);
foreach ($data['results'] as &$result) {
// @todo should call magical display user function
$result['name'] = display_name($result);
unset($result['email']);
......@@ -58,7 +57,7 @@ foreach ($data['results'] as &$result) {
unset($result['username']);
unset($result['firstname']);
unset($result['lastname']);
unset($result['prefname']);
unset($result['preferredname']);
}
print json_encode($data);
......
......@@ -47,7 +47,7 @@ function form_render_userlist($element, Form $form) {
}
if (is_array($value) && count($value)) {
$members = get_records_select('usr','id IN (' . join(',',$value) . ')', null, '', 'id,firstname,lastname,prefname');
$members = get_records_select('usr','id IN (' . join(',',$value) . ')', null, '', 'id,firstname,lastname,preferredname');
foreach($members as &$member) {
$member = display_name($member);
......
......@@ -1008,7 +1008,7 @@ function site_menu() {
/**
* Always use this function for all emails to users
*
* @param object $userto user object to send email to. must contain firstname,lastname,prefname,email
* @param object $userto user object to send email to. must contain firstname,lastname,preferredname,email
* @param object $userfrom user object to send email from. If null, email will come from mahara
* @param string $subject email subject
* @param string $messagetext text version of email
......@@ -1059,14 +1059,14 @@ function email_user($userto, $userfrom, $subject, $messagetext, $messagehtml='')
else {
$mail->Sender = $userfrom->email;
$mail->From = $mail->Sender;
$mail->FromName = display_name($userfrom);
$mail->FromName = display_name($userfrom, $userto);
}
$mail->AddReplyTo($mail->From, $mail->FromName);
$mail->Subject = substr(stripslashes($subject), 0, 78);
$usertoname = display_name($userto);
$usertoname = display_name($userto, $userto);
$mail->AddAddress($userto->email, $usertoname );
$mail->WordWrap = 79;
......@@ -1089,12 +1089,37 @@ function email_user($userto, $userfrom, $subject, $messagetext, $messagehtml='')
. "Error from phpmailer was: " . $mail->ErrorInfo );
}
function display_name($user) {
function display_name($user, $userto=null) {
global $USER;
if (empty($userto)) {
$userto = $USER;
}
if (is_array($user)) {
$user = (object)$user;
}
return $user->firstname . ' ' . $user->lastname;
// @todo
else if (is_numeric($user)) {
$user = get_record('usr', 'id', $user);
}
if (!is_object($user)) {
throw new InvalidArgumentException("Invalid user passed to display_name");
}
// if they don't have a preferred name set, just return here
if (empty($user->preferredname)) {
return $user->firstname . ' ' . $user->lastname;
}
$prefix = get_config('dbprefix');
$sql = 'SELECT c1.member
FROM ' . $prefix . 'community_member c1
JOIN ' .$prefix. 'community_member c2
ON c1.community = c2.community
WHERE c1.member = ? AND c2.member = ? AND c2.tutor = ?';
if (record_exists_sql($sql, array($user->id, $userto->id, 1))) {
return $user->preferredname . ' (' . $user->firstname . ' ' . $user->lastname . ')';
}
return $user->preferredname;
}
/**
......
......@@ -40,22 +40,22 @@ defined('INTERNAL') || die();
* offset => integer, // starting from which result
* results => array( // the result records
* array(
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* prefname => string,
* email => string,
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* preferredname => string,
* email => string,
* ),
* array(
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* prefname => string,
* email => string,
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* preferredname => string,
* email => string,
* ),
* array(...),
* ),
......
......@@ -53,7 +53,7 @@ class PluginNotificationEmaildigest extends PluginNotification {
public static function send_digest() {
$users = array();
$sql = 'SELECT q.id, u.firstname,u.lastname,u.prefname,u.email,q.*,' . db_format_tsfield('ctime').'
$sql = 'SELECT q.id, u.firstname,u.lastname,u.preferredname,u.email,q.*,' . db_format_tsfield('ctime').'
FROM ' . get_config('dbprefix') . 'usr u
JOIN ' . get_config('dbprefix') . 'notification_emaildigest_queue q
ON q.usr = u.id
......@@ -65,11 +65,11 @@ class PluginNotificationEmaildigest extends PluginNotification {
$users[$queue->usr] = new StdClass;
$users[$queue->usr]->user = new StdClass;
$users[$queue->usr]->user->firstname = $queue->firstname;
$users[$queue->usr]->user->lastname = $queue->lastname;
$users[$queue->usr]->user->prefname = $queue->prefname;
$users[$queue->usr]->user->email = $queue->email;
$users[$queue->usr]->user->id = $queue->usr;
$users[$queue->usr]->user->firstname = $queue->firstname;
$users[$queue->usr]->user->lastname = $queue->lastname;
$users[$queue->usr]->user->preferredname = $queue->preferredname;
$users[$queue->usr]->user->email = $queue->email;
$users[$queue->usr]->user->id = $queue->usr;
$users[$queue->usr]->entries = array();
}
......
......@@ -45,22 +45,22 @@ class PluginSearchInternal extends PluginSearch {
* offset => integer, // starting from which result
* results => array( // the result records
* array(
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* prefname => string,
* email => string,
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* preferredname => string,
* email => string,
* ),
* array(
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* prefname => string,
* email => string,
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* preferredname => string,
* email => string,
* ),
* array(...),
* ),
......@@ -70,13 +70,13 @@ class PluginSearchInternal extends PluginSearch {
if ( is_postgres() ) {
$data = get_rows_sql("
SELECT
id, username, institution, firstname, lastname, prefname, email
id, username, institution, firstname, lastname, preferredname, email
FROM
" . get_config('dbprefix') . "usr u
WHERE
firstname ILIKE '%' || ? || '%'
OR lastname ILIKE '%' || ? || '%'
OR prefname ILIKE '%' || ? || '%'
OR preferredname ILIKE '%' || ? || '%'
OR email ILIKE '%' || ? || '%'
",
array($query_string, $query_string, $query_string, $query_string),
......@@ -92,7 +92,7 @@ class PluginSearchInternal extends PluginSearch {
WHERE
firstname ILIKE '%' || ? || '%'
OR lastname ILIKE '%' || ? || '%'
OR prefname ILIKE '%' || ? || '%'
OR preferredname ILIKE '%' || ? || '%'
OR email ILIKE '%' || ? || '%'
",
array($query_string, $query_string, $query_string, $query_string),
......
......@@ -44,23 +44,24 @@ abstract class PluginSearch {
* limit => integer, // how many results are returned
* offset => integer, // starting from which result
* results => array( // the result records
* array(
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* prefname => string,
* email => string,
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* preferredname => string,
* email => string,
* ),
* array(
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* prefname => string,
* email => string,
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* preferredname => string,
* email => string,
* ),
* array(...),
* ),
......
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