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