ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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...
 
 writeAppraiseeSkills ($a_app_id)
 Write appraisee skills. More...
 
 writeSelfEvalSkills (int $user_id)
 Write skills on self evaluation. 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: saml.php:7
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 108 of file class.ilSurveySkill.php.

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

109  {
110  $ilDB = $this->db;
111 
112  $ilDB->replace(
113  "svy_quest_skill",
114  array("q_id" => array("integer", $a_question_id)),
115  array(
116  "survey_id" => array("integer", $this->survey->getId()),
117  "base_skill_id" => array("integer", $a_base_skill_id),
118  "tref_id" => array("integer", $a_tref_id)
119  )
120  );
121  $this->q_skill[$a_question_id] = array("q_id" => $a_question_id,
122  "base_skill_id" => $a_base_skill_id,
123  "tref_id" => $a_tref_id);
124 
125  // add usage
126  include_once("./Services/Skill/classes/class.ilSkillUsage.php");
127  ilSkillUsage::setUsage($this->survey->getId(), $a_base_skill_id, $a_tref_id);
128  }
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 337 of file class.ilSurveySkill.php.

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

338  {
339  include_once("./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php");
340  include_once("./Modules/Survey/classes/class.ilSurveySkill.php");
341  $ssk = new ilSurveySkill($this->survey);
342  $question_ids = $ssk->getQuestionsForSkill($a_base_skill, $a_tref_id);
343  $scale_sum = 0;
344  foreach ($question_ids as $q_id) {
346  if (!is_object($q)) {
347  continue;
348  }
349  $cats = $q->getCategories();
350  $max_scale = 0;
351  for ($i = 0; $i <= $cats->getCategoryCount(); $i++) {
352  $c = $cats->getCategory($i);
353  $n = $c->neutral;
354  $s = $c->scale;
355  if (!$c->neutral) {
356  if ($c->scale > $max_scale) {
357  $max_scale = $c->scale;
358  }
359  }
360  }
361  $scale_sum += $max_scale;
362  }
363 
364  return $scale_sum;
365  }
$s
Definition: pwgen.php:45
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: disco.tpl.php:19
+ 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 252 of file class.ilSurveySkill.php.

References $l, $ld, $results, $s, $t, $title, getAllAssignedSkillsAsOptions(), and getQuestionsForSkill().

Referenced by writeAppraiseeSkills(), and writeSelfEvalSkills().

253  {
254  $skills = array();
255 
256  // get all skills
257  $opts = $this->getAllAssignedSkillsAsOptions();
258  foreach ($opts as $k => $title) {
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  $finished_ids = $this->survey->getFinishedIdsForAppraiseeId($a_appraisee_id, true);
274  } else {
275  $finished_id = $this->survey->getFinishedIdForAppraiseeIdAndRaterId($a_appraisee_id, $a_appraisee_id);
276  if ($finished_id > 0) {
277  $finished_ids = array($finished_id);
278  }
279  }
280 
281  if (!sizeof($finished_ids)) {
282  $finished_ids = array(-1);
283  }
284 
285  $results = $this->survey->getUserSpecificResults($finished_ids);
286  $this->log->debug("Finished IDS: " . print_r($finished_ids, true));
287  foreach ($skills as $k => $s) {
288  $q_ids = $this->getQuestionsForSkill($s["base_skill_id"], $s["tref_id"]);
289  $this->log->debug("Skill: " . $s["base_skill_id"] . ":" . $s["tref_id"] . ", Questions: " . implode(",", $q_ids));
290  $mean_sum = 0;
291  foreach ($q_ids as $q_id) {
292  $qmean = 0;
293  if (is_array($results[$q_id])) {
294  $cnt = 0;
295  $sum = 0;
296  foreach ($results[$q_id] as $uid => $answer) { // answer of user $uid for question $q_id
297  // $answer has the scale values as keys and the answer texts as values.
298  // In case of single choice this is an array with one key => value pair.
299  // For multiple choice questions (currently not supported for being used for competences)
300  // multiple elements may be in the array (in the future).
301  $scale_values = array_keys($answer); // scale values of the answer
302  $this->log->debug("User answer (scale values): " . print_r($scale_values, true));
303  $sum += array_sum($scale_values);
304  $cnt += sizeof($scale_values); // nr of answers (always one in the case of single choice)
305  }
306  if ($cnt > 0) {
307  $qmean = $sum / $cnt;
308  }
309  $this->log->debug("MEAN: " . $qmean);
310  }
311  $mean_sum += $qmean;
312  $this->log->debug("MEAN SUM: " . $mean_sum);
313  }
314  $skills[$k]["mean_sum"] = $mean_sum;
315 
316  include_once("./Modules/Survey/classes/class.ilSurveySkillThresholds.php");
317  $skthr = new ilSurveySkillThresholds($this->survey);
318  $thresholds = $skthr->getThresholds();
319  foreach ($skills[$k]["level_data"] as $l) {
320  $t = $thresholds[$l["id"]][$s["tref_id"]];
321  if ($t > 0 && $mean_sum >= $t) {
322  $skills[$k]["new_level"] = $l["title"];
323  $skills[$k]["new_level_id"] = $l["id"];
324  }
325  }
326  }
327  return $skills;
328  }
$s
Definition: pwgen.php:45
Skill tresholds for 360 surveys.
$ld
Definition: langwiz.php:244
getAllAssignedSkillsAsOptions()
Get skill for question.
global $l
Definition: afr.php:30
$results
Definition: svg-scanner.php:47
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 235 of file class.ilSurveySkill.php.

References ilSkillTreeNode\_lookupTitle().

Referenced by determineSkillLevelsForAppraisee().

236  {
237  $skills = array();
238  include_once("./Services/Skill/classes/class.ilBasicSkill.php");
239  foreach ($this->q_skill as $sk) {
240  $skills[$sk["base_skill_id"] . ":" . $sk["tref_id"]] =
241  ilBasicSkill::_lookupTitle($sk["base_skill_id"]);
242  }
243  return $skills;
244  }
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 88 of file class.ilSurveySkill.php.

References $s.

Referenced by determineSkillLevelsForAppraisee().

89  {
90  $q_ids = array();
91  foreach ($this->q_skill as $q_id => $s) {
92  if ($s["base_skill_id"] == $a_base_skill_id &&
93  $s["tref_id"] == $a_tref_id) {
94  $q_ids[] = $q_id;
95  }
96  }
97  return $q_ids;
98  }
$s
Definition: pwgen.php:45
+ 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 74 of file class.ilSurveySkill.php.

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

◆ handleQuestionDeletion()

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

Remove question skill assignment.

Parameters
int$a_question_idquestion id

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

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

Referenced by SurveyQuestion\delete().

166  {
167  global $DIC;
168 
169  $ilDB = $DIC->database();
170  if (ilObject::_lookupType($a_obj_id) == "svy") {
171  // mantis 11691
172  include_once './Modules/Survey/classes/class.ilObjSurvey.php';
173  $svy = new ilObjSurvey($a_obj_id, false);
174  $svy_skill = new ilSurveySkill($svy);
175  $svy_skill->removeQuestionSkillAssignment($a_question_id);
176  }
177  }
global $DIC
Definition: saml.php:7
Skill/Competence handling in surveys.
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 212 of file class.ilSurveySkill.php.

References $db, and $ilDB.

Referenced by removeUsagesOfSkills().

213  {
214  $ilDB = $this->db;
215 
216  $set = $ilDB->query(
217  "SELECT * FROM svy_quest_skill " .
218  " WHERE base_skill_id = " . $ilDB->quote($a_skill_id, "integer") .
219  " AND tref_id = " . $ilDB->quote($a_tref_id, "integer") .
220  " AND survey_id = " . $ilDB->quote($this->survey->getId(), "integer")
221  );
222  if ($rec = $ilDB->fetchAssoc($set)) {
223  return true;
224  }
225  return false;
226  }
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  include_once("./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php");
58 
59  while ($rec = $ilDB->fetchAssoc($set)) {
60  if (SurveyQuestion::_questionExists($rec["q_id"])) {
61  $this->q_skill[$rec["q_id"]] = array("q_id" => $rec["q_id"],
62  "base_skill_id" => $rec["base_skill_id"],
63  "tref_id" => $rec["tref_id"]);
64  }
65  }
66  }
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 135 of file class.ilSurveySkill.php.

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

136  {
137  $ilDB = $this->db;
138 
139  // read skills that are assigned to the quesiton
140  $set = $ilDB->query(
141  "SELECT * FROM svy_quest_skill " .
142  " WHERE q_id = " . $ilDB->quote($a_question_id, "integer")
143  );
144  $skills = array();
145  while ($rec = $ilDB->fetchAssoc($set)) {
146  $skills[] = array("skill_id" => $rec["base_skill_id"],
147  "tref_id" => $rec["tref_id"]);
148  }
149 
150  // remove assignment of question
151  $ilDB->manipulate(
152  "DELETE FROM svy_quest_skill WHERE " .
153  " q_id = " . $ilDB->quote($a_question_id, "integer")
154  );
155  unset($this->q_skill[$a_question_id]);
156 
157  $this->removeUsagesOfSkills($skills);
158  }
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 185 of file class.ilSurveySkill.php.

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

Referenced by removeQuestionSkillAssignment().

186  {
187  $used_skills = array();
188  foreach ($a_skills as $skill) {
189  if ($this->isSkillAssignedToQuestion($skill["skill_id"], $skill["tref_id"])) {
190  $used_skills[] = $skill["skill_id"] . ":" . $skill["tref_id"];
191  }
192  }
193  reset($a_skills);
194 
195  // now remove all usages that have been confirmed
196  include_once("./Services/Skill/classes/class.ilSkillUsage.php");
197  //var_dump($a_skills);
198  //var_dump($used_skills); exit;
199  foreach ($a_skills as $skill) {
200  if (!in_array($skill["skill_id"] . ":" . $skill["tref_id"], $used_skills)) {
201  ilSkillUsage::setUsage($this->survey->getId(), $skill["skill_id"], $skill["tref_id"], false);
202  }
203  }
204  }
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:

◆ writeAppraiseeSkills()

ilSurveySkill::writeAppraiseeSkills (   $a_app_id)

Write appraisee skills.

Parameters
int$user_id

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

References ilBasicSkill\ACHIEVED, determineSkillLevelsForAppraisee(), writeSelfEvalSkills(), and ilBasicSkill\writeUserSkillLevelStatus().

373  {
374  // write raters evaluation
375  $new_levels = $this->determineSkillLevelsForAppraisee($a_app_id);
376  foreach ($new_levels as $nl) {
377  if ($nl["new_level_id"] > 0) {
379  $nl["new_level_id"],
380  $a_app_id,
381  $this->survey->getRefId(),
382  $nl["tref_id"],
384  true
385  );
386  }
387  }
388 
389  // write self evaluation
390  $this->writeSelfEvalSkills($a_app_id);
391  }
writeSelfEvalSkills(int $user_id)
Write skills on self evaluation.
determineSkillLevelsForAppraisee($a_appraisee_id, $a_self_eval=false)
Determine skill levels for appraisee.
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.
+ Here is the call graph for this function:

◆ writeSelfEvalSkills()

ilSurveySkill::writeSelfEvalSkills ( int  $user_id)

Write skills on self evaluation.

Parameters
int$user_id

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

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

Referenced by writeAppraiseeSkills().

399  {
400  if ($user_id > 0 && in_array($this->survey->getMode(), [ilObjSurvey::MODE_SELF_EVAL, ilObjSurvey::MODE_360])) {
401  $new_levels = $this->determineSkillLevelsForAppraisee($user_id, true);
402  foreach ($new_levels as $nl) {
403  if ($nl["new_level_id"] > 0) {
405  $nl["new_level_id"],
406  $user_id,
407  $this->survey->getRefId(),
408  $nl["tref_id"],
410  true,
411  1
412  );
413  }
414  }
415  }
416  }
determineSkillLevelsForAppraisee($a_appraisee_id, $a_self_eval=false)
Determine skill levels for appraisee.
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.
+ 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: