ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilSkillSelfEvaluation.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
11{
15 protected $db;
16
22 public function __construct($a_id = 0)
23 {
24 global $DIC;
25
26 $this->db = $DIC->database();
27 if ($a_id > 0) {
28 $this->setId($a_id);
29 $this->read();
30 }
31 }
32
38 public function setId($a_val)
39 {
40 $this->id = $a_val;
41 }
42
48 public function getId()
49 {
50 return $this->id;
51 }
52
58 public function setUserId($a_val)
59 {
60 $this->user_id = $a_val;
61 }
62
68 public function getUserId()
69 {
70 return $this->user_id;
71 }
72
78 public function setTopSkillId($a_val)
79 {
80 $this->top_skill_id = $a_val;
81 }
82
88 public function getTopSkillId()
89 {
90 return $this->top_skill_id;
91 }
92
98 public function setCreated($a_val)
99 {
100 $this->created = $a_val;
101 }
102
108 public function getCreated()
109 {
110 return $this->created;
111 }
112
118 public function setLastUpdate($a_val)
119 {
120 $this->last_update = $a_val;
121 }
122
128 public function getLastUpdate()
129 {
130 return $this->last_update;
131 }
132
138 public function setLevels($a_val, $a_keep_existing = false)
139 {
140 if (!$a_keep_existing) {
141 $this->levels = $a_val;
142 } else {
143 if (is_array($a_val)) {
144 foreach ($a_val as $k => $v) {
145 $this->levels[$k] = $v;
146 }
147 }
148 }
149 }
150
156 public function getLevels()
157 {
158 return $this->levels;
159 }
160
167 public function read()
168 {
170
171 $set = $ilDB->query(
172 "SELECT * FROM skl_self_eval WHERE " .
173 " id = " . $ilDB->quote($this->getId(), "integer")
174 );
175 if ($rec = $ilDB->fetchAssoc($set)) {
176 $this->setUserId($rec["user_id"]);
177 $this->setTopSkillId($rec["top_skill_id"]);
178 $this->setCreated($rec["created"]);
179 $this->setLastUpdate($rec["last_update"]);
180 }
181
182 // levels
183 $set = $ilDB->query(
184 "SELECT * FROM skl_self_eval_level WHERE " .
185 " self_eval_id = " . $ilDB->quote($this->getId(), "integer")
186 );
187 $levels = array();
188 while ($rec = $ilDB->fetchAssoc($set)) {
189 $levels[$rec["skill_id"]] = $rec["level_id"];
190 }
191 $this->setLevels($levels);
192 }
193
197 public function create()
198 {
200
201 $this->setId($ilDB->nextId("skl_self_eval"));
202
203 $ilDB->manipulate("INSERT INTO skl_self_eval " .
204 "(id, user_id, top_skill_id, created, last_update) VALUES (" .
205 $ilDB->quote($this->getId(), "integer") . "," .
206 $ilDB->quote($this->getUserId(), "integer") . "," .
207 $ilDB->quote($this->getTopSkillId(), "integer") . "," .
208 $ilDB->now() . "," .
209 $ilDB->now() .
210 ")");
211
212 $levels = $this->getLevels();
213 if (is_array($levels)) {
214 foreach ($levels as $skill_id => $level_id) {
215 $ilDB->manipulate("INSERT INTO skl_self_eval_level " .
216 "(self_eval_id, skill_id, level_id) VALUES (" .
217 $ilDB->quote($this->getId(), "integer") . "," .
218 $ilDB->quote($skill_id, "integer") . "," .
219 $ilDB->quote($level_id, "integer") .
220 ")");
221 }
222 }
223 }
224
228 public function update()
229 {
231
232 $ilDB->manipulate(
233 "UPDATE skl_self_eval SET " .
234 " user_id = " . $ilDB->quote($this->getUserId(), "integer") .
235 ", top_skill_id = " . $ilDB->quote($this->getTopSkillId(), "integer") .
236 ", last_update = " . $ilDB->now() .
237 " WHERE id = " . $ilDB->quote($this->getId(), "integer")
238 );
239
240 $ilDB->manipulate(
241 "DELETE FROM skl_self_eval_level WHERE "
242 . " self_eval_id = " . $ilDB->quote($this->getId(), "integer")
243 );
244
245 $levels = $this->getLevels();
246 if (is_array($levels)) {
247 foreach ($levels as $skill_id => $level_id) {
248 $ilDB->manipulate("INSERT INTO skl_self_eval_level " .
249 "(self_eval_id, skill_id, level_id) VALUES (" .
250 $ilDB->quote($this->getId(), "integer") . "," .
251 $ilDB->quote($skill_id, "integer") . "," .
252 $ilDB->quote($level_id, "integer") .
253 ")");
254 }
255 }
256 }
257
261 public function delete()
262 {
264
265 $ilDB->manipulate(
266 "DELETE FROM skl_self_eval WHERE "
267 . " id = " . $ilDB->quote($this->getId(), "integer")
268 );
269
270 $ilDB->manipulate(
271 "DELETE FROM skl_self_eval_level WHERE "
272 . " self_eval_id = " . $ilDB->quote($this->getId(), "integer")
273 );
274 }
275
279 public static function getAllSelfEvaluationsOfUser($a_user, $a_one_per_top_skill = false)
280 {
281 global $DIC;
282
283 $ilDB = $DIC->database();
284
285 $set = $ilDB->query(
286 "SELECT * FROM skl_self_eval WHERE user_id = " .
287 $ilDB->quote($a_user, "integer") . " " .
288 "ORDER BY last_update DESC"
289 );
290
291 $self_evaluation = array();
292
293 $top_skills = array();
294 while ($rec = $ilDB->fetchAssoc($set)) {
295 if (!$a_one_per_top_skill || !in_array($rec["top_skill_id"], $top_skills)) {
296 $self_evaluation[] = $rec;
297 $top_skills[] = $rec["top_skill_id"];
298 }
299 }
300
301 return $self_evaluation;
302 }
303
310 protected static function lookupProperty($a_id, $a_prop)
311 {
312 global $DIC;
313
314 $ilDB = $DIC->database();
315
316 $set = $ilDB->query(
317 "SELECT $a_prop FROM skl_self_eval WHERE " .
318 " id = " . $ilDB->quote($a_id, "integer")
319 );
320 $rec = $ilDB->fetchAssoc($set);
321 return $rec[$a_prop];
322 }
323
330 public static function getAverageLevel($a_se_id, $a_user_id, $a_top_skill_id)
331 {
332 global $DIC;
333
334 $lng = $DIC->language();
335
336 $lng->loadLanguageModule("skmg");
337
338 $stree = new ilSkillTree();
339 $cnt = 0;
340 $sum = 0;
341 if ($stree->isInTree($a_top_skill_id)) {
342 $se = new ilSkillSelfEvaluation($a_se_id);
343 $levels = $se->getLevels();
344
345 $cnode = $stree->getNodeData($a_top_skill_id);
346 $childs = $stree->getSubTree($cnode);
347
348 foreach ($childs as $child) {
349 if ($child["type"] == "skll") {
350 $sk = new ilBasicSkill($child["child"]);
351 $ls = $sk->getLevelData();
352 $ord = array();
353 foreach ($ls as $k => $l) {
354 $ord[$l["id"]] = $k + 1;
355 }
356 reset($ls);
357 foreach ($ls as $ld) {
358 if ($ld["id"] == $levels[$child["child"]]) {
359 $sum += $ord[$ld["id"]];
360 }
361 }
362 $cnt += 1;
363 }
364 }
365 }
366 if ($cnt > 0) {
367 $avg = round($sum / $cnt);
368 if ($avg > 0) {
369 return (array("skill_title" => $cnode["title"],
370 "ord" => $avg, "avg_title" => $ls[$avg - 1]["title"]));
371 } else {
372 return (array("skill_title" => $cnode["title"],
373 "ord" => $avg, "avg_title" => $lng->txt("skmg_no_skills")));
374 }
375 }
376 return null;
377 }
378
385 public static function determineSteps($a_sn_id)
386 {
387 $steps = array();
388 if ($a_sn_id > 0) {
389 $stree = new ilSkillTree();
390
391 if ($stree->isInTree($a_sn_id)) {
392 $cnode = $stree->getNodeData($a_sn_id);
393 $childs = $stree->getSubTree($cnode);
394 foreach ($childs as $child) {
395 if ($child["type"] == "skll") {
396 $steps[] = $child["child"];
397 }
398 }
399 }
400 }
401 return $steps;
402 }
403}
An exception for terminatinating execution or to throw for unit testing.
Self evaluation application class.
setLevels($a_val, $a_keep_existing=false)
Set level.
setLastUpdate($a_val)
Set last update.
static getAverageLevel($a_se_id, $a_user_id, $a_top_skill_id)
Get average level of user self evaluation.
create()
Create self evaluation.
static determineSteps($a_sn_id)
Determine steps.
static getAllSelfEvaluationsOfUser($a_user, $a_one_per_top_skill=false)
Get all self evaluations.
setTopSkillId($a_val)
Set top skill id.
setCreated($a_val)
Set created at.
update()
Update self evaluation.
static lookupProperty($a_id, $a_prop)
Lookup property.
global $DIC
Definition: goto.php:24
$steps
Definition: latex.php:3
$lng
global $ilDB