From a3118782f4caef2d97c1466f74a65c48f7a81b7d Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Thu, 15 Jan 2009 22:40:03 +0100 Subject: [PATCH] Fetch user names from profile_name_search. Signed-off-by: Florent Bruneau --- classes/profile.php | 40 ++++++++++++++++++++++++++++++---------- classes/user.php | 2 ++ modules/xnetgrp.php | 2 +- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/classes/profile.php b/classes/profile.php index 9c89e25..7eb1d94 100644 --- a/classes/profile.php +++ b/classes/profile.php @@ -38,17 +38,19 @@ class Profile $from = 'profiles AS p'; $where = XDB::format('p.hrpid = {?}', $login); } - // XXX: Temporary, use data from auth_user_md5 (waiting for data from newdirectory - $res = XDB::query('SELECT p.*, u.prenom AS first_name, - IF(u.nom_usage != "", u.nom_usage, u.nom) AS last_name, - pd.promo AS promo, - CONCAT(u.prenom, " ", u.nom) AS short_name, - IF(u.nom_usage != "", - CONCAT(u.nom_usage, " (", u.nom, "),", u.prenom), - CONCAT(u.nom, ", ", u.prenom)) AS full_name + $res = XDB::query('SELECT p.*, pe.entry_year, pe.grad_year, + pns_f.name AS firstname, pns_l.name AS lastname, pns_n.name AS nickname, + IF(pns_uf.name IS NULL, pns_f.name, pns_uf.name) AS firstname_usual, + IF(pns_ul.name IS NULL, pns_l.name, pns_ul.name) AS lastname_usual, + pd.promo AS promo, pd.short_name, pd.directory_name AS full_name FROM ' . $from . ' - INNER JOIN auth_user_md5 AS u ON (u.user_id = p.pid) INNER JOIN profile_display AS pd ON (pd.pid = p.pid) + INNER JOIN profile_education AS pe ON (pe.uid = p.pid AND FIND_IN_SET(\'primary\', pe.flags)) + INNER JOIN profile_name_search AS pns_f ON (pns_f.pid = p.pid AND pns_f.typeid = ' . self::getNameTypeId('Nom patronymique', true) . ') + INNER JOIN profile_name_search AS pns_l ON (pns_l.pid = p.pid AND pns_l.typeid = ' . self::getNameTypeId('Prénom', true) . ') + LEFT JOIN profile_name_search AS pns_uf ON (pns_uf.pid = p.pid AND pns_uf.typeid = ' . self::getNameTypeId('Prénom usuel', true) . ') + LEFT JOIN profile_name_search AS pns_ul ON (pns_ul.pid = p.pid AND pns_ul.typeid = ' . self::getNameTypeId('Nom usuel', true) . ') + LEFT JOIN profile_name_search aS pns_n ON (pns_n.pid = p.pid AND pns_n.typeid = ' . self::getNameTypeId('Surnom', true) . ') WHERE ' . $where); if ($res->numRows() != 1) { throw new UserNotFoundException(); @@ -153,7 +155,8 @@ class Profile /** Return the profile associated with the given login. */ - public static function get($login) { + public static function get($login) + { try { return new Profile($login); } catch (UserNotFoundException $e) { @@ -166,6 +169,23 @@ class Profile return null; } } + + public static function getNameTypeId($type, $for_sql = false) + { + if (!S::has('name_types')) { + $table = XDB::fetchAllAssoc('name', 'SELECT id, name + FROM profile_name_search_enum'); + S::set('name_types', $table); + } else { + $table = S::v('name_types'); + } + if ($for_sql) { + return XDB::escape($table[$type]); + } else { + return $table[$type]; + } + } + } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: diff --git a/classes/user.php b/classes/user.php index 5562e47..11e232e 100644 --- a/classes/user.php +++ b/classes/user.php @@ -188,6 +188,8 @@ class User extends PlUser } if (count($fields) > 0) { $fields = ', ' . implode(', ', $fields); + } else { + $fields = ''; } $uids = array_map(array('XDB', 'escape'), $uids); return XDB::iterator('SELECT a.uid, a.hruid, a.registration_date, diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index f8ad347..6f37d5a 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -1007,7 +1007,7 @@ class XnetGrpModule extends PLModule S::assert_xsrf_token(); // Convert user status to X - if (Post::blank('login_X'))) { + if (Post::blank('login_X')) { // TODO: Rewrite changeLogin!!! $forlife = $this->changeLogin($page, $user, $mmlist, Post::t('login_X')); if ($forlife) { -- 2.1.4