ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
5 include_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  {
154  $ilDB = $this->db;
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  {
182  $ilDB = $this->db;
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  {
211  $ilDB = $this->db;
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  {
251  $ilDB = $this->db;
252 
253  // TODO: Split the deletions when refactoring to repository pattern
254 
255  // profile levels
256  $ilDB->manipulate(
257  "DELETE FROM skl_profile_level WHERE " .
258  " profile_id = " . $ilDB->quote($this->getId(), "integer")
259  );
260 
261  // profile users
262  $ilDB->manipulate(
263  "DELETE FROM skl_profile_user WHERE " .
264  " profile_id = " . $ilDB->quote($this->getId(), "integer")
265  );
266 
267  // profile roles
268  $ilDB->manipulate(
269  "DELETE FROM skl_profile_role WHERE " .
270  " profile_id = " . $ilDB->quote($this->getId(), "integer")
271  );
272 
273  // profile
274  $ilDB->manipulate(
275  "DELETE FROM skl_profile WHERE " .
276  " id = " . $ilDB->quote($this->getId(), "integer")
277  );
278  }
279 
286  public static function getProfiles()
287  {
288  global $DIC;
289 
290  $ilDB = $DIC->database();
291 
292  $set = $ilDB->query(
293  "SELECT * FROM skl_profile " .
294  " ORDER BY title "
295  );
296  $profiles = array();
297  while ($rec = $ilDB->fetchAssoc($set)) {
298  $profiles[$rec["id"]] = $rec;
299  }
300 
301  return $profiles;
302  }
303 
310  protected static function lookup($a_id, $a_field)
311  {
312  global $DIC;
313 
314  $ilDB = $DIC->database();
315 
316  $set = $ilDB->query(
317  "SELECT " . $a_field . " FROM skl_profile " .
318  " WHERE id = " . $ilDB->quote($a_id, "integer")
319  );
320  $rec = $ilDB->fetchAssoc($set);
321  return $rec[$a_field];
322  }
323 
330  public static function lookupTitle($a_id)
331  {
332  return self::lookup($a_id, "title");
333  }
334 
338 
342  public function getAssignedUsers()
343  {
344  $ilDB = $this->db;
345 
346  $set = $ilDB->query(
347  "SELECT * FROM skl_profile_user " .
348  " WHERE profile_id = " . $ilDB->quote($this->getId(), "integer")
349  );
350  $users = array();
351  while ($rec = $ilDB->fetchAssoc($set)) {
352  $name = ilObjUser::_lookupName($rec["user_id"]);
353  $users[$rec["user_id"]] = array(
354  "lastname" => $name["lastname"],
355  "firstname" => $name["firstname"],
356  "login" => $name["login"],
357  "id" => $name["user_id"]
358  );
359  }
360  return $users;
361  }
362 
368  public function addUserToProfile($a_user_id)
369  {
370  $ilDB = $this->db;
371 
372  $ilDB->replace(
373  "skl_profile_user",
374  array("profile_id" => array("integer", $this->getId()),
375  "user_id" => array("integer", (int) $a_user_id),
376  ),
377  array()
378  );
379  }
380 
386  public function removeUserFromProfile($a_user_id)
387  {
388  $ilDB = $this->db;
389 
390  $ilDB->manipulate(
391  "DELETE FROM skl_profile_user WHERE " .
392  " profile_id = " . $ilDB->quote($this->getId(), "integer") .
393  " AND user_id = " . $ilDB->quote($a_user_id, "integer")
394  );
395  }
396 
402  public static function removeUserFromAllProfiles($a_user_id)
403  {
404  global $DIC;
405  $ilDB = $DIC->database();
406 
407  $ilDB->manipulate(
408  "DELETE FROM skl_profile_user WHERE " .
409  " user_id = " . $ilDB->quote($a_user_id, "integer")
410  );
411  }
412 
413 
419  public static function getProfilesOfUser($a_user_id)
420  {
421  global $DIC;
422 
423  $ilDB = $DIC->database();
424 
425  $profiles = array();
426  $set = $ilDB->query(
427  "SELECT p.id, p.title FROM skl_profile_user u JOIN skl_profile p " .
428  " ON (u.profile_id = p.id) " .
429  " WHERE user_id = " . $ilDB->quote($a_user_id, "integer") .
430  " ORDER BY p.title ASC"
431  );
432  while ($rec = $ilDB->fetchAssoc($set)) {
433  $profiles[] = $rec;
434  }
435  return $profiles;
436  }
437 
441  public static function countUsers($a_profile_id)
442  {
443  global $DIC;
444 
445  $ilDB = $DIC->database();
446 
447  $set = $ilDB->query(
448  "SELECT count(*) ucnt FROM skl_profile_user " .
449  " WHERE profile_id = " . $ilDB->quote($a_profile_id, "integer")
450  );
451  $rec = $ilDB->fetchAssoc($set);
452  return (int) $rec["ucnt"];
453  }
454 
461  public static function getUsageInfo($a_cskill_ids, &$a_usages)
462  {
463  global $DIC;
464 
465  $ilDB = $DIC->database();
466 
467  include_once("./Services/Skill/classes/class.ilSkillUsage.php");
469  $a_cskill_ids,
470  $a_usages,
472  "skl_profile_level",
473  "profile_id",
474  "base_skill_id"
475  );
476  }
477 }
Get info on usages of skills.
static _lookupName($a_user_id)
lookup user name
static getProfiles()
Get profiles.
global $DIC
Definition: saml.php:7
static removeUserFromAllProfiles($a_user_id)
Remove user from all profiles.
setTitle($a_val)
Set title.
setId($a_val)
Set id.
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.
addUserToProfile($a_user_id)
Add user to profile.
update()
Update skill profile.
getSkillLevels()
Get skill levels.
static getProfilesOfUser($a_user_id)
Get profiles of a user.
getDescription()
Get description.
__construct($a_id=0)
Constructor.
$users
Definition: authpage.php:44
setDescription($a_val)
Set description.
static getUsageInfo($a_cskill_ids, &$a_usages)
Get usage info.
read()
Read skill profile from db.
removeSkillLevel($a_base_skill_id, $a_tref_id, $a_level_id)
Remove skill level.
static countUsers($a_profile_id)
Get assigned users.
global $ilDB
addSkillLevel($a_base_skill_id, $a_tref_id, $a_level_id)
Add skill level.
create()
Create skill profile.
static lookup($a_id, $a_field)
Lookup.
static lookupTitle($a_id)
Lookup title.
getAssignedUsers()
Get assigned users.
removeUserFromProfile($a_user_id)
Remove user from profile.