ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilSkillUsage.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2020 ILIAS open source, Extended GPL, see docs/LICENSE */
4
23{
24 const TYPE_GENERAL = "gen";
25 const USER_ASSIGNED = "user";
26 const PERSONAL_SKILL = "pers";
27 const USER_MATERIAL = "mat";
28 const SELF_EVAL = "seval";
29 const PROFILE = "prof";
30 const RESOURCE = "res";
31
32 // these classes implement the ilSkillUsageInfo interface
33 // currently this array is ok, we do not need any subscription model here
34 /*protected $classes = array("ilBasicSkill", "ilPersonalSkill",
35 "ilSkillSelfEvaluation", "ilSkillProfile", "ilSkillResources", "ilSkillUsage");*/
36 protected $classes = array("ilBasicSkill", "ilPersonalSkill", "ilSkillProfile", "ilSkillResources", "ilSkillUsage");
37
46 public static function setUsage($a_obj_id, $a_skill_id, $a_tref_id, $a_use = true)
47 {
48 global $DIC;
49
50 $ilDB = $DIC->database();
51
52 if ($a_use) {
53 $ilDB->replace(
54 "skl_usage",
55 array(
56 "obj_id" => array("integer", $a_obj_id),
57 "skill_id" => array("integer", $a_skill_id),
58 "tref_id" => array("integer", $a_tref_id)
59 ),
60 array()
61 );
62 } else {
63 $ilDB->manipulate(
64 $q = "DELETE FROM skl_usage WHERE " .
65 " obj_id = " . $ilDB->quote($a_obj_id, "integer") .
66 " AND skill_id = " . $ilDB->quote($a_skill_id, "integer") .
67 " AND tref_id = " . $ilDB->quote($a_tref_id, "integer")
68 );
69 //echo $q; exit;
70 }
71 }
72
73 public static function removeUsagesFromObject($a_obj_id)
74 {
75 global $DIC;
76
77 $ilDB = $DIC->database();
78
79 $ilDB->manipulate(
80 $q = "DELETE FROM skl_usage WHERE " .
81 " obj_id = " . $ilDB->quote($a_obj_id, "integer")
82 );
83 }
84
92 public static function getUsages($a_skill_id, $a_tref_id)
93 {
94 global $DIC;
95
96 $ilDB = $DIC->database();
97
98 $set = $ilDB->query(
99 "SELECT obj_id FROM skl_usage " .
100 " WHERE skill_id = " . $ilDB->quote($a_skill_id, "integer") .
101 " AND tref_id = " . $ilDB->quote($a_tref_id, "integer")
102 );
103 $obj_ids = array();
104 while ($rec = $ilDB->fetchAssoc($set)) {
105 $obj_ids[] = $rec["obj_id"];
106 }
107
108 return $obj_ids;
109 }
110
117 public static function getUsageInfo($a_cskill_ids, &$a_usages)
118 {
119 global $DIC;
120
121 $ilDB = $DIC->database();
122
124 $a_cskill_ids,
125 $a_usages,
127 "skl_usage",
128 "obj_id"
129 );
130 }
131
138 public static function getUsageInfoGeneric(
139 $a_cskill_ids,
140 &$a_usages,
141 $a_usage_type,
142 $a_table,
143 $a_key_field,
144 $a_skill_field = "skill_id",
145 $a_tref_field = "tref_id"
146 ) {
147 global $DIC;
148
149 $ilDB = $DIC->database();
150
151 if (count($a_cskill_ids) == 0) {
152 return;
153 }
154
155 $w = "WHERE";
156 $q = "SELECT " . $a_key_field . ", " . $a_skill_field . ", " . $a_tref_field . " FROM " . $a_table . " ";
157 foreach ($a_cskill_ids as $sk) {
158 $q .= $w . " (" . $a_skill_field . " = " . $ilDB->quote($sk["skill_id"], "integer") .
159 " AND " . $a_tref_field . " = " . $ilDB->quote($sk["tref_id"], "integer") . ") ";
160 $w = "OR";
161 }
162 $q .= " GROUP BY " . $a_key_field . ", " . $a_skill_field . ", " . $a_tref_field;
163
164 $set = $ilDB->query($q);
165 while ($rec = $ilDB->fetchAssoc($set)) {
166 $a_usages[$rec[$a_skill_field] . ":" . $rec[$a_tref_field]][$a_usage_type][] =
167 array("key" => $rec[$a_key_field]);
168 }
169 }
170
171
178 public function getAllUsagesInfo($a_cskill_ids)
179 {
181
182 $usages = array();
183 foreach ($classes as $class) {
184 $class::getUsageInfo($a_cskill_ids, $usages);
185 }
186 return $usages;
187 }
188
196 public function getAllUsagesInfoOfSubtree($a_skill_id, $a_tref_id = 0)
197 {
198 // get nodes
199 $vtree = new ilVirtualSkillTree();
200 $nodes = $vtree->getSubTreeForCSkillId($a_skill_id . ":" . $a_tref_id);
201
202 return $this->getAllUsagesInfo($nodes);
203 }
204
211 public function getAllUsagesInfoOfSubtrees($a_cskill_ids)
212 {
213 // get nodes
214 $vtree = new ilVirtualSkillTree();
215 $allnodes = array();
216 foreach ($a_cskill_ids as $s) {
217 $nodes = $vtree->getSubTreeForCSkillId($s["skill_id"] . ":" . $s["tref_id"]);
218 foreach ($nodes as $n) {
219 $allnodes[] = $n;
220 }
221 }
222
223 return $this->getAllUsagesInfo($allnodes);
224 }
225
232 public function getAllUsagesOfTemplate($a_tempate_id)
233 {
234 $skill_logger = ilLoggerFactory::getLogger('skll');
235 $skill_logger->debug("ilSkillUsage: getAllUsagesOfTemplate(" . $a_tempate_id . ")");
236
237 // get all trefs for template id
239
240 // get all usages of subtrees of template_id:tref
241 $cskill_ids = array();
242 foreach ($trefs as $tref) {
243 $cskill_ids[] = array("skill_id" => $a_tempate_id, "tref_id" => $tref);
244 $skill_logger->debug("ilSkillUsage: ... skill_id: " . $a_tempate_id . ", tref_id: " . $tref . ".");
245 }
246
247 $skill_logger->debug("ilSkillUsage: ... count cskill_ids: " . count($cskill_ids) . ".");
248
249 return $this->getAllUsagesInfoOfSubtrees($cskill_ids);
250 }
251
258 public static function getTypeInfoString($a_type)
259 {
260 global $DIC;
261
262 $lng = $DIC->language();
263
264 return $lng->txt("skmg_usage_type_info_" . $a_type);
265 }
266
273 public static function getObjTypeString($a_type)
274 {
275 global $DIC;
276
277 $lng = $DIC->language();
278
279 switch ($a_type) {
281 case self::RESOURCE:
282 return $lng->txt("skmg_usage_obj_objects");
283 break;
284
288 case self::SELF_EVAL:
289 return $lng->txt("skmg_usage_obj_users");
290 break;
291
292 case self::PROFILE:
293 return $lng->txt("skmg_usage_obj_profiles");
294 break;
295 }
296
297 return $lng->txt("skmg_usage_type_info_" . $a_type);
298 }
299
305 public function getAssignedObjectsForSkill(int $a_skill_id, int $a_tref_id) : array
306 {
307 //$objects = $this->getAllUsagesInfoOfSubtree($a_skill_id, $a_tref_id);
308 $objects = self::getUsages($a_skill_id, $a_tref_id);
309
310 return $objects;
311 }
312
317 public function getAssignedObjectsForSkillTemplate(int $a_template_id) : array
318 {
319 $usages = $this->getAllUsagesOfTemplate($a_template_id);
320 $obj_usages = array_column($usages, "gen");
321 foreach ($obj_usages as $obj) {
322 $objects["objects"] = array_column($obj, "key");
323 }
324
325 return $objects["objects"];
326 }
327
332 public function getAssignedObjectsForSkillProfile(int $a_profile_id) : array
333 {
334 $profile = new ilSkillProfile($a_profile_id);
335 $skills = $profile->getSkillLevels();
336 $objects = array();
337
338 // usages for skills within skill profile
339 foreach ($skills as $skill) {
340 $obj_usages = self::getUsages($skill["base_skill_id"], $skill["tref_id"]);
341 foreach ($obj_usages as $id) {
342 if (!in_array($id, $objects)) {
343 $objects[] = $id;
344 }
345 }
346 }
347
348 // courses and groups which are using skill profile
349 $roles = $profile->getAssignedRoles();
350 foreach ($roles as $role) {
351 if (($role["object_type"] == "crs" || $role["object_type"] == "grp")
352 && !in_array($role["object_id"], $objects)) {
353 $objects[] = $role["object_id"];
354 }
355 }
356
357 return $objects;
358 }
359}
$n
Definition: RandomTest.php:85
An exception for terminatinating execution or to throw for unit testing.
static getLogger($a_component_id)
Get component logger.
static _lookupTrefIdsForTemplateId($a_tid)
Get all tref ids for a template id.
getAssignedObjectsForSkill(int $a_skill_id, int $a_tref_id)
getAssignedObjectsForSkillTemplate(int $a_template_id)
static setUsage($a_obj_id, $a_skill_id, $a_tref_id, $a_use=true)
Set usage.
getAllUsagesInfo($a_cskill_ids)
Get all usages info.
static getUsageInfo($a_cskill_ids, &$a_usages)
Get usage info.
static getUsages($a_skill_id, $a_tref_id)
Get usages.
static getUsageInfoGeneric( $a_cskill_ids, &$a_usages, $a_usage_type, $a_table, $a_key_field, $a_skill_field="skill_id", $a_tref_field="tref_id")
Get standard usage query.
getAllUsagesOfTemplate($a_tempate_id)
Get all usages of template.
getAllUsagesInfoOfSubtrees($a_cskill_ids)
Get all usages info of subtree.
static removeUsagesFromObject($a_obj_id)
static getTypeInfoString($a_type)
Get type info string.
static getObjTypeString($a_type)
Get type info string.
getAssignedObjectsForSkillProfile(int $a_profile_id)
getAllUsagesInfoOfSubtree($a_skill_id, $a_tref_id=0)
Get all usages info of subtree.
global $DIC
Definition: goto.php:24
Get info on usages of skills.
$lng
global $ilDB