ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilBasicSkill.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
6 include_once("./Services/Skill/interfaces/interface.ilSkillUsageInfo.php");
7 
17 {
21  protected $db;
22 
26  protected $user;
27 
28  const ACHIEVED = 1;
29  const NOT_ACHIEVED = 0;
30 
31  const EVAL_BY_OTHERS_= 0;
32  const EVAL_BY_SELF = 1;
33  const EVAL_BY_ALL = 2;
34 
35  public $id;
36 
41  public function __construct($a_id = 0)
42  {
43  global $DIC;
44 
45  $this->db = $DIC->database();
46  $this->user = $DIC->user();
47  parent::__construct($a_id);
48  $this->setType("skll");
49  }
50 
54  public function read()
55  {
56  parent::read();
57  }
58 
63  public function create()
64  {
65  parent::create();
66  }
67 
71  public function delete()
72  {
73  $ilDB = $this->db;
74 
75  $ilDB->manipulate(
76  "DELETE FROM skl_level WHERE "
77  . " skill_id = " . $ilDB->quote($this->getId(), "integer")
78  );
79 
80  $ilDB->manipulate(
81  "DELETE FROM skl_user_has_level WHERE "
82  . " skill_id = " . $ilDB->quote($this->getId(), "integer")
83  );
84 
85  parent::delete();
86  }
87 
91  public function copy()
92  {
93  $skill = new ilBasicSkill();
94  $skill->setTitle($this->getTitle());
95  $skill->setType($this->getType());
96  $skill->setSelfEvaluation($this->getSelfEvaluation());
97  $skill->setOrderNr($this->getOrderNr());
98  $skill->create();
99 
100  $levels = $this->getLevelData();
101  if (sizeof($levels)) {
102  foreach ($levels as $item) {
103  $skill->addLevel($item["title"], $item["description"]);
104  }
105  }
106  $skill->update();
107 
108  return $skill;
109  }
110 
111  //
112  //
113  // Skill level related methods
114  //
115  //
116 
123  public function addLevel($a_title, $a_description, $a_import_id = "")
124  {
125  $ilDB = $this->db;
126 
127  $nr = $this->getMaxLevelNr();
128  $nid = $ilDB->nextId("skl_level");
129  $ilDB->insert("skl_level", array(
130  "id" => array("integer", $nid),
131  "skill_id" => array("integer", $this->getId()),
132  "nr" => array("integer", $nr+1),
133  "title" => array("text", $a_title),
134  "description" => array("clob", $a_description),
135  "import_id" => array("text", $a_import_id),
136  "creation_date" => array("timestamp", ilUtil::now())
137  ));
138  }
139 
145  public function getMaxLevelNr()
146  {
147  $ilDB = $this->db;
148 
149  $set = $ilDB->query(
150  "SELECT MAX(nr) mnr FROM skl_level WHERE " .
151  " skill_id = " . $ilDB->quote($this->getId(), "integer")
152  );
153  $rec = $ilDB->fetchAssoc($set);
154  return (int) $rec["mnr"];
155  }
156 
162  public function getLevelData($a_id = 0)
163  {
164  $ilDB = $this->db;
165 
166  if ($a_id > 0) {
167  $and = " AND id = " . $ilDB->quote($a_id, "integer");
168  }
169 
170  $set = $ilDB->query(
171  "SELECT * FROM skl_level WHERE " .
172  " skill_id = " . $ilDB->quote($this->getId(), "integer") .
173  $and .
174  " ORDER BY nr"
175  );
176  $levels = array();
177  while ($rec = $ilDB->fetchAssoc($set)) {
178  if ($a_id > 0) {
179  return $rec;
180  }
181  $levels[] = $rec;
182  }
183  return $levels;
184  }
185 
192  protected static function lookupLevelProperty($a_id, $a_prop)
193  {
194  global $DIC;
195 
196  $ilDB = $DIC->database();
197 
198  $set = $ilDB->query(
199  "SELECT $a_prop FROM skl_level WHERE " .
200  " id = " . $ilDB->quote($a_id, "integer")
201  );
202  $rec = $ilDB->fetchAssoc($set);
203  return $rec[$a_prop];
204  }
205 
212  public static function lookupLevelTitle($a_id)
213  {
214  return ilBasicSkill::lookupLevelProperty($a_id, "title");
215  }
216 
223  public static function lookupLevelDescription($a_id)
224  {
225  return ilBasicSkill::lookupLevelProperty($a_id, "description");
226  }
227 
234  public static function lookupLevelSkillId($a_id)
235  {
236  return ilBasicSkill::lookupLevelProperty($a_id, "skill_id");
237  }
238 
245  protected static function writeLevelProperty($a_id, $a_prop, $a_value, $a_type)
246  {
247  global $DIC;
248 
249  $ilDB = $DIC->database();
250 
251  $ilDB->update("skl_level", array(
252  $a_prop => array($a_type, $a_value),
253  ), array(
254  "id" => array("integer", $a_id),
255  ));
256  }
257 
264  public static function writeLevelTitle($a_id, $a_title)
265  {
266  ilBasicSkill::writeLevelProperty($a_id, "title", $a_title, "text");
267  }
268 
275  public static function writeLevelDescription($a_id, $a_description)
276  {
277  ilBasicSkill::writeLevelProperty($a_id, "description", $a_description, "clob");
278  }
279 
286  public function updateLevelOrder($order)
287  {
288  $ilDB = $this->db;
289 
290  asort($order);
291 
292  $cnt = 1;
293  foreach ($order as $id => $o) {
294  $ilDB->manipulate(
295  "UPDATE skl_level SET " .
296  " nr = " . $ilDB->quote($cnt, "integer") .
297  " WHERE id = " . $ilDB->quote($id, "integer")
298  );
299  $cnt++;
300  }
301  }
302 
309  public function deleteLevel($a_id)
310  {
311  $ilDB = $this->db;
312 
313  $ilDB->manipulate(
314  "DELETE FROM skl_level WHERE "
315  . " id = " . $ilDB->quote($a_id, "integer")
316  );
317  }
318 
325  public function fixLevelNumbering()
326  {
327  $ilDB = $this->db;
328 
329  $set = $ilDB->query(
330  "SELECT id, nr FROM skl_level WHERE " .
331  " skill_id = " . $ilDB->quote($this->getId(), "integer") .
332  " ORDER BY nr ASC"
333  );
334  $cnt = 1;
335  while ($rec = $ilDB->fetchAssoc($set)) {
336  $ilDB->manipulate(
337  "UPDATE skl_level SET " .
338  " nr = " . $ilDB->quote($cnt, "integer") .
339  " WHERE id = " . $ilDB->quote($rec["id"], "integer")
340  );
341  $cnt++;
342  }
343  }
344 
351  public function getSkillForLevelId($a_level_id)
352  {
353  $ilDB = $this->db;
354 
355  $set = $ilDB->query(
356  "SELECT * FROM skl_level WHERE " .
357  " id = " . $ilDB->quote($a_level_id, "integer")
358  );
359  $skill = null;
360  if ($rec = $ilDB->fetchAssoc($set)) {
361  if (ilSkillTreeNode::isInTree($rec["skill_id"])) {
362  $skill = new ilBasicSkill($rec["skill_id"]);
363  }
364  }
365  return $skill;
366  }
367 
368  //
369  //
370  // User skill (level) related methods
371  //
372  //
373 
374 
387  public static function resetUserSkillLevelStatus($a_user_id, $a_skill_id, $a_tref_id = 0, $a_trigger_ref_id = 0, $a_self_eval = false)
388  {
389  global $DIC;
390 
391  $db = $DIC->database();
392 
393  if (!$a_self_eval) {
394  include_once("./Services/Skill/exceptions/class.ilSkillException.php");
395  throw new ilSkillException("resetUserSkillLevelStatus currently only provided for self evaluations.");
396  }
397 
398  $trigger_obj_id = ($a_trigger_ref_id > 0)
399  ? ilObject::_lookupObjId($a_trigger_ref_id)
400  : 0;
401 
402  $update = false;
403  $status_date = self::hasRecentSelfEvaluation($a_user_id, $a_skill_id, $a_tref_id, $a_trigger_ref_id);
404  if ($status_date != "") {
405  $update = true;
406  }
407 
408  if ($update) {
409  // this will only be set in self eval case, means this will always have a $rec
410  $now = ilUtil::now();
411  $db->manipulate(
412  "UPDATE skl_user_skill_level SET " .
413  " level_id = " . $db->quote(0, "integer") . "," .
414  " status_date = " . $db->quote($now, "timestamp") .
415  " WHERE user_id = " . $db->quote($a_user_id, "integer") .
416  " AND status_date = " . $db->quote($status_date, "timestamp") .
417  " AND skill_id = " . $db->quote($a_skill_id, "integer") .
418  " AND status = " . $db->quote(self::ACHIEVED, "integer") .
419  " AND trigger_obj_id = " . $db->quote($trigger_obj_id, "integer") .
420  " AND tref_id = " . $db->quote((int) $a_tref_id, "integer") .
421  " AND self_eval = " . $db->quote($a_self_eval, "integer")
422  );
423  } else {
424  $now = ilUtil::now();
425  $db->manipulate("INSERT INTO skl_user_skill_level " .
426  "(level_id, user_id, tref_id, status_date, skill_id, status, valid, trigger_ref_id," .
427  "trigger_obj_id, trigger_obj_type, trigger_title, self_eval, unique_identifier) VALUES (" .
428  $db->quote(0, "integer") . "," .
429  $db->quote($a_user_id, "integer") . "," .
430  $db->quote((int) $a_tref_id, "integer") . "," .
431  $db->quote($now, "timestamp") . "," .
432  $db->quote($a_skill_id, "integer") . "," .
433  $db->quote(self::ACHIEVED, "integer") . "," .
434  $db->quote(1, "integer") . "," .
435  $db->quote($a_trigger_ref_id, "integer") . "," .
436  $db->quote($trigger_obj_id, "integer") . "," .
437  $db->quote("", "text") . "," .
438  $db->quote("", "text") . "," .
439  $db->quote($a_self_eval, "integer") . "," .
440  $db->quote("", "text") .
441  ")");
442  }
443 
444  $db->manipulate(
445  "DELETE FROM skl_user_has_level WHERE "
446  . " user_id = " . $db->quote($a_user_id, "integer")
447  . " AND skill_id = " . $db->quote($a_skill_id, "integer")
448  . " AND tref_id = " . $db->quote((int) $a_tref_id, "integer")
449  . " AND trigger_obj_id = " . $db->quote($trigger_obj_id, "integer")
450  . " AND self_eval = " . $db->quote($a_self_eval, "integer")
451  );
452  }
453 
461  protected static function hasRecentSelfEvaluation($a_user_id, $a_skill_id, $a_tref_id = 0, $a_trigger_ref_id = 0)
462  {
463  global $DIC;
464 
465  $db = $DIC->database();
466 
467  $trigger_obj_id = ($a_trigger_ref_id > 0)
468  ? ilObject::_lookupObjId($a_trigger_ref_id)
469  : 0;
470 
471  $recent = "";
472 
473  $db->setLimit(1);
474  $set = $db->query(
475  "SELECT * FROM skl_user_skill_level WHERE " .
476  "skill_id = " . $db->quote($a_skill_id, "integer") . " AND " .
477  "user_id = " . $db->quote($a_user_id, "integer") . " AND " .
478  "tref_id = " . $db->quote((int) $a_tref_id, "integer") . " AND " .
479  "trigger_obj_id = " . $db->quote($trigger_obj_id, "integer") . " AND " .
480  "self_eval = " . $db->quote(1, "integer") .
481  " ORDER BY status_date DESC"
482  );
483  $rec = $db->fetchAssoc($set);
484  $status_day = substr($rec["status_date"], 0, 10);
485  $today = substr(ilUtil::now(), 0, 10);
486  if ($rec["valid"] && $rec["status"] == ilBasicSkill::ACHIEVED && $status_day == $today) {
487  $recent = $rec["status_date"];
488  }
489 
490  return $recent;
491  }
492 
499  public static function getNewAchievementsPerUser($a_timestamp)
500  {
501  global $DIC;
502 
503  $db = $DIC->database();
504 
505  $set = $db->query("SELECT * FROM skl_user_skill_level " .
506  " WHERE status_date >= " . $db->quote($a_timestamp, "timestamp") .
507  " AND valid = " . $db->quote(1, "integer") .
508  " AND status = " . $db->quote(ilBasicSkill::ACHIEVED, "integer") .
509  " AND self_eval = " . $db->quote(0, "integer") .
510  " ORDER BY user_id, status_date ASC ");
511  $achievments = array();
512  while ($rec = $db->fetchAssoc($set)) {
513  $achievments[$rec["user_id"]][] = $rec;
514  }
515 
516  return $achievments;
517  }
518 
519 
532  public static function writeUserSkillLevelStatus(
533  $a_level_id,
534  $a_user_id,
535  $a_trigger_ref_id,
536  $a_tref_id = 0,
537  $a_status = ilBasicSkill::ACHIEVED,
538  $a_force = false,
539  $a_self_eval = false,
540  $a_unique_identifier = ""
541  ) {
542  global $DIC;
543 
544  $ilDB = $DIC->database();
545 
546  $skill_id = ilBasicSkill::lookupLevelSkillId($a_level_id);
547  $trigger_ref_id = $a_trigger_ref_id;
548  $trigger_obj_id = ilObject::_lookupObjId($trigger_ref_id);
549  $trigger_title = ilObject::_lookupTitle($trigger_obj_id);
550  $trigger_type = ilObject::_lookupType($trigger_obj_id);
551 
552  $update = false;
553 
554  // self evaluations will update, if the last self evaluation is on the same day
555  if ($a_self_eval && self::hasRecentSelfEvaluation($a_user_id, $skill_id, $a_tref_id, $trigger_ref_id)) {
556  $status_date = self::hasRecentSelfEvaluation($a_user_id, $skill_id, $a_tref_id, $trigger_ref_id);
557  if ($status_date != "") {
558  $update = true;
559  }
560  }
561 
562  if ($update) {
563  // this will only be set in self eval case, means this will always have a $rec
564  $now = ilUtil::now();
565  $ilDB->manipulate(
566  "UPDATE skl_user_skill_level SET " .
567  " level_id = " . $ilDB->quote($a_level_id, "integer") . "," .
568  " status_date = " . $ilDB->quote($now, "timestamp") .
569  " WHERE user_id = " . $ilDB->quote($a_user_id, "integer") .
570  " AND status_date = " . $ilDB->quote($status_date, "timestamp") .
571  " AND skill_id = " . $ilDB->quote($skill_id, "integer") .
572  " AND status = " . $ilDB->quote($a_status, "integer") .
573  " AND trigger_obj_id = " . $ilDB->quote($trigger_obj_id, "integer") .
574  " AND tref_id = " . $ilDB->quote((int) $a_tref_id, "integer") .
575  " AND self_eval = " . $ilDB->quote($a_self_eval, "integer")
576  );
577  } else {
578  if ($a_unique_identifier != "") {
579  $ilDB->manipulate(
580  "DELETE FROM skl_user_skill_level WHERE " .
581  " user_id = " . $ilDB->quote($a_user_id, "integer") .
582  " AND tref_id = " . $ilDB->quote($a_tref_id, "integer") .
583  " AND skill_id = " . $ilDB->quote($skill_id, "integer") .
584  " AND trigger_ref_id = " . $ilDB->quote($trigger_ref_id, "integer") .
585  " AND trigger_obj_id = " . $ilDB->quote($trigger_obj_id, "integer") .
586  " AND self_eval = " . $ilDB->quote($a_self_eval, "integer") .
587  " AND unique_identifier = " . $ilDB->quote($a_unique_identifier, "text")
588  );
589  }
590 
591  $now = ilUtil::now();
592  $ilDB->manipulate("INSERT INTO skl_user_skill_level " .
593  "(level_id, user_id, tref_id, status_date, skill_id, status, valid, trigger_ref_id," .
594  "trigger_obj_id, trigger_obj_type, trigger_title, self_eval, unique_identifier) VALUES (" .
595  $ilDB->quote($a_level_id, "integer") . "," .
596  $ilDB->quote($a_user_id, "integer") . "," .
597  $ilDB->quote((int) $a_tref_id, "integer") . "," .
598  $ilDB->quote($now, "timestamp") . "," .
599  $ilDB->quote($skill_id, "integer") . "," .
600  $ilDB->quote($a_status, "integer") . "," .
601  $ilDB->quote(1, "integer") . "," .
602  $ilDB->quote($trigger_ref_id, "integer") . "," .
603  $ilDB->quote($trigger_obj_id, "integer") . "," .
604  $ilDB->quote($trigger_type, "text") . "," .
605  $ilDB->quote($trigger_title, "text") . "," .
606  $ilDB->quote($a_self_eval, "integer") . "," .
607  $ilDB->quote($a_unique_identifier, "text") .
608  ")");
609  }
610 
611  // fix (removed level_id and added skill id, since table should hold only
612  // one entry per skill)
613  $ilDB->manipulate(
614  "DELETE FROM skl_user_has_level WHERE "
615  . " user_id = " . $ilDB->quote($a_user_id, "integer")
616  . " AND skill_id = " . $ilDB->quote($skill_id, "integer")
617  . " AND tref_id = " . $ilDB->quote((int) $a_tref_id, "integer")
618  . " AND trigger_obj_id = " . $ilDB->quote($trigger_obj_id, "integer")
619  . " AND self_eval = " . $ilDB->quote($a_self_eval, "integer")
620  );
621 
622  if ($a_status == ilBasicSkill::ACHIEVED) {
623  $ilDB->manipulate("INSERT INTO skl_user_has_level " .
624  "(level_id, user_id, tref_id, status_date, skill_id, trigger_ref_id, trigger_obj_id, trigger_obj_type, trigger_title, self_eval) VALUES (" .
625  $ilDB->quote($a_level_id, "integer") . "," .
626  $ilDB->quote($a_user_id, "integer") . "," .
627  $ilDB->quote($a_tref_id, "integer") . "," .
628  $ilDB->quote($now, "timestamp") . "," .
629  $ilDB->quote($skill_id, "integer") . "," .
630  $ilDB->quote($trigger_ref_id, "integer") . "," .
631  $ilDB->quote($trigger_obj_id, "integer") . "," .
632  $ilDB->quote($trigger_type, "text") . "," .
633  $ilDB->quote($trigger_title, "text") . "," .
634  $ilDB->quote($a_self_eval, "integer") .
635  ")");
636  }
637  }
638 
648  public static function removeAllUserSkillLevelStatusOfObject($a_user_id, $a_trigger_obj_id, $a_self_eval = false, $a_unique_identifier = "")
649  {
650  global $DIC;
651 
652  $db = $DIC->database();
653 
654  if ($a_trigger_obj_id == 0) {
655  return false;
656  }
657 
658  $changed = false;
659 
660  $aff_rows = $db->manipulate(
661  "DELETE FROM skl_user_skill_level WHERE "
662  . " user_id = " . $db->quote($a_user_id, "integer")
663  . " AND trigger_obj_id = " . $db->quote($a_trigger_obj_id, "integer")
664  . " AND self_eval = " . $db->quote($a_self_eval, "integer")
665  . " AND unique_identifier = " . $db->quote($a_unique_identifier, "text")
666  );
667  if ($aff_rows > 0) {
668  $changed = true;
669  }
670 
671  $aff_rows = $db->manipulate(
672  "DELETE FROM skl_user_has_level WHERE "
673  . " user_id = " . $db->quote($a_user_id, "integer")
674  . " AND trigger_obj_id = " . $db->quote($a_trigger_obj_id, "integer")
675  . " AND self_eval = " . $db->quote($a_self_eval, "integer")
676  );
677  if ($aff_rows > 0) {
678  $changed = true;
679  }
680  return $changed;
681  }
682 
688  public static function removeAllUserData($a_user_id)
689  {
690  global $DIC;
691 
692  $db = $DIC->database();
693 
694  $db->manipulate(
695  "DELETE FROM skl_user_skill_level WHERE "
696  . " user_id = " . $db->quote($a_user_id, "integer")
697  );
698  $db->manipulate(
699  "DELETE FROM skl_user_has_level WHERE "
700  . " user_id = " . $db->quote($a_user_id, "integer")
701  );
702  }
703 
704 
711  public function getMaxLevelPerType($a_tref_id, $a_type, $a_user_id = 0, $a_self_eval = 0)
712  {
713  $ilDB = $this->db;
715 
716  if ($a_user_id == 0) {
717  $a_user_id = $ilUser->getId();
718  }
719 
720  $set = $ilDB->query(
721  $q = "SELECT level_id FROM skl_user_has_level " .
722  " WHERE trigger_obj_type = " . $ilDB->quote($a_type, "text") .
723  " AND skill_id = " . $ilDB->quote($this->getId(), "integer") .
724  " AND tref_id = " . $ilDB->quote((int) $a_tref_id, "integer") .
725  " AND user_id = " . $ilDB->quote($a_user_id, "integer") .
726  " AND self_eval = " . $ilDB->quote($a_self_eval, "integer")
727  );
728 
729  $has_level = array();
730  while ($rec = $ilDB->fetchAssoc($set)) {
731  $has_level[$rec["level_id"]] = true;
732  }
733  $max_level = 0;
734  foreach ($this->getLevelData() as $l) {
735  if (isset($has_level[$l["id"]])) {
736  $max_level = $l["id"];
737  }
738  }
739  return $max_level;
740  }
741 
748  public function getAllLevelEntriesOfUser($a_tref_id, $a_user_id = 0, $a_self_eval = 0)
749  {
750  $ilDB = $this->db;
752 
753  if ($a_user_id == 0) {
754  $a_user_id = $ilUser->getId();
755  }
756 
757  $set = $ilDB->query(
758  $q = "SELECT * FROM skl_user_has_level " .
759  " WHERE skill_id = " . $ilDB->quote($this->getId(), "integer") .
760  " AND tref_id = " . $ilDB->quote((int) $a_tref_id, "integer") .
761  " AND user_id = " . $ilDB->quote($a_user_id, "integer") .
762  " AND self_eval = " . $ilDB->quote($a_self_eval, "integer") .
763  " ORDER BY status_date DESC"
764  );
765 
766  $levels = array();
767  while ($rec = $ilDB->fetchAssoc($set)) {
768  $levels[] = $rec;
769  }
770  return $levels;
771  }
772 
779  public function getAllHistoricLevelEntriesOfUser($a_tref_id, $a_user_id = 0, $a_eval_by = 0)
780  {
781  $ilDB = $this->db;
783 
784  if ($a_user_id == 0) {
785  $a_user_id = $ilUser->getId();
786  }
787 
788  $by = ($a_eval_by != self::EVAL_BY_ALL)
789  ? " AND self_eval = " . $ilDB->quote($a_self_eval, "integer")
790  : "";
791 
792  $set = $ilDB->query(
793  $q = "SELECT * FROM skl_user_skill_level " .
794  " WHERE skill_id = " . $ilDB->quote($this->getId(), "integer") .
795  " AND tref_id = " . $ilDB->quote((int) $a_tref_id, "integer") .
796  " AND user_id = " . $ilDB->quote($a_user_id, "integer") .
797  $by .
798  " ORDER BY status_date DESC"
799  );
800  $levels = array();
801  while ($rec = $ilDB->fetchAssoc($set)) {
802  $levels[] = $rec;
803  }
804  return $levels;
805  }
806 
807 
814  public function getMaxLevelPerObject($a_tref_id, $a_object_id, $a_user_id = 0, $a_self_eval = 0)
815  {
816  $ilDB = $this->db;
818 
819  if ($a_user_id == 0) {
820  $a_user_id = $ilUser->getId();
821  }
822 
823  $set = $ilDB->query(
824  $q = "SELECT level_id FROM skl_user_has_level " .
825  " WHERE trigger_obj_id = " . $ilDB->quote($a_object_id, "integer") .
826  " AND skill_id = " . $ilDB->quote($this->getId(), "integer") .
827  " AND tref_id = " . $ilDB->quote((int) $a_tref_id, "integer") .
828  " AND user_id = " . $ilDB->quote($a_user_id, "integer") .
829  " AND self_eval = " . $ilDB->quote($a_self_eval, "integer")
830  );
831 
832  $has_level = array();
833  while ($rec = $ilDB->fetchAssoc($set)) {
834  $has_level[$rec["level_id"]] = true;
835  }
836  $max_level = 0;
837  foreach ($this->getLevelData() as $l) {
838  if (isset($has_level[$l["id"]])) {
839  $max_level = $l["id"];
840  }
841  }
842  return $max_level;
843  }
844 
851  public function getMaxLevel($a_tref_id, $a_user_id = 0, $a_self_eval = 0)
852  {
853  $ilDB = $this->db;
855 
856  if ($a_user_id == 0) {
857  $a_user_id = $ilUser->getId();
858  }
859 
860  $set = $ilDB->query(
861  $q = "SELECT level_id FROM skl_user_has_level " .
862  " WHERE skill_id = " . $ilDB->quote($this->getId(), "integer") .
863  " AND tref_id = " . $ilDB->quote((int) $a_tref_id, "integer") .
864  " AND user_id = " . $ilDB->quote($a_user_id, "integer") .
865  " AND self_eval = " . $ilDB->quote($a_self_eval, "integer")
866  );
867 
868  $has_level = array();
869  while ($rec = $ilDB->fetchAssoc($set)) {
870  $has_level[$rec["level_id"]] = true;
871  }
872  $max_level = 0;
873  foreach ($this->getLevelData() as $l) {
874  if (isset($has_level[$l["id"]])) {
875  $max_level = $l["id"];
876  }
877  }
878  return $max_level;
879  }
880 
881 
890  public static function hasSelfEvaluated($a_user_id, $a_skill_id, $a_tref_id)
891  {
892  global $DIC;
893 
894  $db = $DIC->database();
895 
896  $set = $db->query(
897  $q = "SELECT level_id FROM skl_user_has_level " .
898  " WHERE skill_id = " . $db->quote((int) $a_skill_id, "integer") .
899  " AND tref_id = " . $db->quote((int) $a_tref_id, "integer") .
900  " AND user_id = " . $db->quote($a_user_id, "integer") .
901  " AND self_eval = " . $db->quote(1, "integer")
902  );
903 
904  if ($rec = $db->fetchAssoc($set)) {
905  return true;
906  }
907  return false;
908  }
909 
916  public function getLastLevelPerObject($a_tref_id, $a_object_id, $a_user_id = 0, $a_self_eval = 0)
917  {
918  $ilDB = $this->db;
920 
921  if ($a_user_id == 0) {
922  $a_user_id = $ilUser->getId();
923  }
924 
925  $ilDB->setLimit(1);
926  $set = $ilDB->query(
927  $q = "SELECT level_id FROM skl_user_has_level " .
928  " WHERE trigger_obj_id = " . $ilDB->quote($a_object_id, "integer") .
929  " AND skill_id = " . $ilDB->quote($this->getId(), "integer") .
930  " AND tref_id = " . $ilDB->quote((int) $a_tref_id, "integer") .
931  " AND user_id = " . $ilDB->quote($a_user_id, "integer") .
932  " AND self_eval = " . $ilDB->quote($a_self_eval, "integer") .
933  " ORDER BY status_date DESC"
934  );
935 
936  $rec = $ilDB->fetchAssoc($set);
937 
938  return $rec["level_id"];
939  }
940 
947  public function getLastUpdatePerObject($a_tref_id, $a_object_id, $a_user_id = 0, $a_self_eval = 0)
948  {
949  $ilDB = $this->db;
951 
952  if ($a_user_id == 0) {
953  $a_user_id = $ilUser->getId();
954  }
955 
956  $ilDB->setLimit(1);
957  $set = $ilDB->query(
958  $q = "SELECT status_date FROM skl_user_has_level " .
959  " WHERE trigger_obj_id = " . $ilDB->quote($a_object_id, "integer") .
960  " AND skill_id = " . $ilDB->quote($this->getId(), "integer") .
961  " AND tref_id = " . $ilDB->quote((int) $a_tref_id, "integer") .
962  " AND user_id = " . $ilDB->quote($a_user_id, "integer") .
963  " AND self_eval = " . $ilDB->quote($a_self_eval, "integer") .
964  " ORDER BY status_date DESC"
965  );
966 
967  $rec = $ilDB->fetchAssoc($set);
968 
969  return $rec["status_date"];
970  }
971 
972  //
973  //
974  // Certificate related methods
975  //
976  //
977 
984  public function getTitleForCertificate()
985  {
986  return $this->getTitle();
987  }
988 
995  public function getShortTitleForCertificate()
996  {
997  return "Skill";
998  }
999 
1006  public static function _lookupCertificate($a_skill_id, $a_skill_level_id)
1007  {
1008  $certificatefile = CLIENT_WEB_DIR . "/certificates/skill/" .
1009  ((int) $a_skill_id) . "/" . ((int) $a_skill_level_id) . "/certificate.xml";
1010  if (@file_exists($certificatefile)) {
1011  return true;
1012  } else {
1013  return false;
1014  }
1015  }
1016 
1023  public static function getUsageInfo($a_cskill_ids, &$a_usages)
1024  {
1025  global $DIC;
1026 
1027  $ilDB = $DIC->database();
1028 
1029  include_once("./Services/Skill/classes/class.ilSkillUsage.php");
1031  $a_cskill_ids,
1032  $a_usages,
1034  "skl_user_skill_level",
1035  "user_id"
1036  );
1037  }
1038 
1047  public static function getCommonSkillIdForImportId($a_source_inst_id, $a_skill_import_id, $a_tref_import_id = 0)
1048  {
1049  global $DIC;
1050 
1051  $ilDB = $DIC->database();
1052 
1053  include_once("./Services/Skill/classes/class.ilSkillTree.php");
1054  include_once("./Services/Skill/classes/class.ilSkillTemplateReference.php");
1055  $tree = new ilSkillTree();
1056 
1057  if ($a_source_inst_id == 0) {
1058  return array();
1059  }
1060 
1061  $template_ids = array();
1062  if ($a_tref_import_id > 0) {
1063  $skill_node_type = "sktp";
1064 
1065  // get all matching tref nodes
1066  $set = $ilDB->query("SELECT * FROM skl_tree_node n JOIN skl_tree t ON (n.obj_id = t.child) " .
1067  " WHERE n.import_id = " . $ilDB->quote("il_" . ((int) $a_source_inst_id) . "_sktr_" . $a_tref_import_id, "text") .
1068  " ORDER BY n.creation_date DESC ");
1069  while ($rec = $ilDB->fetchAssoc($set)) {
1070  if (($t = ilSkillTemplateReference::_lookupTemplateId($rec["obj_id"])) > 0) {
1071  $template_ids[$t] = $rec["obj_id"];
1072  }
1073  }
1074  } else {
1075  $skill_node_type = "skll";
1076  }
1077  $set = $ilDB->query("SELECT * FROM skl_tree_node n JOIN skl_tree t ON (n.obj_id = t.child) " .
1078  " WHERE n.import_id = " . $ilDB->quote("il_" . ((int) $a_source_inst_id) . "_" . $skill_node_type . "_" . $a_skill_import_id, "text") .
1079  " ORDER BY n.creation_date DESC ");
1080  $results = array();
1081  while ($rec = $ilDB->fetchAssoc($set)) {
1082  $matching_trefs = array();
1083  if ($a_tref_import_id > 0) {
1084  $skill_template_id = $tree->getTopParentNodeId($rec["obj_id"]);
1085 
1086  // check of skill is in template
1087  foreach ($template_ids as $templ => $tref) {
1088  if ($skill_template_id == $templ) {
1089  $matching_trefs[] = $tref;
1090  }
1091  }
1092  } else {
1093  $matching_trefs = array(0);
1094  }
1095 
1096  foreach ($matching_trefs as $t) {
1097  $results[] = array("skill_id" => $rec["obj_id"], "tref_id" => $t, "creation_date" => $rec["creation_date"]);
1098  }
1099  }
1100  return $results;
1101  }
1102 
1110  public static function getLevelIdForImportId($a_source_inst_id, $a_level_import_id)
1111  {
1112  global $DIC;
1113 
1114  $ilDB = $DIC->database();
1115 
1116  $set = $ilDB->query("SELECT * FROM skl_level l JOIN skl_tree t ON (l.skill_id = t.child) " .
1117  " WHERE l.import_id = " . $ilDB->quote("il_" . ((int) $a_source_inst_id) . "_sklv_" . $a_level_import_id, "text") .
1118  " ORDER BY l.creation_date DESC ");
1119  $results = array();
1120  while ($rec = $ilDB->fetchAssoc($set)) {
1121  $results[] = array("level_id" => $rec["id"], "creation_date" => $rec["creation_date"]);
1122  }
1123  return $results;
1124  }
1125 
1132  public static function getLevelIdForImportIdMatchSkill($a_source_inst_id, $a_level_import_id, $a_skill_import_id, $a_tref_import_id = 0)
1133  {
1134  $level_id_data = self::getLevelIdForImportId($a_source_inst_id, $a_level_import_id);
1135  $skill_data = self::getCommonSkillIdForImportId($a_source_inst_id, $a_skill_import_id, $a_tref_import_id);
1136  $matches = array();
1137  foreach ($level_id_data as $l) {
1138  reset($skill_data);
1139  foreach ($skill_data as $s) {
1140  if (ilBasicSkill::lookupLevelSkillId($l["level_id"]) == $s["skill_id"]) {
1141  $matches[] = array(
1142  "level_id" => $l["level_id"],
1143  "creation_date" => $l["creation_date"],
1144  "skill_id" => $s["skill_id"],
1145  "tref_id" => $s["tref_id"]
1146  );
1147  }
1148  }
1149  }
1150  return $matches;
1151  }
1152 }
Get info on usages of skills.
getShortTitleForCertificate()
Get short title for certificate.
setType($a_type)
Set type.
copy()
Copy basic skill.
create()
Create skill.
addLevel($a_title, $a_description, $a_import_id="")
Add new level.
static getNewAchievementsPerUser($a_timestamp)
Get new achievements.
global $DIC
Definition: saml.php:7
getLevelData($a_id=0)
Get level data.
static lookupLevelTitle($a_id)
Lookup level title.
getLastLevelPerObject($a_tref_id, $a_object_id, $a_user_id=0, $a_self_eval=0)
Get last level set per object.
Skill tree.
static getLevelIdForImportId($a_source_inst_id, $a_level_import_id)
Get level ids for import IDs (newest first)
getMaxLevel($a_tref_id, $a_user_id=0, $a_self_eval=0)
Get max levels per object.
getSkillForLevelId($a_level_id)
Get skill for level id.
getMaxLevelNr()
Get maximum level nr.
static _lookupTitle($a_id)
lookup object title
$s
Definition: pwgen.php:45
getSelfEvaluation()
Get self evaluation.
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.
static now()
Return current timestamp in Y-m-d H:i:s format.
user()
Definition: user.php:4
deleteLevel($a_id)
Delete level.
$a_type
Definition: workflow.php:92
getOrderNr()
Get order nr.
static getLevelIdForImportIdMatchSkill($a_source_inst_id, $a_level_import_id, $a_skill_import_id, $a_tref_import_id=0)
Get level ids for import Ids matching common skills.
static getUsageInfo($a_cskill_ids, &$a_usages)
Get usage info.
static writeLevelProperty($a_id, $a_prop, $a_value, $a_type)
Write level property.
static writeLevelDescription($a_id, $a_description)
Write level description.
fixLevelNumbering()
Fix level numbering.
static isInTree($a_id)
Is id in tree?
read()
Read data from database.
static _lookupObjId($a_id)
static writeLevelTitle($a_id, $a_title)
Write level title.
getMaxLevelPerType($a_tref_id, $a_type, $a_user_id=0, $a_self_eval=0)
Get max levels per type.
$ilUser
Definition: imgupload.php:18
static lookupLevelProperty($a_id, $a_prop)
Lookup level property.
static _lookupTemplateId($a_obj_id)
Lookup template ID.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
static lookupLevelDescription($a_id)
Lookup level description.
static removeAllUserSkillLevelStatusOfObject($a_user_id, $a_trigger_obj_id, $a_self_eval=false, $a_unique_identifier="")
Remove a user skill completely.
Skill exception class.
static _lookupCertificate($a_skill_id, $a_skill_level_id)
Checks whether a skill level has a certificate or not.
getTitleForCertificate()
Get title for certificate.
getMaxLevelPerObject($a_tref_id, $a_object_id, $a_user_id=0, $a_self_eval=0)
Get max levels per object.
updateLevelOrder($order)
Update level order.
global $l
Definition: afr.php:30
static removeAllUserData($a_user_id)
Remove all data of a user.
$results
Definition: svg-scanner.php:47
A node in the skill tree.
global $ilDB
static writeUserSkillLevelStatus( $a_level_id, $a_user_id, $a_trigger_ref_id, $a_tref_id=0, $a_status=ilBasicSkill::ACHIEVED, $a_force=false, $a_self_eval=false, $a_unique_identifier="")
Write skill level status.
static hasRecentSelfEvaluation($a_user_id, $a_skill_id, $a_tref_id=0, $a_trigger_ref_id=0)
Has recent self evaluation.
getAllHistoricLevelEntriesOfUser($a_tref_id, $a_user_id=0, $a_eval_by=0)
Get all historic level entries.
static lookupLevelSkillId($a_id)
Lookup level skill id.
__construct($a_id=0)
Constructor public.
Basic Skill.
static hasSelfEvaluated($a_user_id, $a_skill_id, $a_tref_id)
Has use self evaluated a skill?
getLastUpdatePerObject($a_tref_id, $a_object_id, $a_user_id=0, $a_self_eval=0)
Get last update per object.
getAllLevelEntriesOfUser($a_tref_id, $a_user_id=0, $a_self_eval=0)
Get all level entries.
static getCommonSkillIdForImportId($a_source_inst_id, $a_skill_import_id, $a_tref_import_id=0)
Get common skill ids for import IDs (newest first)
static resetUserSkillLevelStatus($a_user_id, $a_skill_id, $a_tref_id=0, $a_trigger_ref_id=0, $a_self_eval=false)
Reset skill level status.