ILIAS  release_7 Revision v7.30-3-g800a261c036
ilSurveySkill Class Reference

Skill/Competence handling in surveys. More...

+ Collaboration diagram for ilSurveySkill:

Public Member Functions

 __construct (ilObjSurvey $a_survey)
 Constructor. More...
 
 read ()
 Read. More...
 
 getSkillForQuestion ($a_question_id)
 Get skill for question. More...
 
 getQuestionsForSkill ($a_base_skill_id, $a_tref_id)
 Get questions for skill. More...
 
 addQuestionSkillAssignment ($a_question_id, $a_base_skill_id, $a_tref_id)
 Add survey question to skill assignment. More...
 
 removeQuestionSkillAssignment ($a_question_id)
 Remove question skill assignment. More...
 
 removeUsagesOfSkills ($a_skills)
 Remove usages of skills. More...
 
 isSkillAssignedToQuestion ($a_skill_id, $a_tref_id)
 Is skill assigned to any question? More...
 
 getAllAssignedSkillsAsOptions ()
 Get skill for question. More...
 
 determineSkillLevelsForAppraisee ($a_appraisee_id, $a_self_eval=false)
 Determine skill levels for appraisee. More...
 
 determineMaxScale ($a_base_skill, $a_tref_id=0)
 Determine max scales and questions. More...
 
 writeAndAddAppraiseeSkills (int $user_id)
 Write appraisee skills and add them to user's competence records. More...
 
 writeAndAddSelfEvalSkills (int $user_id)
 Write skills on self evaluation and add them to user's competence records. More...
 

Static Public Member Functions

static handleQuestionDeletion ($a_question_id, $a_obj_id)
 Remove question skill assignment. More...
 

Protected Attributes

 $db
 
 $q_skill = array()
 
 $log
 

Detailed Description

Skill/Competence handling in surveys.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 12 of file class.ilSurveySkill.php.

Constructor & Destructor Documentation

◆ __construct()

ilSurveySkill::__construct ( ilObjSurvey  $a_survey)

Constructor.

Parameters

Definition at line 32 of file class.ilSurveySkill.php.

References $DIC, ilLoggerFactory\getLogger(), and read().

33  {
34  global $DIC;
35 
36  $this->db = $DIC->database();
37  $this->survey = $a_survey;
38  $this->read();
39  $this->log = ilLoggerFactory::getLogger("svy");
40  }
global $DIC
Definition: goto.php:24
static getLogger($a_component_id)
Get component logger.
+ Here is the call graph for this function:

Member Function Documentation

◆ addQuestionSkillAssignment()

ilSurveySkill::addQuestionSkillAssignment (   $a_question_id,
  $a_base_skill_id,
  $a_tref_id 
)

Add survey question to skill assignment.

Parameters
int$a_question_idquestion id
int$a_base_skill_idbase skill id
int$a_tref_idskill template reference id (0, if no template involved)

Definition at line 106 of file class.ilSurveySkill.php.

References $db, $ilDB, and ilSkillUsage\setUsage().

107  {
108  $ilDB = $this->db;
109 
110  $ilDB->replace(
111  "svy_quest_skill",
112  array("q_id" => array("integer", $a_question_id)),
113  array(
114  "survey_id" => array("integer", $this->survey->getId()),
115  "base_skill_id" => array("integer", $a_base_skill_id),
116  "tref_id" => array("integer", $a_tref_id)
117  )
118  );
119  $this->q_skill[$a_question_id] = array("q_id" => $a_question_id,
120  "base_skill_id" => $a_base_skill_id,
121  "tref_id" => $a_tref_id);
122 
123  // add usage
124  ilSkillUsage::setUsage($this->survey->getId(), $a_base_skill_id, $a_tref_id);
125  }
static setUsage($a_obj_id, $a_skill_id, $a_tref_id, $a_use=true)
Set usage.
global $ilDB
+ Here is the call graph for this function:

◆ determineMaxScale()

ilSurveySkill::determineMaxScale (   $a_base_skill,
  $a_tref_id = 0 
)

Determine max scales and questions.

Parameters

