2 /***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 /** Terms associated to profile mentoring */
23 class ProfileSettingTerms
implements ProfileSetting
25 public function value(ProfilePage
&$page, $field, $value, &$success)
28 if (is_null($value)) {
30 $res = XDB
::query('SELECT e.jtid, e.full_name
31 FROM profile_mentor_term AS m
32 INNER JOIN profile_job_term_enum AS e ON (m.jtid = e.jtid)
35 $value = $res->fetchAllAssoc();
36 } elseif (!is_array($value)) {
38 } elseif (count($value) > 20) {
39 Platal
::page()->trigError("Le nombre de mots clefs d'expertise est limité à 20.");
42 $missing_full_names = array();
43 foreach ($value as &$term) if (empty($term['full_name'])) {
44 $missing_full_names[] = $term['jtid'];
46 if (count($missing_full_names)) {
47 $res = XDB
::query('SELECT jtid, full_name
48 FROM profile_job_term_enum
51 $term_id_to_name = $res->fetchAllAssoc('jtid', false
);
52 foreach ($value as &$term) {
53 if (empty($term['full_name'])) {
54 $term['full_name'] = $term_id_to_name[$term['jtid']];
60 foreach ($value as &$sss) {
66 public function save(ProfilePage
&$page, $field, $value)
69 XDB
::execute("DELETE FROM profile_mentor_term
75 $mentor_term_values = array();
76 foreach ($value as &$term) {
77 $mentor_term_values[] = '('.XDB
::escape($page->pid()).', '.XDB
::escape($term['jtid']).')';
79 XDB
::execute('INSERT INTO profile_mentor_term (pid, jtid)
80 VALUES '.implode(',', $mentor_term_values));
84 public function getText($value) {
86 foreach ($value as &$term) {
87 $terms[] = $term['full_name'];
89 return implode(', ', $terms);
93 class ProfileSettingCountry
implements ProfileSetting
95 public function value(ProfilePage
&$page, $field, $value, &$success)
98 if (is_null($value)) {
100 $res = XDB
::iterRow("SELECT m.country, gc.countryFR
101 FROM profile_mentor_country AS m
102 INNER JOIN geoloc_countries AS gc ON (m.country = gc.iso_3166_1_a2)
105 while (list($id, $name) = $res->next()) {
108 } else if (!is_array($value)) {
110 } else if (count($value) > 10) {
111 Platal
::page()->trigError("Le nombre de secteurs d'expertise est limité à 10");
118 public function save(ProfilePage
&$page, $field, $value)
120 XDB
::execute("DELETE FROM profile_mentor_country
123 foreach ($value as $id=>&$name) {
124 XDB
::execute("INSERT INTO profile_mentor_country (pid, country)
130 public function getText($value) {
131 return implode(', ', $value);
136 class ProfilePageMentor
extends ProfilePage
138 protected $pg_template = 'profile/mentor.tpl';
140 public function __construct(PlWizard
&$wiz)
142 parent
::__construct($wiz);
143 $this->settings
['expertise'] = null
;
144 $this->settings
['terms'] = new ProfileSettingTerms();
145 $this->settings
['countries'] = new ProfileSettingCountry();
148 protected function _fetchData()
150 $res = XDB
::query("SELECT expertise
154 $this->values
['expertise'] = $res->fetchOneCell();
157 protected function _saveData()
159 if ($this->changed
['expertise']) {
160 $expertise = trim($this->values
['expertise']);
161 if (empty($expertise)) {
162 XDB
::execute("DELETE FROM profile_mentor
165 $this->values
['expertise'] = null
;
167 XDB
::execute('INSERT INTO profile_mentor (pid, expertise)
169 ON DUPLICATE KEY UPDATE expertise = VALUES(expertise)',
170 $this->pid(), $expertise);
171 $this->values
['expertise'] = $expertise;
176 public function _prepare(PlPage
&$page, $id)
178 $page->assign('countryList', XDB
::iterator("SELECT iso_3166_1_a2, countryFR
179 FROM geoloc_countries
180 ORDER BY countryFR"));
181 $page->assign('hrpid', $this->profile
->hrpid
);
185 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: