ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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{
19 protected $db;
20
21 protected $id;
22 protected $title;
23 protected $description;
24 protected $skill_level = array();
25
31 public function __construct($a_id = 0)
32 {
33 global $DIC;
34
35 $this->db = $DIC->database();
36 if ($a_id > 0) {
37 $this->setId($a_id);
38 $this->read();
39 }
40 }
41
47 public function setId($a_val)
48 {
49 $this->id = $a_val;
50 }
51
57 public function getId()
58 {
59 return $this->id;
60 }
61
67 public function setTitle($a_val)
68 {
69 $this->title = $a_val;
70 }
71
77 public function getTitle()
78 {
79 return $this->title;
80 }
81
87 public function setDescription($a_val)
88 {
89 $this->description = $a_val;
90 }
91
97 public function getDescription()
98 {
99 return $this->description;
100 }
101
108 public function addSkillLevel($a_base_skill_id, $a_tref_id, $a_level_id)
109 {
110 //echo "-".$a_base_skill_id."-";
111 $this->skill_level[] = array(
112 "base_skill_id" => $a_base_skill_id,
113 "tref_id" => $a_tref_id,
114 "level_id" => $a_level_id
115 );
116 }
117
124 public function removeSkillLevel($a_base_skill_id, $a_tref_id, $a_level_id)
125 {
126 foreach ($this->skill_level as $k => $sl) {
127 if ((int) $sl["base_skill_id"] == (int) $a_base_skill_id &&
128 (int) $sl["tref_id"] == (int) $a_tref_id &&
129 (int) $sl["level_id"] == (int) $a_level_id) {
130 unset($this->skill_level[$k]);
131 }
132 }
133 }
134
141 public function getSkillLevels()
142 {
143 return $this->skill_level;
144 }
145
152 public function read()
153 {
155
156 $set = $ilDB->query(
157 "SELECT * FROM skl_profile " .
158 " WHERE id = " . $ilDB->quote($this->getId(), "integer")
159 );
160 $rec = $ilDB->fetchAssoc($set);
161 $this->setTitle($rec["title"]);
162 $this->setDescription($rec["description"]);
163
164 $set = $ilDB->query(
165 "SELECT * FROM skl_profile_level " .
166 " WHERE profile_id = " . $ilDB->quote($this->getId(), "integer")
167 );
168 while ($rec = $ilDB->fetchAssoc($set)) {
169 $this->addSkillLevel(
170 (int) $rec["base_skill_id"],
171 (int) $rec["tref_id"],
172 (int) $rec["level_id"]
173 );
174 }
175 }
176
180 public function create()
181 {
183
184 // profile
185 $this->setId($ilDB->nextId("skl_profile"));
186 $ilDB->manipulate("INSERT INTO skl_profile " .
187 "(id, title, description) VALUES (" .
188 $ilDB->quote($this->getId(), "integer") . "," .
189 $ilDB->quote($this->getTitle(), "text") . "," .
190 $ilDB->quote($this->getDescription(), "text") .
191 ")");
192
193 // profile levels
194 foreach ($this->skill_level as $level) {
195 $ilDB->replace(
196 "skl_profile_level",
197 array("profile_id" => array("integer", $this->getId()),
198 "tref_id" => array("integer", (int) $level["tref_id"]),
199 "base_skill_id" => array("integer", (int) $level["base_skill_id"])
200 ),
201 array("level_id" => array("integer", (int) $level["level_id"]))
202 );
203 }
204 }
205
209 public function update()
210 {
212
213 // profile
214 $ilDB->manipulate(
215 "UPDATE skl_profile SET " .
216 " title = " . $ilDB->quote($this->getTitle(), "text") . "," .
217 " description = " . $ilDB->quote($this->getDescription(), "text") .
218 " WHERE id = " . $ilDB->quote($this->getId(), "integer")
219 );
220
221 // profile levels
222 $ilDB->manipulate(
223 "DELETE FROM skl_profile_level WHERE " .
224 " profile_id = " . $ilDB->quote($this->getId(), "integer")
225 );
226 foreach ($this->skill_level as $level) {
227 $ilDB->replace(
228 "skl_profile_level",
229 array("profile_id" => array("integer", $this->getId()),
230 "tref_id" => array("integer", (int) $level["tref_id"]),
231 "base_skill_id" => array("integer", (int) $level["base_skill_id"])
232 ),
233 array("level_id" => array("integer", (int) $level["level_id"]))
234 );
235
236 /*$ilDB->manipulate("INSERT INTO skl_profile_level ".
237 "(profile_id, base_skill_id, tref_id, level_id) VALUES (".
238 $ilDB->quote($this->getId(), "integer").",".
239 $ilDB->quote((int) $level["base_skill_id"], "integer").",".
240 $ilDB->quote((int) $level["tref_id"], "integer").",".
241 $ilDB->quote((int) $level["level_id"], "integer").
242 ")");*/
243 }
244 }
245
249 public function delete()
250 {
252
253 // profile levels
254 $ilDB->manipulate(
255 "DELETE FROM skl_profile_level WHERE " .
256 " profile_id = " . $ilDB->quote($this->getId(), "integer")
257 );
258
259 // profile
260 $ilDB->manipulate(
261 "DELETE FROM skl_profile WHERE " .
262 " id = " . $ilDB->quote($this->getId(), "integer")
263 );
264 }
265
272 public static function getProfiles()
273 {
274 global $DIC;
275
276 $ilDB = $DIC->database();
277
278 $set = $ilDB->query(
279 "SELECT * FROM skl_profile " .
280 " ORDER BY title "
281 );
282 $profiles = array();
283 while ($rec = $ilDB->fetchAssoc($set)) {
284 $profiles[$rec["id"]] = $rec;
285 }
286
287 return $profiles;
288 }
289
296 protected static function lookup($a_id, $a_field)
297 {
298 global $DIC;
299
300 $ilDB = $DIC->database();
301
302 $set = $ilDB->query(
303 "SELECT " . $a_field . " FROM skl_profile " .
304 " WHERE id = " . $ilDB->quote($a_id, "integer")
305 );
306 $rec = $ilDB->fetchAssoc($set);
307 return $rec[$a_field];
308 }
309
316 public static function lookupTitle($a_id)
317 {
318 return self::lookup($a_id, "title");
319 }
320
324
328 public function getAssignedUsers()
329 {
331
332 $set = $ilDB->query(
333 "SELECT * FROM skl_profile_user " .
334 " WHERE profile_id = " . $ilDB->quote($this->getId(), "integer")
335 );
336 $users = array();
337 while ($rec = $ilDB->fetchAssoc($set)) {
338 $name = ilObjUser::_lookupName($rec["user_id"]);
339 $users[$rec["user_id"]] = array(
340 "lastname" => $name["lastname"],
341 "firstname" => $name["firstname"],
342 "login" => $name["login"],
343 "id" => $name["user_id"]
344 );
345 }
346 return $users;
347 }
348
354 public function addUserToProfile($a_user_id)
355 {
357
358 $ilDB->replace(
359 "skl_profile_user",
360 array("profile_id" => array("integer", $this->getId()),
361 "user_id" => array("integer", (int) $a_user_id),
362 ),
363 array()
364 );
365 }
366
372 public function removeUserFromProfile($a_user_id)
373 {
375
376 $ilDB->manipulate(
377 "DELETE FROM skl_profile_user WHERE " .
378 " profile_id = " . $ilDB->quote($this->getId(), "integer") .
379 " AND user_id = " . $ilDB->quote($a_user_id, "integer")
380 );
381 }
382
388 public static function removeUserFromAllProfiles($a_user_id)
389 {
390 global $DIC;
391 $ilDB = $DIC->database();
392
393 $ilDB->manipulate(
394 "DELETE FROM skl_profile_user WHERE " .
395 " user_id = " . $ilDB->quote($a_user_id, "integer")
396 );
397 }
398
399
405 public static function getProfilesOfUser($a_user_id)
406 {
407 global $DIC;
408
409 $ilDB = $DIC->database();
410
411 $profiles = array();
412 $set = $ilDB->query(
413 "SELECT p.id, p.title FROM skl_profile_user u JOIN skl_profile p " .
414 " ON (u.profile_id = p.id) " .
415 " WHERE user_id = " . $ilDB->quote($a_user_id, "integer") .
416 " ORDER BY p.title ASC"
417 );
418 while ($rec = $ilDB->fetchAssoc($set)) {
419 $profiles[] = $rec;
420 }
421 return $profiles;
422 }
423
427 public static function countUsers($a_profile_id)
428 {
429 global $DIC;
430
431 $ilDB = $DIC->database();
432
433 $set = $ilDB->query(
434 "SELECT count(*) ucnt FROM skl_profile_user " .
435 " WHERE profile_id = " . $ilDB->quote($a_profile_id, "integer")
436 );
437 $rec = $ilDB->fetchAssoc($set);
438 return (int) $rec["ucnt"];
439 }
440
447 public static function getUsageInfo($a_cskill_ids, &$a_usages)
448 {
449 global $DIC;
450
451 $ilDB = $DIC->database();
452
453 include_once("./Services/Skill/classes/class.ilSkillUsage.php");
455 $a_cskill_ids,
456 $a_usages,
458 "skl_profile_level",
459 "profile_id",
460 "base_skill_id"
461 );
462 }
463}
$users
Definition: authpage.php:44
An exception for terminatinating execution or to throw for unit testing.
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.
static removeUserFromAllProfiles($a_user_id)
Remove user from all profiles.
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.
if($format !==null) $name
Definition: metadata.php:146
global $DIC
Definition: saml.php:7
global $ilDB