ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilSurveySkill.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
13 {
14  protected $q_skill = array(); // key: question id, value:
15  // array("base_skill_id" =>..., "tref_id" =>... )
19  protected $log;
20 
27  function __construct(ilObjSurvey $a_survey)
28  {
29  $this->survey = $a_survey;
30  $this->read();
31  $this->log = ilLoggerFactory::getLogger("svy");
32  }
33 
40  function read()
41  {
42  global $ilDB;
43 
44  $set = $ilDB->query("SELECT * FROM svy_quest_skill ".
45  " WHERE survey_id = ".$ilDB->quote($this->survey->getId(), "integer")
46  );
47 
48  include_once("./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php");
49 
50  while ($rec = $ilDB->fetchAssoc($set))
51  {
52  if (SurveyQuestion::_questionExists($rec["q_id"]))
53  {
54  $this->q_skill[$rec["q_id"]] = array("q_id" => $rec["q_id"],
55  "base_skill_id" => $rec["base_skill_id"],
56  "tref_id" => $rec["tref_id"]);
57  }
58  }
59  }
60 
67  function getSkillForQuestion($a_question_id)
68  {
69  if (isset($this->q_skill[$a_question_id]))
70  {
71  return $this->q_skill[$a_question_id];
72  }
73  return false;
74  }
75 
82  function getQuestionsForSkill($a_base_skill_id, $a_tref_id)
83  {
84  $q_ids = array();
85  foreach ($this->q_skill as $q_id => $s)
86  {
87  if ($s["base_skill_id"] == $a_base_skill_id &&
88  $s["tref_id"] == $a_tref_id)
89  {
90  $q_ids[] = $q_id;
91  }
92  }
93  return $q_ids;
94  }
95 
96 
104  function addQuestionSkillAssignment($a_question_id, $a_base_skill_id, $a_tref_id)
105  {
106  global $ilDB;
107 
108  $ilDB->replace("svy_quest_skill",
109  array("q_id" => array("integer", $a_question_id)),
110  array(
111  "survey_id" => array("integer", $this->survey->getId()),
112  "base_skill_id" => array("integer", $a_base_skill_id),
113  "tref_id" => array("integer", $a_tref_id)
114  )
115  );
116  $this->q_skill[$a_question_id] = array("q_id" => $a_question_id,
117  "base_skill_id" => $a_base_skill_id,
118  "tref_id" => $a_tref_id);
119 
120  // add usage
121  include_once("./Services/Skill/classes/class.ilSkillUsage.php");
122  ilSkillUsage::setUsage($this->survey->getId(), $a_base_skill_id, $a_tref_id);
123 
124  }
125 
131  function removeQuestionSkillAssignment($a_question_id)
132  {
133  global $ilDB;
134 
135  // read skills that are assigned to the quesiton
136  $set = $ilDB->query("SELECT * FROM svy_quest_skill ".
137  " WHERE q_id = ".$ilDB->quote($a_question_id, "integer")
138  );
139  $skills = array();
140  while ($rec = $ilDB->fetchAssoc($set))
141  {
142  $skills[] = array("skill_id" => $rec["base_skill_id"],
143  "tref_id" => $rec["tref_id"]);
144  }
145 
146  // remove assignment of question
147  $ilDB->manipulate("DELETE FROM svy_quest_skill WHERE ".
148  " q_id = ".$ilDB->quote($a_question_id, "integer")
149  );
150  unset($this->q_skill[$a_question_id]);
151 
152  $this->removeUsagesOfSkills($skills);
153  }
154 
160  static function handleQuestionDeletion($a_question_id, $a_obj_id)
161  {
162  global $ilDB;
163  if (ilObject::_lookupType($a_obj_id) == "svy")
164  {
165  // mantis 11691
166  include_once './Modules/Survey/classes/class.ilObjSurvey.php';
167  $svy = new ilObjSurvey($a_obj_id, false);
168  $svy_skill = new ilSurveySkill($svy);
169  $svy_skill->removeQuestionSkillAssignment($a_question_id);
170  }
171  }
172 
179  function removeUsagesOfSkills($a_skills)
180  {
181  $used_skills = array();
182  foreach ($a_skills as $skill)
183  {
184  if ($this->isSkillAssignedToQuestion($skill["skill_id"], $skill["tref_id"]))
185  {
186  $used_skills[] = $skill["skill_id"].":".$skill["tref_id"];
187  }
188  }
189  reset($a_skills);
190 
191  // now remove all usages that have been confirmed
192  include_once("./Services/Skill/classes/class.ilSkillUsage.php");
193 //var_dump($a_skills);
194 //var_dump($used_skills); exit;
195  foreach ($a_skills as $skill)
196  {
197  if (!in_array($skill["skill_id"].":".$skill["tref_id"], $used_skills))
198  {
199  ilSkillUsage::setUsage($this->survey->getId(), $skill["skill_id"], $skill["tref_id"], false);
200  }
201  }
202  }
203 
210  function isSkillAssignedToQuestion($a_skill_id, $a_tref_id)
211  {
212  global $ilDB;
213 
214  $set = $ilDB->query("SELECT * FROM svy_quest_skill ".
215  " WHERE base_skill_id = ".$ilDB->quote($a_skill_id, "integer").
216  " AND tref_id = ".$ilDB->quote($a_tref_id, "integer").
217  " AND survey_id = ".$ilDB->quote($this->survey->getId(), "integer")
218  );
219  if ($rec = $ilDB->fetchAssoc($set))
220  {
221  return true;
222  }
223  return false;
224  }
225 
226 
234  {
235  $skills = array();
236  include_once("./Services/Skill/classes/class.ilBasicSkill.php");
237  foreach ($this->q_skill as $sk)
238  {
239  $skills[$sk["base_skill_id"].":".$sk["tref_id"]] =
240  ilBasicSkill::_lookupTitle($sk["base_skill_id"]);
241  }
242  return $skills;
243  }
244 
251  function determineSkillLevelsForAppraisee($a_appraisee_id, $a_self_eval = false)
252  {
253  $skills = array();
254 
255  // get all skills
256  $opts = $this->getAllAssignedSkillsAsOptions();
257  foreach ($opts as $k => $title)
258  {
259  $k = explode(":", $k);
260 
261  $bs = new ilBasicSkill((int) $k[0]);
262  $ld = $bs->getLevelData();
263 
264  $skills[] = array(
265  "base_skill_id" => (int) $k[0],
266  "tref_id" => (int) $k[1],
267  "skill_title" => $title,
268  "level_data" => $ld
269  );
270  }
271 
272  if (!$a_self_eval)
273  {
274  $finished_ids = $this->survey->getFinishedIdsForAppraiseeId($a_appraisee_id, true);
275  }
276  else
277  {
278  $finished_id = $this->survey->getFinishedIdForAppraiseeIdAndRaterId($a_appraisee_id, $a_appraisee_id);
279  if ($finished_id > 0)
280  {
281  $finished_ids = array($finished_id);
282  }
283  }
284 
285  if(!sizeof($finished_ids))
286  {
287  $finished_ids = array(-1);
288  }
289 
290  $results = $this->survey->getUserSpecificResults($finished_ids);
291  $this->log->debug("Finished IDS: ".print_r($finished_ids, true));
292  foreach ($skills as $k => $s)
293  {
294  $q_ids = $this->getQuestionsForSkill($s["base_skill_id"], $s["tref_id"]);
295  $this->log->debug("Skill: ".$s["base_skill_id"].":".$s["tref_id"].", Questions: ".implode(",",$q_ids));
296  $mean_sum = 0;
297  foreach ($q_ids as $q_id)
298  {
299  $qmean = 0;
300  if (is_array($results[$q_id]))
301  {
302  $cnt = 0;
303  $sum = 0;
304  foreach ($results[$q_id] as $uid => $answer) // answer of user $uid for question $q_id
305  {
306  // $answer has the scale values as keys and the answer texts as values.
307  // In case of single choice this is an array with one key => value pair.
308  // For multiple choice questions (currently not supported for being used for competences)
309  // multiple elements may be in the array (in the future).
310  $scale_values = array_keys($answer); // scale values of the answer
311  $this->log->debug("User answer (scale values): ".print_r($scale_values, true));
312  $sum += array_sum($scale_values);
313  $cnt += sizeof($scale_values); // nr of answers (always one in the case of single choice)
314  }
315  if ($cnt > 0)
316  {
317  $qmean = $sum/$cnt;
318  }
319  $this->log->debug("MEAN: ".$qmean);
320  }
321  $mean_sum += $qmean;
322  $this->log->debug("MEAN SUM: ".$mean_sum);
323  }
324  $skills[$k]["mean_sum"] = $mean_sum;
325 
326  include_once("./Modules/Survey/classes/class.ilSurveySkillThresholds.php");
327  $skthr = new ilSurveySkillThresholds($this->survey);
328  $thresholds = $skthr->getThresholds();
329  foreach ($skills[$k]["level_data"] as $l)
330  {
331  $t = $thresholds[$l["id"]][$s["tref_id"]];
332  if ($t > 0 && $mean_sum >= $t)
333  {
334  $skills[$k]["new_level"] = $l["title"];
335  $skills[$k]["new_level_id"] = $l["id"];
336  }
337  }
338  }
339  return $skills;
340  }
341 
342 
349  function determineMaxScale($a_base_skill, $a_tref_id = 0)
350  {
351  include_once("./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php");
352  include_once("./Modules/Survey/classes/class.ilSurveySkill.php");
353  $ssk = new ilSurveySkill($this->survey);
354  $question_ids = $ssk->getQuestionsForSkill($a_base_skill, $a_tref_id);
355  $scale_sum = 0;
356  foreach ($question_ids as $q_id)
357  {
359  if(!is_object($q))
360  {
361  continue;
362  }
363  $cats = $q->getCategories();
364  $max_scale = 0;
365  for($i = 0; $i<= $cats->getCategoryCount(); $i++)
366  {
367  $c = $cats->getCategory($i);
368  $n = $c->neutral;
369  $s = $c->scale;
370  if (!$c->neutral)
371  {
372  if ($c->scale > $max_scale)
373  {
374  $max_scale = $c->scale;
375  }
376  }
377  }
378  $scale_sum+= $max_scale;
379  }
380 
381  return $scale_sum;
382  }
383 
390  function writeAppraiseeSkills($a_app_id)
391  {
392  // write raters evaluation
393  $new_levels = $this->determineSkillLevelsForAppraisee($a_app_id);
394  foreach ($new_levels as $nl)
395  {
396  if ($nl["new_level_id"] > 0)
397  {
398  ilBasicSkill::writeUserSkillLevelStatus($nl["new_level_id"],
399  $a_app_id, $this->survey->getRefId(), $nl["tref_id"], ilBasicSkill::ACHIEVED, true);
400  }
401  }
402 
403  // write self evaluation
404  $new_levels = $this->determineSkillLevelsForAppraisee($a_app_id, true);
405  foreach ($new_levels as $nl)
406  {
407  if ($nl["new_level_id"] > 0)
408  {
409  ilBasicSkill::writeUserSkillLevelStatus($nl["new_level_id"],
410  $a_app_id, $this->survey->getRefId(), $nl["tref_id"], ilBasicSkill::ACHIEVED, true, 1);
411  }
412  }
413  }
414 
415 }
416 
417 ?>
static handleQuestionDeletion($a_question_id, $a_obj_id)
Remove question skill assignment.
writeAppraiseeSkills($a_app_id)
Write appraisee skills.
__construct(ilObjSurvey $a_survey)
Constructor.
determineSkillLevelsForAppraisee($a_appraisee_id, $a_self_eval=false)
Determine skill levels for appraisee.
static setUsage($a_obj_id, $a_skill_id, $a_tref_id, $a_use=true)
Set usage.
isSkillAssignedToQuestion($a_skill_id, $a_tref_id)
Is skill assigned to any question?
Skill/Competence handling in surveys.
Skill tresholds for 360 surveys.
$ld
Definition: langwiz.php:244
removeQuestionSkillAssignment($a_question_id)
Remove question skill assignment.
static _questionExists($question_id)
Returns true if the question already exists in the database.
static writeUserSkillLevelStatus($a_level_id, $a_user_id, $a_trigger_ref_id, $a_tref_id=0, $a_status=ilBasicSkill::ACHIEVED, $a_force=false, $a_self_eval=false, $a_unique_identifier="")
Write skill level status.
removeUsagesOfSkills($a_skills)
Remove usages of skills.
$n
Definition: RandomTest.php:80
$results
determineMaxScale($a_base_skill, $a_tref_id=0)
Determine max scales and questions.
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
static _lookupTitle($a_obj_id, $a_tref_id=0)
Lookup Title.
getSkillForQuestion($a_question_id)
Get skill for question.
getAllAssignedSkillsAsOptions()
Get skill for question.
global $l
Definition: afr.php:30
global $ilDB
addQuestionSkillAssignment($a_question_id, $a_base_skill_id, $a_tref_id)
Add survey question to skill assignment.
static getLogger($a_component_id)
Get component logger.
getQuestionsForSkill($a_base_skill_id, $a_tref_id)
Get questions for skill.
Basic Skill.