ILIAS  release_8 Revision v8.24
class.SkillProfileManager.php
Go to the documentation of this file.
1<?php
2
20namespace ILIAS\Skill\Profile;
21
26{
31 protected \ilRbacReview $rbac_review;
32
33 public function __construct(
34 ?\ILIAS\Skill\Profile\SkillProfileDBRepository $profile_repo = null,
38 ) {
39 global $DIC;
40
41 $this->profile_repo = ($profile_repo) ?: $DIC->skills()->internal()->repo()->getProfileRepo();
42 $this->profile_levels_repo = ($profile_levels_repo) ?: $DIC->skills()->internal()->repo()->getProfileLevelsRepo();
43 $this->profile_user_repo = ($profile_user_repo) ?: $DIC->skills()->internal()->repo()->getProfileUserRepo();
44 $this->profile_role_repo = ($profile_role_repo) ?: $DIC->skills()->internal()->repo()->getProfileRoleRepo();
45 $this->rbac_review = $DIC->rbac()->review();
46 }
47
51 public function getById(int $profile_id): SkillProfile
52 {
53 return $this->profile_repo->getById($profile_id);
54 }
55
56 public function createProfile(SkillProfile $profile): SkillProfile
57 {
58 // profile
59 $new_profile = $this->profile_repo->createProfile($profile);
60
61 // profile levels
62 $this->profile_levels_repo->createProfileLevels($new_profile->getId(), $new_profile->getSkillLevels());
63
64 return $new_profile;
65 }
66
67 public function updateProfile(SkillProfile $profile): SkillProfile
68 {
69 // profile
70 $updated_profile = $this->profile_repo->updateProfile($profile);
71
72 // profile levels
73 $this->profile_levels_repo->updateProfileLevels($profile->getId(), $profile->getSkillLevels());
74
75 return $updated_profile;
76 }
77
78 public function delete(int $profile_id): void
79 {
80 $this->deleteProfile($profile_id);
81 $this->deleteProfileLevels($profile_id);
82 $this->deleteProfileUsers($profile_id);
83 $this->deleteProfileRoles($profile_id);
84 }
85
86 protected function deleteProfile(int $profile_id): void
87 {
88 $this->profile_repo->deleteProfile($profile_id);
89 }
90
91 protected function deleteProfileLevels(int $profile_id): void
92 {
93 $this->profile_levels_repo->deleteProfileLevels($profile_id);
94 }
95
96 protected function deleteProfileUsers(int $profile_id): void
97 {
98 $this->profile_user_repo->deleteProfileUsers($profile_id);
99 }
100
101 protected function deleteProfileRoles(int $profile_id): void
102 {
103 $this->profile_role_repo->deleteProfileRoles($profile_id);
104 }
105
106 public function deleteProfilesFromObject(int $ref_id): void
107 {
108 $this->profile_repo->deleteProfilesFromObject($ref_id);
109 }
110
111 public function updateSkillOrder(int $profile_id, array $order): void
112 {
113 asort($order);
114
115 $this->profile_levels_repo->updateSkillOrder($profile_id, $order);
116 }
117
118 public function fixSkillOrderNumbering(int $profile_id): void
119 {
120 $this->profile_levels_repo->fixSkillOrderNumbering($profile_id);
121 }
122
123 public function getMaxLevelOrderNr(int $profile_id): int
124 {
125 $max = $this->profile_levels_repo->getMaxLevelOrderNr($profile_id);
126 return $max;
127 }
128
129 public function getProfilesForAllSkillTrees(): array
130 {
131 $profiles = $this->profile_repo->getProfilesForAllSkillTrees();
132 return $profiles;
133 }
134
135 public function getProfilesForSkillTree(int $skill_tree_id): array
136 {
137 $profiles = $this->profile_repo->getProfilesForSkillTree($skill_tree_id);
138 return $profiles;
139 }
140
141 public function getAllGlobalProfiles(): array
142 {
143 $profiles = $this->profile_repo->getAllGlobalProfiles();
144 return $profiles;
145 }
146
147 public function getLocalProfilesForObject(int $ref_id): array
148 {
149 $profiles = $this->profile_repo->getLocalProfilesForObject($ref_id);
150 return $profiles;
151 }
152
153 public function lookupTitle(int $profile_id): string
154 {
155 $title = $this->profile_repo->lookup($profile_id, "title");
156 return $title;
157 }
158
159 public function lookupRefId(int $profile_id): int
160 {
161 $ref_id = $this->profile_repo->lookup($profile_id, "ref_id");
162 return (int) $ref_id;
163 }
164
168 public function updateRefIdAfterImport(int $profile_id, int $new_ref_id): void
169 {
170 $this->profile_repo->updateRefIdAfterImport($profile_id, $new_ref_id);
171 }
172
173 public function getTreeId(int $profile_id): int
174 {
175 $tree_id = $this->profile_repo->getTreeId($profile_id);
176 return $tree_id;
177 }
178
182
186 public function getAssignments(int $profile_id): array
187 {
188 $assignments = [];
189
190 $users = $this->getAssignedUsers($profile_id);
191 $roles = $this->getAssignedRoles($profile_id);
192 $assignments = array_merge($users, $roles);
193
194 return $assignments;
195 }
196
197 public function getAssignedUsers(int $profile_id): array
198 {
199 $users = $this->profile_user_repo->getAssignedUsers($profile_id);
200 return $users;
201 }
202
203 public function getAssignedUsersForRole(int $role_id): array
204 {
205 return $this->rbac_review->assignedUsers($role_id);
206 }
207
208 public function getAssignedUserIdsIncludingRoleAssignments(int $profile_id): array
209 {
210 $all = [];
211 $users = $this->getAssignedUsers($profile_id);
212 foreach ($users as $user) {
213 $all[] = $user["id"];
214 }
215
216 $roles = $this->getAssignedRoles($profile_id);
217 foreach ($roles as $role) {
218 $role_users = $this->rbac_review->assignedUsers($role["id"]);
219 foreach ($role_users as $user_id) {
220 if (!in_array($user_id, $all)) {
221 $all[] = $user_id;
222 }
223 }
224 }
225
226 return $all;
227 }
228
229 public function addUserToProfile(int $profile_id, int $user_id): void
230 {
231 $this->profile_user_repo->addUserToProfile($profile_id, $user_id);
232 }
233
234 public function removeUserFromProfile(int $profile_id, int $user_id): void
235 {
236 $this->profile_user_repo->removeUserFromProfile($profile_id, $user_id);
237 }
238
239 public function removeUserFromAllProfiles(int $user_id): void
240 {
241 $this->profile_user_repo->removeUserFromAllProfiles($user_id);
242 }
243
247 public function getProfilesOfUser(int $user_id): array
248 {
249 $all_profiles = [];
250
251 // competence profiles coming from user assignments
252 $user_profiles = $this->profile_user_repo->getProfilesOfUser($user_id);
253
254 // competence profiles coming from role assignments
255 $role_profiles = [];
256 $user_roles = $this->rbac_review->assignedRoles($user_id);
257 foreach ($user_roles as $role) {
258 $profiles = $this->getGlobalProfilesOfRole($role);
259 foreach ($profiles as $profile) {
260 $role_profiles[] = $profile;
261 }
262 }
263
264 // merge competence profiles and remove multiple occurrences
265 $all_profiles = array_merge($user_profiles, $role_profiles);
266 $temp_profiles = [];
267 foreach ($all_profiles as $v) {
268 if (!isset($temp_profiles[$v["id"]])) {
269 $temp_profiles[$v["id"]] = $v;
270 }
271 }
272 $all_profiles = array_values($temp_profiles);
273 return $all_profiles;
274 }
275
276 public function countUsers(int $profile_id): int
277 {
278 $count = $this->profile_user_repo->countUsers($profile_id);
279 return $count;
280 }
281
282 public function getAssignedRoles(int $profile_id): array
283 {
284 $roles = $this->profile_role_repo->getAssignedRoles($profile_id);
285 return $roles;
286 }
287
288 public function addRoleToProfile(int $profile_id, int $role_id): void
289 {
290 $this->profile_role_repo->addRoleToProfile($profile_id, $role_id);
291 }
292
293 public function removeRoleFromProfile(int $profile_id, int $role_id): void
294 {
295 $this->profile_role_repo->removeRoleFromProfile($profile_id, $role_id);
296 }
297
298 public function removeRoleFromAllProfiles(int $role_id): void
299 {
300 $this->profile_role_repo->removeRoleFromAllProfiles($role_id);
301 }
302
307 public function getAllProfilesOfRole(int $role_id): array
308 {
309 $profiles = $this->profile_role_repo->getAllProfilesOfRole($role_id);
310 return $profiles;
311 }
312
316 public function getGlobalProfilesOfRole(int $role_id): array
317 {
318 $profiles = $this->profile_role_repo->getGlobalProfilesOfRole($role_id);
319 return $profiles;
320 }
321
322 public function getLocalProfilesOfRole(int $role_id, int $ref_id): array
323 {
324 $profiles = $this->profile_role_repo->getLocalProfilesOfRole($role_id, $ref_id);
325 return $profiles;
326 }
327
328 public function countRoles(int $profile_id): int
329 {
330 $count = $this->profile_role_repo->countRoles($profile_id);
331 return $count;
332 }
333}
removeRoleFromProfile(int $profile_id, int $role_id)
SkillProfileLevelsDBRepository $profile_levels_repo
getAssignments(int $profile_id)
Get all assignments (users and roles)
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.
removeUserFromProfile(int $profile_id, int $user_id)
__construct(?\ILIAS\Skill\Profile\SkillProfileDBRepository $profile_repo=null, ?\ILIAS\Skill\Profile\SkillProfileLevelsDBRepository $profile_levels_repo=null, ?\ILIAS\Skill\Profile\SkillProfileUserDBRepository $profile_user_repo=null, ?\ILIAS\Skill\Profile\SkillProfileRoleDBRepository $profile_role_repo=null)
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.