ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 {
18  const ACHIEVED = 1;
19  const NOT_ACHIEVED = 0;
20 
21  const EVAL_BY_OTHERS_= 0;
22  const EVAL_BY_SELF = 1;
23  const EVAL_BY_ALL = 2;
24 
25  var $id;
26 
31  function __construct($a_id = 0)
32  {
34  $this->setType("skll");
35  }
36 
40  function read()
41  {
42  parent::read();
43  }
44 
49  function create()
50  {
52  }
53 
57  function delete()
58  {
59  global $ilDB;
60 
61  $ilDB->manipulate("DELETE FROM skl_level WHERE "
62  ." skill_id = ".$ilDB->quote($this->getId(), "integer")
63  );
64 
65  $ilDB->manipulate("DELETE FROM skl_user_has_level WHERE "
66  ." skill_id = ".$ilDB->quote($this->getId(), "integer")
67  );
68 
70  }
71 
75  function copy()
76  {
77  $skill = new ilBasicSkill();
78  $skill->setTitle($this->getTitle());
79  $skill->setType($this->getType());
80  $skill->setSelfEvaluation($this->getSelfEvaluation());
81  $skill->setOrderNr($this->getOrderNr());
82  $skill->create();
83 
84  $levels = $this->getLevelData();
85  if (sizeof($levels))
86  {
87  foreach($levels as $item)
88  {
89  $skill->addLevel($item["title"], $item["description"]);
90  }
91  }
92  $skill->update();
93 
94  return $skill;
95  }
96 
97  //
98  //
99  // Skill level related methods
100  //
101  //
102 
109  function addLevel($a_title, $a_description)
110  {
111  global $ilDB;
112 
113  $nr = $this->getMaxLevelNr();
114  $nid = $ilDB->nextId("skl_level");
115  $ilDB->insert("skl_level", array(
116  "id" => array("integer", $nid),
117  "skill_id" => array("integer", $this->getId()),
118  "nr" => array("integer", $nr+1),
119  "title" => array("text", $a_title),
120  "description" => array("clob", $a_description)
121  ));
122 
123  }
124 
130  function getMaxLevelNr()
131  {
132  global $ilDB;
133 
134  $set = $ilDB->query("SELECT MAX(nr) mnr FROM skl_level WHERE ".
135  " skill_id = ".$ilDB->quote($this->getId(), "integer")
136  );
137  $rec = $ilDB->fetchAssoc($set);
138  return (int) $rec["mnr"];
139  }
140 
146  function getLevelData($a_id = 0)
147  {
148  global $ilDB;
149 
150  if ($a_id > 0)
151  {
152  $and = " AND id = ".$ilDB->quote($a_id, "integer");
153  }
154 
155  $set = $ilDB->query("SELECT * FROM skl_level WHERE ".
156  " skill_id = ".$ilDB->quote($this->getId(), "integer").
157  $and.
158  " ORDER BY nr"
159  );
160  $levels = array();
161  while ($rec = $ilDB->fetchAssoc($set))
162  {
163  if ($a_id > 0)
164  {
165  return $rec;
166  }
167  $levels[] = $rec;
168  }
169  return $levels;
170  }
171 
178  protected static function lookupLevelProperty($a_id, $a_prop)
179  {
180  global $ilDB;
181 
182  $set = $ilDB->query("SELECT $a_prop FROM skl_level WHERE ".
183  " id = ".$ilDB->quote($a_id, "integer")
184  );
185  $rec = $ilDB->fetchAssoc($set);
186  return $rec[$a_prop];
187  }
188 
195  static function lookupLevelTitle($a_id)
196  {
197  return ilBasicSkill::lookupLevelProperty($a_id, "title");
198  }
199 
206  static function lookupLevelDescription($a_id)
207  {
208  return ilBasicSkill::lookupLevelProperty($a_id, "description");
209  }
210 
217  static function lookupLevelTrigger($a_id)
218  {
219 die("ilBasicSkill::lookupLevelTrigger is deprecated.");
220  $ref_id = ilBasicSkill::lookupLevelProperty($a_id, "trigger_ref_id");
221  $obj_id = ilBasicSkill::lookupLevelProperty($a_id, "trigger_obj_id");
222  return array("ref_id" => $ref_id, "obj_id" => $obj_id);
223  }
224 
231  static function lookupLevelSkillId($a_id)
232  {
233  return ilBasicSkill::lookupLevelProperty($a_id, "skill_id");
234  }
235 
242  static protected function writeLevelProperty($a_id, $a_prop, $a_value, $a_type)
243  {
244  global $ilDB;
245 
246  $ilDB->update("skl_level", array(
247  $a_prop => array($a_type, $a_value),
248  ), array(
249  "id" => array("integer", $a_id),
250  ));
251  }
252 
259  static function writeLevelTitle($a_id, $a_title)
260  {
261  ilBasicSkill::writeLevelProperty($a_id, "title", $a_title, "text");
262  }
263 
270  static function writeLevelDescription($a_id, $a_description)
271  {
272  ilBasicSkill::writeLevelProperty($a_id, "description", $a_description, "clob");
273  }
274 
281  static function writeLevelTrigger($a_id, $a_trigger_ref_id)
282  {
283 die("ilBasicSkill::writeLevelTrigger is deprecated.");
284  $a_trigger_obj_id = 0;
285  if ($a_trigger_ref_id > 0)
286  {
287  $a_trigger_obj_id = ilObject::_lookupObjId($a_trigger_ref_id);
288  }
289  ilBasicSkill::writeLevelProperty($a_id, "trigger_ref_id", $a_trigger_ref_id, "integer");
290  ilBasicSkill::writeLevelProperty($a_id, "trigger_obj_id", $a_trigger_obj_id, "integer");
291  }
292 
299  function updateLevelOrder($order)
300  {
301  global $ilDB;
302 
303  asort($order);
304 
305  $cnt = 1;
306  foreach ($order as $id => $o)
307  {
308  $ilDB->manipulate("UPDATE skl_level SET ".
309  " nr = ".$ilDB->quote($cnt, "integer").
310  " WHERE id = ".$ilDB->quote($id, "integer")
311  );
312  $cnt++;
313  }
314  }
315 
322  function deleteLevel($a_id)
323  {
324  global $ilDB;
325 
326  $ilDB->manipulate("DELETE FROM skl_level WHERE "
327  ." id = ".$ilDB->quote($a_id, "integer")
328  );
329 
330  }
331 
338  function fixLevelNumbering()
339  {
340  global $ilDB;
341 
342  $set = $ilDB->query("SELECT id, nr FROM skl_level WHERE ".
343  " skill_id = ".$ilDB->quote($this->getId(), "integer").
344  " ORDER BY nr ASC"
345  );
346  $cnt = 1;
347  while ($rec = $ilDB->fetchAssoc($set))
348  {
349  $ilDB->manipulate("UPDATE skl_level SET ".
350  " nr = ".$ilDB->quote($cnt, "integer").
351  " WHERE id = ".$ilDB->quote($rec["id"], "integer")
352  );
353  $cnt++;
354  }
355  }
356 
363  function lookupLevelsForTriggerRefId($a_ref_id)
364  {
365  global $ilDB;
366 die("ilBasicSkill::lookupLevelsForTriggerRefId is deprecated.");
367  $set = $ilDB->query("SELECT id FROM skl_level WHERE ".
368  " trigger_ref_id = ".$ilDB->quote($a_ref_id, "integer")
369  );
370  $levels = array();
371  while ($rec = $ilDB->fetchAssoc($set))
372  {
373  $levels[] = $rec["id"];
374  }
375  return $levels;
376  }
377 
384  function getSkillForLevelId($a_level_id)
385  {
386  global $ilDB;
387 
388  $set = $ilDB->query("SELECT * FROM skl_level WHERE ".
389  " id = ".$ilDB->quote($a_level_id, "integer")
390  );
391  $skill = null;
392  if ($rec = $ilDB->fetchAssoc($set))
393  {
394  if (ilSkillTreeNode::isInTree($rec["skill_id"]))
395  {
396  $skill = new ilBasicSkill($rec["skill_id"]);
397  }
398  }
399  return $skill;
400  }
401 
402  //
403  //
404  // User skill (level) related methods
405  //
406  //
407 
408 
413  public static function updateAllUserSkillLevels()
414  {
415  global $ilDB;
416 die("ilBasicSkill::updateAllUserSkillLevels is deprecated.");
417  $set = $ilDB->query("SELECT id, trigger_obj_id FROM skl_level WHERE ".
418  " trigger_obj_id > ".$ilDB->quote(0, "integer")
419  );
420  while ($rec = $ilDB->fetchAssoc($set)) // all trigger objects
421  {
422  $skill_level_id = $rec["id"];
423  $tr_obj_id = $rec["trigger_obj_id"];
424 
425  if (ilObject::_hasUntrashedReference($tr_obj_id))
426  {
427  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
428  $completed = ilLPStatusWrapper::_lookupCompletedForObject($tr_obj_id);
429  foreach ($completed as $user_id)
430  {
432  $user_id, ilBasicSkill::ACHIEVED);
433  }
434  }
435  }
436  }
437 
442  public static function updateSkillLevelsByTriggerRef($a_user_id, $a_ref_id)
443  {
444  global $ilDB;
445 die("ilBasicSkill::updateSkillLevelsByTriggerRef is deprecated.");
446  $set = $ilDB->query("SELECT id, trigger_obj_id FROM skl_level WHERE ".
447  " trigger_ref_id = ".$ilDB->quote($a_ref_id, "integer")
448  );
449  while ($rec = $ilDB->fetchAssoc($set)) // all trigger objects
450  {
451  $skill_level_id = $rec["id"];
452  $tr_obj_id = $rec["trigger_obj_id"];
453 
454  if (ilObject::_hasUntrashedReference($tr_obj_id))
455  {
456  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
457  $completed = ilLPStatusWrapper::_lookupCompletedForObject($tr_obj_id);
458  foreach ($completed as $user_id)
459  {
460  if ($a_user_id == $user_id)
461  {
463  $user_id, ilBasicSkill::ACHIEVED);
464  }
465  }
466  }
467  }
468  }
469 
477  static function writeUserSkillLevelStatus($a_level_id, $a_user_id,
478  $a_trigger_ref_id, $a_tref_id = 0, $a_status = ilBasicSkill::ACHIEVED, $a_force = false,
479  $a_self_eval = 0)
480  {
481  global $ilDB;
482 
483  $skill_id = ilBasicSkill::lookupLevelSkillId($a_level_id);
484  $trigger_ref_id = $a_trigger_ref_id;
485  $trigger_obj_id = ilObject::_lookupObjId($trigger_ref_id);
486  $trigger_title = ilObject::_lookupTitle($trigger_obj_id);
487  $trigger_type = ilObject::_lookupType($trigger_obj_id);
488 
489  $update = false;
490 
491  // check whether current skill user level is identical
492  // to the one that should be set (-> no change required)
493 /* $ilDB->setLimit(1);
494  $set = $ilDB->query("SELECT status, valid FROM skl_user_skill_level WHERE ".
495  "level_id = ".$ilDB->quote($a_level_id, "integer")." AND ".
496  "user_id = ".$ilDB->quote($a_user_id, "integer")." AND ".
497  "tref_id = ".$ilDB->quote((int) $a_tref_id, "integer")." AND ".
498  "trigger_obj_id = ".$ilDB->quote($trigger_obj_id, "integer")." AND ".
499  "self_eval = ".$ilDB->quote($a_self_eval, "integer").
500  " ORDER BY status_date DESC"
501  );
502  $rec = $ilDB->fetchAssoc($set);
503  if (!$rec["valid"] || $rec["status"] != $a_status)
504  {
505  $save = true;
506  }*/
507 
508  if ($a_self_eval)
509  {
510  $ilDB->setLimit(1);
511  $set = $ilDB->query("SELECT * FROM skl_user_skill_level WHERE ".
512  "skill_id = ".$ilDB->quote($skill_id, "integer")." AND ".
513  "user_id = ".$ilDB->quote($a_user_id, "integer")." AND ".
514  "tref_id = ".$ilDB->quote((int) $a_tref_id, "integer")." AND ".
515  "trigger_obj_id = ".$ilDB->quote($trigger_obj_id, "integer")." AND ".
516  "self_eval = ".$ilDB->quote($a_self_eval, "integer").
517  " ORDER BY status_date DESC"
518  );
519  $rec = $ilDB->fetchAssoc($set);
520  $status_day = substr($rec["status_date"], 0, 10);
521  $today = substr(ilUtil::now(), 0, 10);
522  if ($rec["valid"] && $rec["status"] == $a_status && $status_day == $today)
523  {
524  $update = true;
525  }
526  }
527 
528  if ($update)
529  {
530  $now = ilUtil::now();
531  $ilDB->manipulate("UPDATE skl_user_skill_level SET ".
532  " level_id = ".$ilDB->quote($a_level_id, "integer").",".
533  " status_date = ".$ilDB->quote($now, "timestamp").
534  " WHERE user_id = ".$ilDB->quote($a_user_id, "integer").
535  " AND status_date = ".$ilDB->quote($rec["status_date"], "timestamp").
536  " AND skill_id = ".$ilDB->quote($rec["skill_id"], "integer").
537  " AND status = ".$ilDB->quote($a_status, "integer").
538  " AND trigger_obj_id = ".$ilDB->quote($trigger_obj_id, "integer").
539  " AND tref_id = ".$ilDB->quote((int) $a_tref_id, "integer").
540  " AND self_eval = ".$ilDB->quote($a_self_eval, "integer")
541  );
542  }
543  else
544  {
545  $now = ilUtil::now();
546  $ilDB->manipulate("INSERT INTO skl_user_skill_level ".
547  "(level_id, user_id, tref_id, status_date, skill_id, status, valid, trigger_ref_id,".
548  "trigger_obj_id, trigger_obj_type, trigger_title, self_eval) VALUES (".
549  $ilDB->quote($a_level_id, "integer").",".
550  $ilDB->quote($a_user_id, "integer").",".
551  $ilDB->quote((int) $a_tref_id, "integer").",".
552  $ilDB->quote($now, "timestamp").",".
553  $ilDB->quote($skill_id, "integer").",".
554  $ilDB->quote($a_status, "integer").",".
555  $ilDB->quote(1, "integer").",".
556  $ilDB->quote($trigger_ref_id, "integer").",".
557  $ilDB->quote($trigger_obj_id, "integer").",".
558  $ilDB->quote($trigger_type, "text").",".
559  $ilDB->quote($trigger_title, "text").",".
560  $ilDB->quote($a_self_eval, "integer").
561  ")");
562  }
563 
564  // fix (removed level_id and added skill id, since table should hold only
565  // one entry per skill)
566  $ilDB->manipulate("DELETE FROM skl_user_has_level WHERE "
567  ." user_id = ".$ilDB->quote($a_user_id, "integer")
568  ." AND skill_id = ".$ilDB->quote($skill_id, "integer")
569  ." AND tref_id = ".$ilDB->quote((int) $a_tref_id, "integer")
570  ." AND trigger_obj_id = ".$ilDB->quote($trigger_obj_id, "integer")
571  ." AND self_eval = ".$ilDB->quote($a_self_eval, "integer")
572  );
573 
574  if ($a_status == ilBasicSkill::ACHIEVED)
575  {
576  $ilDB->manipulate("INSERT INTO skl_user_has_level ".
577  "(level_id, user_id, tref_id, status_date, skill_id, trigger_ref_id, trigger_obj_id, trigger_obj_type, trigger_title, self_eval) VALUES (".
578  $ilDB->quote($a_level_id, "integer").",".
579  $ilDB->quote($a_user_id, "integer").",".
580  $ilDB->quote($a_tref_id, "integer").",".
581  $ilDB->quote($now, "timestamp").",".
582  $ilDB->quote($skill_id, "integer").",".
583  $ilDB->quote($trigger_ref_id, "integer").",".
584  $ilDB->quote($trigger_obj_id, "integer").",".
585  $ilDB->quote($trigger_type, "text").",".
586  $ilDB->quote($trigger_title, "text").",".
587  $ilDB->quote($a_self_eval, "integer").
588  ")");
589  }
590  }
591 
598  function getMaxLevelPerType($a_tref_id, $a_type, $a_user_id = 0, $a_self_eval = 0)
599  {
600  global $ilDB, $ilUser;
601 
602  if ($a_user_id == 0)
603  {
604  $a_user_id = $ilUser->getId();
605  }
606 
607  $set = $ilDB->query($q = "SELECT level_id FROM skl_user_has_level ".
608  " WHERE trigger_obj_type = ".$ilDB->quote($a_type, "text").
609  " AND skill_id = ".$ilDB->quote($this->getId(), "integer").
610  " AND tref_id = ".$ilDB->quote((int) $a_tref_id, "integer").
611  " AND user_id = ".$ilDB->quote($a_user_id, "integer").
612  " AND self_eval = ".$ilDB->quote($a_self_eval, "integer")
613  );
614 
615  $has_level = array();
616  while ($rec = $ilDB->fetchAssoc($set))
617  {
618  $has_level[$rec["level_id"]] = true;
619  }
620  $max_level = 0;
621  foreach ($this->getLevelData() as $l)
622  {
623  if (isset($has_level[$l["id"]]))
624  {
625  $max_level = $l["id"];
626  }
627  }
628  return $max_level;
629  }
630 
637  function getAllLevelEntriesOfUser($a_tref_id, $a_user_id = 0, $a_self_eval = 0)
638  {
639  global $ilDB, $ilUser;
640 
641  if ($a_user_id == 0)
642  {
643  $a_user_id = $ilUser->getId();
644  }
645 
646  $set = $ilDB->query($q = "SELECT * FROM skl_user_has_level ".
647  " WHERE skill_id = ".$ilDB->quote($this->getId(), "integer").
648  " AND tref_id = ".$ilDB->quote((int) $a_tref_id, "integer").
649  " AND user_id = ".$ilDB->quote($a_user_id, "integer").
650  " AND self_eval = ".$ilDB->quote($a_self_eval, "integer").
651  " ORDER BY status_date DESC"
652  );
653 
654  $levels = array();
655  while ($rec = $ilDB->fetchAssoc($set))
656  {
657  $levels[] = $rec;
658  }
659  return $levels;
660  }
661 
668  function getAllHistoricLevelEntriesOfUser($a_tref_id, $a_user_id = 0, $a_eval_by = 0)
669  {
670  global $ilDB, $ilUser;
671 
672  if ($a_user_id == 0)
673  {
674  $a_user_id = $ilUser->getId();
675  }
676 
677  $by = ($a_eval_by != self::EVAL_BY_ALL)
678  ? " AND self_eval = ".$ilDB->quote($a_self_eval, "integer")
679  : "";
680 
681  $set = $ilDB->query($q = "SELECT * FROM skl_user_skill_level ".
682  " WHERE skill_id = ".$ilDB->quote($this->getId(), "integer").
683  " AND tref_id = ".$ilDB->quote((int) $a_tref_id, "integer").
684  " AND user_id = ".$ilDB->quote($a_user_id, "integer").
685  $by.
686  " ORDER BY status_date DESC"
687  );
688  $levels = array();
689  while ($rec = $ilDB->fetchAssoc($set))
690  {
691  $levels[] = $rec;
692  }
693  return $levels;
694  }
695 
696 
703  function getMaxLevelPerObject($a_tref_id, $a_object_id, $a_user_id = 0, $a_self_eval = 0)
704  {
705  global $ilDB, $ilUser;
706 
707  if ($a_user_id == 0)
708  {
709  $a_user_id = $ilUser->getId();
710  }
711 
712  $set = $ilDB->query($q = "SELECT level_id FROM skl_user_has_level ".
713  " WHERE trigger_obj_id = ".$ilDB->quote($a_object_id, "integer").
714  " AND skill_id = ".$ilDB->quote($this->getId(), "integer").
715  " AND tref_id = ".$ilDB->quote((int) $a_tref_id, "integer").
716  " AND user_id = ".$ilDB->quote($a_user_id, "integer").
717  " AND self_eval = ".$ilDB->quote($a_self_eval, "integer")
718  );
719 
720  $has_level = array();
721  while ($rec = $ilDB->fetchAssoc($set))
722  {
723  $has_level[$rec["level_id"]] = true;
724  }
725  $max_level = 0;
726  foreach ($this->getLevelData() as $l)
727  {
728  if (isset($has_level[$l["id"]]))
729  {
730  $max_level = $l["id"];
731  }
732  }
733  return $max_level;
734  }
735 
742  function getLastLevelPerObject($a_tref_id, $a_object_id, $a_user_id = 0, $a_self_eval = 0)
743  {
744  global $ilDB, $ilUser;
745 
746  if ($a_user_id == 0)
747  {
748  $a_user_id = $ilUser->getId();
749  }
750 
751  $ilDB->setLimit(1);
752  $set = $ilDB->query($q = "SELECT level_id FROM skl_user_has_level ".
753  " WHERE trigger_obj_id = ".$ilDB->quote($a_object_id, "integer").
754  " AND skill_id = ".$ilDB->quote($this->getId(), "integer").
755  " AND tref_id = ".$ilDB->quote((int) $a_tref_id, "integer").
756  " AND user_id = ".$ilDB->quote($a_user_id, "integer").
757  " AND self_eval = ".$ilDB->quote($a_self_eval, "integer").
758  " ORDER BY status_date DESC"
759  );
760 
761  $rec = $ilDB->fetchAssoc($set);
762 
763  return $rec["level_id"];
764  }
765 
772  function getLastUpdatePerObject($a_tref_id, $a_object_id, $a_user_id = 0, $a_self_eval = 0)
773  {
774  global $ilDB, $ilUser;
775 
776  if ($a_user_id == 0)
777  {
778  $a_user_id = $ilUser->getId();
779  }
780 
781  $ilDB->setLimit(1);
782  $set = $ilDB->query($q = "SELECT status_date FROM skl_user_has_level ".
783  " WHERE trigger_obj_id = ".$ilDB->quote($a_object_id, "integer").
784  " AND skill_id = ".$ilDB->quote($this->getId(), "integer").
785  " AND tref_id = ".$ilDB->quote((int) $a_tref_id, "integer").
786  " AND user_id = ".$ilDB->quote($a_user_id, "integer").
787  " AND self_eval = ".$ilDB->quote($a_self_eval, "integer").
788  " ORDER BY status_date DESC"
789  );
790 
791  $rec = $ilDB->fetchAssoc($set);
792 
793  return $rec["status_date"];
794  }
795 
802  static function getCompletionDateForTriggerRefId($a_user_id, $a_ref_id = null, $a_self_eval = 0)
803  {
804  global $ilDB;
805 die("ilBasicSkill::getCompletionDateForTriggerRefId is deprecated.");
806  if ($a_ref_id == "")
807  {
808  $a_ref_id = null;
809  }
810  else if (!is_array($a_ref_id))
811  {
812  $a_ref_id = array($a_ref_id);
813  }
814  if (!is_array($a_user_id))
815  {
816  $a_user_id = array($a_user_id);
817  }
818 
819  if ($a_ref_id != null)
820  {
821  if (!is_array($a_ref_id))
822  {
823  $a_ref_id = array($a_ref_id);
824  }
825 
826  $set = $ilDB->query($q = "SELECT user_id, status_date, trigger_ref_id FROM skl_user_has_level WHERE ".
827  $ilDB->in("user_id", $a_user_id, false, "integer")." AND ".
828  $ilDB->in("trigger_ref_id", $a_ref_id, false, "integer")
829  );
830 
831  $completion = array();
832  while ($rec = $ilDB->fetchAssoc($set))
833  {
834  if (!isset($completion[$rec["user_id"]][$rec["trigger_ref_id"]]))
835  {
836  $completion[$rec["user_id"]][$rec["trigger_ref_id"]] = $rec["status_date"];
837  }
838  else if ($rec["status_date"] < $completion[$rec["user_id"]][$rec["trigger_ref_id"]])
839  {
840  $completion[$rec["user_id"]][$rec["trigger_ref_id"]] = $rec["status_date"];
841  }
842  }
843 
844  foreach ($a_ref_id as $ref_id)
845  {
846  foreach ($a_user_id as $user_id)
847  {
848  if (!isset($completion[$user_id][$ref_id]))
849  {
850  $completion[$user_id][$ref_id] = false;
851  }
852  }
853  }
854  }
855  else
856  {
857  $completion = array();
858  foreach ($a_user_id as $user_id)
859  {
860  include_once 'Services/Membership/classes/class.ilParticipants.php';
861  $a_ref_id = ilParticipants::_getMembershipByType($user_id, 'crs', true);
862 
863  $set = $ilDB->query($q = "SELECT user_id, status_date, trigger_ref_id FROM skl_user_has_level WHERE ".
864  "user_id = ".$ilDB->quote($user_id, "integer")." AND ".
865  $ilDB->in("trigger_ref_id", $a_ref_id, false, "integer")
866  );
867 
868  while ($rec = $ilDB->fetchAssoc($set))
869  {
870  if (!isset($completion[$user_id][$rec["trigger_ref_id"]]))
871  {
872  $completion[$user_id][$rec["trigger_ref_id"]] = $rec["status_date"];
873  }
874  else if ($rec["status_date"] < $completion[$user_id][$rec["trigger_ref_id"]])
875  {
876  $completion[$user_id][$rec["trigger_ref_id"]] = $rec["status_date"];
877  }
878  }
879  foreach ($a_ref_id as $ref_id)
880  {
881  if (!isset($completion[$user_id][$ref_id]))
882  {
883  $completion[$user_id][$ref_id] = false;
884  }
885  }
886  }
887 
888  }
889  return $completion;
890  }
891 
898  static function checkUserCertificateForTriggerRefId($a_user_id, $a_ref_id, $a_self_eval = 0)
899  {
900  global $ilDB;
901 die("ilBasicSkill::checkUserCertificateForTriggerRefId is deprecated.");
902  if (!is_array($a_ref_id))
903  {
904  $a_ref_id = array($a_ref_id);
905  }
906  if (!is_array($a_user_id))
907  {
908  $a_user_id = array($a_user_id);
909  }
910  $set = $ilDB->query($q = "SELECT user_id, status_date, trigger_ref_id, level_id, skill_id FROM skl_user_has_level WHERE ".
911  $ilDB->in("user_id", $a_user_id, false, "integer")." AND ".
912  $ilDB->in("trigger_ref_id", $a_ref_id, false, "integer")
913  );
914 
915  $completion = array();
916 
917  $completion = array();
918  while ($rec = $ilDB->fetchAssoc($set))
919  {
920  if (!isset($completion[$rec["user_id"]][$rec["trigger_ref_id"]])
921  && ilBasicSkill::_lookupCertificate($rec["skill_id"], $rec["level_id"]))
922  {
923  $completion[$rec["user_id"]][$rec["trigger_ref_id"]] = true;
924  }
925  }
926 
927  foreach ($a_ref_id as $ref_id)
928  {
929  foreach ($a_user_id as $user_id)
930  {
931  if (!isset($completion[$user_id][$ref_id]))
932  {
933  $completion[$user_id][$ref_id] = false;
934  }
935  }
936  }
937  return $completion;
938 
939  }
940 
947  function lookupLevelAchievementDate($a_user_id, $a_level_id, $a_self_eval = 0)
948  {
949  global $ilDB;
950 die("ilBasicSkill::lookupLevelAchievementDate is deprecated.");
951  $set = $ilDB->query("SELECT user_id, status_date, trigger_ref_id, level_id, skill_id FROM skl_user_has_level WHERE ".
952  " user_id = ".$ilDB->quote($a_user_id, "integer").
953  " AND user_id = ".$ilDB->quote($a_user_id, "integer")
954  );
955  if ($rec = $ilDB->fetchAssoc($set))
956  {
957  return $rec["status_date"];
958  }
959 
960  return false;
961  }
962 
969  static function getTriggerOfAllCertificates($a_user_id, $a_self_eval = 0)
970  {
971  global $ilDB, $tree;
972 die("ilBasicSkill::getTriggerOfAllCertificates is deprecated.");
973  if (!is_array($a_user_id))
974  {
975  $a_user_id = array($a_user_id);
976  }
977 
978  $set = $ilDB->query($q = "SELECT user_id, status_date, trigger_ref_id, level_id, skill_id FROM skl_user_has_level WHERE ".
979  $ilDB->in("user_id", $a_user_id, false, "integer")
980  );
981 
982  $completion = array();
983 
984  while ($rec = $ilDB->fetchAssoc($set))
985  {
986  if ((!is_array($completion[$rec["user_id"]]) || !in_array($rec["trigger_ref_id"], $completion[$rec["user_id"]]))
987  && ilBasicSkill::_lookupCertificate($rec["skill_id"], $rec["level_id"]))
988  {
989  if ($tree->isInTree($rec["trigger_ref_id"]))
990  {
991  $completion[$rec["user_id"]][] = $rec["trigger_ref_id"];
992  }
993  }
994  }
995 
996  foreach ($a_user_id as $user_id)
997  {
998  if (!is_array($completion[$user_id]))
999  {
1000  $completion[$user_id] = array();
1001  }
1002  }
1003  return $completion;
1004  }
1005 
1012  static function getSkillLevelsForTrigger($a_ref_id)
1013  {
1014  global $ilDB;
1015 die("ilBasicSkill::getSkillLevelsForTrigger is deprecated.");
1016  $set = $ilDB->query($q = "SELECT id FROM skl_level".
1017  " WHERE trigger_ref_id = ".$ilDB->quote($a_ref_id, "integer"));
1018 
1019  $skill_levels = array();
1020  while ($rec = $ilDB->fetchAssoc($set))
1021  {
1022  $skill_levels[] = $rec["id"];
1023  }
1024 
1025  return $skill_levels;
1026 
1027  }
1028 
1029  //
1030  //
1031  // Certificate related methods
1032  //
1033  //
1034 
1042  {
1043  return $this->getTitle();
1044  }
1045 
1052  function getLevelTitleForCertificate($a_level_id)
1053  {
1054 die("ilBasicSkill::getLevelTitleForCertificate is deprecated.");
1055  return ilBasicSkill::lookupLevelTitle($a_level_id);
1056  }
1057 
1064  function getTriggerTitleForCertificate($a_level_id)
1065  {
1066 die("ilBasicSkill::getTriggerTitleForCertificate is deprecated.");
1067  $tr = ilBasicSkill::lookupLevelTrigger($a_level_id);
1068  return ilObject::_lookupTitle($tr["obj_id"]);
1069  }
1070 
1078  {
1079  return "Skill";
1080  }
1081 
1088  public static function _lookupCertificate($a_skill_id, $a_skill_level_id)
1089  {
1090  $certificatefile = CLIENT_WEB_DIR."/certificates/skill/".
1091  ((int)$a_skill_id)."/".((int) $a_skill_level_id)."/certificate.xml";
1092  if (@file_exists($certificatefile))
1093  {
1094  return true;
1095  }
1096  else
1097  {
1098  return false;
1099  }
1100  }
1101 
1108  static public function getUsageInfo($a_cskill_ids, &$a_usages)
1109  {
1110  global $ilDB;
1111 
1112  include_once("./Services/Skill/classes/class.ilSkillUsage.php");
1114  "skl_user_skill_level", "user_id");
1115  }
1116 
1117 
1118 }
1119 ?>