ILIAS  release_8 Revision v8.24
class.SkillProfileCompletionManager.php
Go to the documentation of this file.
1<?php
2
20namespace ILIAS\Skill\Profile;
21
30{
33 protected \ilTree $tree_service;
34 protected \ilObjectDefinition $obj_definition;
35
36 public function __construct(
39 ) {
40 global $DIC;
41
42 $this->profile_manager = $profile_manager;
43 $this->profile_completion_repo = ($profile_completion_repo)
44 ?: $DIC->skills()->internal()->repo()->getProfileCompletionRepo();
45 $this->tree_service = $DIC->repositoryTree();
46 $this->obj_definition = $DIC["objDefinition"];
47 }
48
53 public function getActualMaxLevels(
54 int $user_id,
55 array $skills,
56 string $gap_mode = "",
57 string $gap_mode_type = "",
58 int $gap_mode_obj_id = 0
59 ): array {
60 // get actual levels for gap analysis
61 $actual_levels = [];
62 foreach ($skills as $sk) {
63 $bs = new \ilBasicSkill($sk["base_skill_id"]);
64 if ($gap_mode == "max_per_type") {
65 $max = $bs->getMaxLevelPerType($sk["tref_id"], $gap_mode_type, $user_id);
66 } elseif ($gap_mode == "max_per_object") {
67 if ($this->obj_definition->isContainer(\ilObject::_lookupType($gap_mode_obj_id))) {
68 $sub_objects = $this->tree_service->getSubTree(
69 $this->tree_service->getNodeData((int) current(\ilObject::_getAllReferences($gap_mode_obj_id))),
70 false,
72 );
73 $max = 0;
74 foreach ($sub_objects as $ref_id) {
76 $max_tmp = $bs->getMaxLevelPerObject($sk["tref_id"], $obj_id, $user_id);
77 if ($max_tmp > $max) {
78 $max = $max_tmp;
79 }
80 }
81 } else {
82 $max = $bs->getMaxLevelPerObject($sk["tref_id"], $gap_mode_obj_id, $user_id);
83 }
84 } else {
85 $max = $bs->getMaxLevel($sk["tref_id"], $user_id);
86 }
87 $actual_levels[$sk["base_skill_id"]][$sk["tref_id"]] = $max;
88 }
89
90 return $actual_levels;
91 }
92
93 public function getActualLastLevels(
94 int $user_id,
95 array $skills,
96 string $gap_mode = "",
97 string $gap_mode_type = "",
98 int $gap_mode_obj_id = 0
99 ): array {
100 // todo for coming feature
101 return [];
102 }
103
109 int $user_id,
110 array $skills,
111 string $gap_mode = "",
112 string $gap_mode_type = "",
113 int $gap_mode_obj_id = 0
114 ): array {
115 // get actual next level fulfilments for gap analysis
116 $fuls = [];
117 foreach ($skills as $sk) {
118 $bs = new \ilBasicSkill($sk["base_skill_id"]);
119 if ($gap_mode == "max_per_type") {
120 $perc = $bs->getNextLevelFulfilmentPerType($sk["tref_id"], $gap_mode_type, $user_id);
121 } elseif ($gap_mode == "max_per_object") {
122 $perc = $bs->getNextLevelFulfilmentPerObject($sk["tref_id"], $gap_mode_obj_id, $user_id);
123 } else {
124 $perc = $bs->getNextLevelFulfilment($sk["tref_id"], $user_id);
125 }
126 $fuls[$sk["base_skill_id"]][$sk["tref_id"]] = $perc;
127 }
128
129 return $fuls;
130 }
131
135 public function getProfileProgress(int $user_id, int $profile_id): int
136 {
137 $profile = $this->profile_manager->getById($profile_id);
138 $profile_levels = $profile->getSkillLevels();
139 $skills = [];
140 foreach ($profile_levels as $l) {
141 $skills[] = array(
142 "base_skill_id" => $l["base_skill_id"],
143 "tref_id" => $l["tref_id"],
144 "level_id" => $l["level_id"]
145 );
146 }
147 $actual_levels = $this->getActualMaxLevels($user_id, $skills);
148
149 $profile_count = 0;
150 $achieved_count = 0;
151 foreach ($profile_levels as $profile) {
152 if ($actual_levels[$profile["base_skill_id"]][$profile["tref_id"]] >= $profile["level_id"]) {
153 $achieved_count++;
154 }
155 $profile_count++;
156 }
157 if ($profile_count == 0) {
158 return 0;
159 }
160 $progress = $achieved_count / $profile_count * 100;
161
162 return (int) $progress;
163 }
164
168 public function isProfileFulfilled(int $user_id, int $profile_id): bool
169 {
170 if ($this->getProfileProgress($user_id, $profile_id) == 100) {
171 return true;
172 }
173 return false;
174 }
175
180 public function getAllProfileCompletionsForUser(int $user_id): array
181 {
182 $user_profiles = $this->profile_manager->getProfilesOfUser($user_id);
183 $profile_comps = [];
184 foreach ($user_profiles as $p) {
185 if ($this->isProfileFulfilled($user_id, $p["id"])) {
186 $profile_comps[$p["id"]] = true;
187 } else {
188 $profile_comps[$p["id"]] = false;
189 }
190 }
191
192 return $profile_comps;
193 }
194
198 public function getEntries(int $user_id, int $profile_id): array
199 {
200 return $this->profile_completion_repo->getEntries($user_id, $profile_id);
201 }
202
207 public function getFulfilledEntriesForUser(int $user_id): array
208 {
209 return $this->profile_completion_repo->getFulfilledEntriesForUser($user_id);
210 }
211
215 public function getAllEntriesForUser(int $user_id): array
216 {
217 return $this->profile_completion_repo->getAllEntriesForUser($user_id);
218 }
219
223 public function getAllEntriesForProfile(int $profile_id): array
224 {
225 return $this->profile_completion_repo->getAllEntriesForProfile($profile_id);
226 }
227
231 public function writeCompletionEntryForAllProfiles(int $user_id): void
232 {
233 $completions = $this->getAllProfileCompletionsForUser($user_id);
234 foreach ($completions as $profile_id => $fulfilled) {
235 if ($fulfilled) {
236 $this->profile_completion_repo->addFulfilmentEntry($user_id, $profile_id);
237 } else {
238 $this->profile_completion_repo->addNonFulfilmentEntry($user_id, $profile_id);
239 }
240 }
241 }
242
246 public function writeCompletionEntryForSingleProfile(int $user_id, int $profile_id): void
247 {
248 if ($this->isProfileFulfilled($user_id, $profile_id)) {
249 $this->profile_completion_repo->addFulfilmentEntry($user_id, $profile_id);
250 } else {
251 $this->profile_completion_repo->addNonFulfilmentEntry($user_id, $profile_id);
252 }
253 }
254
258 public function deleteEntriesForProfile(int $profile_id): void
259 {
260 $this->profile_completion_repo->deleteEntriesForProfile($profile_id);
261 }
262
266 public function deleteEntriesForUser(int $user_id): void
267 {
268 $this->profile_completion_repo->deleteEntriesForUser($user_id);
269 }
270}
getEntries(int $user_id, int $profile_id)
Get profile completion entries for given user-profile-combination.
getActualLastLevels(int $user_id, array $skills, string $gap_mode="", string $gap_mode_type="", int $gap_mode_obj_id=0)
getAllProfileCompletionsForUser(int $user_id)
Get all profiles of user which are fulfilled or non-fulfilled.
__construct(SkillProfileManager $profile_manager, ?SkillProfileCompletionDBRepository $profile_completion_repo=null)
writeCompletionEntryForAllProfiles(int $user_id)
Write profile completion entries (fulfilled or non-fulfilled) of user for all profiles.
getAllEntriesForProfile(int $profile_id)
Get all completion entries for a single profile.
isProfileFulfilled(int $user_id, int $profile_id)
Check if a profile is fulfilled (progress = 100%)
deleteEntriesForProfile(int $profile_id)
Delete all profile completion entries for a 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)
deleteEntriesForUser(int $user_id)
Delete all profile completion entries for a user.
getActualMaxLevels(int $user_id, array $skills, string $gap_mode="", string $gap_mode_type="", int $gap_mode_obj_id=0)
getFulfilledEntriesForUser(int $user_id)
Get all profile completion entries for a user.
getAllEntriesForUser(int $user_id)
Get all profile completion entries for a user.
writeCompletionEntryForSingleProfile(int $user_id, int $profile_id)
Write profile completion entry (fulfilled or non-fulfilled) of user for given profile.
static getSupportedObjectTypes()
static _lookupObjectId(int $ref_id)
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
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...