ILIAS  release_7 Revision v7.30-3-g800a261c036
SkillUserLevelManager.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 
5 namespace ILIAS\Skill\Service;
6 
12 {
16  protected $level_repo;
17 
21  protected $user_level_repo;
22 
26  protected $obj_adapter;
27 
34  public function __construct(
35  \ilBasicSkillLevelRepository $a_level_repo = null,
36  \ilBasicSkillUserLevelRepository $a_user_level_repo = null,
37  \ilSkillObjectAdapterInterface $a_obj_adapter = null
38  ) {
39  global $DIC;
40 
41  $this->level_repo = ($a_level_repo)
42  ? $a_level_repo
43  : $DIC->skills()->internal()->repo()->getLevelRepo();
44  $this->user_level_repo = ($a_user_level_repo)
45  ? $a_user_level_repo
46  : $DIC->skills()->internal()->repo()->getUserLevelRepo();
47  $this->obj_adapter = ($a_obj_adapter)
48  ? $a_obj_adapter
49  : new \ilSkillObjectAdapter();
50  }
51 
61  public function writeSkillLevel(
62  int $user_id,
63  int $a_level_id,
64  int $a_trigger_ref_id,
65  int $a_tref_id,
66  bool $a_self_eval,
67  string $a_unique_identifier,
68  float $a_next_level_fulfilment
69  ) {
70  $skill_id = $this->level_repo->lookupLevelSkillId($a_level_id);
71  $trigger_ref_id = $a_trigger_ref_id;
72  $trigger_obj_id = $this->obj_adapter->getObjIdForRefId($trigger_ref_id);
73  $trigger_title = $this->obj_adapter->getTitleForObjId($trigger_obj_id);
74  $trigger_type = $this->obj_adapter->getTypeForObjId($trigger_obj_id);
75 
76  //next level percentage fulfilment value must be >=0 and <1
77  if (!($a_next_level_fulfilment >= 0) || !($a_next_level_fulfilment < 1)) {
78  throw new \UnexpectedValueException(
79  "Next level fulfilment must be equal to or greater than 0 and less than 1, '" .
80  $a_next_level_fulfilment . "' given."
81  );
82  }
83 
84  $update = false;
85 
86  // self evaluations will update, if the last self evaluation is on the same day
87  if ($a_self_eval && $this->user_level_repo->hasRecentSelfEvaluation($trigger_obj_id, $user_id, $skill_id,
88  $a_tref_id, $trigger_ref_id)) {
89  $status_date = $this->user_level_repo->hasRecentSelfEvaluation($trigger_obj_id, $user_id, $skill_id,
90  $a_tref_id, $trigger_ref_id);
91  if ($status_date != "") {
92  $update = true;
93  }
94  }
95 
96  $this->user_level_repo->writeUserSkillLevelStatus($skill_id, $trigger_ref_id, $trigger_obj_id, $trigger_title,
97  $trigger_type, $update, $status_date, $a_level_id, $user_id, $a_tref_id, $a_self_eval, $a_unique_identifier,
98  $a_next_level_fulfilment);
99  }
100 }
__construct(\ilBasicSkillLevelRepository $a_level_repo=null, \ilBasicSkillUserLevelRepository $a_user_level_repo=null, \ilSkillObjectAdapterInterface $a_obj_adapter=null)
Constructor.
Class ilBasicSkillObjectAdapter.
Interface ilBasicSkillLevelRepository.
writeSkillLevel(int $user_id, int $a_level_id, int $a_trigger_ref_id, int $a_tref_id, bool $a_self_eval, string $a_unique_identifier, float $a_next_level_fulfilment)
global $DIC
Definition: goto.php:24
Interface ilBasicSkillUserLevelRepository.