New main page of the site with a multi-topic site preview based on PlWizard
[platal.git] / modules / profile / skills.inc.php
CommitLineData
f25e1a56
FB
1<?php
2/***************************************************************************
3 * Copyright (C) 2003-2007 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
22class ProfileSkill 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 {$this->table}_def AS s
41 INNER JOIN {$this->table}_ins AS i ON(s.id = i.{$this->skill_field})
42 WHERE i.uid = {?}",
43 S::i('uid'));
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 {$this->table}_def
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 {$this->table}_ins
68 WHERE uid = {?}",
69 S::i('uid'));
70 if (!count($value)) {
71 return;
72 }
73 foreach ($value as $id=>&$skill) {
74 XDB::execute("INSERT INTO {$this->table}_ins (uid, {$this->skill_field}, level)
75 VALUES ({?}, {?}, {?})",
76 S::i('uid'), $id, $skill['level']);
77 }
78 }
79}
80
81class ProfileSkills extends ProfilePage
82{
83 protected $pg_template = 'profile/skill.tpl';
84
85 public function __construct(PlWizard &$wiz)
86 {
87 parent::__construct($wiz);
88 $this->settings['competences'] = new ProfileSkill('competences', 'cid', 'text_fr');
89 $this->settings['langues'] = new ProfileSkill('langues', 'lid', 'langue_fr');
90 }
91
ddb64990 92 public function prepare(PlatalPage &$page, $id)
f25e1a56 93 {
ddb64990 94 parent::prepare($page, $id);
f25e1a56
FB
95 $page->assign('comp_list', XDB::iterator("SELECT id, text_fr, FIND_IN_SET('titre',flags) AS title
96 FROM competences_def"));
97 $page->assign('comp_level', array('initié' => 'initié',
98 'bonne connaissance' => 'bonne connaissance',
99 'expert' => 'expert'));
100 $page->assign('lang_list', XDB::iterator("SELECT id, langue_fr
101 FROM langues_def"));
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?>