ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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  ): int {
456  if ($a_user_id == 0) {
457  $a_user_id = $this->user->getId();
458  }
459  $skill_id = $this->getId();
460  $levels = $this->getLevelData();
461 
462  return $this->bsc_skl_usr_lvl_db_rep->getMaxLevelPerObject(
463  $skill_id,
464  $levels,
465  $a_tref_id,
466  $a_object_id,
467  $a_user_id,
468  $a_self_eval
469  );
470  }
471 
473  int $a_tref_id,
474  int $a_object_id,
475  int $a_user_id = 0,
476  int $a_self_eval = 0
477  ): float {
478  if ($a_user_id == 0) {
479  $a_user_id = $this->user->getId();
480  }
481  $skill_id = $this->getId();
482 
483  return $this->bsc_skl_usr_lvl_db_rep->getNextLevelFulfilmentPerObject(
484  $skill_id,
485  $a_tref_id,
486  $a_object_id,
487  $a_user_id,
488  $a_self_eval
489  );
490  }
491 
492  public function getMaxLevel(
493  int $a_tref_id,
494  int $a_user_id = 0,
495  int $a_self_eval = 0
496  ): int {
497  if ($a_user_id == 0) {
498  $a_user_id = $this->user->getId();
499  }
500  $skill_id = $this->getId();
501  $levels = $this->getLevelData();
502 
503  return $this->bsc_skl_usr_lvl_db_rep->getMaxLevel($skill_id, $levels, $a_tref_id, $a_user_id, $a_self_eval);
504  }
505 
506  public function getNextLevelFulfilment(
507  int $a_tref_id,
508  int $a_user_id = 0,
509  int $a_self_eval = 0
510  ): float {
511  if ($a_user_id == 0) {
512  $a_user_id = $this->user->getId();
513  }
514  $skill_id = $this->getId();
515 
516  return $this->bsc_skl_usr_lvl_db_rep->getNextLevelFulfilment($skill_id, $a_tref_id, $a_user_id, $a_self_eval);
517  }
518 
519  public static function hasSelfEvaluated(
520  int $a_user_id,
521  int $a_skill_id,
522  int $a_tref_id
523  ): bool {
524  global $DIC;
525 
526  $ilDB = $DIC->database();
527 
528  $repository = new ilSkillUserLevelDBRepository($ilDB);
529 
530  return $repository->hasSelfEvaluated($a_user_id, $a_skill_id, $a_tref_id);
531  }
532 
533  public function getLastLevelPerObject(
534  int $a_tref_id,
535  int $a_object_id,
536  int $a_user_id = 0,
537  int $a_self_eval = 0
538  ): int {
539  if ($a_user_id == 0) {
540  $a_user_id = $this->user->getId();
541  }
542  $skill_id = $this->getId();
543 
544  return $this->bsc_skl_usr_lvl_db_rep->getLastLevelPerObject(
545  $skill_id,
546  $a_tref_id,
547  $a_object_id,
548  $a_user_id,
549  $a_self_eval
550  );
551  }
552 
553  public function getLastUpdatePerObject(
554  int $a_tref_id,
555  int $a_object_id,
556  int $a_user_id = 0,
557  int $a_self_eval = 0
558  ): string {
559  if ($a_user_id == 0) {
560  $a_user_id = $this->user->getId();
561  }
562  $skill_id = $this->getId();
563 
564  return $this->bsc_skl_usr_lvl_db_rep->getLastUpdatePerObject(
565  $skill_id,
566  $a_tref_id,
567  $a_object_id,
568  $a_user_id,
569  $a_self_eval
570  );
571  }
572 
573  //
574  //
575  // Certificate related methods
576  //
577  //
578 
579  public function getTitleForCertificate(): string
580  {
581  return $this->getTitle();
582  }
583 
584  public function getShortTitleForCertificate(): string
585  {
586  return "Skill";
587  }
588 
592  public static function getUsageInfo(array $a_cskill_ids): array
593  {
594  global $DIC;
595 
596  $usage_manager = $DIC->skills()->internal()->manager()->getUsageManager();
597 
598  return $usage_manager->getUsageInfoGeneric(
599  $a_cskill_ids,
600  Usage\SkillUsageManager::USER_ASSIGNED,
601  "skl_user_skill_level",
602  "user_id"
603  );
604  }
605 
606  public static function getCommonSkillIdForImportId(
607  int $a_source_inst_id,
608  int $a_skill_import_id,
609  int $a_tref_import_id = 0
610  ): array {
611  global $DIC;
612 
613  if ($a_source_inst_id == 0) {
614  return [];
615  }
616 
617  $repository = $DIC->skills()->internal()->repo()->getTreeRepo();
618  return $repository->getCommonSkillIdForImportId(
619  $a_source_inst_id,
620  $a_skill_import_id,
621  $a_tref_import_id
622  );
623  }
624 
625  public static function getLevelIdForImportId(int $a_source_inst_id, int $a_level_import_id): array
626  {
627  global $DIC;
628 
629  $repository = $DIC->skills()->internal()->repo()->getTreeRepo();
630 
631  return $repository->getLevelIdForImportId($a_source_inst_id, $a_level_import_id);
632  }
633 
634  public static function getLevelIdForImportIdMatchSkill(
635  int $a_source_inst_id,
636  int $a_level_import_id,
637  int $a_skill_import_id,
638  int $a_tref_import_id = 0
639  ): array {
640  $level_id_data = self::getLevelIdForImportId($a_source_inst_id, $a_level_import_id);
641  $skill_data = self::getCommonSkillIdForImportId($a_source_inst_id, $a_skill_import_id, $a_tref_import_id);
642  $matches = [];
643  foreach ($level_id_data as $l) {
644  reset($skill_data);
645  foreach ($skill_data as $s) {
646  if (ilBasicSkill::lookupLevelSkillId($l["level_id"]) == $s["skill_id"]) {
647  $matches[] = array(
648  "level_id" => $l["level_id"],
649  "creation_date" => $l["creation_date"],
650  "skill_id" => $s["skill_id"],
651  "tref_id" => $s["tref_id"]
652  );
653  }
654  }
655  }
656  return $matches;
657  }
658 }
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.
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)
getMaxLevelPerObject(int $a_tref_id, int $a_object_id, int $a_user_id=0, int $a_self_eval=0)
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:22
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)
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)