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