From: Florent Bruneau Date: Wed, 21 Jan 2009 12:49:40 +0000 (+0100) Subject: Merge commit 'origin/fusionax' into account X-Git-Tag: xorg/1.0.0~332^2~411 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=32742f846e13a7806dde6b7b912c423a46f933d8;p=platal.git Merge commit 'origin/fusionax' into account Conflicts: modules/profile/general.inc.php Signed-off-by: Florent Bruneau --- 32742f846e13a7806dde6b7b912c423a46f933d8 diff --cc classes/profile.php index 49109fb,0000000..b4843fd mode 100644,000000..100644 --- a/classes/profile.php +++ b/classes/profile.php @@@ -1,193 -1,0 +1,194 @@@ +id()); + } else if (is_numeric($login)) { + $from = 'profiles AS p'; + $where = XDB::format('p.pid = {?}', $login); + } else { + $from = 'profiles AS p'; + $where = XDB::format('p.hrpid = {?}', $login); + } + $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 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) . ') ++ INNER JOIN profile_name AS pns_f ON (pns_f.pid = p.pid AND pns_f.typeid = ' . self::getNameTypeId('Nom patronymique', true) . ') ++ INNER JOIN profile_name AS pns_l ON (pns_l.pid = p.pid AND pns_l.typeid = ' . self::getNameTypeId('Prénom', true) . ') ++ LEFT JOIN profile_name AS pns_uf ON (pns_uf.pid = p.pid AND pns_uf.typeid = ' . self::getNameTypeId('Prénom usuel', true) . ') ++ LEFT JOIN profile_name AS pns_ul ON (pns_ul.pid = p.pid AND pns_ul.typeid = ' . self::getNameTypeId('Nom usuel', true) . ') ++ LEFT JOIN profile_name aS pns_n ON (pns_n.pid = p.pid AND pns_n.typeid = ' . self::getNameTypeId('Surnom', true) . ') + WHERE ' . $where); + if ($res->numRows() != 1) { ++ __autoload('PlUser'); + throw new UserNotFoundException(); + } + $this->data = $res->fetchOneAssoc(); + $this->pid = $this->data['pid']; + $this->hrpid = $this->data['hrpid']; + } + + public function id() + { + return $this->pid; + } + + public function hrid() + { + return $this->hrpid; + } + + public function promo() + { + return $this->promo; + } + + /** Print a name with the given formatting: + * %s = • for women + * %f = firstname + * %l = lastname + * %F = fullname + * %S = shortname + * %p = promo + */ + public function name($format) + { + return str_replace(array('%s', '%f', '%l', '%F', '%S', '%p'), + array($this->isFemale() ? '•' : '', + $this->first_name, $this->last_name, + $this->full_name, $this->short_name, + $this->promo), $format); + } + + public function fullName($with_promo = false) + { + if ($with_promo) { + return $this->full_name . ' (' . $this->promo . ')'; + } + return $this->full_name; + } + + public function shortName($with_promo = false) + { + if ($with_promo) { + return $this->short_name . ' (' . $this->promo . ')'; + } + return $this->short_name; + } + + public function firstName() + { + return $this->first_name; + } + + public function lastName() + { + return $this->last_name; + } + + public function isFemale() + { + return $this->sex == PlUser::GENDER_FEMALE; + } + + public function data() + { + $this->first_name; + return $this->data; + } + + public function __get($name) + { + if (property_exists($this, $name)) { + return $this->$name; + } + + if (isset($this->data[$name])) { + return $this->data[$name]; + } + + return null; + } + + public function __isset($name) + { + return property_exists($this, $name) || isset($this->data[$name]); + } + + + public function owner() + { + return User::getSilent($this); + } + + /** Return the profile associated with the given login. + */ + public static function get($login) + { + try { + return new Profile($login); + } catch (UserNotFoundException $e) { + /* Let say we can identify a profile using the identifiers of its owner. + */ + if (!($login instanceof PlUser)) { + $user = User::getSilent($login); + if ($user && $user->hasProfile()) { + return $user->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'); ++ FROM profile_name_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 --cc modules/profile/general.inc.php index f260c16,33e9915..9856dc8 --- a/modules/profile/general.inc.php +++ b/modules/profile/general.inc.php @@@ -21,14 -21,10 +21,11 @@@ class ProfileSearchNames implements ProfileSetting { - private $public_name; - private $private_name; - private $directory_name; - private $short_name; - private $sort_name; + private $private_name_end; + private $search_names; - private function matchWord($old, $new, $newLen) { + private function matchWord($old, $new, $newLen) + { return ($i = strpos($old, $new)) !== false && ($i == 0 || $old{$i-1} == ' ') && ($i + $newLen == strlen($old) || $old{$i + $newLen} == ' '); @@@ -66,14 -62,15 +63,15 @@@ FIND_IN_SET('has_particle', e.flags) AS has_particle, FIND_IN_SET('always_displayed', e.flags) AS always_displayed, FIND_IN_SET('public', e.flags) AS pub - FROM profile_name_search AS sn - INNER JOIN profile_name_search_enum AS e ON (e.id = sn.typeid) + FROM profile_name AS sn + INNER JOIN profile_name_enum AS e ON (e.id = sn.typeid) WHERE sn.pid = {?} AND NOT FIND_IN_SET('not_displayed', e.flags) ORDER BY NOT FIND_IN_SET('always_displayed', e.flags), e.id, sn.name", - S::v('uid')); + $page->pid()); - $sn_types = XDB::iterator("SELECT id, name, FIND_IN_SET('has_particle', flags) AS has_particle - FROM profile_name_search_enum + $sn_types = XDB::iterator("SELECT id, type, name, + FIND_IN_SET('has_particle', flags) AS has_particle + FROM profile_name_enum WHERE NOT FIND_IN_SET('not_displayed', flags) AND FIND_IN_SET('always_displayed', flags) ORDER BY id"); @@@ -83,36 -80,39 +81,41 @@@ while ($sn_type = $sn_types->next()) { if ($sn_type['id'] == $sn['typeid']) { $value[] = $sn; - $sn = $sn_all->next(); + if ($sn) { + $sn = $sn_all->next(); + } } else { - $value[] = array('typeid' => $sn_type['id'], - 'type' => $sn_type['name'], - 'pub' => 1, + $value[] = array('typeid' => $sn_type['id'], + 'type' => $sn_type['type'], + 'type_name' => $sn_type['name'], + 'pub' => 1, 'has_particle' => $sn_type['has_particle'], 'always_displayed' => 1); } } - while ($sn) { - $value[] = $sn; - $sn = $sn_all->next(); + if ($sn) { + do { + $value[] = $sn; + } while ($sn = $sn_all->next()); } } else { + require_once 'name.func.inc.php'; + $res = XDB::query("SELECT s.particle, s.name - FROM profile_name_search AS s - INNER JOIN profile_name_search_enum AS e ON (e.id = s.typeid) - WHERE s.pid = {?} AND e.name LIKE '%initial' - ORDER BY e.name = 'Prénom initial'", + FROM profile_name AS s + INNER JOIN profile_name_enum AS e ON (e.id = s.typeid) + WHERE s.pid = {?} AND e.type LIKE '%ini' + ORDER BY e.type = 'firstname_ini'", - S::i('uid')); + $page->pid()); $res = $res->fetchAllAssoc(); $initial = array(); - $initial['Nom patronymique'] = $res[0]['particle'] . $res[0]['name']; - $initial['Prénom'] = $res[1]['name']; - $search_names = array(); - foreach ($value as $key => &$sn) { + $initial['lastname'] = $res[0]['particle'] . $res[0]['name']; + $initial['firstname'] = $res[1]['name']; + $sn_types = build_types(); + $this->search_names = array(); + foreach ($value as &$sn) { $sn['name'] = trim($sn['name']); - if ($sn['type'] == 'Prénom' || $sn['type'] == 'Nom patronymique') { + if ($sn['type'] == 'firstname' || $sn['type'] == 'lastname') { $sn['name'] = $this->prepare($page, $sn['type'], $sn['name'], $initial[$sn['type']], $success_tmp); $success = $success && $success_tmp; @@@ -142,38 -164,26 +167,26 @@@ public function save(ProfilePage &$page, $field, $value) { + require_once 'name.func.inc.php'; + $sn_old = build_sn_pub(); XDB::execute("DELETE FROM s - USING profile_name_search AS s - INNER JOIN profile_name_search_enum AS e ON (s.typeid = e.id) + USING profile_name AS s + INNER JOIN profile_name_enum AS e ON (s.typeid = e.id) WHERE s.pid = {?} AND NOT FIND_IN_SET('not_displayed', e.flags)", - S::i('uid')); + $page->pid()); - foreach ($value as $sn) { - if ($sn['name'] != '') { - if ($sn['particle']) { - list($particle, $name) = explode(' ', $sn['name'], 2); - $particle = trim($particle) . ' '; - if (!$name) { - list($particle, $name) = explode('\'', $sn['name'], 2); - $particle = trim($particle); - } - } else { - $particle = ''; - $name = $sn['name']; - } - $name = trim($name); - XDB::execute("INSERT INTO profile_name_search (particle, name, typeid, pid) - VALUES ({?}, {?}, {?}, {?})", - $particle, $name, $sn['typeid'], $page->pid()); - } + $has_new = set_alias_names($this->search_names, $sn_old); + + // Only requires validation if modification in public names + if ($has_new) { + $new_names = new NamesReq(S::user(), $this->search_names, $this->private_name_end); + $new_names->submit(); + Platal::page()->trigWarning("La demande de modification de tes noms a bien été prises en compte." . + " Tu recevras un email dès que ces changements auront été effectués."); + } else { + $display_names = array(); + build_display_names($display_names, $this->search_names, $this->private_name_end); + set_profile_display($display_names); } - XDB::execute("UPDATE profile_display - SET public_name = {?}, private_name = {?}, - directory_name = {?}, short_name = {?}, sort_name = {?} - WHERE pid = {?}", - $this->public_name, $this->private_name, $this->directory_name, - $this->short_name, $this->sort_name, $page->pid()); - /*require_once('user.func.inc.php'); - user_reindex(S::v('uid'));*/ } }