ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilBasicSkill.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2020 ILIAS open source, Extended GPL, see docs/LICENSE */
4
10{
14 protected $user;
15
20
25
30
31 //TODO: What to do with these constants?
32 const ACHIEVED = 1;
33 const NOT_ACHIEVED = 0;
34
35 const EVAL_BY_OTHERS_ = 0;
36 const EVAL_BY_SELF = 1;
37 const EVAL_BY_ALL = 2;
38
39 public $id;
40
48 public function __construct(
49 int $a_id = 0,
53 ) {
54 global $DIC;
55
56 $this->db = $DIC->database();
57 $this->user = $DIC->user();
58
59 if (is_null($bsc_skl_lvl_db_rep)) {
60 $this->bsc_skl_lvl_db_rep = $DIC->skills()->internal()->repo()->getLevelRepo();
61 }
62 else {
63 $this->bsc_skl_lvl_db_rep = $bsc_skl_lvl_db_rep;
64 }
65
66 if (is_null($bsc_skl_usr_lvl_db_rep)) {
67 $this->bsc_skl_usr_lvl_db_rep = $DIC->skills()->internal()->repo()->getUserLevelRepo();
68 }
69 else {
70 $this->bsc_skl_usr_lvl_db_rep = $bsc_skl_usr_lvl_db_rep;
71 }
72
73 if (is_null($bsc_skl_tre_rep)) {
74 $this->bsc_skl_tre_rep = $DIC->skills()->internal()->repo()->getTreeRepo();
75 }
76 else {
77 $this->bsc_skl_tre_rep = $bsc_skl_tre_rep;
78 }
79
81 $this->setType("skll");
82 }
83
87 public function read()
88 {
89 parent::read();
90 }
91
95 public function create()
96 {
97 parent::create();
98 }
99
103 public function delete()
104 {
105 $skill_id = $this->getId();
106 $this->bsc_skl_lvl_db_rep->deleteLevelsOfSkill($skill_id);
107 $this->bsc_skl_usr_lvl_db_rep->deleteUserLevelsOfSkill($skill_id);
108
109 parent::delete();
110 }
111
115 public function copy()
116 {
117 $skill = new ilBasicSkill();
118 $skill->setTitle($this->getTitle());
119 $skill->setDescription($this->getDescription());
120 $skill->setType($this->getType());
121 $skill->setSelfEvaluation($this->getSelfEvaluation());
122 $skill->setOrderNr($this->getOrderNr());
123 $skill->create();
124
125 $levels = $this->getLevelData();
126 if (sizeof($levels)) {
127 foreach ($levels as $item) {
128 $skill->addLevel($item["title"], $item["description"]);
129 }
130 }
131 $skill->update();
132
133 return $skill;
134 }
135
136 //
137 //
138 // Skill level related methods
139 //
140 //
141
142 public function addLevel(string $a_title, string $a_description, string $a_import_id = "")
143 {
144 $skill_id = $this->getId();
145 $this->bsc_skl_lvl_db_rep->addLevel($skill_id, $a_title, $a_description, $a_import_id);
146 }
147
148 public function getLevelData(int $a_id = 0) : array
149 {
150 $skill_id = $this->getId();
151
152 return $this->bsc_skl_lvl_db_rep->getLevelData($skill_id, $a_id);
153 }
154
155 public static function lookupLevelTitle(int $a_id) : string
156 {
157 global $DIC;
158
159 $ilDB = $DIC->database();
160
161 $repository = new ilBasicSkillLevelDBRepository($ilDB);
162
163 return $repository->lookupLevelTitle($a_id);
164 }
165
166 public static function lookupLevelDescription(int $a_id) : string
167 {
168 global $DIC;
169
170 $ilDB = $DIC->database();
171
172 $repository = new ilBasicSkillLevelDBRepository($ilDB);
173
174 return $repository->lookupLevelDescription($a_id);
175 }
176
177 public static function lookupLevelSkillId(int $a_id) : int
178 {
179 global $DIC;
180
181 $ilDB = $DIC->database();
182
183 $repository = new ilBasicSkillLevelDBRepository($ilDB);
184
185 return $repository->lookupLevelSkillId($a_id);
186 }
187
188 public static function writeLevelTitle(int $a_id, string $a_title)
189 {
190 global $DIC;
191
192 $ilDB = $DIC->database();
193
194 $repository = new ilBasicSkillLevelDBRepository($ilDB);
195 $repository->writeLevelTitle($a_id, $a_title);
196 }
197
198 public static function writeLevelDescription(int $a_id, string $a_description)
199 {
200 global $DIC;
201
202 $ilDB = $DIC->database();
203
204 $repository = new ilBasicSkillLevelDBRepository($ilDB);
205 $repository->writeLevelDescription($a_id, $a_description);
206 }
207
208 public function updateLevelOrder(array $order)
209 {
210 asort($order);
211 $this->bsc_skl_lvl_db_rep->updateLevelOrder($order);
212 }
213
214 public function deleteLevel(int $a_id)
215 {
216 $this->bsc_skl_lvl_db_rep->deleteLevel($a_id);
217 }
218
219 public function fixLevelNumbering()
220 {
221 $skill_id = $this->getId();
222 $this->bsc_skl_lvl_db_rep->fixLevelNumbering($skill_id);
223 }
224
225 public function getSkillForLevelId(int $a_level_id)
226 {
227 return $this->bsc_skl_lvl_db_rep->getSkillForLevelId($a_level_id);
228 }
229
230 //
231 //
232 // User skill (level) related methods
233 //
234 //
235
236 public static function resetUserSkillLevelStatus(
237 int $a_user_id,
238 int $a_skill_id,
239 int $a_tref_id = 0,
240 int $a_trigger_ref_id = 0,
241 bool $a_self_eval = false
242 ) {
243 global $DIC;
244
245 $ilDB = $DIC->database();
246
247 if (!$a_self_eval) {
248 throw new ilSkillException("resetUserSkillLevelStatus currently only provided for self evaluations.");
249 }
250
251 $obj_adapter = new ilSkillObjectAdapter();
252 $trigger_obj_id = ($a_trigger_ref_id > 0)
253 ? $obj_adapter->getObjIdForRefId($a_trigger_ref_id)
254 : 0;
255
256 $update = false;
257 $repository = new ilBasicSkillUserLevelDBRepository($ilDB);
258 $status_date = $repository->hasRecentSelfEvaluation($a_user_id, $a_skill_id, $a_tref_id, $a_trigger_ref_id);
259 if ($status_date != "") {
260 $update = true;
261 }
262
263 $repository->resetUserSkillLevelStatus($update, $trigger_obj_id, $status_date, $a_user_id, $a_skill_id,
264 $a_tref_id, $a_trigger_ref_id, $a_self_eval);
265 }
266
267 protected static function hasRecentSelfEvaluation(
268 int $a_user_id,
269 int $a_skill_id,
270 int $a_tref_id = 0,
271 int $a_trigger_ref_id = 0
272 ) {
273 global $DIC;
274
275 $ilDB = $DIC->database();
276
277 $obj_adapter = new ilSkillObjectAdapter();
278 $trigger_obj_id = ($a_trigger_ref_id > 0)
279 ? $obj_adapter->getObjIdForRefId($a_trigger_ref_id)
280 : 0;
281 $repository = new ilBasicSkillUserLevelDBRepository($ilDB);
282
283 return $repository->hasRecentSelfEvaluation($trigger_obj_id, $a_user_id, $a_skill_id, $a_tref_id,
284 $a_trigger_ref_id);
285 }
286
287 public static function getNewAchievementsPerUser(
288 string $a_timestamp,
289 string $a_timestamp_to = null,
290 int $a_user_id = 0,
291 int $a_self_eval = 0
292 ) : array {
293 global $DIC;
294
295 $ilDB = $DIC->database();
296
297 $repository = new ilBasicSkillUserLevelDBRepository($ilDB);
298
299 return $repository->getNewAchievementsPerUser($a_timestamp, $a_timestamp_to, $a_user_id, $a_self_eval);
300 }
301
302 public static function writeUserSkillLevelStatus(
303 int $a_level_id,
304 int $a_user_id,
305 int $a_trigger_ref_id,
306 int $a_tref_id = 0,
307 int $a_status = ilBasicSkill::ACHIEVED,
308 bool $a_force = false,
309 bool $a_self_eval = false,
310 string $a_unique_identifier = "",
311 float $a_next_level_fulfilment = 0.0
312 ) {
313 global $DIC;
314
315 $ilDB = $DIC->database();
316
317 $skill_id = ilBasicSkill::lookupLevelSkillId($a_level_id);
318 $trigger_ref_id = $a_trigger_ref_id;
319 $obj_adapter = new ilSkillObjectAdapter();
320 $trigger_obj_id = $obj_adapter->getObjIdForRefId($trigger_ref_id);
321 $trigger_title = $obj_adapter->getTitleForObjId($trigger_obj_id);
322 $trigger_type = $obj_adapter->getTypeForObjId($trigger_obj_id);
323
324 $update = false;
325
326 // self evaluations will update, if the last self evaluation is on the same day
327 if ($a_self_eval && self::hasRecentSelfEvaluation($a_user_id, $skill_id, $a_tref_id, $trigger_ref_id)) {
328 $status_date = self::hasRecentSelfEvaluation($a_user_id, $skill_id, $a_tref_id, $trigger_ref_id);
329 if ($status_date != "") {
330 $update = true;
331 }
332 }
333
334 //next level percentage fulfilment value must be >=0 and <1
335 if (!($a_next_level_fulfilment >= 0) || !($a_next_level_fulfilment < 1)) {
336 throw new \UnexpectedValueException(
337 "Next level fulfilment must be equal to or greater than 0 and less than 1, '" .
338 $a_next_level_fulfilment . "' given."
339 );
340 }
341
342 $repository = new ilBasicSkillUserLevelDBRepository($ilDB);
343 $repository->writeUserSkillLevelStatus($skill_id, $trigger_ref_id, $trigger_obj_id, $trigger_title,
344 $trigger_type, $update, $status_date, $a_level_id, $a_user_id, $a_tref_id, $a_self_eval,
345 $a_unique_identifier, $a_next_level_fulfilment);
346 }
347
349 int $a_user_id,
350 int $a_trigger_obj_id,
351 bool $a_self_eval = false,
352 string $a_unique_identifier = ""
353 ) : bool {
354 global $DIC;
355
356 $ilDB = $DIC->database();
357
358 if ($a_trigger_obj_id == 0) {
359 return false;
360 }
361 $repository = new ilBasicSkillUserLevelDBRepository($ilDB);
362
363 return $repository->removeAllUserSkillLevelStatusOfObject($a_user_id, $a_trigger_obj_id, $a_self_eval,
364 $a_unique_identifier);
365 }
366
367 public static function removeAllUserData(int $a_user_id)
368 {
369 global $DIC;
370
371 $ilDB = $DIC->database();
372
373 $repository = new ilBasicSkillUserLevelDBRepository($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($skill_id, $levels, $a_tref_id, $a_type, $a_user_id,
390 $a_self_eval);
391 }
392
394 int $a_tref_id,
395 int $a_user_id = 0,
396 int $a_self_eval = 0
397 ) : array {
398 if ($a_user_id == 0) {
399 $a_user_id = $this->user->getId();
400 }
401 $skill_id = $this->getId();
402
403 return $this->bsc_skl_usr_lvl_db_rep->getAllLevelEntriesOfUser($skill_id, $a_tref_id, $a_user_id, $a_self_eval);
404 }
405
407 int $a_tref_id,
408 int $a_user_id = 0,
409 int $a_eval_by = 0
410 ) : array {
411 if ($a_user_id == 0) {
412 $a_user_id = $this->user->getId();
413 }
414 $skill_id = $this->getId();
415
416 return $this->bsc_skl_usr_lvl_db_rep->getAllHistoricLevelEntriesOfUser($skill_id, $a_tref_id, $a_user_id,
417 $a_eval_by);
418 }
419
420 public function getMaxLevelPerObject(
421 int $a_tref_id,
422 int $a_object_id,
423 int $a_user_id = 0,
424 int $a_self_eval = 0
425 ) : int {
426 if ($a_user_id == 0) {
427 $a_user_id = $this->user->getId();
428 }
429 $skill_id = $this->getId();
430 $levels = $this->getLevelData();
431
432 return $this->bsc_skl_usr_lvl_db_rep->getMaxLevelPerObject($skill_id, $levels, $a_tref_id, $a_object_id,
433 $a_user_id, $a_self_eval);
434 }
435
436 public function getMaxLevel(
437 int $a_tref_id,
438 int $a_user_id = 0,
439 int $a_self_eval = 0
440 ) : int {
441 if ($a_user_id == 0) {
442 $a_user_id = $this->user->getId();
443 }
444 $skill_id = $this->getId();
445 $levels = $this->getLevelData();
446
447 return $this->bsc_skl_usr_lvl_db_rep->getMaxLevel($skill_id, $levels, $a_tref_id, $a_user_id, $a_self_eval);
448 }
449
450 public static function hasSelfEvaluated(
451 int $a_user_id,
452 int $a_skill_id,
453 int $a_tref_id
454 ) : bool {
455 global $DIC;
456
457 $ilDB = $DIC->database();
458
459 $repository = new ilBasicSkillUserLevelDBRepository($ilDB);
460
461 return $repository->hasSelfEvaluated($a_user_id, $a_skill_id, $a_tref_id);
462 }
463
464 public function getLastLevelPerObject(
465 int $a_tref_id,
466 int $a_object_id,
467 int $a_user_id = 0,
468 int $a_self_eval = 0
469 ) {
470 if ($a_user_id == 0) {
471 $a_user_id = $this->user->getId();
472 }
473 $skill_id = $this->getId();
474
475 return $this->bsc_skl_usr_lvl_db_rep->getLastLevelPerObject($skill_id, $a_tref_id, $a_object_id, $a_user_id,
476 $a_self_eval);
477 }
478
479 public function getLastUpdatePerObject(
480 int $a_tref_id,
481 int $a_object_id,
482 int $a_user_id = 0,
483 int $a_self_eval = 0
484 ) {
485 if ($a_user_id == 0) {
486 $a_user_id = $this->user->getId();
487 }
488 $skill_id = $this->getId();
489
490 return $this->bsc_skl_usr_lvl_db_rep->getLastUpdatePerObject($skill_id, $a_tref_id, $a_object_id, $a_user_id,
491 $a_self_eval);
492 }
493
494 //
495 //
496 // Certificate related methods
497 //
498 //
499
504 public function getTitleForCertificate()
505 {
506 return $this->getTitle();
507 }
508
514 {
515 return "Skill";
516 }
517
524 public static function _lookupCertificate(int $a_skill_id, int $a_skill_level_id)
525 {
526 $certificatefile = CLIENT_WEB_DIR . "/certificates/skill/" .
527 ((int) $a_skill_id) . "/" . ((int) $a_skill_level_id) . "/certificate.xml";
528 if (@file_exists($certificatefile)) {
529 return true;
530 } else {
531 return false;
532 }
533 }
534
540 public static function getUsageInfo($a_cskill_ids, &$a_usages)
541 {
543 $a_cskill_ids,
544 $a_usages,
546 "skl_user_skill_level",
547 "user_id"
548 );
549 }
550
551 public static function getCommonSkillIdForImportId(
552 int $a_source_inst_id,
553 int $a_skill_import_id,
554 int $a_tref_import_id = 0
555 ) : array {
556 global $DIC;
557
558 $ilDB = $DIC->database();
559
560 $tree = new ilSkillTree();
561
562 if ($a_source_inst_id == 0) {
563 return array();
564 }
565
566 $repository = new ilBasicSkillTreeDBRepository($ilDB);
567 return $repository->getCommonSkillIdForImportId($tree, $a_source_inst_id, $a_skill_import_id,
568 $a_tref_import_id);
569 }
570
571 public static function getLevelIdForImportId(int $a_source_inst_id, int $a_level_import_id) : array
572 {
573 global $DIC;
574
575 $ilDB = $DIC->database();
576
577 $repository = new ilBasicSkillTreeDBRepository($ilDB);
578
579 return $repository->getLevelIdForImportId($a_source_inst_id, $a_level_import_id);
580 }
581
590 public static function getLevelIdForImportIdMatchSkill(
591 int $a_source_inst_id,
592 int $a_level_import_id,
593 int $a_skill_import_id,
594 int $a_tref_import_id = 0
595 ) : array {
596 $level_id_data = self::getLevelIdForImportId($a_source_inst_id, $a_level_import_id);
597 $skill_data = self::getCommonSkillIdForImportId($a_source_inst_id, $a_skill_import_id, $a_tref_import_id);
598 $matches = array();
599 foreach ($level_id_data as $l) {
600 reset($skill_data);
601 foreach ($skill_data as $s) {
602 if (ilBasicSkill::lookupLevelSkillId($l["level_id"]) == $s["skill_id"]) {
603 $matches[] = array(
604 "level_id" => $l["level_id"],
605 "creation_date" => $l["creation_date"],
606 "skill_id" => $s["skill_id"],
607 "tref_id" => $s["tref_id"]
608 );
609 }
610 }
611 }
612 return $matches;
613 }
614}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
Class ilBasicSkillLevelDBRepository.
updateLevelOrder(array $order)
static removeAllUserSkillLevelStatusOfObject(int $a_user_id, int $a_trigger_obj_id, bool $a_self_eval=false, string $a_unique_identifier="")
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)
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)
Get level ids for import Ids matching common skills.
getMaxLevel(int $a_tref_id, int $a_user_id=0, int $a_self_eval=0)
static _lookupCertificate(int $a_skill_id, int $a_skill_level_id)
Checks whether a skill level has a certificate or not.
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)
getTitleForCertificate()
Get title for certificate.
getLevelData(int $a_id=0)
__construct(int $a_id=0, ilBasicSkillLevelRepository $bsc_skl_lvl_db_rep=null, ilBasicSkillUserLevelRepository $bsc_skl_usr_lvl_db_rep=null, ilBasicSkillTreeRepository $bsc_skl_tre_rep=null)
ilBasicSkill constructor.
static getUsageInfo($a_cskill_ids, &$a_usages)
Get usage info.
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.
getAllHistoricLevelEntriesOfUser(int $a_tref_id, int $a_user_id=0, int $a_eval_by=0)
getShortTitleForCertificate()
Get short title for certificate.
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)
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)
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)
Skill exception class.
Class ilBasicSkillObjectAdapter.
A node in the skill tree.
getDescription()
Get description.
setType($a_type)
Set type.
getOrderNr()
Get order nr.
getSelfEvaluation()
Get self evaluation.
static getUsageInfoGeneric( $a_cskill_ids, &$a_usages, $a_usage_type, $a_table, $a_key_field, $a_skill_field="skill_id", $a_tref_field="tref_id")
Get standard usage query.
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
Definition: confirmReg.php:12
const CLIENT_WEB_DIR
Definition: constants.php:45
global $DIC
Definition: goto.php:24
Interface ilBasicSkillLevelRepository.
Interface ilBasicSkillTreeRepository.
Interface ilBasicSkillUserLevelRepository.
Get info on usages of skills.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilDB