2 /***************************************************************************
3 * Copyright (C) 2003-2009 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 class ProfileSecteurs
implements ProfileSetting
24 public function value(ProfilePage
&$page, $field, $value, &$success)
27 if (is_null($value)) {
29 $res = XDB
::iterRow("SELECT m.secteur, m.ss_secteur, ss.label
30 FROM mentor_secteurs AS m
31 INNER JOIN emploi_secteur AS s ON(m.secteur = s.id)
32 INNER JOIN emploi_ss_secteur AS ss ON(s.id = ss.secteur AND m.ss_secteur = ss.id)
35 while (list($s, $ss, $ssname) = $res->next()) {
36 if (!isset($value[$s])) {
37 $value[$s] = array($ss => $ssname);
39 $value[$s][$ss] = $ssname;
42 } else if (!is_array($value)) {
44 } else if (count($value) > 10) {
45 Platal
::page()->trigError("Le nombre de secteurs d'expertise est limité à 10");
49 foreach ($value as &$sss) {
55 public function save(ProfilePage
&$page, $field, $value)
58 XDB
::execute("DELETE FROM mentor_secteurs
64 foreach ($value as $id=>&$sect) {
65 foreach ($sect as $sid=>&$name) {
66 XDB
::execute("INSERT INTO mentor_secteurs (uid, secteur, ss_secteur)
67 VALUES ({?}, {?}, {?})",
68 S
::i('uid'), $id, $sid);
74 class ProfileCountry
implements ProfileSetting
76 public function value(ProfilePage
&$page, $field, $value, &$success)
79 if (is_null($value)) {
81 $res = XDB
::iterRow("SELECT m.pid, p.pays
83 INNER JOIN geoloc_pays AS p ON(m.pid = p.a2)
86 while (list($id, $name) = $res->next()) {
89 } else if (!is_array($value)) {
91 } else if (count($value) > 10) {
92 Platal
::page()->trigError("Le nombre de secteurs d'expertise est limité à 10");
99 public function save(ProfilePage
&$page, $field, $value)
101 XDB
::execute("DELETE FROM mentor_pays
104 foreach ($value as $id=>&$name) {
105 XDB
::execute("INSERT INTO mentor_pays (uid, pid)
113 class ProfileMentor
extends ProfilePage
115 protected $pg_template = 'profile/mentor.tpl';
117 public function __construct(PlWizard
&$wiz)
119 parent
::__construct($wiz);
120 $this->settings
['expertise'] = null
;
121 $this->settings
['secteurs'] = new ProfileSecteurs();
122 $this->settings
['countries'] = new ProfileCountry();
125 protected function _fetchData()
127 $res = XDB
::query("SELECT expertise
131 $this->values
['expertise'] = $res->fetchOneCell();
134 protected function _saveData()
136 if ($this->changed
['expertise']) {
137 $expertise = trim($this->values
['expertise']);
138 if (empty($expertise)) {
139 XDB
::execute("DELETE FROM mentor
142 $this->values
['expertise'] = null
;
144 XDB
::execute("REPLACE INTO mentor (uid, expertise)
146 S
::i('uid'), $expertise);
147 $this->values
['expertise'] = $expertise;
152 public function _prepare(PlPage
&$page, $id)
154 $page->assign('secteurs_sel', XDB
::iterator("SELECT id, label
155 FROM emploi_secteur"));
159 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: