ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilPersonalSkill.php
Go to the documentation of this file.
1 <?php
2 
26 {
30  public static function getSelectedUserSkills(int $a_user_id): array
31  {
32  global $DIC;
33 
34  $ilDB = $DIC->database();
35 
36  $repo = $DIC->skills()->internal()->repo()->getTreeRepo();
37 
38  $set = $ilDB->query(
39  "SELECT * FROM skl_personal_skill " .
40  " WHERE user_id = " . $ilDB->quote($a_user_id, "integer")
41  );
42  $pskills = [];
43  while ($rec = $ilDB->fetchAssoc($set)) {
44  if ($repo->isInAnyTree($rec["skill_node_id"])) {
45  $pskills[(int) $rec["skill_node_id"]] = array(
46  "skill_node_id" => (int) $rec["skill_node_id"],
47  "title" => ilSkillTreeNode::_lookupTitle($rec["skill_node_id"])
48  );
49  }
50  }
51  return $pskills;
52  }
53 
54  public static function addPersonalSkill(int $a_user_id, int $a_skill_node_id): void
55  {
56  global $DIC;
57 
58  $ilDB = $DIC->database();
59 
60  $set = $ilDB->query(
61  "SELECT * FROM skl_personal_skill " .
62  " WHERE user_id = " . $ilDB->quote($a_user_id, "integer") .
63  " AND skill_node_id = " . $ilDB->quote($a_skill_node_id, "integer")
64  );
65  if (!$ilDB->fetchAssoc($set)) {
66  $ilDB->manipulate("INSERT INTO skl_personal_skill " .
67  "(user_id, skill_node_id) VALUES (" .
68  $ilDB->quote($a_user_id, "integer") . "," .
69  $ilDB->quote($a_skill_node_id, "integer") .
70  ")");
71  }
72  }
73 
74  public static function removeSkill(int $a_user_id, int $a_skill_node_id): void
75  {
76  global $DIC;
77 
78  $ilDB = $DIC->database();
79 
80  $ilDB->manipulate(
81  "DELETE FROM skl_personal_skill WHERE " .
82  " user_id = " . $ilDB->quote($a_user_id, "integer") .
83  " AND skill_node_id = " . $ilDB->quote($a_skill_node_id, "integer")
84  );
85  }
86 
87  public static function removeSkills(int $a_user_id): void
88  {
89  global $DIC;
90 
91  $ilDB = $DIC->database();
92 
93  $ilDB->manipulate(
94  "DELETE FROM skl_personal_skill WHERE " .
95  " user_id = " . $ilDB->quote($a_user_id, "integer")
96  );
97  }
98 
99 
100  //
101  // Assigned materials
102  //
103 
114  public static function assignMaterial(
115  int $a_user_id,
116  int $a_top_skill,
117  int $a_tref_id,
118  int $a_basic_skill,
119  int $a_level,
120  int $a_wsp_id
121  ): void {
122  global $DIC;
123 
124  $ilDB = $DIC->database();
125 
126  $set = $ilDB->query(
127  "SELECT * FROM skl_assigned_material " .
128  " WHERE user_id = " . $ilDB->quote($a_user_id, "integer") .
129  " AND top_skill_id = " . $ilDB->quote($a_top_skill, "integer") .
130  " AND tref_id = " . $ilDB->quote($a_tref_id, "integer") .
131  " AND skill_id = " . $ilDB->quote($a_basic_skill, "integer") .
132  " AND level_id = " . $ilDB->quote($a_level, "integer") .
133  " AND wsp_id = " . $ilDB->quote($a_wsp_id, "integer")
134  );
135  if (!$ilDB->fetchAssoc($set)) {
136  $ilDB->manipulate("INSERT INTO skl_assigned_material " .
137  "(user_id, top_skill_id, tref_id, skill_id, level_id, wsp_id) VALUES (" .
138  $ilDB->quote($a_user_id, "integer") . "," .
139  $ilDB->quote($a_top_skill, "integer") . "," .
140  $ilDB->quote($a_tref_id, "integer") . "," .
141  $ilDB->quote($a_basic_skill, "integer") . "," .
142  $ilDB->quote($a_level, "integer") . "," .
143  $ilDB->quote($a_wsp_id, "integer") .
144  ")");
145  }
146  }
147 
152  public static function getAssignedMaterial(int $a_user_id, int $a_tref_id, int $a_level): array
153  {
154  global $DIC;
155 
156  $ilDB = $DIC->database();
157 
158  $set = $ilDB->query(
159  "SELECT * FROM skl_assigned_material " .
160  " WHERE level_id = " . $ilDB->quote($a_level, "integer") .
161  " AND tref_id = " . $ilDB->quote($a_tref_id, "integer") .
162  " AND user_id = " . $ilDB->quote($a_user_id, "integer")
163  );
164  $mat = [];
165  while ($rec = $ilDB->fetchAssoc($set)) {
166  $rec['user_id'] = (int) $rec['user_id'];
167  $rec['top_skill_id'] = (int) $rec['top_skill_id'];
168  $rec['skill_id'] = (int) $rec['skill_id'];
169  $rec['level_id'] = (int) $rec['level_id'];
170  $rec['wsp_id'] = (int) $rec['wsp_id'];
171  $rec['tref_id'] = (int) $rec['tref_id'];
172  $mat[] = $rec;
173  }
174  return $mat;
175  }
176 
180  public static function countAssignedMaterial(int $a_user_id, int $a_tref_id, int $a_level): int
181  {
182  global $DIC;
183 
184  $ilDB = $DIC->database();
185 
186  $set = $ilDB->query(
187  "SELECT count(*) as cnt FROM skl_assigned_material " .
188  " WHERE level_id = " . $ilDB->quote($a_level, "integer") .
189  " AND tref_id = " . $ilDB->quote($a_tref_id, "integer") .
190  " AND user_id = " . $ilDB->quote($a_user_id, "integer")
191  );
192  $rec = $ilDB->fetchAssoc($set);
193  return (int) $rec["cnt"];
194  }
195 
196  public static function removeMaterial(int $a_user_id, int $a_tref_id, int $a_level_id, int $a_wsp_id): void
197  {
198  global $DIC;
199 
200  $ilDB = $DIC->database();
201 
202  $t = "DELETE FROM skl_assigned_material WHERE " .
203  " user_id = " . $ilDB->quote($a_user_id, "integer") .
204  " AND tref_id = " . $ilDB->quote($a_tref_id, "integer") .
205  " AND level_id = " . $ilDB->quote($a_level_id, "integer") .
206  " AND wsp_id = " . $ilDB->quote($a_wsp_id, "integer");
207 
208  $ilDB->manipulate($t);
209  }
210 
211  public static function removeMaterials(int $a_user_id): void
212  {
213  global $DIC;
214 
215  $ilDB = $DIC->database();
216 
217  $t = "DELETE FROM skl_assigned_material WHERE " .
218  " user_id = " . $ilDB->quote($a_user_id, "integer");
219  $ilDB->manipulate($t);
220  }
221 
222  //
223  // Self evaluation
224  //
225 
233  public static function saveSelfEvaluation(
234  int $a_user_id,
235  int $a_top_skill,
236  int $a_tref_id,
237  int $a_basic_skill,
238  int $a_level
239  ): void {
240  if ($a_level > 0) {
242  $a_level,
243  $a_user_id,
244  0,
245  $a_tref_id,
247  false,
248  1
249  );
250  } else {
251  ilBasicSkill::resetUserSkillLevelStatus($a_user_id, $a_basic_skill, $a_tref_id, 0, true);
252  }
253  }
254 
262  public static function getSelfEvaluation(
263  int $a_user_id,
264  int $a_top_skill,
265  int $a_tref_id,
266  int $a_basic_skill
267  ): ?int {
268  $bs = new ilBasicSkill($a_basic_skill);
269  return $bs->getLastLevelPerObject($a_tref_id, 0, $a_user_id, 1);
270  }
271 
279  public static function getSelfEvaluationDate(
280  int $a_user_id,
281  int $a_top_skill,
282  int $a_tref_id,
283  int $a_basic_skill
284  ): ?string {
285  $bs = new ilBasicSkill($a_basic_skill);
286  return $bs->getLastUpdatePerObject($a_tref_id, 0, $a_user_id, 1);
287  }
288 
294  public static function getUsageInfo(array $a_cskill_ids): array
295  {
296  global $DIC;
297 
298  $ilDB = $DIC->database();
299 
300  // material
302  $a_cskill_ids,
304  "skl_assigned_material",
305  "user_id"
306  );
307 
308  // users that use the skills as personal skills
309  $pskill_ids = [];
310  $tref_ids = [];
311  foreach ($a_cskill_ids as $cs) {
312  if ($cs["tref_id"] > 0) {
313  if (ilSkillTemplateReference::_lookupTemplateId($cs["tref_id"]) == $cs["skill_id"]) {
314  $pskill_ids[$cs["tref_id"]] = $cs["tref_id"];
315  $tref_ids[(int) $cs["tref_id"]] = $cs["skill_id"];
316  }
317  } else {
318  $pskill_ids[$cs["skill_id"]] = $cs["skill_id"];
319  }
320  }
321  $set = $ilDB->query(
322  "SELECT skill_node_id, user_id FROM skl_personal_skill " .
323  " WHERE " . $ilDB->in("skill_node_id", $pskill_ids, false, "integer") .
324  " GROUP BY skill_node_id, user_id"
325  );
326  while ($rec = $ilDB->fetchAssoc($set)) {
327  if (isset($tref_ids[(int) $rec["skill_node_id"]])) {
328  $a_usages[$tref_ids[$rec["skill_node_id"]] . ":" . $rec["skill_node_id"]][ilSkillUsage::PERSONAL_SKILL][] =
329  array("key" => $rec["user_id"]);
330  } else {
331  $a_usages[$rec["skill_node_id"] . ":0"][ilSkillUsage::PERSONAL_SKILL][] =
332  array("key" => $rec["user_id"]);
333  }
334  }
335 
336  return $a_usages;
337  }
338 }
Get info on usages of skills.
static getAssignedMaterial(int $a_user_id, int $a_tref_id, int $a_level)
Get assigned material (for a skill level and user)
static removeSkills(int $a_user_id)
static getUsageInfo(array $a_cskill_ids)
static getSelfEvaluationDate(int $a_user_id, int $a_top_skill, int $a_tref_id, int $a_basic_skill)
static removeSkill(int $a_user_id, int $a_skill_node_id)
static _lookupTitle(int $a_obj_id, int $a_tref_id=0)
static removeMaterial(int $a_user_id, int $a_tref_id, int $a_level_id, int $a_wsp_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
static writeUserSkillLevelStatus(int $a_level_id, int $a_user_id, int $a_trigger_ref_id, int $a_tref_id=0, int $a_status=ilBasicSkill::ACHIEVED, bool $a_force=false, bool $a_self_eval=false, string $a_unique_identifier="", float $a_next_level_fulfilment=0.0, string $trigger_user_id="")
static getSelectedUserSkills(int $a_user_id)
static countAssignedMaterial(int $a_user_id, int $a_tref_id, int $a_level)
Count assigned material (for a skill level and user)
static removeMaterials(int $a_user_id)
static getUsageInfoGeneric(array $a_cskill_ids, string $a_usage_type, string $a_table, string $a_key_field, string $a_skill_field="skill_id", string $a_tref_field="tref_id")
Get standard usage query.
static addPersonalSkill(int $a_user_id, int $a_skill_node_id)
static saveSelfEvaluation(int $a_user_id, int $a_top_skill, int $a_tref_id, int $a_basic_skill, int $a_level)
static assignMaterial(int $a_user_id, int $a_top_skill, int $a_tref_id, int $a_basic_skill, int $a_level, int $a_wsp_id)
Assign material to skill level.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static resetUserSkillLevelStatus(int $a_user_id, int $a_skill_id, int $a_tref_id=0, int $a_trigger_ref_id=0, bool $a_self_eval=false)
static getSelfEvaluation(int $a_user_id, int $a_top_skill, int $a_tref_id, int $a_basic_skill)