X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fprofile%2Fmentor.inc.php;h=06b1ac9482224659c31bde6d21ffb47a2b87609a;hb=9f5bd98e936d8cef7ca9f774eeef64dbb8a1b079;hp=fbc06ecc63e88a1ba89943574cc900500f3f6915;hpb=ddb649901f5a88d695a7050f2a59da140842ec89;p=platal.git diff --git a/modules/profile/mentor.inc.php b/modules/profile/mentor.inc.php index fbc06ec..06b1ac9 100644 --- a/modules/profile/mentor.inc.php +++ b/modules/profile/mentor.inc.php @@ -1,6 +1,6 @@ 10) { - global $page; - $page->trig("Le nombre de secteurs d'expertise est limité à 10"); + Platal::page()->trigError("Le nombre de secteurs d'expertise est limité à 10"); $success = false; } ksort($value); @@ -90,8 +89,7 @@ class ProfileCountry implements ProfileSetting } else if (!is_array($value)) { $value = array(); } else if (count($value) > 10) { - global $page; - $page->trig("Le nombre de secteurs d'expertise est limité à 10"); + Platal::page()->trigError("Le nombre de secteurs d'expertise est limité à 10"); $success = false; } ksort($value); @@ -124,33 +122,35 @@ class ProfileMentor extends ProfilePage $this->settings['countries'] = new ProfileCountry(); } - protected function fetchData() + protected function _fetchData() { - if (count($this->orig) > 0) { - $this->values = $this->orig; - return; - } $res = XDB::query("SELECT expertise FROM mentor WHERE uid = {?}", S::i('uid')); - $this->value['expertise'] = $res->fetchOneCell(); - parent::fetchData(); + $this->values['expertise'] = $res->fetchOneCell(); } - protected function saveData() + protected function _saveData() { - parent::saveData(); if ($this->changed['expertise']) { - XDB::execute("REPLACE INTO mentor (uid, expertise) - VALUES ({?}, {?})", - S::i('uid'), $this->values['expertise']); + $expertise = trim($this->values['expertise']); + if (empty($expertise)) { + XDB::execute("DELETE FROM mentor + WHERE uid = {?}", + S::i('uid')); + $this->values['expertise'] = null; + } else { + XDB::execute("REPLACE INTO mentor (uid, expertise) + VALUES ({?}, {?})", + S::i('uid'), $expertise); + $this->values['expertise'] = $expertise; + } } } - public function prepare(PlatalPage &$page, $id) + public function _prepare(PlPage &$page, $id) { - parent::prepare($page, $id); $page->assign('secteurs_sel', XDB::iterator("SELECT id, label FROM emploi_secteur")); }