Updates Changelog (Closes #1512).
[platal.git] / modules / profile / skills.inc.php
CommitLineData
f25e1a56
FB
1<?php
2/***************************************************************************
5e1513f6 3 * Copyright (C) 2003-2011 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 22class ProfileSettingSkill implements ProfileSetting
f25e1a56
FB
23{
24 private $table;
43c653a1 25 private $id;
f25e1a56
FB
26 private $skill_field;
27 private $text_field;
28
43c653a1 29 public function __construct($table, $id, $skill, $text)
f25e1a56
FB
30 {
31 $this->table = $table;
43c653a1 32 $this->id = $id;
f25e1a56
FB
33 $this->skill_field = $skill;
34 $this->text_field = $text;
35 }
36
26ba053e 37 public function value(ProfilePage $page, $field, $value, &$success)
f25e1a56
FB
38 {
39 if (is_null($value)) {
40 $value = array();
43c653a1 41 $res = XDB::iterRow("SELECT s.{$this->id}, s.{$this->text_field}, i.level
5c8a71f2 42 FROM profile_{$this->table}_enum AS s
43c653a1 43 INNER JOIN profile_{$this->table}s AS i ON (s.{$this->id} = i.{$this->skill_field})
afc183ec 44 WHERE i.pid = {?}",
e5bcd851 45 $page->pid());
f25e1a56
FB
46 while (list($sid, $text, $level) = $res->next()) {
47 $value[$sid] = array('text' => $text, 'level' => $level);
48 }
49 }
50 if (!is_array($value)) {
51 $value = array();
52 } else {
53 foreach ($value as $id=>&$skill) {
54 if (!isset($skill['text']) || empty($skill['text'])) {
55 $res = XDB::query("SELECT {$this->text_field}
5c8a71f2 56 FROM profile_{$this->table}_enum
43c653a1 57 WHERE {$this->id} = {?}", $id);
f25e1a56
FB
58 $skill['text'] = $res->fetchOneCell();
59 }
60 }
61 }
62 ksort($value);
63 $success = true;
64 return $value;
65 }
66
26ba053e 67 public function save(ProfilePage $page, $field, $value)
f25e1a56 68 {
5c8a71f2 69 XDB::execute("DELETE FROM profile_{$this->table}s
bdd977d7 70 WHERE pid = {?}",
e5bcd851 71 $page->pid());
f25e1a56
FB
72 if (!count($value)) {
73 return;
74 }
75 foreach ($value as $id=>&$skill) {
afc183ec 76 XDB::execute("INSERT INTO profile_{$this->table}s (pid, {$this->skill_field}, level)
f25e1a56 77 VALUES ({?}, {?}, {?})",
e5bcd851 78 $page->pid(), $id, $skill['level']);
f25e1a56
FB
79 }
80 }
a0fce0c6
SJ
81
82 public function getText($value) {
83 $skills = array();
14aba233
SJ
84
85 if ($this->table == 'langskill') {
86 static $levels = array(
87 1 => 'connaissance basique',
88 2 => 'maîtrise des bases',
89 3 => 'maîtrise limitée',
90 4 => 'maîtrise générale',
91 5 => 'bonne maîtrise',
92 6 => 'maîtrise complète'
93 );
94 foreach ($value as $skill) {
95 $skills[] = $skill['text'] . ' (' . $levels[$skill['level']] . ')';
96 }
97 } else {
98 foreach ($value as $skill) {
99 $skills[] = $skill['text'] . ' (' . $skill['level'] . ')';
100 }
a0fce0c6 101 }
14aba233
SJ
102
103 return implode(', ' , $skills);
a0fce0c6 104 }
f25e1a56
FB
105}
106
66c4bdaf 107class ProfilePageSkills extends ProfilePage
f25e1a56
FB
108{
109 protected $pg_template = 'profile/skill.tpl';
110
26ba053e 111 public function __construct(PlWizard $wiz)
f25e1a56
FB
112 {
113 parent::__construct($wiz);
43c653a1
SJ
114 $this->settings['competences'] = new ProfileSettingSkill('skill', 'id', 'cid', 'text_fr');
115 $this->settings['langues'] = new ProfileSettingSkill('langskill', 'iso_639_2b', 'lid', 'language');
f25e1a56
FB
116 }
117
26ba053e 118 public function _prepare(PlPage $page, $id)
f25e1a56 119 {
f25e1a56 120 $page->assign('comp_list', XDB::iterator("SELECT id, text_fr, FIND_IN_SET('titre',flags) AS title
5c8a71f2 121 FROM profile_skill_enum"));
f25e1a56
FB
122 $page->assign('comp_level', array('initié' => 'initié',
123 'bonne connaissance' => 'bonne connaissance',
124 'expert' => 'expert'));
43c653a1 125 $page->assign('lang_list', XDB::iterator('SELECT iso_639_2b, language
071c4269 126 FROM profile_langskill_enum
43c653a1 127 ORDER BY language'));
f25e1a56
FB
128 $page->assign('lang_level', array(1 => 'connaissance basique',
129 2 => 'maîtrise des bases',
130 3 => 'maîtrise limitée',
131 4 => 'maîtrise générale',
132 5 => 'bonne maîtrise',
133 6 => 'maîtrise complète'));
134 }
135}
136
137// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
138?>