ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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{
19 function __construct($a_id = 0)
20 {
21 if ($a_id > 0)
22 {
23 $this->setId($a_id);
24 $this->read();
25 }
26 }
27
33 function setId($a_val)
34 {
35 $this->id = $a_val;
36 }
37
43 function getId()
44 {
45 return $this->id;
46 }
47
53 function setUserId($a_val)
54 {
55 $this->user_id = $a_val;
56 }
57
63 function getUserId()
64 {
65 return $this->user_id;
66 }
67
73 function setTopSkillId($a_val)
74 {
75 $this->top_skill_id = $a_val;
76 }
77
83 function getTopSkillId()
84 {
85 return $this->top_skill_id;
86 }
87
93 function setCreated($a_val)
94 {
95 $this->created = $a_val;
96 }
97
103 function getCreated()
104 {
105 return $this->created;
106 }
107
113 function setLastUpdate($a_val)
114 {
115 $this->last_update = $a_val;
116 }
117
123 function getLastUpdate()
124 {
125 return $this->last_update;
126 }
127
133 function setLevels($a_val, $a_keep_existing = false)
134 {
135 if (!$a_keep_existing)
136 {
137 $this->levels = $a_val;
138 }
139 else
140 {
141 if (is_array($a_val))
142 {
143 foreach ($a_val as $k => $v)
144 {
145 $this->levels[$k] = $v;
146 }
147 }
148 }
149 }
150
156 function getLevels()
157 {
158 return $this->levels;
159 }
160
167 function read()
168 {
169 global $ilDB;
170
171 $set = $ilDB->query("SELECT * FROM skl_self_eval WHERE ".
172 " id = ".$ilDB->quote($this->getId(), "integer")
173 );
174 if ($rec = $ilDB->fetchAssoc($set))
175 {
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("SELECT * FROM skl_self_eval_level WHERE ".
184 " self_eval_id = ".$ilDB->quote($this->getId(), "integer")
185 );
186 $levels = array();
187 while ($rec = $ilDB->fetchAssoc($set))
188 {
189 $levels[$rec["skill_id"]] = $rec["level_id"];
190 }
191 $this->setLevels($levels);
192
193 }
194
198 function create()
199 {
200 global $ilDB;
201
202 $this->setId($ilDB->nextId("skl_self_eval"));
203
204 $ilDB->manipulate("INSERT INTO skl_self_eval ".
205 "(id, user_id, top_skill_id, created, last_update) VALUES (".
206 $ilDB->quote($this->getId(), "integer").",".
207 $ilDB->quote($this->getUserId(), "integer").",".
208 $ilDB->quote($this->getTopSkillId(), "integer").",".
209 $ilDB->now().",".
210 $ilDB->now().
211 ")");
212
213 $levels = $this->getLevels();
214 if (is_array($levels))
215 {
216 foreach ($levels as $skill_id => $level_id)
217 {
218 $ilDB->manipulate("INSERT INTO skl_self_eval_level ".
219 "(self_eval_id, skill_id, level_id) VALUES (".
220 $ilDB->quote($this->getId(), "integer").",".
221 $ilDB->quote($skill_id, "integer").",".
222 $ilDB->quote($level_id, "integer").
223 ")");
224 }
225 }
226 }
227
231 function update()
232 {
233 global $ilDB;
234
235 $ilDB->manipulate("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("DELETE FROM skl_self_eval_level WHERE "
243 ." self_eval_id = ".$ilDB->quote($this->getId(), "integer")
244 );
245
246 $levels = $this->getLevels();
247 if (is_array($levels))
248 {
249 foreach ($levels as $skill_id => $level_id)
250 {
251 $ilDB->manipulate("INSERT INTO skl_self_eval_level ".
252 "(self_eval_id, skill_id, level_id) VALUES (".
253 $ilDB->quote($this->getId(), "integer").",".
254 $ilDB->quote($skill_id, "integer").",".
255 $ilDB->quote($level_id, "integer").
256 ")");
257 }
258 }
259 }
260
264 function delete()
265 {
266 global $ilDB;
267
268 $ilDB->manipulate("DELETE FROM skl_self_eval WHERE "
269 ." id = ".$ilDB->quote($this->getId(), "integer")
270 );
271
272 $ilDB->manipulate("DELETE FROM skl_self_eval_level WHERE "
273 ." self_eval_id = ".$ilDB->quote($this->getId(), "integer")
274 );
275 }
276
280 static function getAllSelfEvaluationsOfUser($a_user, $a_one_per_top_skill = false)
281 {
282 global $ilDB;
283
284 $set = $ilDB->query("SELECT * FROM skl_self_eval WHERE user_id = ".
285 $ilDB->quote($a_user, "integer")." ".
286 "ORDER BY last_update DESC"
287 );
288
289 $self_evaluation = array();
290
291 $top_skills = array();
292 while ($rec = $ilDB->fetchAssoc($set))
293 {
294 if (!$a_one_per_top_skill || !in_array($rec["top_skill_id"], $top_skills))
295 {
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 $ilDB;
313
314 $set = $ilDB->query("SELECT $a_prop FROM skl_self_eval WHERE ".
315 " id = ".$ilDB->quote($a_id, "integer")
316 );
317 $rec = $ilDB->fetchAssoc($set);
318 return $rec[$a_prop];
319 }
320
327 static function getAverageLevel($a_se_id, $a_user_id, $a_top_skill_id)
328 {
329 global $lng;
330
331 $lng->loadLanguageModule("skmg");
332
333 include_once("./Services/Skill/classes/class.ilSkillTree.php");
334 include_once("./Services/Skill/classes/class.ilBasicSkill.php");
335 $stree = new ilSkillTree();
336 $cnt = 0;
337 $sum = 0;
338 if ($stree->isInTree($a_top_skill_id))
339 {
340 $se = new ilSkillSelfEvaluation($a_se_id);
341 $levels = $se->getLevels();
342
343 $cnode = $stree->getNodeData($a_top_skill_id);
344 $childs = $stree->getSubTree($cnode);
345
346 foreach ($childs as $child)
347 {
348 if ($child["type"] == "skll")
349 {
350 $sk = new ilBasicSkill($child["child"]);
351 $ls = $sk->getLevelData();
352 $ord = array();
353 foreach ($ls as $k => $l)
354 {
355 $ord[$l["id"]] = $k + 1;
356 }
357 reset($ls);
358 foreach ($ls as $ld)
359 {
360 if ($ld["id"] == $levels[$child["child"]])
361 {
362 $sum+= $ord[$ld["id"]];
363 }
364 }
365 $cnt+= 1;
366 }
367 }
368 }
369 if ($cnt > 0)
370 {
371 $avg = round($sum/$cnt);
372 if ($avg > 0)
373 {
374 return (array("skill_title" => $cnode["title"],
375 "ord" => $avg, "avg_title" => $ls[$avg - 1]["title"]));
376 }
377 else
378 {
379 return (array("skill_title" => $cnode["title"],
380 "ord" => $avg, "avg_title" => $lng->txt("skmg_no_skills")));
381 }
382 }
383 return null;
384 }
385
392 static function determineSteps($a_sn_id)
393 {
394 $steps = array();
395 if ($a_sn_id > 0 )
396 {
397 include_once("./Services/Skill/classes/class.ilSkillTree.php");
398 include_once("./Services/Skill/classes/class.ilSkillSelfEvalSkillTableGUI.php");
399 $stree = new ilSkillTree();
400
401 if ($stree->isInTree($a_sn_id))
402 {
403 $cnode = $stree->getNodeData($a_sn_id);
404 $childs = $stree->getSubTree($cnode);
405 foreach ($childs as $child)
406 {
407 if ($child["type"] == "skll")
408 {
409 $steps[] = $child["child"];
410 }
411 }
412 }
413 }
414 return $steps;
415 }
416
417
418}
419
420?>
global $l
Definition: afr.php:30
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 $lng
Definition: privfeed.php:40
global $ilDB
$steps
Definition: latex.php:3