2 /***************************************************************************
3 * Copyright (C) 2003-2008 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) {
46 $page->trigError("Le nombre de secteurs d'expertise est limité à 10");
50 foreach ($value as &$sss) {
56 public function save(ProfilePage
&$page, $field, $value)
59 XDB
::execute("DELETE FROM mentor_secteurs
65 foreach ($value as $id=>&$sect) {
66 foreach ($sect as $sid=>&$name) {
67 XDB
::execute("INSERT INTO mentor_secteurs (uid, secteur, ss_secteur)
68 VALUES ({?}, {?}, {?})",
69 S
::i('uid'), $id, $sid);
75 class ProfileCountry
implements ProfileSetting
77 public function value(ProfilePage
&$page, $field, $value, &$success)
80 if (is_null($value)) {
82 $res = XDB
::iterRow("SELECT m.pid, p.pays
84 INNER JOIN geoloc_pays AS p ON(m.pid = p.a2)
87 while (list($id, $name) = $res->next()) {
90 } else if (!is_array($value)) {
92 } else if (count($value) > 10) {
94 $page->trigError("Le nombre de secteurs d'expertise est limité à 10");
101 public function save(ProfilePage
&$page, $field, $value)
103 XDB
::execute("DELETE FROM mentor_pays
106 foreach ($value as $id=>&$name) {
107 XDB
::execute("INSERT INTO mentor_pays (uid, pid)
115 class ProfileMentor
extends ProfilePage
117 protected $pg_template = 'profile/mentor.tpl';
119 public function __construct(PlWizard
&$wiz)
121 parent
::__construct($wiz);
122 $this->settings
['expertise'] = null
;
123 $this->settings
['secteurs'] = new ProfileSecteurs();
124 $this->settings
['countries'] = new ProfileCountry();
127 protected function _fetchData()
129 $res = XDB
::query("SELECT expertise
133 $this->values
['expertise'] = $res->fetchOneCell();
136 protected function _saveData()
138 if ($this->changed
['expertise']) {
139 $expertise = trim($this->values
['expertise']);
140 if (empty($expertise)) {
141 XDB
::execute("DELETE FROM mentor
144 $this->values
['expertise'] = null
;
146 XDB
::execute("REPLACE INTO mentor (uid, expertise)
148 S
::i('uid'), $expertise);
149 $this->values
['expertise'] = $expertise;
154 public function _prepare(PlatalPage
&$page, $id)
156 $page->assign('secteurs_sel', XDB
::iterator("SELECT id, label
157 FROM emploi_secteur"));
161 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: