Commit | Line | Data |
---|---|---|
6457b5e4 FB |
1 | <?php |
2 | /*************************************************************************** | |
9f5bd98e | 3 | * Copyright (C) 2003-2010 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 | ||
12bcf04b | 22 | class ProfileSettingSectors 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) | |
ce0b2c6f | 33 | WHERE m.pid = {?}", |
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 |
ce0b2c6f | 59 | WHERE pid = {?}", |
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) { | |
ce0b2c6f | 66 | XDB::execute("INSERT INTO profile_mentor_sector (pid, sectorid, subsectorid) |
6457b5e4 | 67 | VALUES ({?}, {?}, {?})", |
e5bcd851 | 68 | $page->pid(), $id, $sid); |
6457b5e4 FB |
69 | } |
70 | } | |
71 | } | |
a0fce0c6 SJ |
72 | |
73 | public function getText($value) { | |
74 | $sectors = array(); | |
75 | foreach ($value as $sector) { | |
76 | foreach ($sector as $subsector) { | |
77 | $sectors[] = $subsector; | |
78 | } | |
79 | } | |
80 | return implode(', ', $sectors); | |
81 | } | |
6457b5e4 FB |
82 | } |
83 | ||
12bcf04b | 84 | class ProfileSettingCountry implements ProfileSetting |
6457b5e4 FB |
85 | { |
86 | public function value(ProfilePage &$page, $field, $value, &$success) | |
87 | { | |
88 | $success = true; | |
89 | if (is_null($value)) { | |
90 | $value = array(); | |
e4cd7a1f | 91 | $res = XDB::iterRow("SELECT m.country, gc.countryFR |
5fecdf6d | 92 | FROM profile_mentor_country AS m |
e4cd7a1f | 93 | INNER JOIN geoloc_countries AS gc ON (m.country = gc.iso_3166_1_a2) |
ce0b2c6f | 94 | WHERE m.pid = {?}", |
e5bcd851 | 95 | $page->pid()); |
6457b5e4 FB |
96 | while (list($id, $name) = $res->next()) { |
97 | $value[$id] = $name; | |
98 | } | |
99 | } else if (!is_array($value)) { | |
100 | $value = array(); | |
101 | } else if (count($value) > 10) { | |
d7610c35 | 102 | Platal::page()->trigError("Le nombre de secteurs d'expertise est limité à 10"); |
6457b5e4 FB |
103 | $success = false; |
104 | } | |
105 | ksort($value); | |
106 | return $value; | |
107 | } | |
108 | ||
109 | public function save(ProfilePage &$page, $field, $value) | |
110 | { | |
5fecdf6d | 111 | XDB::execute("DELETE FROM profile_mentor_country |
ce0b2c6f | 112 | WHERE pid = {?}", |
e5bcd851 | 113 | $page->pid()); |
6457b5e4 | 114 | foreach ($value as $id=>&$name) { |
ce0b2c6f | 115 | XDB::execute("INSERT INTO profile_mentor_country (pid, country) |
6457b5e4 | 116 | VALUES ({?}, {?})", |
e5bcd851 | 117 | $page->pid(), $id); |
6457b5e4 FB |
118 | } |
119 | } | |
a0fce0c6 SJ |
120 | |
121 | public function getText($value) { | |
122 | return implode(', ', $value); | |
123 | } | |
6457b5e4 FB |
124 | } |
125 | ||
126 | ||
12bcf04b | 127 | class ProfileSettingMentor extends ProfilePage |
6457b5e4 FB |
128 | { |
129 | protected $pg_template = 'profile/mentor.tpl'; | |
130 | ||
131 | public function __construct(PlWizard &$wiz) | |
132 | { | |
133 | parent::__construct($wiz); | |
134 | $this->settings['expertise'] = null; | |
12bcf04b RB |
135 | $this->settings['sectors'] = new ProfileSettingSectors(); |
136 | $this->settings['countries'] = new ProfileSettingCountry(); | |
6457b5e4 FB |
137 | } |
138 | ||
7c2e0f0d | 139 | protected function _fetchData() |
6457b5e4 | 140 | { |
6457b5e4 | 141 | $res = XDB::query("SELECT expertise |
bdc3d2e9 | 142 | FROM profile_mentor |
ce0b2c6f | 143 | WHERE pid = {?}", |
e5bcd851 | 144 | $this->pid()); |
e21e0b11 | 145 | $this->values['expertise'] = $res->fetchOneCell(); |
6457b5e4 FB |
146 | } |
147 | ||
7c2e0f0d | 148 | protected function _saveData() |
6457b5e4 | 149 | { |
6457b5e4 | 150 | if ($this->changed['expertise']) { |
6dae45b3 FB |
151 | $expertise = trim($this->values['expertise']); |
152 | if (empty($expertise)) { | |
bdc3d2e9 | 153 | XDB::execute("DELETE FROM profile_mentor |
ce0b2c6f | 154 | WHERE pid = {?}", |
e5bcd851 | 155 | $this->pid()); |
6dae45b3 FB |
156 | $this->values['expertise'] = null; |
157 | } else { | |
ce0b2c6f | 158 | XDB::execute("REPLACE INTO profile_mentor (pid, expertise) |
6dae45b3 | 159 | VALUES ({?}, {?})", |
e5bcd851 | 160 | $this->pid(), $expertise); |
6dae45b3 FB |
161 | $this->values['expertise'] = $expertise; |
162 | } | |
6457b5e4 FB |
163 | } |
164 | } | |
165 | ||
04334c61 | 166 | public function _prepare(PlPage &$page, $id) |
6457b5e4 | 167 | { |
bdc3d2e9 SJ |
168 | $page->assign('sectorList', XDB::iterator('SELECT id, name |
169 | FROM profile_job_sector_enum')); | |
2aa2c77a SJ |
170 | |
171 | $page->assign('countryList', XDB::iterator("SELECT iso_3166_1_a2, countryFR | |
172 | FROM geoloc_countries | |
173 | ORDER BY countryFR")); | |
7a7167d3 | 174 | $page->assign('hrpid', $this->profile->hrpid); |
6457b5e4 FB |
175 | } |
176 | } | |
177 | ||
178 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
179 | ?> |