X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fprofile%2Fmentor.inc.php;h=2ecb60b653b895a356003ee4ffb0a6e645269905;hb=483da16573717c21c7e6da3eacc094048ab7d72f;hp=d1509a83f362504e6b426d2cc4e2a76de5213ceb;hpb=730a173a333507926e0029d8a96c3a26b55756e4;p=platal.git diff --git a/modules/profile/mentor.inc.php b/modules/profile/mentor.inc.php index d1509a8..2ecb60b 100644 --- a/modules/profile/mentor.inc.php +++ b/modules/profile/mentor.inc.php @@ -1,6 +1,6 @@ pid()); while (list($s, $ss, $ssname) = $res->next()) { if (!isset($value[$s])) { $value[$s] = array($ss => $ssname); @@ -39,11 +39,10 @@ class ProfileSecteurs implements ProfileSetting $value[$s][$ss] = $ssname; } } - } else if (!is_array($value)) { + } elseif (!is_array($value)) { $value = array(); - } else if (count($value) > 10) { - global $page; - $page->trig("Le nombre de secteurs d'expertise est limité à 10"); + } elseif (count($value) > 10) { + Platal::page()->trigError("Le nombre de secteurs d'expertise est limité à 10."); $success = false; } ksort($value); @@ -56,17 +55,17 @@ class ProfileSecteurs implements ProfileSetting public function save(ProfilePage &$page, $field, $value) { - XDB::execute("DELETE FROM mentor_secteurs + XDB::execute("DELETE FROM profile_mentor_sector WHERE uid = {?}", - S::i('uid')); + $page->pid()); if (!count($value)) { return; } - foreach ($value as $id=>&$sect) { - foreach ($sect as $sid=>&$name) { - XDB::execute("INSERT INTO mentor_secteurs (uid, secteur, ss_secteur) + foreach ($value as $id => $sect) { + foreach ($sect as $sid => $name) { + XDB::execute("INSERT INTO profile_mentor_sector (uid, sectorid, subsectorid) VALUES ({?}, {?}, {?})", - S::i('uid'), $id, $sid); + $page->pid(), $id, $sid); } } } @@ -79,19 +78,18 @@ class ProfileCountry implements ProfileSetting $success = true; if (is_null($value)) { $value = array(); - $res = XDB::iterRow("SELECT m.pid, p.pays - FROM mentor_pays AS m - INNER JOIN geoloc_pays AS p ON(m.pid = p.a2) + $res = XDB::iterRow("SELECT m.country, gc.countryFR + FROM profile_mentor_country AS m + INNER JOIN geoloc_countries AS gc ON (m.country = gc.iso_3166_1_a2) WHERE m.uid = {?}", - S::i('uid')); + $page->pid()); while (list($id, $name) = $res->next()) { $value[$id] = $name; } } 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); @@ -100,13 +98,13 @@ class ProfileCountry implements ProfileSetting public function save(ProfilePage &$page, $field, $value) { - XDB::execute("DELETE FROM mentor_pays + XDB::execute("DELETE FROM profile_mentor_country WHERE uid = {?}", - S::i('uid')); + $page->pid()); foreach ($value as $id=>&$name) { - XDB::execute("INSERT INTO mentor_pays (uid, pid) + XDB::execute("INSERT INTO profile_mentor_country (uid, country) VALUES ({?}, {?})", - S::i('uid'), $id); + $page->pid(), $id); } } } @@ -120,32 +118,45 @@ class ProfileMentor extends ProfilePage { parent::__construct($wiz); $this->settings['expertise'] = null; - $this->settings['secteurs'] = new ProfileSecteurs(); + $this->settings['sectors'] = new ProfileSectors(); $this->settings['countries'] = new ProfileCountry(); } protected function _fetchData() { $res = XDB::query("SELECT expertise - FROM mentor + FROM profile_mentor WHERE uid = {?}", - S::i('uid')); + $this->pid()); $this->values['expertise'] = $res->fetchOneCell(); } protected function _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 profile_mentor + WHERE uid = {?}", + $this->pid()); + $this->values['expertise'] = null; + } else { + XDB::execute("REPLACE INTO profile_mentor (uid, expertise) + VALUES ({?}, {?})", + $this->pid(), $expertise); + $this->values['expertise'] = $expertise; + } } } - public function _prepare(PlatalPage &$page, $id) + public function _prepare(PlPage &$page, $id) { - $page->assign('secteurs_sel', XDB::iterator("SELECT id, label - FROM emploi_secteur")); + $page->assign('sectorList', XDB::iterator('SELECT id, name + FROM profile_job_sector_enum')); + + $page->assign('countryList', XDB::iterator("SELECT iso_3166_1_a2, countryFR + FROM geoloc_countries + ORDER BY countryFR")); } }