pid()); $value = $res->fetchAllAssoc(); } elseif (!is_array($value)) { $value = array(); } 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) { ksort($sss); } return $value; } public function save(ProfilePage &$page, $field, $value) { XDB::execute("DELETE FROM profile_mentor_term WHERE pid = {?}", $page->pid()); if (!count($value)) { return; } $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 ProfileSettingCountry implements ProfileSetting { public function value(ProfilePage &$page, $field, $value, &$success) { $success = true; if (is_null($value)) { $value = array(); $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 = {?}", $page->pid()); while (list($id, $name) = $res->next()) { $value[$id] = $name; } } else if (!is_array($value)) { $value = array(); } else if (count($value) > 10) { Platal::page()->trigError("Le nombre de secteurs d'expertise est limité à 10"); $success = false; } ksort($value); return $value; } public function save(ProfilePage &$page, $field, $value) { XDB::execute("DELETE FROM profile_mentor_country WHERE pid = {?}", $page->pid()); foreach ($value as $id=>&$name) { XDB::execute("INSERT INTO profile_mentor_country (pid, country) VALUES ({?}, {?})", $page->pid(), $id); } } public function getText($value) { return implode(', ', $value); } } class ProfilePageMentor extends ProfilePage { protected $pg_template = 'profile/mentor.tpl'; public function __construct(PlWizard &$wiz) { parent::__construct($wiz); $this->settings['expertise'] = null; $this->settings['terms'] = new ProfileSettingTerms(); $this->settings['countries'] = new ProfileSettingCountry(); } protected function _fetchData() { $res = XDB::query("SELECT expertise FROM profile_mentor WHERE pid = {?}", $this->pid()); $this->values['expertise'] = $res->fetchOneCell(); } protected function _saveData() { if ($this->changed['expertise']) { $expertise = trim($this->values['expertise']); if (empty($expertise)) { XDB::execute("DELETE FROM profile_mentor WHERE pid = {?}", $this->pid()); $this->values['expertise'] = null; } else { 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) { $page->assign('countryList', XDB::iterator("SELECT iso_3166_1_a2, country FROM geoloc_countries ORDER BY country")); $page->assign('hrpid', $this->profile->hrpid); } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>