ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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  ): array {
65  // get actual levels for gap analysis
66  $actual_levels = [];
67  foreach ($skills as $sk) {
68  $bs = new \ilBasicSkill($sk->getBaseSkillId());
69  if ($gap_mode == "max_per_type") {
70  $max = $bs->getMaxLevelPerType($sk->getTrefId(), $gap_mode_type, $user_id);
71  } elseif ($gap_mode == "max_per_object") {
72  if ($this->obj_definition->isContainer(\ilObject::_lookupType($gap_mode_obj_id))) {
73  $sub_objects = $this->tree_service->getSubTree(
74  $this->tree_service->getNodeData((int) current(\ilObject::_getAllReferences($gap_mode_obj_id))),
75  false,
77  );
78  $max = 0;
79  foreach ($sub_objects as $ref_id) {
80  $obj_id = \ilContainerReference::_lookupObjectId($ref_id);
81  $max_tmp = $bs->getMaxLevelPerObject($sk->getTrefId(), $obj_id, $user_id);
82  if ($max_tmp > $max) {
83  $max = $max_tmp;
84  }
85  }
86  } else {
87  $max = $bs->getMaxLevelPerObject($sk->getTrefId(), $gap_mode_obj_id, $user_id);
88  }
89  } else {
90  $max = $bs->getMaxLevel($sk->getTrefId(), $user_id);
91  }
92  $actual_levels[$sk->getBaseSkillId()][$sk->getTrefId()] = $max;
93  }
94 
95  return $actual_levels;
96  }
97 
98  public function getActualLastLevels(
99  int $user_id,
100  array $skills,
101  string $gap_mode = "",
102  string $gap_mode_type = "",
103  int $gap_mode_obj_id = 0
104  ): array {
105  // todo for coming feature
106  return [];
107  }
108 
114  int $user_id,
115  array $skills,
116  string $gap_mode = "",
117  string $gap_mode_type = "",
118  int $gap_mode_obj_id = 0
119  ): array {
120  // get actual next level fulfilments for gap analysis
121  $fuls = [];
122  foreach ($skills as $sk) {
123  $bs = new \ilBasicSkill($sk->getBaseSkillId());
124  if ($gap_mode == "max_per_type") {
125  $perc = $bs->getNextLevelFulfilmentPerType($sk->getTrefId(), $gap_mode_type, $user_id);
126  } elseif ($gap_mode == "max_per_object") {
127  $perc = $bs->getNextLevelFulfilmentPerObject($sk->getTrefId(), $gap_mode_obj_id, $user_id);
128  } else {
129  $perc = $bs->getNextLevelFulfilment($sk->getTrefId(), $user_id);
130  }
131  $fuls[$sk->getBaseSkillId()][$sk->getTrefId()] = $perc;
132  }
133 
134  return $fuls;
135  }
136 
140  public function getProfileProgress(int $user_id, int $profile_id): int
141  {
142  $profile_levels = $this->profile_manager->getSkillLevels($profile_id);
143  $actual_levels = $this->getActualMaxLevels($user_id, $profile_levels);
144 
145  $profile_count = 0;
146  $achieved_count = 0;
147  foreach ($profile_levels as $level) {
148  if ($actual_levels[$level->getBaseSkillId()][$level->getTrefId()] >= $level->getLevelId()) {
149  $achieved_count++;
150  }
151  $profile_count++;
152  }
153  if ($profile_count == 0) {
154  return 0;
155  }
156  $progress = $achieved_count / $profile_count * 100;
157 
158  return (int) $progress;
159  }
160 
164  public function isProfileFulfilled(int $user_id, int $profile_id): bool
165  {
166  if ($this->getProfileProgress($user_id, $profile_id) == 100) {
167  return true;
168  }
169  return false;
170  }
171 
176  public function getAllProfileCompletionsForUser(int $user_id): array
177  {
178  $user_profiles = $this->profile_manager->getProfilesOfUser($user_id);
179  $profile_comps = [];
180  foreach ($user_profiles as $p) {
181  if ($this->isProfileFulfilled($user_id, $p->getId())) {
182  $profile_comps[$p->getId()] = true;
183  } else {
184  $profile_comps[$p->getId()] = false;
185  }
186  }
187 
188  return $profile_comps;
189  }
190 
195  public function getEntries(int $user_id, int $profile_id): array
196  {
197  return $this->profile_completion_repo->getEntries($user_id, $profile_id);
198  }
199 
204  public function getFulfilledEntriesForUser(int $user_id): array
205  {
206  return $this->profile_completion_repo->getFulfilledEntriesForUser($user_id);
207  }
208 
213  public function getAllEntriesForUser(int $user_id): array
214  {
215  return $this->profile_completion_repo->getAllEntriesForUser($user_id);
216  }
217 
222  public function getAllEntriesForProfile(int $profile_id): array
223  {
224  return $this->profile_completion_repo->getAllEntriesForProfile($profile_id);
225  }
226 
230  public function writeCompletionEntryForAllProfilesOfUser(int $user_id): void
231  {
232  $completions = $this->getAllProfileCompletionsForUser($user_id);
233  foreach ($completions as $profile_id => $fulfilled) {
234  if ($fulfilled) {
235  $this->profile_completion_repo->addFulfilmentEntry($user_id, $profile_id);
236  } else {
237  $this->profile_completion_repo->addNonFulfilmentEntry($user_id, $profile_id);
238  }
239  }
240  }
241 
245  public function writeCompletionEntryForSingleProfileOfUser(int $user_id, int $profile_id): void
246  {
247  if ($this->isProfileFulfilled($user_id, $profile_id)) {
248  $this->profile_completion_repo->addFulfilmentEntry($user_id, $profile_id);
249  } else {
250  $this->profile_completion_repo->addNonFulfilmentEntry($user_id, $profile_id);
251  }
252  }
253 
257  public function writeCompletionEntryForAllAssignedUsersOfProfile(int $profile_id): void
258  {
259  $users = $this->profile_manager->getAssignedUserIdsIncludingRoleAssignments($profile_id);
260  foreach ($users as $user_id) {
261  $this->writeCompletionEntryForSingleProfileOfUser($user_id, $profile_id);
262  }
263  }
264 
268  public function writeCompletionEntryForRole(int $role_id, int $profile_id): void
269  {
270  $r_users = $this->profile_manager->getAssignedUsersForRole($role_id);
271  foreach ($r_users as $user_id) {
272  $this->writeCompletionEntryForSingleProfileOfUser($user_id, $profile_id);
273  }
274  }
275 
279  public function deleteEntriesForProfile(int $profile_id): void
280  {
281  $this->profile_completion_repo->deleteEntriesForProfile($profile_id);
282  }
283 
287  public function deleteEntriesForUser(int $user_id): void
288  {
289  $this->profile_completion_repo->deleteEntriesForUser($user_id);
290  }
291 }
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.
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
deleteEntriesForUser(int $user_id)
Delete all profile completion entries for a user.
getAllEntriesForUser(int $user_id)
Get all profile completion entries for a user.
getAllEntriesForProfile(int $profile_id)
Get all completion entries for a single profile.
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%)
getActualMaxLevels(int $user_id, array $skills, string $gap_mode="", string $gap_mode_type="", int $gap_mode_obj_id=0)
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)