ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilSkillProfile.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once("./Services/Skill/interfaces/interface.ilSkillUsageInfo.php");
6
15{
16 protected $id;
17 protected $title;
18 protected $description;
19 protected $skill_level = array();
20
26 function __construct($a_id = 0)
27 {
28 if ($a_id > 0)
29 {
30 $this->setId($a_id);
31 $this->read();
32 }
33 }
34
40 function setId($a_val)
41 {
42 $this->id = $a_val;
43 }
44
50 function getId()
51 {
52 return $this->id;
53 }
54
60 function setTitle($a_val)
61 {
62 $this->title = $a_val;
63 }
64
70 function getTitle()
71 {
72 return $this->title;
73 }
74
80 function setDescription($a_val)
81 {
82 $this->description = $a_val;
83 }
84
90 function getDescription()
91 {
92 return $this->description;
93 }
94
101 function addSkillLevel($a_base_skill_id, $a_tref_id, $a_level_id)
102 {
103//echo "-".$a_base_skill_id."-";
104 $this->skill_level[] = array(
105 "base_skill_id" => $a_base_skill_id,
106 "tref_id" => $a_tref_id,
107 "level_id" => $a_level_id
108 );
109 }
110
117 function removeSkillLevel($a_base_skill_id, $a_tref_id, $a_level_id)
118 {
119 foreach ($this->skill_level as $k => $sl)
120 {
121 if ((int) $sl["base_skill_id"] == (int) $a_base_skill_id &&
122 (int) $sl["tref_id"] == (int) $a_tref_id &&
123 (int) $sl["level_id"] == (int) $a_level_id)
124 {
125 unset($this->skill_level[$k]);
126 }
127 }
128 }
129
136 function getSkillLevels()
137 {
138 return $this->skill_level;
139 }
140
147 function read()
148 {
149 global $ilDB;
150
151 $set = $ilDB->query("SELECT * FROM skl_profile ".
152 " WHERE id = ".$ilDB->quote($this->getId(), "integer")
153 );
154 $rec = $ilDB->fetchAssoc($set);
155 $this->setTitle($rec["title"]);
156 $this->setDescription($rec["description"]);
157
158 $set = $ilDB->query("SELECT * FROM skl_profile_level ".
159 " WHERE profile_id = ".$ilDB->quote($this->getId(), "integer")
160 );
161 while ($rec = $ilDB->fetchAssoc($set))
162 {
163 $this->addSkillLevel((int) $rec["base_skill_id"], (int) $rec["tref_id"],
164 (int) $rec["level_id"]);
165 }
166 }
167
171 function create()
172 {
173 global $ilDB;
174
175 // profile
176 $this->setId($ilDB->nextId("skl_profile"));
177 $ilDB->manipulate("INSERT INTO skl_profile ".
178 "(id, title, description) VALUES (".
179 $ilDB->quote($this->getId(), "integer").",".
180 $ilDB->quote($this->getTitle(), "text").",".
181 $ilDB->quote($this->getDescription(), "text").
182 ")");
183
184 // profile levels
185 foreach ($this->skill_level as $level)
186 {
187 $ilDB->replace("skl_profile_level",
188 array("profile_id" => array("integer", $this->getId()),
189 "tref_id" => array("integer", (int) $level["tref_id"]),
190 "base_skill_id" => array("integer", (int) $level["base_skill_id"])
191 ),
192 array("level_id" => array("integer", (int) $level["level_id"]))
193 );
194 }
195 }
196
200 function update()
201 {
202 global $ilDB;
203
204 // profile
205 $ilDB->manipulate("UPDATE skl_profile SET ".
206 " title = ".$ilDB->quote($this->getTitle(), "text").",".
207 " description = ".$ilDB->quote($this->getDescription(), "text").
208 " WHERE id = ".$ilDB->quote($this->getId(), "integer")
209 );
210
211 // profile levels
212 $ilDB->manipulate("DELETE FROM skl_profile_level WHERE ".
213 " profile_id = ".$ilDB->quote($this->getId(), "integer")
214 );
215 foreach ($this->skill_level as $level)
216 {
217 $ilDB->replace("skl_profile_level",
218 array("profile_id" => array("integer", $this->getId()),
219 "tref_id" => array("integer", (int) $level["tref_id"]),
220 "base_skill_id" => array("integer", (int) $level["base_skill_id"])
221 ),
222 array("level_id" => array("integer", (int) $level["level_id"]))
223 );
224
225 /*$ilDB->manipulate("INSERT INTO skl_profile_level ".
226 "(profile_id, base_skill_id, tref_id, level_id) VALUES (".
227 $ilDB->quote($this->getId(), "integer").",".
228 $ilDB->quote((int) $level["base_skill_id"], "integer").",".
229 $ilDB->quote((int) $level["tref_id"], "integer").",".
230 $ilDB->quote((int) $level["level_id"], "integer").
231 ")");*/
232 }
233 }
234
238 function delete()
239 {
240 global $ilDB;
241
242 // profile levels
243 $ilDB->manipulate("DELETE FROM skl_profile_level WHERE ".
244 " profile_id = ".$ilDB->quote($this->getId(), "integer")
245 );
246
247 // profile
248 $ilDB->manipulate("DELETE FROM skl_profile WHERE ".
249 " id = ".$ilDB->quote($this->getId(), "integer")
250 );
251
252 }
253
260 static function getProfiles()
261 {
262 global $ilDB;
263
264 $set = $ilDB->query("SELECT * FROM skl_profile ".
265 " ORDER BY title "
266 );
267 $profiles = array();
268 while ($rec = $ilDB->fetchAssoc($set))
269 {
270 $profiles[$rec["id"]] = $rec;
271 }
272
273 return $profiles;
274 }
275
282 static protected function lookup($a_id, $a_field)
283 {
284 global $ilDB;
285
286 $set = $ilDB->query("SELECT ".$a_field." FROM skl_profile ".
287 " WHERE id = ".$ilDB->quote($a_id, "integer")
288 );
289 $rec = $ilDB->fetchAssoc($set);
290 return $rec[$a_field];
291 }
292
299 static function lookupTitle($a_id)
300 {
301 return self::lookup($a_id, "title");
302 }
303
307
312 {
313 global $ilDB;
314
315 $set = $ilDB->query("SELECT * FROM skl_profile_user ".
316 " WHERE profile_id = ".$ilDB->quote($this->getId(), "integer")
317 );
318 $users = array();
319 while ($rec = $ilDB->fetchAssoc($set))
320 {
321 $name = ilObjUser::_lookupName($rec["user_id"]);
322 $users[$rec["user_id"]] = array(
323 "lastname" => $name["lastname"],
324 "firstname" => $name["firstname"],
325 "login" => $name["login"],
326 "id" => $name["user_id"]
327 );
328 }
329 return $users;
330 }
331
337 function addUserToProfile($a_user_id)
338 {
339 global $ilDB;
340
341 $ilDB->replace("skl_profile_user",
342 array("profile_id" => array("integer", $this->getId()),
343 "user_id" => array("integer", (int) $a_user_id),
344 ),
345 array()
346 );
347 }
348
354 function removeUserFromProfile($a_user_id)
355 {
356 global $ilDB;
357
358 $ilDB->manipulate("DELETE FROM skl_profile_user WHERE ".
359 " profile_id = ".$ilDB->quote($this->getId(), "integer").
360 " AND user_id = ".$ilDB->quote($a_user_id, "integer")
361 );
362 }
363
369 static function getProfilesOfUser($a_user_id)
370 {
371 global $ilDB;
372
373 $profiles = array();
374 $set = $ilDB->query("SELECT p.id, p.title FROM skl_profile_user u JOIN skl_profile p ".
375 " ON (u.profile_id = p.id) ".
376 " WHERE user_id = ".$ilDB->quote($a_user_id, "integer").
377 " ORDER BY p.title ASC"
378 );
379 while ($rec = $ilDB->fetchAssoc($set))
380 {
381 $profiles[] = $rec;
382 }
383 return $profiles;
384 }
385
389 static function countUsers($a_profile_id)
390 {
391 global $ilDB;
392
393 $set = $ilDB->query("SELECT count(*) ucnt FROM skl_profile_user ".
394 " WHERE profile_id = ".$ilDB->quote($a_profile_id, "integer")
395 );
396 $rec = $ilDB->fetchAssoc($set);
397 return (int) $rec["ucnt"];
398 }
399
406 static public function getUsageInfo($a_cskill_ids, &$a_usages)
407 {
408 global $ilDB;
409
410 include_once("./Services/Skill/classes/class.ilSkillUsage.php");
412 "skl_profile_level", "profile_id", "base_skill_id");
413 }
414
415
416}
417
418?>
static _lookupName($a_user_id)
lookup user name
__construct($a_id=0)
Constructor.
setTitle($a_val)
Set title.
static getProfilesOfUser($a_user_id)
Get profiles of a user.
getSkillLevels()
Get skill levels.
setId($a_val)
Set id.
getAssignedUsers()
Get assigned users.
read()
Read skill profile from db.
addSkillLevel($a_base_skill_id, $a_tref_id, $a_level_id)
Add skill level.
static lookup($a_id, $a_field)
Lookup.
static getUsageInfo($a_cskill_ids, &$a_usages)
Get usage info.
removeSkillLevel($a_base_skill_id, $a_tref_id, $a_level_id)
Remove skill level.
static countUsers($a_profile_id)
Get assigned users.
update()
Update skill profile.
create()
Create skill profile.
setDescription($a_val)
Set description.
removeUserFromProfile($a_user_id)
Remove user from profile.
addUserToProfile($a_user_id)
Add user to profile.
static getProfiles()
Get profiles.
getDescription()
Get description.
static lookupTitle($a_id)
Lookup title.
static getUsageInfoGeneric($a_cskill_ids, &$a_usages, $a_usage_type, $a_table, $a_key_field, $a_skill_field="skill_id", $a_tref_field="tref_id")
Get standard usage query.
Get info on usages of skills.
global $ilDB