X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fprofile%2Fmentor.inc.php;h=a2e1b06b03c57c1485bab2077d843c7be0627aab;hb=48dba8feba7c3653a925aab5273fc30a6c257240;hp=6ad25981c161ec84f9a5f2740b69e9c4c499b649;hpb=164566891eef6e4027b2dfccda0040d37f10605b;p=platal.git diff --git a/modules/profile/mentor.inc.php b/modules/profile/mentor.inc.php index 6ad2598..a2e1b06 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) + { + if (is_null($value)) { + $value = array(); + $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($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) + public function value(ProfilePage $page, $field, $value, &$success) { $success = true; if (is_null($value)) { @@ -63,7 +148,7 @@ class ProfileSettingTerms implements ProfileSetting return $value; } - public function save(ProfilePage &$page, $field, $value) + public function save(ProfilePage $page, $field, $value) { XDB::execute("DELETE FROM profile_mentor_term @@ -92,7 +177,7 @@ class ProfileSettingTerms 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)) { @@ -115,7 +200,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 = {?}", @@ -137,12 +222,14 @@ 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['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() @@ -173,14 +260,28 @@ class ProfilePageMentor extends ProfilePage } } - public function _prepare(PlPage &$page, $id) + public function _prepare(PlPage $page, $id) { $page->assign('countryList', XDB::iterator("SELECT iso_3166_1_a2, country FROM geoloc_countries 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')); } } -// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: ?>