X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fprofile%2Fmentor.inc.php;h=279a105ccef4fee6482363f680ca4c2e0607ef93;hb=285e2fe72d086ae94fc95696a0cefc8755113277;hp=d026ed0c28446c2efcd84cf2efe4f73e8d8d1a9e;hpb=0073747ac81cc9cff9e43847eb008f0e815255f0;p=platal.git diff --git a/modules/profile/mentor.inc.php b/modules/profile/mentor.inc.php index d026ed0..279a105 100644 --- a/modules/profile/mentor.inc.php +++ b/modules/profile/mentor.inc.php @@ -1,6 +1,6 @@ table = $table; + $this->id = $id; + $this->skill_field = $skill; + $this->text_field = $text; + } + + public function value(ProfilePage $page, $field, $value, &$success) { - $success = true; if (is_null($value)) { $value = array(); - $res = XDB::iterRow("SELECT m.sectorid, m.subsectorid, ss.name - FROM profile_mentor_sector AS m - INNER JOIN profile_job_sector_enum AS s ON (m.sectorid = s.id) - INNER JOIN profile_job_subsector_enum AS ss ON (s.id = ss.sectorid AND m.subsectorid = ss.id) - WHERE m.pid = {?}", + $res = XDB::iterRow("SELECT s.{$this->id}, s.{$this->text_field}, i.level + FROM profile_{$this->table}_enum AS s + INNER JOIN profile_{$this->table}s AS i ON (s.{$this->id} = i.{$this->skill_field}) + WHERE i.pid = {?}", $page->pid()); - while (list($s, $ss, $ssname) = $res->next()) { - if (!isset($value[$s])) { - $value[$s] = array($ss => $ssname); - } else { - $value[$s][$ss] = $ssname; + while (list($sid, $text, $level) = $res->next()) { + $value[$sid] = array('text' => $text, 'level' => $level); + } + } + if (!is_array($value)) { + $value = array(); + } else { + foreach ($value as $id=>&$skill) { + if (!isset($skill['text']) || empty($skill['text'])) { + $res = XDB::query("SELECT {$this->text_field} + FROM profile_{$this->table}_enum + WHERE {$this->id} = {?}", $id); + $skill['text'] = $res->fetchOneCell(); } } + } + ksort($value); + $success = true; + return $value; + } + + public function save(ProfilePage $page, $field, $value) + { + XDB::execute("DELETE FROM profile_{$this->table}s + WHERE pid = {?}", + $page->pid()); + if (!count($value)) { + return; + } + foreach ($value as $id=>&$skill) { + XDB::execute("INSERT INTO profile_{$this->table}s (pid, {$this->skill_field}, level) + VALUES ({?}, {?}, {?})", + $page->pid(), $id, $skill['level']); + } + } + + public function getText($value) { + $skills = array(); + + if ($this->table == 'langskill') { + static $levels = array( + 1 => 'connaissance basique', + 2 => 'maîtrise des bases', + 3 => 'maîtrise limitée', + 4 => 'maîtrise générale', + 5 => 'bonne maîtrise', + 6 => 'maîtrise complète' + ); + foreach ($value as $skill) { + $skills[] = $skill['text'] . ' (' . $levels[$skill['level']] . ')'; + } + } else { + foreach ($value as $skill) { + $skills[] = $skill['text'] . ' (' . $skill['level'] . ')'; + } + } + + return implode(', ' , $skills); + } +} + +/** Terms associated to profile mentoring */ +class ProfileSettingTerms implements ProfileSetting +{ + public function value(ProfilePage $page, $field, $value, &$success) + { + $success = true; + if (is_null($value)) { + $value = array(); + $res = XDB::query('SELECT e.jtid, e.full_name + FROM profile_mentor_term AS m + INNER JOIN profile_job_term_enum AS e ON (m.jtid = e.jtid) + WHERE m.pid = {?}', + $page->pid()); + $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,33 +148,41 @@ class ProfileSectors 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) { + $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) + 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 = {?}", @@ -96,7 +200,7 @@ class ProfileCountry 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 = {?}", @@ -107,19 +211,25 @@ class ProfileCountry implements ProfileSetting $page->pid(), $id); } } + + public function getText($value) { + return implode(', ', $value); + } } -class ProfileMentor 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 ProfileSectors(); - $this->settings['countries'] = new ProfileCountry(); + $this->settings['terms'] = new ProfileSettingTerms(); + $this->settings['countries'] = new ProfileSettingCountry(); + $this->settings['competences'] = new ProfileSettingSkill('skill', 'id', 'cid', 'text_fr'); + $this->settings['langues'] = new ProfileSettingSkill('langskill', 'iso_639_2b', 'lid', 'language'); } protected function _fetchData() @@ -141,22 +251,35 @@ class ProfileMentor 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); + $page->assign('comp_list', XDB::iterator("SELECT id, text_fr, FIND_IN_SET('titre',flags) AS title + FROM profile_skill_enum")); + $page->assign('comp_level', array('initié' => 'initié', + 'bonne connaissance' => 'bonne connaissance', + 'expert' => 'expert')); + $page->assign('lang_list', XDB::iterator('SELECT iso_639_2b, language + FROM profile_langskill_enum + ORDER BY language')); + $page->assign('lang_level', array(1 => 'connaissance basique', + 2 => 'maîtrise des bases', + 3 => 'maîtrise limitée', + 4 => 'maîtrise générale', + 5 => 'bonne maîtrise', + 6 => 'maîtrise complète')); } }