Definition at line 340 of file class.ilSurveySkill.php.

References $c, $i, $n, and SurveyQuestion\_instanciateQuestion().

341  {
342  $ssk = new ilSurveySkill($this->survey);
343  $question_ids = $ssk->getQuestionsForSkill($a_base_skill, $a_tref_id);
344  $scale_sum = 0;
345  foreach ($question_ids as $q_id) {
347  if (!is_object($q)) {
348  continue;
349  }
350  $cats = $q->getCategories();
351  $max_scale = 0;
352  for ($i = 0; $i <= $cats->getCategoryCount(); $i++) {
353  $c = $cats->getCategory($i);
354  $n = $c->neutral;
355  $s = $c->scale;
356  if (!$c->neutral) {
357  if ($c->scale > $max_scale) {
358  $max_scale = $c->scale;
359  }
360  }
361  }
362  $scale_sum += $max_scale;
363  }
364 
365  return $scale_sum;
366  }
$c
Definition: cli.php:37
Skill/Competence handling in surveys.
$n
Definition: RandomTest.php:85
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
$i
Definition: metadata.php:24
+ Here is the call graph for this function:

◆ determineSkillLevelsForAppraisee()

ilSurveySkill::determineSkillLevelsForAppraisee (   $a_appraisee_id,
  $a_self_eval = false 
)

Determine skill levels for appraisee.

Parameters
$a_appraisee_idint user id of appraisee
Returns
array array with lots of information

Definition at line 244 of file class.ilSurveySkill.php.

References $results, getAllAssignedSkillsAsOptions(), and getQuestionsForSkill().

Referenced by writeAndAddAppraiseeSkills(), and writeAndAddSelfEvalSkills().

245  {
246  $skills = array();
247 
248  // get all skills
249  $opts = $this->getAllAssignedSkillsAsOptions();
250  foreach ($opts as $k => $title) {
251  $k = explode(":", $k);
252 
253  $bs = new ilBasicSkill((int) $k[0]);
254  $ld = $bs->getLevelData();
255 
256  $skills[] = array(
257  "base_skill_id" => (int) $k[0],
258  "tref_id" => (int) $k[1],
259  "skill_title" => $title,
260  "level_data" => $ld
261  );
262  }
263 
264  if (!$a_self_eval) {
265  $finished_ids = $this->survey->getFinishedIdsForAppraiseeId($a_appraisee_id, true);
266  } else {
267  $finished_id = $this->survey->getFinishedIdForAppraiseeIdAndRaterId($a_appraisee_id, $a_appraisee_id);
268  if ($finished_id > 0) {
269  $finished_ids = array($finished_id);
270  }
271  }
272 
273  if (!is_array($finished_ids)) {
274  $finished_ids = array(-1);
275  }
276 
277  $results = $this->survey->getUserSpecificResults($finished_ids);
278  $this->log->debug("Finished IDS: " . print_r($finished_ids, true));
279  foreach ($skills as $k => $s) {
280  $q_ids = $this->getQuestionsForSkill($s["base_skill_id"], $s["tref_id"]);
281  $this->log->debug("Skill: " . $s["base_skill_id"] . ":" . $s["tref_id"] . ", Questions: " . implode(",", $q_ids));
282  $mean_sum = 0;
283  foreach ($q_ids as $q_id) {
284  $qmean = 0;
285  if (is_array($results[$q_id])) {
286  $cnt = 0;
287  $sum = 0;
288  foreach ($results[$q_id] as $uid => $answer) { // answer of user $uid for question $q_id
289  // $answer has the scale values as keys and the answer texts as values.
290  // In case of single choice this is an array with one key => value pair.
291  // For multiple choice questions (currently not supported for being used for competences)
292  // multiple elements may be in the array (in the future).
293  $scale_values = array_keys($answer); // scale values of the answer
294  $this->log->debug("User answer (scale values): " . print_r($scale_values, true));
295  $sum += array_sum($scale_values);
296  $cnt += sizeof($scale_values); // nr of answers (always one in the case of single choice)
297  }
298  if ($cnt > 0) {
299  $qmean = $sum / $cnt;
300  }
301  $this->log->debug("MEAN: " . $qmean);
302  }
303  $mean_sum += $qmean;
304  $this->log->debug("MEAN SUM: " . $mean_sum);
305  }
306  $skills[$k]["mean_sum"] = $mean_sum;
307 
308  $skthr = new ilSurveySkillThresholds($this->survey);
309  $thresholds = $skthr->getThresholds();
310  $previous = 0;
311  $previous_t = 0;
312  foreach ($skills[$k]["level_data"] as $l) {
313  $t = $thresholds[$l["id"]][$s["tref_id"]];
314  if ($t > 0 && $mean_sum >= $t) {
315  $skills[$k]["new_level"] = $l["title"];
316  $skills[$k]["new_level_id"] = $l["id"];
317  $skills[$k]["next_level_perc"] = 0;
318  } elseif ($t > 0 && $mean_sum < $t) {
319  // first unfulfilled level
320  if ($previous == $skills[$k]["new_level_id"] && !isset($skills[$k]["next_level_perc"])) {
321  $skills[$k]["next_level_perc"] = 1 / ($t - $previous_t) * ($mean_sum - $previous_t);
322  }
323  }
324  if ($t > 0) {
325  $previous = $l["id"];
326  $previous_t = $t;
327  }
328  }
329  }
330  return $skills;
331  }
Skill tresholds for 360 surveys.
$results
getAllAssignedSkillsAsOptions()
Get skill for question.
getQuestionsForSkill($a_base_skill_id, $a_tref_id)
Get questions for skill.
Basic Skill.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAllAssignedSkillsAsOptions()

