ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.SkillProfileCompletionManager.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 namespace ILIAS\Skill\Profile;
23 
26 
35 {
38  protected \ilTree $tree_service;
39  protected \ilObjectDefinition $obj_definition;
40 
41  public function __construct(
42  SkillProfileManager $profile_manager,
43  ?SkillProfileCompletionDBRepository $profile_completion_repo = null
44  ) {
45  global $DIC;
46 
47  $this->profile_manager = $profile_manager;
48  $this->profile_completion_repo = ($profile_completion_repo)
49  ?: $DIC->skills()->internal()->repo()->getProfileCompletionRepo();
50  $this->tree_service = $DIC->repositoryTree();
51  $this->obj_definition = $DIC["objDefinition"];
52  }
53 
58  public function getActualMaxLevels(
59  int $user_id,
60  array $skills,
61  string $gap_mode = "",
62  string $gap_mode_type = "",
63  int $gap_mode_obj_id = 0,
64  string $trigger_user = ""
65  ): array {
66  // get actual levels for gap analysis
67  $actual_levels = [];
68  foreach ($skills as $sk) {
69  $bs = new \ilBasicSkill($sk->getBaseSkillId());
70  if ($gap_mode == "max_per_type") {
71  $max = $bs->getMaxLevelPerType($sk->getTrefId(), $gap_mode_type, $user_id);
72  } elseif ($gap_mode == "max_per_object") {
73  if ($this->obj_definition->isContainer(\ilObject::_lookupType($gap_mode_obj_id))) {
74  $sub_objects = $this->tree_service->getSubTree(
75  $this->tree_service->getNodeData((int) current(\ilObject::_getAllReferences($gap_mode_obj_id))),
76  false,
78  );
79  $max = 0;
80  foreach ($sub_objects as $ref_id) {
81  $obj_id = \ilContainerReference::_lookupObjectId($ref_id);
82  $max_tmp = $bs->getMaxLevelPerObject($sk->getTrefId(), $obj_id, $user_id, 0, $trigger_user);
83  if ($max_tmp > $max) {
84  $max = $max_tmp;
85  }
86  }
87  } else {
88  $max = $bs->getMaxLevelPerObject($sk->getTrefId(), $gap_mode_obj_id, $user_id, 0, $trigger_user);
89  }
90  } else {
91  $max = $bs->getMaxLevel($sk->getTrefId(), $user_id);
92  }
93  $actual_levels[$sk->getBaseSkillId()][$sk->getTrefId()] = $max;
94  }
95 
96  return $actual_levels;
97  }
98 
104  int $user_id,
105  array $skills,
106  int $obj_id,
107  string $trigger_user
108  ): array {
109  // get actual levels for gap analysis
110  $last_levels = [];
111  foreach ($skills as $sk) {
112  $bs = new \ilBasicSkill($sk->getBaseSkillId());
113  $last = $bs->getLastLevelEntryOfUser(
114  $sk->getTrefId(),
115  $user_id,
116  $obj_id,
117  0,
118  $trigger_user
119  );
120  $last_levels[$sk->getBaseSkillId()][$sk->getTrefId()] = $last;
121  }
122  return $last_levels;
123  }
124 
125  public function getActualLastLevels(
126  int $user_id,
127  array $skills,
128  string $gap_mode = "",
129  string $gap_mode_type = "",
130  int $gap_mode_obj_id = 0
131  ): array {
132  // todo for coming feature
133  return [];
134  }
135 
141  int $user_id,
142  array $skills,
143  string $gap_mode = "",
144  string $gap_mode_type = "",
145  int $gap_mode_obj_id = 0
146  ): array {
147  // get actual next level fulfilments for gap analysis
148  $fuls = [];
149  foreach ($skills as $sk) {
150  $bs = new \ilBasicSkill($sk->getBaseSkillId());
151  if ($gap_mode == "max_per_type") {
152  $perc = $bs->getNextLevelFulfilmentPerType($sk->getTrefId(), $gap_mode_type, $user_id);
153  } elseif ($gap_mode == "max_per_object") {
154  $perc = $bs->getNextLevelFulfilmentPerObject($sk->getTrefId(), $gap_mode_obj_id, $user_id);
155  } else {
156  $perc = $bs->getNextLevelFulfilment($sk->getTrefId(), $user_id);
157  }
158  $fuls[$sk->getBaseSkillId()][$sk->getTrefId()] = $perc;
159  }
160 
161  return $fuls;
162  }
163 
167  public function getProfileProgress(int $user_id, int $profile_id): int
168  {
169  $profile_levels = $this->profile_manager->getSkillLevels($profile_id);
170  $actual_levels = $this->getActualMaxLevels($user_id, $profile_levels);
171 
172  $profile_count = 0;
173  $achieved_count = 0;
174  foreach ($profile_levels as $level) {
175  if (isset($actual_levels[$level->getBaseSkillId()][$level->getTrefId()]) &&
176  $actual_levels[$level->getBaseSkillId()][$level->getTrefId()] >= $level->getLevelId()) {
177  $achieved_count++;
178  }
179  $profile_count++;
180  }
181  if ($profile_count == 0) {
182  return 0;
183  }
184  $progress = $achieved_count / $profile_count * 100;
185 
186  return (int) $progress;
187  }
188 
192  public function isProfileFulfilled(int $user_id, int $profile_id): bool
193  {
194  if ($this->getProfileProgress($user_id, $profile_id) == 100) {
195  return true;
196  }
197  return false;
198  }
199 
204  public function getAllProfileCompletionsForUser(int $user_id): array
205  {
206  $user_profiles = $this->profile_manager->getProfilesOfUser($user_id);
207  $profile_comps = [];
208  foreach ($user_profiles as $p) {
209  if ($this->isProfileFulfilled($user_id, $p->getId())) {
210  $profile_comps[$p->getId()] = true;
211  } else {
212  $profile_comps[$p->getId()] = false;
213  }
214  }
215 
216  return $profile_comps;
217  }
218 
223  public function getEntries(int $user_id, int $profile_id): array
224  {
225  return $this->profile_completion_repo->getEntries($user_id, $profile_id);
226  }
227 
232  public function getFulfilledEntriesForUser(int $user_id): array
233  {
234  return $this->profile_completion_repo->getFulfilledEntriesForUser($user_id);
235  }
236 
241  public function getAllEntriesForUser(int $user_id): array
242  {
243  return $this->profile_completion_repo->getAllEntriesForUser($user_id);
244  }
245 
250  public function getAllEntriesForProfile(int $profile_id): array
251  {
252  return $this->profile_completion_repo->getAllEntriesForProfile($profile_id);
253  }
254 
259  {
260  $completions = $this->getAllProfileCompletionsForUser($user_id);
261  foreach ($completions as $profile_id => $fulfilled) {
262  if ($fulfilled) {
263  $this->profile_completion_repo->addFulfilmentEntry($user_id, $profile_id);
264  } else {
265  $this->profile_completion_repo->addNonFulfilmentEntry($user_id, $profile_id);
266  }
267  }
268  }
269 
273  public function writeCompletionEntryForSingleProfileOfUser(int $user_id, int $profile_id): void
274  {
275  if ($this->isProfileFulfilled($user_id, $profile_id)) {
276  $this->profile_completion_repo->addFulfilmentEntry($user_id, $profile_id);
277  } else {
278  $this->profile_completion_repo->addNonFulfilmentEntry($user_id, $profile_id);
279  }
280  }
281 
285  public function writeCompletionEntryForAllAssignedUsersOfProfile(int $profile_id): void
286  {
287  $users = $this->profile_manager->getAssignedUserIdsIncludingRoleAssignments($profile_id);
288  foreach ($users as $user_id) {
289  $this->writeCompletionEntryForSingleProfileOfUser($user_id, $profile_id);
290  }
291  }
292 
296  public function writeCompletionEntryForRole(int $role_id, int $profile_id): void
297  {
298  $r_users = $this->profile_manager->getAssignedUsersForRole($role_id);
299  foreach ($r_users as $user_id) {
300  $this->writeCompletionEntryForSingleProfileOfUser($user_id, $profile_id);
301  }
302  }
303 
307  public function deleteEntriesForProfile(int $profile_id): void
308  {
309  $this->profile_completion_repo->deleteEntriesForProfile($profile_id);
310  }
311 
315  public function deleteEntriesForUser(int $user_id): void
316  {
317  $this->profile_completion_repo->deleteEntriesForUser($user_id);
318  }
319 }
writeCompletionEntryForAllAssignedUsersOfProfile(int $profile_id)
Write completion entries for a profile for all assigned users of the given profile.
getProfileProgress(int $user_id, int $profile_id)
Get progress in percent for a profile.
getActualNextLevelFulfilments(int $user_id, array $skills, string $gap_mode="", string $gap_mode_type="", int $gap_mode_obj_id=0)
getActualLastLevels(int $user_id, array $skills, string $gap_mode="", string $gap_mode_type="", int $gap_mode_obj_id=0)
deleteEntriesForProfile(int $profile_id)
Delete all profile completion entries for a profile.
static getSupportedObjectTypes()
static _getAllReferences(int $id)
get all reference ids for object ID
getEntries(int $user_id, int $profile_id)
Get profile completion entries for given user-profile-combination.
$ref_id
Definition: ltiauth.php:66
deleteEntriesForUser(int $user_id)
Delete all profile completion entries for a user.
getAllEntriesForUser(int $user_id)
Get all profile completion entries for a user.
global $DIC
Definition: shib_login.php:25
getAllEntriesForProfile(int $profile_id)
Get all completion entries for a single profile.
getActualMaxLevels(int $user_id, array $skills, string $gap_mode="", string $gap_mode_type="", int $gap_mode_obj_id=0, string $trigger_user="")
static _lookupObjectId(int $ref_id)
getFulfilledEntriesForUser(int $user_id)
Get all fulfilled profile completion entries for a user.
writeCompletionEntryForAllProfilesOfUser(int $user_id)
Write profile completion entries (fulfilled or non-fulfilled) of user for all profiles.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(SkillProfileManager $profile_manager, ?SkillProfileCompletionDBRepository $profile_completion_repo=null)
getAllProfileCompletionsForUser(int $user_id)
Get all profiles of user which are fulfilled or non-fulfilled.
isProfileFulfilled(int $user_id, int $profile_id)
Check if a profile is fulfilled (progress = 100%)
getLastLevelPerObjectAndTriggerUser(int $user_id, array $skills, int $obj_id, string $trigger_user)
This does not include any container logic currently only used for survey, individual assessment...
writeCompletionEntryForRole(int $role_id, int $profile_id)
Write completion entries for a profile for assigned users of a role.
writeCompletionEntryForSingleProfileOfUser(int $user_id, int $profile_id)
Write profile completion entry (fulfilled or non-fulfilled) of user for given profile.
static _lookupType(int $id, bool $reference=false)