ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilBasicSkill.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
23 
28 class ilBasicSkill extends ilSkillTreeNode implements Usage\SkillUsageInfo
29 {
30  protected ilObjUser $user;
34 
35  //TODO: What to do with these constants?
36  public const ACHIEVED = 1;
37  public const NOT_ACHIEVED = 0;
38 
39  public const EVAL_BY_OTHERS = 0;
40  public const EVAL_BY_SELF = 1;
41  public const EVAL_BY_ALL = 2;
42 
43  public function __construct(
44  int $a_id = 0,
45  ilSkillLevelRepository $bsc_skl_lvl_db_rep = null,
46  ilSkillUserLevelRepository $bsc_skl_usr_lvl_db_rep = null,
47  ilSkillTreeRepository $bsc_skl_tre_rep = null
48  ) {
49  global $DIC;
50 
51  $this->user = $DIC->user();
52 
53  if (is_null($bsc_skl_lvl_db_rep)) {
54  $this->bsc_skl_lvl_db_rep = $DIC->skills()->internal()->repo()->getLevelRepo();
55  } else {
56  $this->bsc_skl_lvl_db_rep = $bsc_skl_lvl_db_rep;
57  }
58 
59  if (is_null($bsc_skl_usr_lvl_db_rep)) {
60  $this->bsc_skl_usr_lvl_db_rep = $DIC->skills()->internal()->repo()->getUserLevelRepo();
61  } else {
62  $this->bsc_skl_usr_lvl_db_rep = $bsc_skl_usr_lvl_db_rep;
63  }
64 
65  if (is_null($bsc_skl_tre_rep)) {
66  $this->bsc_skl_tre_rep = $DIC->skills()->internal()->repo()->getTreeRepo();
67  } else {
68  $this->bsc_skl_tre_rep = $bsc_skl_tre_rep;
69  }
70 
71  parent::__construct($a_id);
72  $this->setType("skll");
73  }
74 
78  public function read(): void
79  {
80  parent::read();
81  }
82 
86  public function create(): void
87  {
88  parent::create();
89  }
90 
94  public function copy(): ilBasicSkill
95  {
96  $skill = new ilBasicSkill();
97  $skill->setTitle($this->getTitle());
98  $skill->setDescription($this->getDescription());
99  $skill->setType($this->getType());
100  $skill->setSelfEvaluation($this->getSelfEvaluation());
101  $skill->setOrderNr($this->getOrderNr());
102  $skill->create();
103 
104  $levels = $this->getLevelData();
105  if (sizeof($levels)) {
106  foreach ($levels as $item) {
107  $skill->addLevel($item["title"], $item["description"]);
108  }
109  }
110  $skill->update();
111 
112  return $skill;
113  }
114 
115  //
116  //
117  // Skill level related methods
118  //
119  //
120 
121  public function addLevel(string $a_title, string $a_description, string $a_import_id = ""): void
122  {
123  $skill_id = $this->getId();
124  $this->bsc_skl_lvl_db_rep->addLevel($skill_id, $a_title, $a_description, $a_import_id);
125  }
126 
127  public function getLevelData(int $a_id = 0): array
128  {
129  $skill_id = $this->getId();
130 
131  return $this->bsc_skl_lvl_db_rep->getLevelData($skill_id, $a_id);
132  }
133 
134  public static function lookupLevelTitle(int $a_id): string
135  {
136  global $DIC;
137 
138  $repository = $DIC->skills()->internal()->repo()->getLevelRepo();
139 
140  return $repository->lookupLevelTitle($a_id);
141  }
142 
143  public static function lookupLevelDescription(int $a_id): string
144  {
145  global $DIC;
146 
147  $repository = $DIC->skills()->internal()->repo()->getLevelRepo();
148 
149  return $repository->lookupLevelDescription($a_id);
150  }
151 
152  public static function lookupLevelSkillId(int $a_id): int
153  {
154  global $DIC;
155 
156  $repository = $DIC->skills()->internal()->repo()->getLevelRepo();
157 
158  return $repository->lookupLevelSkillId($a_id);
159  }
160 
161  public static function writeLevelTitle(int $a_id, string $a_title): void
162  {
163  global $DIC;
164 
165  $repository = $DIC->skills()->internal()->repo()->getLevelRepo();
166  $repository->writeLevelTitle($a_id, $a_title);
167  }
168 
169  public static function writeLevelDescription(int $a_id, string $a_description): void
170  {
171  global $DIC;
172 
173  $repository = $DIC->skills()->internal()->repo()->getLevelRepo();
174  $repository->writeLevelDescription($a_id, $a_description);
175  }
176 
177  public function updateLevelOrder(array $order): void
178  {
179  asort($order);
180  $this->bsc_skl_lvl_db_rep->updateLevelOrder($order);
181  }
182 
183  public function deleteLevel(int $a_id): void
184  {
185  $this->bsc_skl_lvl_db_rep->deleteLevel($a_id);
186  }
187 
188  public function fixLevelNumbering(): void
189  {
190  $skill_id = $this->getId();
191  $this->bsc_skl_lvl_db_rep->fixLevelNumbering($skill_id);
192  }
193 
194  public function getSkillForLevelId(int $a_level_id): ?ilBasicSkill
195  {
196  return $this->bsc_skl_lvl_db_rep->getSkillForLevelId($a_level_id);
197  }
198 
199  //
200  //
201  // User skill (level) related methods
202  //
203  //
204 
205  public static function resetUserSkillLevelStatus(
206  int $a_user_id,
207  int $a_skill_id,
208  int $a_tref_id = 0,
209  int $a_trigger_ref_id = 0,
210  bool $a_self_eval = false
211  ): void {
212  global $DIC;
213 
214  $ilDB = $DIC->database();
215 
216  if (!$a_self_eval) {
217  throw new ilSkillException("resetUserSkillLevelStatus currently only provided for self evaluations.");
218  }
219 
220  $obj_adapter = new ilSkillObjectAdapter();
221  $trigger_obj_id = ($a_trigger_ref_id > 0)
222  ? $obj_adapter->getObjIdForRefId($a_trigger_ref_id)
223  : 0;
224 
225  $update = false;
226  $repository = new ilSkillUserLevelDBRepository($ilDB);
227  $status_date = $repository->hasRecentSelfEvaluation($a_user_id, $a_skill_id, $a_tref_id, $a_trigger_ref_id);
228  if ($status_date != "") {
229  $update = true;
230  }
231 
232  $repository->resetUserSkillLevelStatus(
233  $update,
234  $trigger_obj_id,
235  $status_date,
236  $a_user_id,
237  $a_skill_id,
238  $a_tref_id,
239  $a_trigger_ref_id,
240  $a_self_eval
241  );
242  }
243 
244  protected static function hasRecentSelfEvaluation(
245  int $a_user_id,
246  int $a_skill_id,
247  int $a_tref_id = 0,
248  int $a_trigger_ref_id = 0
249  ): string {
250  global $DIC;
251 
252  $ilDB = $DIC->database();
253 
254  $obj_adapter = new ilSkillObjectAdapter();
255  $trigger_obj_id = ($a_trigger_ref_id > 0)
256  ? $obj_adapter->getObjIdForRefId($a_trigger_ref_id)
257  : 0;
258  $repository = new ilSkillUserLevelDBRepository($ilDB);
259 
260  return $repository->hasRecentSelfEvaluation(
261  $trigger_obj_id,
262  $a_user_id,
263  $a_skill_id,
264  $a_tref_id,
265  $a_trigger_ref_id
266  );
267  }
268 
269  public static function getNewAchievementsPerUser(
270  string $a_timestamp,
271  string $a_timestamp_to = null,
272  int $a_user_id = 0,
273  int $a_self_eval = 0
274  ): array {
275  global $DIC;
276 
277  $ilDB = $DIC->database();
278 
279  $repository = new ilSkillUserLevelDBRepository($ilDB);
280 
281  return $repository->getNewAchievementsPerUser($a_timestamp, $a_timestamp_to, $a_user_id, $a_self_eval);
282  }
283 
284  public static function writeUserSkillLevelStatus(
285  int $a_level_id,
286  int $a_user_id,
287  int $a_trigger_ref_id,
288  int $a_tref_id = 0,
289  int $a_status = ilBasicSkill::ACHIEVED,
290  bool $a_force = false,
291  bool $a_self_eval = false,
292  string $a_unique_identifier = "",
293  float $a_next_level_fulfilment = 0.0,
294  string $trigger_user_id = ""
295  ): void {
296  global $DIC;
297 
298  $ilDB = $DIC->database();
299 
300  $skill_id = ilBasicSkill::lookupLevelSkillId($a_level_id);
301  $trigger_ref_id = $a_trigger_ref_id;
302  $obj_adapter = new ilSkillObjectAdapter();
303  $trigger_obj_id = $obj_adapter->getObjIdForRefId($trigger_ref_id);
304  $trigger_title = $obj_adapter->getTitleForObjId($trigger_obj_id);
305  $trigger_type = $obj_adapter->getTypeForObjId($trigger_obj_id);
306 
307  $status_date = "";
308  $update = false;
309 
310  // self evaluations will update, if the last self evaluation is on the same day
311  if ($a_self_eval && self::hasRecentSelfEvaluation($a_user_id, $skill_id, $a_tref_id, $trigger_ref_id)) {
312  $status_date = self::hasRecentSelfEvaluation($a_user_id, $skill_id, $a_tref_id, $trigger_ref_id);
313  if ($status_date != "") {
314  $update = true;
315  }
316  }
317 
318  //next level percentage fulfilment value must be >=0 and <1
319  if (!($a_next_level_fulfilment >= 0) || !($a_next_level_fulfilment < 1)) {
320  throw new \UnexpectedValueException(
321  "Next level fulfilment must be equal to or greater than 0 and less than 1, '" .
322  $a_next_level_fulfilment . "' given."
323  );
324  }
325 
326  $repository = new ilSkillUserLevelDBRepository($ilDB);
327  $repository->writeUserSkillLevelStatus(
328  $skill_id,
329  $trigger_ref_id,
330  $trigger_obj_id,
331  $trigger_title,
332  $trigger_type,
333  $update,
334  $status_date,
335  $a_level_id,
336  $a_user_id,
337  $a_tref_id,
338  $a_self_eval,
339  $a_unique_identifier,
340  $a_next_level_fulfilment,
341  $trigger_user_id
342  );
343  }
344 
346  int $a_user_id,
347  int $a_trigger_obj_id,
348  bool $a_self_eval = false,
349  string $a_unique_identifier = ""
350  ): bool {
351  global $DIC;
352 
353  $ilDB = $DIC->database();
354 
355  if ($a_trigger_obj_id == 0) {
356  return false;
357  }
358  $repository = new ilSkillUserLevelDBRepository($ilDB);
359 
360  return $repository->removeAllUserSkillLevelStatusOfObject(
361  $a_user_id,
362  $a_trigger_obj_id,
363  $a_self_eval,
364  $a_unique_identifier
365  );
366  }
367 
368  public static function removeAllUserData(int $a_user_id): void
369  {
370  global $DIC;
371 
372  $ilDB = $DIC->database();
373 
374  $repository = new ilSkillUserLevelDBRepository($ilDB);
375  $repository->removeAllUserData($a_user_id);
376  }
377 
378  public function getMaxLevelPerType(
379  int $a_tref_id,
380  string $a_type,
381  int $a_user_id = 0,
382  int $a_self_eval = 0
383  ): int {
384  if ($a_user_id == 0) {
385  $a_user_id = $this->user->getId();
386  }
387  $skill_id = $this->getId();
388  $levels = $this->getLevelData();
389 
390  return $this->bsc_skl_usr_lvl_db_rep->getMaxLevelPerType(
391  $skill_id,
392  $levels,
393  $a_tref_id,
394  $a_type,
395  $a_user_id,
396  $a_self_eval
397  );
398  }
399 
401  int $a_tref_id,
402  string $a_type,
403  int $a_user_id = 0,
404  int $a_self_eval = 0
405  ): float {
406  if ($a_user_id == 0) {
407  $a_user_id = $this->user->getId();
408  }
409  $skill_id = $this->getId();
410 
411  return $this->bsc_skl_usr_lvl_db_rep->getNextLevelFulfilmentPerType(
412  $skill_id,
413  $a_tref_id,
414  $a_type,
415  $a_user_id,
416  $a_self_eval
417  );
418  }
419 
420  public function getAllLevelEntriesOfUser(
421  int $a_tref_id,
422  int $a_user_id = 0,
423  int $a_self_eval = 0
424  ): array {
425  if ($a_user_id == 0) {
426  $a_user_id = $this->user->getId();
427  }
428  $skill_id = $this->getId();
429 
430  return $this->bsc_skl_usr_lvl_db_rep->getAllLevelEntriesOfUser($skill_id, $a_tref_id, $a_user_id, $a_self_eval);
431  }
432 
434  int $a_tref_id,
435  int $a_user_id = 0,
436  int $a_eval_by = 0
437  ): array {
438  if ($a_user_id == 0) {
439  $a_user_id = $this->user->getId();
440  }
441  $skill_id = $this->getId();
442 
443  return $this->bsc_skl_usr_lvl_db_rep->getAllHistoricLevelEntriesOfUser(
444  $skill_id,
445  $a_tref_id,
446  $a_user_id,
447  $a_eval_by
448  );
449  }
450 
451  public function getMaxLevelPerObject(
452  int $a_tref_id,
453  int $a_object_id,
454  int $a_user_id = 0,
455  int $a_self_eval = 0
456  ): int {
457  if ($a_user_id == 0) {
458  $a_user_id = $this->user->getId();
459  }
460  $skill_id = $this->getId();
461  $levels = $this->getLevelData();
462 
463  return $this->bsc_skl_usr_lvl_db_rep->getMaxLevelPerObject(
464  $skill_id,
465  $levels,
466  $a_tref_id,
467  $a_object_id,
468  $a_user_id,
469  $a_self_eval
470  );
471  }
472 
474  int $a_tref_id,
475  int $a_object_id,
476  int $a_user_id = 0,
477  int $a_self_eval = 0
478  ): float {
479  if ($a_user_id == 0) {
480  $a_user_id = $this->user->getId();
481  }
482  $skill_id = $this->getId();
483 
484  return $this->bsc_skl_usr_lvl_db_rep->getNextLevelFulfilmentPerObject(
485  $skill_id,
486  $a_tref_id,
487  $a_object_id,
488  $a_user_id,
489  $a_self_eval
490  );
491  }
492 
493  public function getMaxLevel(
494  int $a_tref_id,
495  int $a_user_id = 0,
496  int $a_self_eval = 0
497  ): int {
498  if ($a_user_id == 0) {
499  $a_user_id = $this->user->getId();
500  }
501  $skill_id = $this->getId();
502  $levels = $this->getLevelData();
503 
504  return $this->bsc_skl_usr_lvl_db_rep->getMaxLevel($skill_id, $levels, $a_tref_id, $a_user_id, $a_self_eval);
505  }
506 
507  public function getNextLevelFulfilment(
508  int $a_tref_id,
509  int $a_user_id = 0,
510  int $a_self_eval = 0
511  ): float {
512  if ($a_user_id == 0) {
513  $a_user_id = $this->user->getId();
514  }
515  $skill_id = $this->getId();
516 
517  return $this->bsc_skl_usr_lvl_db_rep->getNextLevelFulfilment($skill_id, $a_tref_id, $a_user_id, $a_self_eval);
518  }
519 
520  public static function hasSelfEvaluated(
521  int $a_user_id,
522  int $a_skill_id,
523  int $a_tref_id
524  ): bool {
525  global $DIC;
526 
527  $ilDB = $DIC->database();
528 
529  $repository = new ilSkillUserLevelDBRepository($ilDB);
530 
531  return $repository->hasSelfEvaluated($a_user_id, $a_skill_id, $a_tref_id);
532  }
533 
534  public function getLastLevelPerObject(
535  int $a_tref_id,
536  int $a_object_id,
537  int $a_user_id = 0,
538  int $a_self_eval = 0
539  ): int {
540  if ($a_user_id == 0) {
541  $a_user_id = $this->user->getId();
542  }
543  $skill_id = $this->getId();
544 
545  return $this->bsc_skl_usr_lvl_db_rep->getLastLevelPerObject(
546  $skill_id,
547  $a_tref_id,
548  $a_object_id,
549  $a_user_id,
550  $a_self_eval
551  );
552  }
553 
554  public function getLastUpdatePerObject(
555  int $a_tref_id,
556  int $a_object_id,
557  int $a_user_id = 0,
558  int $a_self_eval = 0
559  ): string {
560  if ($a_user_id == 0) {
561  $a_user_id = $this->user->getId();
562  }
563  $skill_id = $this->getId();
564 
565  return $this->bsc_skl_usr_lvl_db_rep->getLastUpdatePerObject(
566  $skill_id,
567  $a_tref_id,
568  $a_object_id,
569  $a_user_id,
570  $a_self_eval
571  );
572  }
573 
574  //
575  //
576  // Certificate related methods
577  //
578  //
579 
580  public function getTitleForCertificate(): string
581  {
582  return $this->getTitle();
583  }
584 
585  public function getShortTitleForCertificate(): string
586  {
587  return "Skill";
588  }
589 
593  public static function getUsageInfo(array $a_cskill_ids): array
594  {
595  global $DIC;
596 
597  $usage_manager = $DIC->skills()->internal()->manager()->getUsageManager();
598 
599  return $usage_manager->getUsageInfoGeneric(
600  $a_cskill_ids,
601  Usage\SkillUsageManager::USER_ASSIGNED,
602  "skl_user_skill_level",
603  "user_id"
604  );
605  }
606 
607  public static function getCommonSkillIdForImportId(
608  int $a_source_inst_id,
609  int $a_skill_import_id,
610  int $a_tref_import_id = 0
611  ): array {
612  global $DIC;
613 
614  if ($a_source_inst_id == 0) {
615  return [];
616  }
617 
618  $repository = $DIC->skills()->internal()->repo()->getTreeRepo();
619  return $repository->getCommonSkillIdForImportId(
620  $a_source_inst_id,
621  $a_skill_import_id,
622  $a_tref_import_id
623  );
624  }
625 
626  public static function getLevelIdForImportId(int $a_source_inst_id, int $a_level_import_id): array
627  {
628  global $DIC;
629 
630  $repository = $DIC->skills()->internal()->repo()->getTreeRepo();
631 
632  return $repository->getLevelIdForImportId($a_source_inst_id, $a_level_import_id);
633  }
634 
635  public static function getLevelIdForImportIdMatchSkill(
636  int $a_source_inst_id,
637  int $a_level_import_id,
638  int $a_skill_import_id,
639  int $a_tref_import_id = 0
640  ): array {
641  $level_id_data = self::getLevelIdForImportId($a_source_inst_id, $a_level_import_id);
642  $skill_data = self::getCommonSkillIdForImportId($a_source_inst_id, $a_skill_import_id, $a_tref_import_id);
643  $matches = [];
644  foreach ($level_id_data as $l) {
645  reset($skill_data);
646  foreach ($skill_data as $s) {
647  if (ilBasicSkill::lookupLevelSkillId($l["level_id"]) == $s["skill_id"]) {
648  $matches[] = array(
649  "level_id" => $l["level_id"],
650  "creation_date" => $l["creation_date"],
651  "skill_id" => $s["skill_id"],
652  "tref_id" => $s["tref_id"]
653  );
654  }
655  }
656  }
657  return $matches;
658  }
659 }
static writeLevelTitle(int $a_id, string $a_title)
getAllHistoricLevelEntriesOfUser(int $a_tref_id, int $a_user_id=0, int $a_eval_by=0)
copy()
Copy basic skill.
setType(string $a_type)
create()
Create skill.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getAllLevelEntriesOfUser(int $a_tref_id, int $a_user_id=0, int $a_self_eval=0)
__construct(int $a_id=0, ilSkillLevelRepository $bsc_skl_lvl_db_rep=null, ilSkillUserLevelRepository $bsc_skl_usr_lvl_db_rep=null, ilSkillTreeRepository $bsc_skl_tre_rep=null)
getLastLevelPerObject(int $a_tref_id, int $a_object_id, int $a_user_id=0, int $a_self_eval=0)
static lookupLevelSkillId(int $a_id)
getMaxLevelPerObject(int $a_tref_id, int $a_object_id, int $a_user_id=0, int $a_self_eval=0)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static removeAllUserSkillLevelStatusOfObject(int $a_user_id, int $a_trigger_obj_id, bool $a_self_eval=false, string $a_unique_identifier="")
static lookupLevelTitle(int $a_id)
ilSkillUserLevelRepository $bsc_skl_usr_lvl_db_rep
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getCommonSkillIdForImportId(int $a_source_inst_id, int $a_skill_import_id, int $a_tref_import_id=0)
static writeLevelDescription(int $a_id, string $a_description)
updateLevelOrder(array $order)
static hasSelfEvaluated(int $a_user_id, int $a_skill_id, int $a_tref_id)
global $DIC
Definition: feed.php:28
addLevel(string $a_title, string $a_description, string $a_import_id="")
ilSkillLevelRepository $bsc_skl_lvl_db_rep
__construct(VocabulariesInterface $vocabularies)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getNewAchievementsPerUser(string $a_timestamp, string $a_timestamp_to=null, int $a_user_id=0, int $a_self_eval=0)
read()
Read data from database.
static writeUserSkillLevelStatus(int $a_level_id, int $a_user_id, int $a_trigger_ref_id, int $a_tref_id=0, int $a_status=ilBasicSkill::ACHIEVED, bool $a_force=false, bool $a_self_eval=false, string $a_unique_identifier="", float $a_next_level_fulfilment=0.0, string $trigger_user_id="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getLevelData(int $a_id=0)
ilSkillTreeRepository $bsc_skl_tre_rep
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static removeAllUserData(int $a_user_id)
static hasRecentSelfEvaluation(int $a_user_id, int $a_skill_id, int $a_tref_id=0, int $a_trigger_ref_id=0)
getMaxLevel(int $a_tref_id, int $a_user_id=0, int $a_self_eval=0)
getNextLevelFulfilmentPerObject(int $a_tref_id, int $a_object_id, int $a_user_id=0, int $a_self_eval=0)
getMaxLevelPerType(int $a_tref_id, string $a_type, int $a_user_id=0, int $a_self_eval=0)
static lookupLevelDescription(int $a_id)
static getLevelIdForImportIdMatchSkill(int $a_source_inst_id, int $a_level_import_id, int $a_skill_import_id, int $a_tref_import_id=0)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getUsageInfo(array $a_cskill_ids)
getNextLevelFulfilmentPerType(int $a_tref_id, string $a_type, int $a_user_id=0, int $a_self_eval=0)
static getLevelIdForImportId(int $a_source_inst_id, int $a_level_import_id)
deleteLevel(int $a_id)
getLastUpdatePerObject(int $a_tref_id, int $a_object_id, int $a_user_id=0, int $a_self_eval=0)
Basic Skill.
getSkillForLevelId(int $a_level_id)
static resetUserSkillLevelStatus(int $a_user_id, int $a_skill_id, int $a_tref_id=0, int $a_trigger_ref_id=0, bool $a_self_eval=false)
getNextLevelFulfilment(int $a_tref_id, int $a_user_id=0, int $a_self_eval=0)