Renames classes that extend ProfilePage into ProfilePageXXXX.
[platal.git] / modules / profile / skills.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
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
22 class ProfileSettingSkill implements ProfileSetting
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
40 FROM profile_{$this->table}_enum AS s
41 INNER JOIN profile_{$this->table}s AS i ON(s.id = i.{$this->skill_field})
42 WHERE i.pid = {?}",
43 $page->pid());
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}
54 FROM profile_{$this->table}_enum
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 {
67 XDB::execute("DELETE FROM profile_{$this->table}s
68 WHERE pid = {?}",
69 $page->pid());
70 if (!count($value)) {
71 return;
72 }
73 foreach ($value as $id=>&$skill) {
74 XDB::execute("INSERT INTO profile_{$this->table}s (pid, {$this->skill_field}, level)
75 VALUES ({?}, {?}, {?})",
76 $page->pid(), $id, $skill['level']);
77 }
78 }
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 }
87 }
88
89 class ProfilePageSkills extends ProfilePage
90 {
91 protected $pg_template = 'profile/skill.tpl';
92
93 public function __construct(PlWizard &$wiz)
94 {
95 parent::__construct($wiz);
96 $this->settings['competences'] = new ProfileSettingSkill('skill', 'cid', 'text_fr');
97 $this->settings['langues'] = new ProfileSettingSkill('langskill', 'lid', 'langue_fr');
98 }
99
100 public function _prepare(PlPage &$page, $id)
101 {
102 $page->assign('comp_list', XDB::iterator("SELECT id, text_fr, FIND_IN_SET('titre',flags) AS title
103 FROM profile_skill_enum"));
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
108 FROM profile_langskill_enum
109 ORDER BY langue_fr"));
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 ?>