X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fprofile%2Fmentor.inc.php;h=4fc7b944236567b9aae4e13e7bf4d8ed8b767168;hb=541e8d0307af50554cdd030fc35e5cdac30dd355;hp=928987899f7ccc2661e86a0e001b3ed09705cee8;hpb=179afa7fa79902e11498314d37fe4dbf452b3617;p=platal.git diff --git a/modules/profile/mentor.inc.php b/modules/profile/mentor.inc.php index 9289878..4fc7b94 100644 --- a/modules/profile/mentor.inc.php +++ b/modules/profile/mentor.inc.php @@ -1,6 +1,6 @@ next()) { @@ -42,8 +42,7 @@ class ProfileSecteurs 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); @@ -56,7 +55,7 @@ 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')); if (!count($value)) { @@ -64,7 +63,7 @@ class ProfileSecteurs implements ProfileSetting } foreach ($value as $id=>&$sect) { foreach ($sect as $sid=>&$name) { - XDB::execute("INSERT INTO mentor_secteurs (uid, secteur, ss_secteur) + XDB::execute("INSERT INTO profile_mentor_sector (uid, sectorid, subsectorid) VALUES ({?}, {?}, {?})", S::i('uid'), $id, $sid); } @@ -79,9 +78,9 @@ 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')); while (list($id, $name) = $res->next()) { @@ -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); @@ -100,11 +98,11 @@ 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')); 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); } @@ -120,7 +118,7 @@ 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(); } @@ -130,22 +128,35 @@ class ProfileMentor extends ProfilePage FROM mentor WHERE uid = {?}", S::i('uid')); - $this->value['expertise'] = $res->fetchOneCell(); + $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 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) { - $page->assign('secteurs_sel', XDB::iterator("SELECT id, label - FROM emploi_secteur")); + $page->assign('sectors', 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")); } }