X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fprofile%2Fmentor.inc.php;h=7a14e2de157086d6970deb175cbbb05e1cc7e8a6;hb=2b13c66c646c46b57037bc6b1ff0adf84988b3fc;hp=dc0492ac2f0af925a113b7e2659107e40019d726;hpb=8def9eb54fa949fce13b35a4e26add2a8118e6aa;p=platal.git diff --git a/modules/profile/mentor.inc.php b/modules/profile/mentor.inc.php index dc0492a..7a14e2d 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) { @@ -52,43 +63,41 @@ class ProfileSettingSectors implements ProfileSetting return $value; } - public function save(ProfilePage &$page, $field, $value) + public function save(ProfilePage $page, $field, $value) { - XDB::execute("DELETE FROM profile_mentor_sector + 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 (pid, 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) { - $sectors = array(); - foreach ($value as $sector) { - foreach ($sector as $subsector) { - $sectors[] = $subsector; - } + $terms = array(); + foreach ($value as &$term) { + $terms[] = $term['full_name']; } - return implode(', ', $sectors); + return implode(', ', $terms); } } class ProfileSettingCountry implements ProfileSetting { - public function value(ProfilePage &$page, $field, $value, &$success) + public function value(ProfilePage $page, $field, $value, &$success) { $success = true; if (is_null($value)) { $value = array(); - $res = XDB::iterRow("SELECT m.country, gc.countryFR + $res = XDB::iterRow("SELECT m.country, gc.country FROM profile_mentor_country AS m INNER JOIN geoloc_countries AS gc ON (m.country = gc.iso_3166_1_a2) WHERE m.pid = {?}", @@ -106,7 +115,7 @@ class ProfileSettingCountry implements ProfileSetting return $value; } - public function save(ProfilePage &$page, $field, $value) + public function save(ProfilePage $page, $field, $value) { XDB::execute("DELETE FROM profile_mentor_country WHERE pid = {?}", @@ -124,15 +133,15 @@ class ProfileSettingCountry implements ProfileSetting } -class ProfileSettingMentor extends ProfilePage +class ProfilePageMentor extends ProfilePage { protected $pg_template = 'profile/mentor.tpl'; - public function __construct(PlWizard &$wiz) + public function __construct(PlWizard $wiz) { parent::__construct($wiz); $this->settings['expertise'] = null; - $this->settings['sectors'] = new ProfileSettingSectors(); + $this->settings['terms'] = new ProfileSettingTerms(); $this->settings['countries'] = new ProfileSettingCountry(); } @@ -155,22 +164,21 @@ class ProfileSettingMentor extends ProfilePage $this->pid()); $this->values['expertise'] = null; } else { - XDB::execute("REPLACE INTO profile_mentor (pid, expertise) - VALUES ({?}, {?})", + XDB::execute('INSERT INTO profile_mentor (pid, expertise) + VALUES ({?}, {?}) + ON DUPLICATE KEY UPDATE expertise = VALUES(expertise)', $this->pid(), $expertise); $this->values['expertise'] = $expertise; } } } - public function _prepare(PlPage &$page, $id) + 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 + $page->assign('countryList', XDB::iterator("SELECT iso_3166_1_a2, country FROM geoloc_countries - ORDER BY countryFR")); + ORDER BY country")); + $page->assign('hrpid', $this->profile->hrpid); } }