X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;ds=sidebyside;f=modules%2Fprofile%2Fgeneral.inc.php;h=4359cacbaacf5e60345e17710df56f28b2578546;hb=a6483c122527912e19f708b0c54086d620251c26;hp=2449a6c6097cb086396af52e2d65b7dc53bdaa98;hpb=93d42b4fcc6f055a428c9b63e386ac62c918d08a;p=platal.git diff --git a/modules/profile/general.inc.php b/modules/profile/general.inc.php index 2449a6c..4359cac 100644 --- a/modules/profile/general.inc.php +++ b/modules/profile/general.inc.php @@ -23,6 +23,11 @@ class ProfileSettingSearchNames implements ProfileSetting { private $private_name_end; private $search_names; + private $name_types; + + public function __construct() { + $this->name_types = DirEnum::getOptions(DirEnum::NAMES); + } private function matchWord($old, $new, $newLen) { @@ -47,12 +52,33 @@ class ProfileSettingSearchNames implements ProfileSetting || ($field == 'lastname' && $new == 'DE ' . $ini); if (!$success) { $field = strtolower($field); - Platal::page()->trigError("Le " . $field . " que tu as choisi (" . $value . - ") est trop loin de ton " . $field . " initial (" . $init . ")."); + Platal::page()->trigError("Le " . $this->name_types[$field] . " que tu as choisi (" . $value . + ") est trop loin de ton " . $this->name_types[$field] . " initial (" . $init . ")."); } return $success ? $value : $init; } + /* Removes duplicated entries for the fields that do not allow them. */ + private function clean($value) + { + $single_types = XDB::fetchAllAssoc('id', + 'SELECT id, 0 + FROM profile_name_enum + WHERE NOT FIND_IN_SET(\'allow_duplicates\', flags)'); + + foreach ($value as $key => $item) { + if (isset($single_types[$item['typeid']])) { + if ($single_types[$item['typeid']] === true) { + unset($value[$key]); + } else { + $single_types[$item['typeid']] = true; + } + } + } + + return $value; + } + public function value(ProfilePage &$page, $field, $value, &$success) { $success = true; @@ -101,9 +127,11 @@ class ProfileSettingSearchNames implements ProfileSetting $value[] = $sn; } while ($sn = $sn_all->next()); } + $value = $this->clean($value); } else { require_once 'name.func.inc.php'; + $value = $this->clean($value); $res = XDB::query("SELECT s.particle, s.name FROM profile_name AS s INNER JOIN profile_name_enum AS e ON (e.id = s.typeid) @@ -172,24 +200,25 @@ class ProfileSettingSearchNames implements ProfileSetting public function save(ProfilePage &$page, $field, $value) { require_once 'name.func.inc.php'; - $sn_old = build_sn_pub(); + $sn_old = build_sn_pub($page->pid()); XDB::execute("DELETE FROM s 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)", $page->pid()); - $has_new = set_alias_names($this->search_names, $sn_old); + $has_new = set_alias_names($this->search_names, $sn_old, $page->pid(), $page->owner->id()); // 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é prise en compte." . - " Tu recevras un email dès que ces changements auront été effectués."); + Platal::page()->trigWarning('La demande de modification de tes noms a bien été prise 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); + build_display_names($display_names, $this->search_names, + $page->profile->isFemale(), $this->private_name_end); + set_profile_display($display_names, $page->pid()); } } } @@ -563,6 +592,7 @@ class ProfileSettingGeneral extends ProfilePage $res = $res->fetchOneRow(); $page->assign('public_name', $res[0]); $page->assign('private_name', $res[1]); + $page->assign('isFemale', $this->profile->isFemale() ? 1 : 0); } }