X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fprofile%2Fmentor.inc.php;h=3aa41403a156232538615609db9e4b06bd668953;hb=3ac45f10c6b54e4db4bfeb0aeb5eef0f5ee5d1b2;hp=2ecb60b653b895a356003ee4ffb0a6e645269905;hpb=353f2d2b11c4e3c6c0bc3553813368b6f42fa9c6;p=platal.git diff --git a/modules/profile/mentor.inc.php b/modules/profile/mentor.inc.php index 2ecb60b..3aa4140 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); - } else { - $value[$s][$ss] = $ssname; - } - } + $value = $res->fetchAllAssoc(); } elseif (!is_array($value)) { $value = array(); - } elseif (count($value) > 10) { - Platal::page()->trigError("Le nombre de secteurs d'expertise est limité à 10."); + } elseif (count($value) > 20) { + Platal::page()->trigError("Le nombre de mots clefs d'expertise est limité à 20."); $success = false; + } else { + $missing_full_names = array(); + foreach ($value as &$term) if (empty($term['full_name'])) { + $missing_full_names[] = $term['jtid']; + } + if (count($missing_full_names)) { + $res = XDB::query('SELECT jtid, full_name + FROM profile_job_term_enum + WHERE jtid IN {?}', + $missing_full_names); + $term_id_to_name = $res->fetchAllAssoc('jtid', false); + foreach ($value as &$term) { + if (empty($term['full_name'])) { + $term['full_name'] = $term_id_to_name[$term['jtid']]; + } + } + } } ksort($value); foreach ($value as &$sss) { @@ -55,23 +66,31 @@ class ProfileSectors implements ProfileSetting public function save(ProfilePage &$page, $field, $value) { - XDB::execute("DELETE FROM profile_mentor_sector - WHERE uid = {?}", + XDB::execute("DELETE FROM profile_mentor_term + WHERE pid = {?}", $page->pid()); if (!count($value)) { return; } - foreach ($value as $id => $sect) { - foreach ($sect as $sid => $name) { - XDB::execute("INSERT INTO profile_mentor_sector (uid, sectorid, subsectorid) - VALUES ({?}, {?}, {?})", - $page->pid(), $id, $sid); - } + $mentor_term_values = array(); + foreach ($value as &$term) { + $mentor_term_values[] = '('.XDB::escape($page->pid()).', '.XDB::escape($term['jtid']).')'; } + XDB::execute('INSERT INTO profile_mentor_term (pid, jtid) + VALUES '.implode(',', $mentor_term_values)); + + } + + public function getText($value) { + $terms = array(); + foreach ($value as &$term) { + $terms[] = $term['full_name']; + } + return implode(', ', $terms); } } -class ProfileCountry implements ProfileSetting +class ProfileSettingCountry implements ProfileSetting { public function value(ProfilePage &$page, $field, $value, &$success) { @@ -81,7 +100,7 @@ class ProfileCountry implements ProfileSetting $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 = {?}", + WHERE m.pid = {?}", $page->pid()); while (list($id, $name) = $res->next()) { $value[$id] = $name; @@ -99,18 +118,22 @@ class ProfileCountry implements ProfileSetting public function save(ProfilePage &$page, $field, $value) { XDB::execute("DELETE FROM profile_mentor_country - WHERE uid = {?}", + WHERE pid = {?}", $page->pid()); foreach ($value as $id=>&$name) { - XDB::execute("INSERT INTO profile_mentor_country (uid, country) + XDB::execute("INSERT INTO profile_mentor_country (pid, country) VALUES ({?}, {?})", $page->pid(), $id); } } + + public function getText($value) { + return implode(', ', $value); + } } -class ProfileMentor extends ProfilePage +class ProfileSettingMentor extends ProfilePage { protected $pg_template = 'profile/mentor.tpl'; @@ -118,15 +141,15 @@ class ProfileMentor extends ProfilePage { parent::__construct($wiz); $this->settings['expertise'] = null; - $this->settings['sectors'] = new ProfileSectors(); - $this->settings['countries'] = new ProfileCountry(); + $this->settings['terms'] = new ProfileSettingTerms(); + $this->settings['countries'] = new ProfileSettingCountry(); } protected function _fetchData() { $res = XDB::query("SELECT expertise FROM profile_mentor - WHERE uid = {?}", + WHERE pid = {?}", $this->pid()); $this->values['expertise'] = $res->fetchOneCell(); } @@ -137,11 +160,11 @@ class ProfileMentor extends ProfilePage $expertise = trim($this->values['expertise']); if (empty($expertise)) { XDB::execute("DELETE FROM profile_mentor - WHERE uid = {?}", + WHERE pid = {?}", $this->pid()); $this->values['expertise'] = null; } else { - XDB::execute("REPLACE INTO profile_mentor (uid, expertise) + XDB::execute("REPLACE INTO profile_mentor (pid, expertise) VALUES ({?}, {?})", $this->pid(), $expertise); $this->values['expertise'] = $expertise; @@ -151,12 +174,10 @@ class ProfileMentor extends ProfilePage public function _prepare(PlPage &$page, $id) { - $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")); + $page->assign('hrpid', $this->profile->hrpid); } }