ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.SkillProfileManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Skill\Profile;
22
24
29{
34 protected \ilRbacReview $rbac_review;
35 protected \ilLanguage $lng;
36
37 public function __construct(
42 ) {
43 global $DIC;
44
45 $this->profile_repo = ($profile_repo) ?: $DIC->skills()->internal()->repo()->getProfileRepo();
46 $this->profile_levels_repo = ($profile_levels_repo) ?: $DIC->skills()->internal()->repo()->getProfileLevelsRepo();
47 $this->profile_user_repo = ($profile_user_repo) ?: $DIC->skills()->internal()->repo()->getProfileUserRepo();
48 $this->profile_role_repo = ($profile_role_repo) ?: $DIC->skills()->internal()->repo()->getProfileRoleRepo();
49 $this->rbac_review = $DIC->rbac()->review();
50 $this->lng = $DIC->language();
51 }
52
56 public function getProfile(int $profile_id): SkillProfile
57 {
58 return $this->profile_repo->get($profile_id);
59 }
60
61 public function createProfile(SkillProfile $profile): SkillProfile
62 {
63 // profile
64 $new_profile = $this->profile_repo->createProfile($profile);
65
66 return $new_profile;
67 }
68
69 public function updateProfile(SkillProfile $profile): SkillProfile
70 {
71 // profile
72 $updated_profile = $this->profile_repo->updateProfile($profile);
73
74 return $updated_profile;
75 }
76
77 public function delete(int $profile_id): void
78 {
79 $this->deleteProfile($profile_id);
80 $this->deleteProfileLevels($profile_id);
81 $this->deleteProfileUsers($profile_id);
82 $this->deleteProfileRoles($profile_id);
83 }
84
85 protected function deleteProfile(int $profile_id): void
86 {
87 $this->profile_repo->deleteProfile($profile_id);
88 }
89
90 protected function deleteProfileLevels(int $profile_id): void
91 {
92 $this->profile_levels_repo->deleteAllForProfile($profile_id);
93 }
94
95 public function deleteProfileLevelsForSkill(int $skill_node_id, bool $is_reference = false): void
96 {
97 $this->profile_levels_repo->deleteAllForSkill($skill_node_id, $is_reference);
98 }
99
100 protected function deleteProfileUsers(int $profile_id): void
101 {
102 $this->profile_user_repo->deleteProfileUsers($profile_id);
103 }
104
105 protected function deleteProfileRoles(int $profile_id): void
106 {
107 $this->profile_role_repo->deleteProfileRoles($profile_id);
108 }
109
110 public function deleteProfilesFromObject(int $ref_id): void
111 {
112 $this->profile_repo->deleteProfilesFromObject($ref_id);
113 }
114
118 public function getSkillLevels(int $profile_id): array
119 {
120 $levels = $this->profile_levels_repo->getAll($profile_id);
121 usort($levels, static function (SkillProfileLevel $level_a, SkillProfileLevel $level_b): int {
122 return $level_a->getOrderNr() <=> $level_b->getOrderNr();
123 });
124
125 return $levels;
126 }
127
128 public function getSkillLevel(int $profile_id, int $base_skill_id, int $tref_id): SkillProfileLevel
129 {
130 $level = $this->profile_levels_repo->get($profile_id, $base_skill_id, $tref_id);
131 return $level;
132 }
133
134 public function addSkillLevel(SkillProfileLevel $skill_level_obj): void
135 {
136 $this->profile_levels_repo->createOrUpdate($skill_level_obj);
137 }
138
139 public function updateSkillLevel(SkillProfileLevel $skill_level_obj): void
140 {
141 $this->profile_levels_repo->createOrUpdate($skill_level_obj);
142 }
143
144 public function removeSkillLevel(SkillProfileLevel $skill_level_obj): void
145 {
146 $this->profile_levels_repo->delete($skill_level_obj);
147 }
148
149 public function updateSkillOrder(int $profile_id, array $order): void
150 {
151 asort($order);
152
153 $this->profile_levels_repo->updateSkillOrder($profile_id, $order);
154 }
155
156 public function fixSkillOrderNumbering(int $profile_id): void
157 {
158 $this->profile_levels_repo->fixSkillOrderNumbering($profile_id);
159 }
160
161 public function getMaxLevelOrderNr(int $profile_id): int
162 {
163 $max = $this->profile_levels_repo->getMaxOrderNr($profile_id);
164 return $max;
165 }
166
170 public function getProfilesForAllSkillTrees(): array
171 {
172 $profiles = $this->profile_repo->getProfilesForAllSkillTrees();
173 return $profiles;
174 }
175
179 public function getProfilesForSkillTree(int $skill_tree_id): array
180 {
181 $profiles = $this->profile_repo->getProfilesForSkillTree($skill_tree_id);
182 return $profiles;
183 }
184
188 public function getAllGlobalProfiles(): array
189 {
190 $profiles = $this->profile_repo->getAllGlobalProfiles();
191 return $profiles;
192 }
193
197 public function getLocalProfilesForObject(int $ref_id): array
198 {
199 $profiles = $this->profile_repo->getLocalProfilesForObject($ref_id);
200 return $profiles;
201 }
202
203 public function lookupTitle(int $profile_id): string
204 {
205 $title = $this->profile_repo->lookup($profile_id, "title");
206 return $title;
207 }
208
209 public function lookupRefId(int $profile_id): int
210 {
211 $ref_id = $this->profile_repo->lookup($profile_id, "ref_id");
212 return (int) $ref_id;
213 }
214
218 public function updateRefIdAfterImport(int $profile_id, int $new_ref_id): void
219 {
220 $this->profile_repo->updateRefIdAfterImport($profile_id, $new_ref_id);
221 }
222
223 public function getTreeId(int $profile_id): int
224 {
225 $tree_id = $this->profile_repo->getTreeId($profile_id);
226 return $tree_id;
227 }
228
232
237 public function getAssignments(int $profile_id): array
238 {
239 $assignments = [];
240
241 $users = $this->getUserAssignments($profile_id);
242 $roles = $this->getRoleAssignments($profile_id);
243 $assignments = array_merge($users, $roles);
244
245 return $assignments;
246 }
247
251 public function getUserAssignments(int $profile_id): array
252 {
254
255 $users = $this->profile_user_repo->get($profile_id);
257 $users_as_obj = [];
258 foreach ($users as $u) {
259 $u["user_id"] = (int) $u["user_id"];
260 $u["profile_id"] = (int) $u["profile_id"];
261 $name = \ilUserUtil::getNamePresentation($u["user_id"]);
262
263 $user_restructured = [
264 "name" => $name,
265 "id" => $u["user_id"]
266 ];
267
268 $users_as_obj[] = $this->profile_user_repo->getFromRecord($user_restructured);
269 }
270
271 return $users_as_obj;
272 }
273
277 public function getAssignedUsersForRole(int $role_id): array
278 {
279 return $this->rbac_review->assignedUsers($role_id);
280 }
281
285 public function getAssignedUserIdsIncludingRoleAssignments(int $profile_id): array
286 {
287 $all = [];
288 $users = $this->getUserAssignments($profile_id);
289 foreach ($users as $user) {
290 $all[] = $user->getId();
291 }
292
293 $roles = $this->getRoleAssignments($profile_id);
294 foreach ($roles as $role) {
295 $role_users = $this->rbac_review->assignedUsers($role->getId());
296 foreach ($role_users as $user_id) {
297 if (!in_array($user_id, $all)) {
298 $all[] = $user_id;
299 }
300 }
301 }
302
303 return $all;
304 }
305
306 public function addUserToProfile(int $profile_id, int $user_id): void
307 {
308 $this->profile_user_repo->addUserToProfile($profile_id, $user_id);
309 }
310
311 public function removeUserFromProfile(int $profile_id, int $user_id): void
312 {
313 $this->profile_user_repo->removeUserFromProfile($profile_id, $user_id);
314 }
315
316 public function removeUserFromAllProfiles(int $user_id): void
317 {
318 $this->profile_user_repo->removeUserFromAllProfiles($user_id);
319 }
320
324 public function getProfilesOfUser(int $user_id): array
325 {
326 $all_profiles = [];
327
328 // competence profiles coming from user assignments
329 $user_profiles = $this->profile_user_repo->getProfilesOfUser($user_id);
330
331 // competence profiles coming from role assignments
332 $role_profiles = [];
333 $user_roles = $this->rbac_review->assignedRoles($user_id);
334 foreach ($user_roles as $role) {
335 $profiles = $this->getGlobalProfilesOfRole($role);
336 foreach ($profiles as $profile) {
337 $role_profiles[] = $profile;
338 }
339 }
340
341 // merge competence profiles and remove multiple occurrences
342
344 $all_profiles = array_merge($user_profiles, $role_profiles);
346 $temp_profiles = [];
347 foreach ($all_profiles as $v) {
348 if (!isset($temp_profiles[$v->getId()])) {
349 $temp_profiles[$v->getId()] = $v;
350 }
351 }
352 $all_profiles = array_values($temp_profiles);
353 return $all_profiles;
354 }
355
356 public function countUsers(int $profile_id): int
357 {
358 $count = $this->profile_user_repo->countUsers($profile_id);
359 return $count;
360 }
361
365 public function getRoleAssignments(int $profile_id, bool $with_objects_in_trash = false): array
366 {
368 $review = $this->rbac_review;
369
370 $roles = $this->profile_role_repo->get($profile_id);
372 $roles_as_obj_without_trash = [];
374 $roles_as_obj_with_trash = [];
375 foreach ($roles as $r) {
376 $r["role_id"] = (int) $r["role_id"];
377 $r["profile_id"] = (int) $r["profile_id"];
379 // get object of role
380 $obj_id = \ilObject::_lookupObjectId($review->getObjectReferenceOfRole($r["role_id"]));
381 $obj_title = \ilObject::_lookupTitle($obj_id);
382 $obj_type = \ilObject::_lookupType($obj_id);
383
384 $role_restructured = [
385 "name" => $name,
386 "id" => $r["role_id"],
387 "object_title" => $obj_title,
388 "object_type" => $obj_type,
389 "object_id" => $obj_id
390 ];
391
392 if (!$with_objects_in_trash && \ilObject::_hasUntrashedReference($obj_id)) {
393 $roles_as_obj_without_trash[] = $this->profile_role_repo->getRoleAssignmentFromRecord($role_restructured);
394 }
395 $roles_as_obj_with_trash[] = $this->profile_role_repo->getRoleAssignmentFromRecord($role_restructured);
396 }
397
398 if ($with_objects_in_trash) {
399 return $roles_as_obj_with_trash;
400 }
401 return $roles_as_obj_without_trash;
402 }
403
404 public function addRoleToProfile(int $profile_id, int $role_id): void
405 {
406 $this->profile_role_repo->addRoleToProfile($profile_id, $role_id);
407 }
408
409 public function removeRoleFromProfile(int $profile_id, int $role_id): void
410 {
411 $this->profile_role_repo->removeRoleFromProfile($profile_id, $role_id);
412 }
413
414 public function removeRoleFromAllProfiles(int $role_id): void
415 {
416 $this->profile_role_repo->removeRoleFromAllProfiles($role_id);
417 }
418
423 public function getAllProfilesOfRole(int $role_id): array
424 {
425 $profiles = $this->profile_role_repo->getAllProfilesOfRole($role_id);
426 return $profiles;
427 }
428
432 public function getGlobalProfilesOfRole(int $role_id): array
433 {
434 $profiles = $this->profile_role_repo->getGlobalProfilesOfRole($role_id);
435 return $profiles;
436 }
437
441 public function getLocalProfilesOfRole(int $role_id): array
442 {
443 $profiles = $this->profile_role_repo->getLocalProfilesOfRole($role_id);
444 return $profiles;
445 }
446
447 public function countRoles(int $profile_id): int
448 {
449 $count = $this->profile_role_repo->countRoles($profile_id);
450 return $count;
451 }
452
456 public static function getUsageInfo(array $a_cskill_ids): array
457 {
458 global $DIC;
459
460 $usage_manager = $DIC->skills()->internal()->manager()->getUsageManager();
461
462 return $usage_manager->getUsageInfoGeneric(
463 $a_cskill_ids,
465 "skl_profile_level",
466 "profile_id",
467 "base_skill_id"
468 );
469 }
470}
getSkillLevel(int $profile_id, int $base_skill_id, int $tref_id)
static getUsageInfo(array $a_cskill_ids)
Get title of an assigned item.array<string, array<string, array{key: string}[]>>
removeRoleFromProfile(int $profile_id, int $role_id)
SkillProfileLevelsDBRepository $profile_levels_repo
addSkillLevel(SkillProfileLevel $skill_level_obj)
getAssignments(int $profile_id)
Get all assignments (users and roles)
updateSkillLevel(SkillProfileLevel $skill_level_obj)
deleteProfileLevelsForSkill(int $skill_node_id, bool $is_reference=false)
getAllProfilesOfRole(int $role_id)
Get global and local profiles of a role.
updateRefIdAfterImport(int $profile_id, int $new_ref_id)
Update the old ref id with the new ref id after import.
removeSkillLevel(SkillProfileLevel $skill_level_obj)
removeUserFromProfile(int $profile_id, int $user_id)
__construct(?SkillProfileDBRepository $profile_repo=null, ?SkillProfileLevelsDBRepository $profile_levels_repo=null, ?SkillProfileUserDBRepository $profile_user_repo=null, ?SkillProfileRoleDBRepository $profile_role_repo=null)
static _getTranslation(string $a_role_title)
static _lookupObjectId(int $ref_id)
static _lookupType(int $id, bool $reference=false)
static _hasUntrashedReference(int $obj_id)
checks whether an object has at least one reference that is not in trash
static _lookupTitle(int $obj_id)
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link='', bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path=null)
Default behaviour is:
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:26