Commit | Line | Data |
---|---|---|
6457b5e4 FB |
1 | <?php |
2 | /*************************************************************************** | |
8d84c630 | 3 | * Copyright (C) 2003-2009 Polytechnique.org * |
6457b5e4 FB |
4 | * http://opensource.polytechnique.org/ * |
5 | * * | |
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. * | |
10 | * * | |
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. * | |
15 | * * | |
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 * | |
18 | * Foundation, Inc., * | |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
20 | ***************************************************************************/ | |
21 | ||
541e8d03 | 22 | class ProfileSectors implements ProfileSetting |
6457b5e4 FB |
23 | { |
24 | public function value(ProfilePage &$page, $field, $value, &$success) | |
25 | { | |
26 | $success = true; | |
27 | if (is_null($value)) { | |
28 | $value = array(); | |
5fecdf6d SJ |
29 | $res = XDB::iterRow("SELECT m.sectorid, m.subsectorid, ss.name |
30 | FROM profile_mentor_sector AS m | |
31 | INNER JOIN profile_job_sector_enum AS s ON (m.sectorid = s.id) | |
32 | INNER JOIN profile_job_subsector_enum AS ss ON (s.id = ss.sectorid AND m.subsectorid = ss.id) | |
6457b5e4 | 33 | WHERE m.uid = {?}", |
e5bcd851 | 34 | $page->pid()); |
6457b5e4 FB |
35 | while (list($s, $ss, $ssname) = $res->next()) { |
36 | if (!isset($value[$s])) { | |
37 | $value[$s] = array($ss => $ssname); | |
38 | } else { | |
39 | $value[$s][$ss] = $ssname; | |
40 | } | |
41 | } | |
bdc3d2e9 | 42 | } elseif (!is_array($value)) { |
6457b5e4 | 43 | $value = array(); |
bdc3d2e9 | 44 | } elseif (count($value) > 10) { |
5fecdf6d | 45 | Platal::page()->trigError("Le nombre de secteurs d'expertise est limité à 10."); |
6457b5e4 FB |
46 | $success = false; |
47 | } | |
48 | ksort($value); | |
49 | foreach ($value as &$sss) { | |
50 | ksort($sss); | |
51 | } | |
52 | return $value; | |
53 | } | |
54 | ||
55 | public function save(ProfilePage &$page, $field, $value) | |
56 | { | |
57 | ||
5fecdf6d | 58 | XDB::execute("DELETE FROM profile_mentor_sector |
6457b5e4 | 59 | WHERE uid = {?}", |
e5bcd851 | 60 | $page->pid()); |
6457b5e4 FB |
61 | if (!count($value)) { |
62 | return; | |
63 | } | |
bdc3d2e9 SJ |
64 | foreach ($value as $id => $sect) { |
65 | foreach ($sect as $sid => $name) { | |
5fecdf6d | 66 | XDB::execute("INSERT INTO profile_mentor_sector (uid, sectorid, subsectorid) |
6457b5e4 | 67 | VALUES ({?}, {?}, {?})", |
e5bcd851 | 68 | $page->pid(), $id, $sid); |
6457b5e4 FB |
69 | } |
70 | } | |
71 | } | |
72 | } | |
73 | ||
74 | class ProfileCountry implements ProfileSetting | |
75 | { | |
76 | public function value(ProfilePage &$page, $field, $value, &$success) | |
77 | { | |
78 | $success = true; | |
79 | if (is_null($value)) { | |
80 | $value = array(); | |
e4cd7a1f | 81 | $res = XDB::iterRow("SELECT m.country, gc.countryFR |
5fecdf6d | 82 | FROM profile_mentor_country AS m |
e4cd7a1f | 83 | INNER JOIN geoloc_countries AS gc ON (m.country = gc.iso_3166_1_a2) |
6457b5e4 | 84 | WHERE m.uid = {?}", |
e5bcd851 | 85 | $page->pid()); |
6457b5e4 FB |
86 | while (list($id, $name) = $res->next()) { |
87 | $value[$id] = $name; | |
88 | } | |
89 | } else if (!is_array($value)) { | |
90 | $value = array(); | |
91 | } else if (count($value) > 10) { | |
d7610c35 | 92 | Platal::page()->trigError("Le nombre de secteurs d'expertise est limité à 10"); |
6457b5e4 FB |
93 | $success = false; |
94 | } | |
95 | ksort($value); | |
96 | return $value; | |
97 | } | |
98 | ||
99 | public function save(ProfilePage &$page, $field, $value) | |
100 | { | |
5fecdf6d | 101 | XDB::execute("DELETE FROM profile_mentor_country |
6457b5e4 | 102 | WHERE uid = {?}", |
e5bcd851 | 103 | $page->pid()); |
6457b5e4 | 104 | foreach ($value as $id=>&$name) { |
5fecdf6d | 105 | XDB::execute("INSERT INTO profile_mentor_country (uid, country) |
6457b5e4 | 106 | VALUES ({?}, {?})", |
e5bcd851 | 107 | $page->pid(), $id); |
6457b5e4 FB |
108 | } |
109 | } | |
110 | } | |
111 | ||
112 | ||
113 | class ProfileMentor extends ProfilePage | |
114 | { | |
115 | protected $pg_template = 'profile/mentor.tpl'; | |
116 | ||
117 | public function __construct(PlWizard &$wiz) | |
118 | { | |
119 | parent::__construct($wiz); | |
120 | $this->settings['expertise'] = null; | |
541e8d03 | 121 | $this->settings['sectors'] = new ProfileSectors(); |
6457b5e4 FB |
122 | $this->settings['countries'] = new ProfileCountry(); |
123 | } | |
124 | ||
7c2e0f0d | 125 | protected function _fetchData() |
6457b5e4 | 126 | { |
6457b5e4 | 127 | $res = XDB::query("SELECT expertise |
bdc3d2e9 | 128 | FROM profile_mentor |
6457b5e4 | 129 | WHERE uid = {?}", |
e5bcd851 | 130 | $this->pid()); |
e21e0b11 | 131 | $this->values['expertise'] = $res->fetchOneCell(); |
6457b5e4 FB |
132 | } |
133 | ||
7c2e0f0d | 134 | protected function _saveData() |
6457b5e4 | 135 | { |
6457b5e4 | 136 | if ($this->changed['expertise']) { |
6dae45b3 FB |
137 | $expertise = trim($this->values['expertise']); |
138 | if (empty($expertise)) { | |
bdc3d2e9 | 139 | XDB::execute("DELETE FROM profile_mentor |
6dae45b3 | 140 | WHERE uid = {?}", |
e5bcd851 | 141 | $this->pid()); |
6dae45b3 FB |
142 | $this->values['expertise'] = null; |
143 | } else { | |
bdc3d2e9 | 144 | XDB::execute("REPLACE INTO profile_mentor (uid, expertise) |
6dae45b3 | 145 | VALUES ({?}, {?})", |
e5bcd851 | 146 | $this->pid(), $expertise); |
6dae45b3 FB |
147 | $this->values['expertise'] = $expertise; |
148 | } | |
6457b5e4 FB |
149 | } |
150 | } | |
151 | ||
04334c61 | 152 | public function _prepare(PlPage &$page, $id) |
6457b5e4 | 153 | { |
bdc3d2e9 SJ |
154 | $page->assign('sectorList', XDB::iterator('SELECT id, name |
155 | FROM profile_job_sector_enum')); | |
2aa2c77a SJ |
156 | |
157 | $page->assign('countryList', XDB::iterator("SELECT iso_3166_1_a2, countryFR | |
158 | FROM geoloc_countries | |
159 | ORDER BY countryFR")); | |
6457b5e4 FB |
160 | } |
161 | } | |
162 | ||
163 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
164 | ?> |