Commit | Line | Data |
---|---|---|
f25e1a56 FB |
1 | <?php |
2 | /*************************************************************************** | |
9f5bd98e | 3 | * Copyright (C) 2003-2010 Polytechnique.org * |
f25e1a56 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 ProfileSettingSkill implements ProfileSetting |
f25e1a56 FB |
23 | { |
24 | private $table; | |
25 | private $skill_field; | |
26 | private $text_field; | |
27 | ||
28 | public function __construct($table, $skill, $text) | |
29 | { | |
30 | $this->table = $table; | |
31 | $this->skill_field = $skill; | |
32 | $this->text_field = $text; | |
33 | } | |
34 | ||
35 | public function value(ProfilePage &$page, $field, $value, &$success) | |
36 | { | |
37 | if (is_null($value)) { | |
38 | $value = array(); | |
39 | $res = XDB::iterRow("SELECT s.id, s.{$this->text_field}, i.level | |
5c8a71f2 FB |
40 | FROM profile_{$this->table}_enum AS s |
41 | INNER JOIN profile_{$this->table}s AS i ON(s.id = i.{$this->skill_field}) | |
afc183ec | 42 | WHERE i.pid = {?}", |
e5bcd851 | 43 | $page->pid()); |
f25e1a56 FB |
44 | while (list($sid, $text, $level) = $res->next()) { |
45 | $value[$sid] = array('text' => $text, 'level' => $level); | |
46 | } | |
47 | } | |
48 | if (!is_array($value)) { | |
49 | $value = array(); | |
50 | } else { | |
51 | foreach ($value as $id=>&$skill) { | |
52 | if (!isset($skill['text']) || empty($skill['text'])) { | |
53 | $res = XDB::query("SELECT {$this->text_field} | |
5c8a71f2 | 54 | FROM profile_{$this->table}_enum |
f25e1a56 FB |
55 | WHERE id = {?}", $id); |
56 | $skill['text'] = $res->fetchOneCell(); | |
57 | } | |
58 | } | |
59 | } | |
60 | ksort($value); | |
61 | $success = true; | |
62 | return $value; | |
63 | } | |
64 | ||
65 | public function save(ProfilePage &$page, $field, $value) | |
66 | { | |
5c8a71f2 | 67 | XDB::execute("DELETE FROM profile_{$this->table}s |
bdd977d7 | 68 | WHERE pid = {?}", |
e5bcd851 | 69 | $page->pid()); |
f25e1a56 FB |
70 | if (!count($value)) { |
71 | return; | |
72 | } | |
73 | foreach ($value as $id=>&$skill) { | |
afc183ec | 74 | XDB::execute("INSERT INTO profile_{$this->table}s (pid, {$this->skill_field}, level) |
f25e1a56 | 75 | VALUES ({?}, {?}, {?})", |
e5bcd851 | 76 | $page->pid(), $id, $skill['level']); |
f25e1a56 FB |
77 | } |
78 | } | |
79 | } | |
80 | ||
12bcf04b | 81 | class ProfileSettingSkills extends ProfilePage |
f25e1a56 FB |
82 | { |
83 | protected $pg_template = 'profile/skill.tpl'; | |
84 | ||
85 | public function __construct(PlWizard &$wiz) | |
86 | { | |
87 | parent::__construct($wiz); | |
12bcf04b RB |
88 | $this->settings['competences'] = new ProfileSettingSkill('skill', 'cid', 'text_fr'); |
89 | $this->settings['langues'] = new ProfileSettingSkill('langskill', 'lid', 'langue_fr'); | |
f25e1a56 FB |
90 | } |
91 | ||
04334c61 | 92 | public function _prepare(PlPage &$page, $id) |
f25e1a56 | 93 | { |
f25e1a56 | 94 | $page->assign('comp_list', XDB::iterator("SELECT id, text_fr, FIND_IN_SET('titre',flags) AS title |
5c8a71f2 | 95 | FROM profile_skill_enum")); |
f25e1a56 FB |
96 | $page->assign('comp_level', array('initié' => 'initié', |
97 | 'bonne connaissance' => 'bonne connaissance', | |
98 | 'expert' => 'expert')); | |
99 | $page->assign('lang_list', XDB::iterator("SELECT id, langue_fr | |
071c4269 PC |
100 | FROM profile_langskill_enum |
101 | ORDER BY langue_fr")); | |
f25e1a56 FB |
102 | $page->assign('lang_level', array(1 => 'connaissance basique', |
103 | 2 => 'maîtrise des bases', | |
104 | 3 => 'maîtrise limitée', | |
105 | 4 => 'maîtrise générale', | |
106 | 5 => 'bonne maîtrise', | |
107 | 6 => 'maîtrise complète')); | |
108 | } | |
109 | } | |
110 | ||
111 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
112 | ?> |