ilSurveySkill::getAllAssignedSkillsAsOptions ( )

Get skill for question.

Parameters
int$a_question_idquestion id
Returns
array skill array

Definition at line 228 of file class.ilSurveySkill.php.

References ilSkillTreeNode\_lookupTitle().

Referenced by determineSkillLevelsForAppraisee().

229  {
230  $skills = array();
231  foreach ($this->q_skill as $sk) {
232  $skills[$sk["base_skill_id"] . ":" . $sk["tref_id"]] =
233  ilBasicSkill::_lookupTitle($sk["base_skill_id"]);
234  }
235  return $skills;
236  }
static _lookupTitle($a_obj_id, $a_tref_id=0)
Lookup Title.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getQuestionsForSkill()

ilSurveySkill::getQuestionsForSkill (   $a_base_skill_id,
  $a_tref_id 
)

Get questions for skill.

Parameters

Definition at line 86 of file class.ilSurveySkill.php.

Referenced by determineSkillLevelsForAppraisee().

87  {
88  $q_ids = array();
89  foreach ($this->q_skill as $q_id => $s) {
90  if ($s["base_skill_id"] == $a_base_skill_id &&
91  $s["tref_id"] == $a_tref_id) {
92  $q_ids[] = $q_id;
93  }
94  }
95  return $q_ids;
96  }
+ Here is the caller graph for this function:

◆ getSkillForQuestion()

ilSurveySkill::getSkillForQuestion (   $a_question_id)

Get skill for question.

Parameters
int$a_question_idquestion id
Returns
array skill array

Definition at line 72 of file class.ilSurveySkill.php.

73  {
74  if (isset($this->q_skill[$a_question_id])) {
75  return $this->q_skill[$a_question_id];
76  }
77  return false;
78  }

◆ handleQuestionDeletion()

static ilSurveySkill::handleQuestionDeletion (   $a_question_id,
  $a_obj_id 
)
static

Remove question skill assignment.

Parameters
int$a_question_idquestion id

Definition at line 162 of file class.ilSurveySkill.php.

References $DIC, $ilDB, and ilObject\_lookupType().

Referenced by SurveyQuestion\delete().

163  {
164  global $DIC;
165 
166  $ilDB = $DIC->database();
167  if (ilObject::_lookupType($a_obj_id) == "svy") {
168  // mantis 11691
169  $svy = new ilObjSurvey($a_obj_id, false);
170  $svy_skill = new ilSurveySkill($svy);
171  $svy_skill->removeQuestionSkillAssignment($a_question_id);
172  }
173  }
Class ilObjSurvey.
Skill/Competence handling in surveys.
global $DIC
Definition: goto.php:24
static _lookupType($a_id, $a_reference=false)
lookup object type
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isSkillAssignedToQuestion()

ilSurveySkill::isSkillAssignedToQuestion (   $a_skill_id,
  $a_tref_id 
)

Is skill assigned to any question?

Parameters

Definition at line 205 of file class.ilSurveySkill.php.

References $db, and $ilDB.

Referenced by removeUsagesOfSkills().

206  {
207  $ilDB = $this->db;
208 
209  $set = $ilDB->query(
210  "SELECT * FROM svy_quest_skill " .
211  " WHERE base_skill_id = " . $ilDB->quote($a_skill_id, "integer") .
212  " AND tref_id = " . $ilDB->quote($a_tref_id, "integer") .
213  " AND survey_id = " . $ilDB->quote($this->survey->getId(), "integer")
214  );
215  if ($rec = $ilDB->fetchAssoc($set)) {
216  return true;
217  }
218  return false;
219  }
global $ilDB
+ Here is the caller graph for this function:

◆ read()

ilSurveySkill::read ( )

Read.

Parameters

Definition at line 48 of file class.ilSurveySkill.php.

References $db, $ilDB, and SurveyQuestion\_questionExists().

Referenced by __construct().

49  {
50  $ilDB = $this->db;
51 
52  $set = $ilDB->query(
53  "SELECT * FROM svy_quest_skill " .
54  " WHERE survey_id = " . $ilDB->quote($this->survey->getId(), "integer")
55  );
56 
57  while ($rec = $ilDB->fetchAssoc($set)) {
58  if (SurveyQuestion::_questionExists($rec["q_id"])) {
59  $this->q_skill[$rec["q_id"]] = array("q_id" => $rec["q_id"],
60  "base_skill_id" => $rec["base_skill_id"],
61  "tref_id" => $rec["tref_id"]);
62  }
63  }
64  }
static _questionExists($question_id)
Returns true if the question already exists in the database.
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeQuestionSkillAssignment()

ilSurveySkill::removeQuestionSkillAssignment (   $a_question_id)

Remove question skill assignment.

Parameters
int$a_question_idquestion id

Definition at line 132 of file class.ilSurveySkill.php.

References $db, $ilDB, and removeUsagesOfSkills().

133  {
134  $ilDB = $this->db;
135 
136  // read skills that are assigned to the quesiton
137  $set = $ilDB->query(
138  "SELECT * FROM svy_quest_skill " .
139  " WHERE q_id = " . $ilDB->quote($a_question_id, "integer")
140  );
141  $skills = array();
142  while ($rec = $ilDB->fetchAssoc($set)) {
143  $skills[] = array("skill_id" => $rec["base_skill_id"],
144  "tref_id" => $rec["tref_id"]);
145  }
146 
147  // remove assignment of question
148  $ilDB->manipulate(
149  "DELETE FROM svy_quest_skill WHERE " .
150  " q_id = " . $ilDB->quote($a_question_id, "integer")
151  );
152  unset($this->q_skill[$a_question_id]);
153 
154  $this->removeUsagesOfSkills($skills);
155  }
removeUsagesOfSkills($a_skills)
Remove usages of skills.
global $ilDB
+ Here is the call graph for this function:

◆ removeUsagesOfSkills()

ilSurveySkill::removeUsagesOfSkills (   $a_skills)

Remove usages of skills.

This function checks, if the skills are really not in use anymore

Parameters
arrayarray of arrays with keys "skill_id" and "tref_id"

Definition at line 181 of file class.ilSurveySkill.php.

References isSkillAssignedToQuestion(), and ilSkillUsage\setUsage().

Referenced by removeQuestionSkillAssignment().

