ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilSkillSelfEvaluation.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
13{
17 protected $db;
18
24 public function __construct($a_id = 0)
25 {
26 global $DIC;
27
28 $this->db = $DIC->database();
29 if ($a_id > 0) {
30 $this->setId($a_id);
31 $this->read();
32 }
33 }
34
40 public function setId($a_val)
41 {
42 $this->id = $a_val;
43 }
44
50 public function getId()
51 {
52 return $this->id;
53 }
54
60 public function setUserId($a_val)
61 {
62 $this->user_id = $a_val;
63 }
64
70 public function getUserId()
71 {
72 return $this->user_id;
73 }
74
80 public function setTopSkillId($a_val)
81 {
82 $this->top_skill_id = $a_val;
83 }
84
90 public function getTopSkillId()
91 {
92 return $this->top_skill_id;
93 }
94
100 public function setCreated($a_val)
101 {
102 $this->created = $a_val;
103 }
104
110 public function getCreated()
111 {
112 return $this->created;
113 }
114
120 public function setLastUpdate($a_val)
121 {
122 $this->last_update = $a_val;
123 }
124
130 public function getLastUpdate()
131 {
132 return $this->last_update;
133 }
134
140 public function setLevels($a_val, $a_keep_existing = false)
141 {
142 if (!$a_keep_existing) {
143 $this->levels = $a_val;
144 } else {
145 if (is_array($a_val)) {
146 foreach ($a_val as $k => $v) {
147 $this->levels[$k] = $v;
148 }
149 }
150 }
151 }
152
158 public function getLevels()
159 {
160 return $this->levels;
161 }
162
169 public function read()
170 {
172
173 $set = $ilDB->query(
174 "SELECT * FROM skl_self_eval WHERE " .
175 " id = " . $ilDB->quote($this->getId(), "integer")
176 );
177 if ($rec = $ilDB->fetchAssoc($set)) {
178 $this->setUserId($rec["user_id"]);
179 $this->setTopSkillId($rec["top_skill_id"]);
180 $this->setCreated($rec["created"]);
181 $this->setLastUpdate($rec["last_update"]);
182 }
183
184 // levels
185 $set = $ilDB->query(
186 "SELECT * FROM skl_self_eval_level WHERE " .
187 " self_eval_id = " . $ilDB->quote($this->getId(), "integer")
188 );
189 $levels = array();
190 while ($rec = $ilDB->fetchAssoc($set)) {
191 $levels[$rec["skill_id"]] = $rec["level_id"];
192 }
193 $this->setLevels($levels);
194 }
195
199 public function create()
200 {
202
203 $this->setId($ilDB->nextId("skl_self_eval"));
204
205 $ilDB->manipulate("INSERT INTO skl_self_eval " .
206 "(id, user_id, top_skill_id, created, last_update) VALUES (" .
207 $ilDB->quote($this->getId(), "integer") . "," .
208 $ilDB->quote($this->getUserId(), "integer") . "," .
209 $ilDB->quote($this->getTopSkillId(), "integer") . "," .
210 $ilDB->now() . "," .
211 $ilDB->now() .
212 ")");
213
214 $levels = $this->getLevels();
215 if (is_array($levels)) {
216 foreach ($levels as $skill_id => $level_id) {
217 $ilDB->manipulate("INSERT INTO skl_self_eval_level " .
218 "(self_eval_id, skill_id, level_id) VALUES (" .
219 $ilDB->quote($this->getId(), "integer") . "," .
220 $ilDB->quote($skill_id, "integer") . "," .
221 $ilDB->quote($level_id, "integer") .
222 ")");
223 }
224 }
225 }
226
230 public function update()
231 {
233
234 $ilDB->manipulate(
235 "UPDATE skl_self_eval SET " .
236 " user_id = " . $ilDB->quote($this->getUserId(), "integer") .
237 ", top_skill_id = " . $ilDB->quote($this->getTopSkillId(), "integer") .
238 ", last_update = " . $ilDB->now() .
239 " WHERE id = " . $ilDB->quote($this->getId(), "integer")
240 );
241
242 $ilDB->manipulate(
243 "DELETE FROM skl_self_eval_level WHERE "
244 . " self_eval_id = " . $ilDB->quote($this->getId(), "integer")
245 );
246
247 $levels = $this->getLevels();
248 if (is_array($levels)) {
249 foreach ($levels as $skill_id => $level_id) {
250 $ilDB->manipulate("INSERT INTO skl_self_eval_level " .
251 "(self_eval_id, skill_id, level_id) VALUES (" .
252 $ilDB->quote($this->getId(), "integer") . "," .
253 $ilDB->quote($skill_id, "integer") . "," .
254 $ilDB->quote($level_id, "integer") .
255 ")");
256 }
257 }
258 }
259
263 public function delete()
264 {
266
267 $ilDB->manipulate(
268 "DELETE FROM skl_self_eval WHERE "
269 . " id = " . $ilDB->quote($this->getId(), "integer")
270 );
271
272 $ilDB->manipulate(
273 "DELETE FROM skl_self_eval_level WHERE "
274 . " self_eval_id = " . $ilDB->quote($this->getId(), "integer")
275 );
276 }
277
281 public static function getAllSelfEvaluationsOfUser($a_user, $a_one_per_top_skill = false)
282 {
283 global $DIC;
284
285 $ilDB = $DIC->database();
286
287 $set = $ilDB->query(
288 "SELECT * FROM skl_self_eval WHERE user_id = " .
289 $ilDB->quote($a_user, "integer") . " " .
290 "ORDER BY last_update DESC"
291 );
292
293 $self_evaluation = array();
294
295 $top_skills = array();
296 while ($rec = $ilDB->fetchAssoc($set)) {
297 if (!$a_one_per_top_skill || !in_array($rec["top_skill_id"], $top_skills)) {
298 $self_evaluation[] = $rec;
299 $top_skills[] = $rec["top_skill_id"];
300 }
301 }
302
303 return $self_evaluation;
304 }
305
312 protected static function lookupProperty($a_id, $a_prop)
313 {
314 global $DIC;
315
316 $ilDB = $DIC->database();
317
318 $set = $ilDB->query(
319 "SELECT $a_prop FROM skl_self_eval WHERE " .
320 " id = " . $ilDB->quote($a_id, "integer")
321 );
322 $rec = $ilDB->fetchAssoc($set);
323 return $rec[$a_prop];
324 }
325
332 public static function getAverageLevel($a_se_id, $a_user_id, $a_top_skill_id)
333 {
334 global $DIC;
335
336 $lng = $DIC->language();
337
338 $lng->loadLanguageModule("skmg");
339
340 include_once("./Services/Skill/classes/class.ilSkillTree.php");
341 include_once("./Services/Skill/classes/class.ilBasicSkill.php");
342 $stree = new ilSkillTree();
343 $cnt = 0;
344 $sum = 0;
345 if ($stree->isInTree($a_top_skill_id)) {
346 $se = new ilSkillSelfEvaluation($a_se_id);
347 $levels = $se->getLevels();
348
349 $cnode = $stree->getNodeData($a_top_skill_id);
350 $childs = $stree->getSubTree($cnode);
351
352 foreach ($childs as $child) {
353 if ($child["type"] == "skll") {
354 $sk = new ilBasicSkill($child["child"]);
355 $ls = $sk->getLevelData();
356 $ord = array();
357 foreach ($ls as $k => $l) {
358 $ord[$l["id"]] = $k + 1;
359 }
360 reset($ls);
361 foreach ($ls as $ld) {
362 if ($ld["id"] == $levels[$child["child"]]) {
363 $sum += $ord[$ld["id"]];
364 }
365 }
366 $cnt += 1;
367 }
368 }
369 }
370 if ($cnt > 0) {
371 $avg = round($sum / $cnt);
372 if ($avg > 0) {
373 return (array("skill_title" => $cnode["title"],
374 "ord" => $avg, "avg_title" => $ls[$avg - 1]["title"]));
375 } else {
376 return (array("skill_title" => $cnode["title"],
377 "ord" => $avg, "avg_title" => $lng->txt("skmg_no_skills")));
378 }
379 }
380 return null;
381 }
382
389 public static function determineSteps($a_sn_id)
390 {
391 $steps = array();
392 if ($a_sn_id > 0) {
393 include_once("./Services/Skill/classes/class.ilSkillTree.php");
394 include_once("./Services/Skill/classes/class.ilSkillSelfEvalSkillTableGUI.php");
395 $stree = new ilSkillTree();
396
397 if ($stree->isInTree($a_sn_id)) {
398 $cnode = $stree->getNodeData($a_sn_id);
399 $childs = $stree->getSubTree($cnode);
400 foreach ($childs as $child) {
401 if ($child["type"] == "skll") {
402 $steps[] = $child["child"];
403 }
404 }
405 }
406 }
407 return $steps;
408 }
409}
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.
$lng
global $ilDB
$steps
Definition: latex.php:3
$DIC
Definition: xapitoken.php:46