Merge remote branch 'origin/master' into xnet_accounts
[platal.git] / modules / profile / skills.inc.php
CommitLineData
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 22class 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 }
a0fce0c6
SJ
79
80 public function getText($value) {
81 $skills = array();
82 foreach ($value as $skill) {
83 $skills[] = 'Compétance : ' . $skill['text'] . ', niveau : ' . $skill['level'];
84 }
85 return implode(' ; ' , $skills);
86 }
f25e1a56
FB
87}
88
12bcf04b 89class ProfileSettingSkills extends ProfilePage
f25e1a56
FB
90{
91 protected $pg_template = 'profile/skill.tpl';
92
93 public function __construct(PlWizard &$wiz)
94 {
95 parent::__construct($wiz);
12bcf04b
RB
96 $this->settings['competences'] = new ProfileSettingSkill('skill', 'cid', 'text_fr');
97 $this->settings['langues'] = new ProfileSettingSkill('langskill', 'lid', 'langue_fr');
f25e1a56
FB
98 }
99
04334c61 100 public function _prepare(PlPage &$page, $id)
f25e1a56 101 {
f25e1a56 102 $page->assign('comp_list', XDB::iterator("SELECT id, text_fr, FIND_IN_SET('titre',flags) AS title
5c8a71f2 103 FROM profile_skill_enum"));
f25e1a56
FB
104 $page->assign('comp_level', array('initié' => 'initié',
105 'bonne connaissance' => 'bonne connaissance',
106 'expert' => 'expert'));
107 $page->assign('lang_list', XDB::iterator("SELECT id, langue_fr
071c4269
PC
108 FROM profile_langskill_enum
109 ORDER BY langue_fr"));
f25e1a56
FB
110 $page->assign('lang_level', array(1 => 'connaissance basique',
111 2 => 'maîtrise des bases',
112 3 => 'maîtrise limitée',
113 4 => 'maîtrise générale',
114 5 => 'bonne maîtrise',
115 6 => 'maîtrise complète'));
116 }
117}
118
119// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
120?>