182  {
183  $used_skills = array();
184  foreach ($a_skills as $skill) {
185  if ($this->isSkillAssignedToQuestion($skill["skill_id"], $skill["tref_id"])) {
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  foreach ($a_skills as $skill) {
193  if (!in_array($skill["skill_id"] . ":" . $skill["tref_id"], $used_skills)) {
194  ilSkillUsage::setUsage($this->survey->getId(), $skill["skill_id"], $skill["tref_id"], false);
195  }
196  }
197  }
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?
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeAndAddAppraiseeSkills()

ilSurveySkill::writeAndAddAppraiseeSkills ( int  $user_id)

Write appraisee skills and add them to user's competence records.

Parameters
int$user_id

Definition at line 373 of file class.ilSurveySkill.php.

References ilBasicSkill\ACHIEVED, ilPersonalSkill\addPersonalSkill(), determineSkillLevelsForAppraisee(), writeAndAddSelfEvalSkills(), and ilBasicSkill\writeUserSkillLevelStatus().

374  {
375  // write raters evaluation
376  $new_levels = $this->determineSkillLevelsForAppraisee($user_id);
377  foreach ($new_levels as $nl) {
378  if ($nl["new_level_id"] > 0) {
380  $nl["new_level_id"],
381  $user_id,
382  $this->survey->getRefId(),
383  $nl["tref_id"],
385  true,
386  false,
387  "",
388  $nl["next_level_perc"]
389  );
390 
391  if ($nl["tref_id"] > 0) {
392  ilPersonalSkill::addPersonalSkill($user_id, $nl["tref_id"]);
393  } else {
394  ilPersonalSkill::addPersonalSkill($user_id, $nl["base_skill_id"]);
395  }
396  }
397  }
398 
399  // write self evaluation
400  $this->writeAndAddSelfEvalSkills($user_id);
401  }
determineSkillLevelsForAppraisee($a_appraisee_id, $a_self_eval=false)
Determine skill levels for appraisee.
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)
writeAndAddSelfEvalSkills(int $user_id)
Write skills on self evaluation and add them to user&#39;s competence records.
static addPersonalSkill($a_user_id, $a_skill_node_id)
Add personal skill.
+ Here is the call graph for this function:

◆ writeAndAddSelfEvalSkills()

ilSurveySkill::writeAndAddSelfEvalSkills ( int  $user_id)

Write skills on self evaluation and add them to user's competence records.

Parameters
int$user_id

Definition at line 408 of file class.ilSurveySkill.php.

References ilBasicSkill\ACHIEVED, ilPersonalSkill\addPersonalSkill(), determineSkillLevelsForAppraisee(), ilObjSurvey\MODE_360, ilObjSurvey\MODE_SELF_EVAL, and ilBasicSkill\writeUserSkillLevelStatus().

Referenced by writeAndAddAppraiseeSkills().

409  {
410  if ($user_id > 0 && in_array($this->survey->getMode(), [ilObjSurvey::MODE_SELF_EVAL, ilObjSurvey::MODE_360])) {
411  $new_levels = $this->determineSkillLevelsForAppraisee($user_id, true);
412  foreach ($new_levels as $nl) {
413  if ($nl["new_level_id"] > 0) {
415  $nl["new_level_id"],
416  $user_id,
417  $this->survey->getRefId(),
418  $nl["tref_id"],
420  true,
421  1,
422  "",
423  $nl["next_level_perc"]
424  );
425 
426  if ($nl["tref_id"] > 0) {
427  ilPersonalSkill::addPersonalSkill($user_id, $nl["tref_id"]);
428  } else {
429  ilPersonalSkill::addPersonalSkill($user_id, $nl["base_skill_id"]);
430  }
431  }
432  }
433  }
434  }
determineSkillLevelsForAppraisee($a_appraisee_id, $a_self_eval=false)
Determine skill levels for appraisee.
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)
static addPersonalSkill($a_user_id, $a_skill_node_id)
Add personal skill.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $db

ilSurveySkill::$db
protected

◆ $log

ilSurveySkill::$log
protected

Definition at line 24 of file class.ilSurveySkill.php.

◆ $q_skill

ilSurveySkill::$q_skill = array()
protected

Definition at line 19 of file class.ilSurveySkill.php.


The documentation for this class was generated from the following file: