ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTestSkillEvaluation.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Modules/Test/classes/class.ilTestSkillQuestionAssignmentList.php';
5 require_once 'Modules/Test/classes/class.ilTestSkillLevelThresholdList.php';
6 require_once 'Services/Skill/classes/class.ilBasicSkill.php';
7 
15 {
19  private $db;
20 
24  private $testOBJ;
25 
30 
35 
39  private $questions;
40 
45 
50 
55 
60 
62  {
63  $this->db = $db;
64  $this->testOBJ = $testOBJ;
65 
66  $this->skillQuestionAssignmentList = new ilTestSkillQuestionAssignmentList($this->db);
67  $this->skillQuestionAssignmentList->setTestId($this->testOBJ->getTestId());
68 
69  $this->skillLevelThresholdList = new ilTestSkillLevelThresholdList($this->db);
70  $this->skillLevelThresholdList->setTestId($this->testOBJ->getTestId());
71 
72  $this->questions = array();
73  $this->maxPointsByQuestion = array();
74  }
75 
76  public function init()
77  {
78  $this->skillQuestionAssignmentList->loadFromDb();
79  $this->skillLevelThresholdList->loadFromDb();
80 
81  $this->initTestQuestionData();
82 
83  return $this;
84  }
85 
86  public function evaluate($activeId, $pass, $userId)
87  {
88  $this->reset();
89 
90  $this->initTestResultData($activeId, $pass);
91 
92  $this->drawUpSkillPointAccounts();
93  $this->evaluateSkillPointAccounts($userId);
94  }
95 
96  public function trigger($activeId, $pass, $userId)
97  {
98  $this->evaluate($activeId, $pass, $userId);
99 
100  $this->triggerSkillService();
101  }
102 
103  public function getReachedSkillLevels()
104  {
106  }
107 
108  private function reset()
109  {
110  $this->reachedPointsByQuestion = array();
111  $this->skillPointAccounts = array();
112  $this->reachedSkillLevels = array();
113  }
114 
115  private function initTestQuestionData()
116  {
117  foreach($this->testOBJ->getTestQuestions() as $question)
118  {
119  $this->questions[] = $question['question_id'];
120 
121  $this->maxPointsByQuestion[ $question['question_id'] ] = $question['points'];
122  }
123  }
124 
125  private function initTestResultData($activeId, $pass)
126  {
127  $testResults = $this->testOBJ->getTestResult($activeId, $pass, true);
128  foreach($testResults as $key => $result)
129  {
130  if($key === 'pass' || $key === 'test') // note: key int 0 IS == 'pass' or 'buxtehude'
131  {
132  continue;
133  }
134 
135  $this->reachedPointsByQuestion[ $result['qid'] ] = $result['reached'];
136  }
137  }
138 
139  private function drawUpSkillPointAccounts()
140  {
141  foreach($this->questions as $questionId)
142  {
143  $maxTestPoints = $this->maxPointsByQuestion[$questionId];
144  $reachedTestPoints = $this->reachedPointsByQuestion[$questionId];
145 
146  $assignments = $this->skillQuestionAssignmentList->getAssignmentsByQuestionId($questionId);
147 
148  foreach($assignments as $assignment)
149  {
150  $reachedSkillPoints = $this->calculateReachedSkillPoints(
151  $assignment->getSkillPoints(), $maxTestPoints, $reachedTestPoints
152  );
153 
155  $assignment->getSkillBaseId(), $assignment->getSkillTrefId(), $reachedSkillPoints
156  );
157  }
158  }
159  }
160 
161  private function calculateReachedSkillPoints($skillPoints, $maxTestPoints, $reachedTestPoints)
162  {
163  if( $reachedTestPoints < 0 )
164  {
165  $reachedTestPoints = 0;
166  }
167 
168  $factor = 0;
169 
170  if( $maxTestPoints > 0 )
171  {
172  $factor = $reachedTestPoints / $maxTestPoints;
173  }
174 
175  return ($skillPoints * $factor);
176  }
177 
178  private function bookToSkillPointAccount($skillBaseId, $skillTrefId, $reachedSkillPoints)
179  {
180  $skillKey = $skillBaseId.':'.$skillTrefId;
181 
182  if( !isset($this->skillPointAccounts[$skillKey]) )
183  {
184  $this->skillPointAccounts[$skillKey] = 0;
185  }
186 
187  $this->skillPointAccounts[$skillKey] += $reachedSkillPoints;
188  }
189 
190  private function evaluateSkillPointAccounts($userId)
191  {
192  foreach($this->skillPointAccounts as $skillKey => $skillPoints)
193  {
194  list($skillBaseId, $skillTrefId) = explode(':', $skillKey);
195 
196  $skill = new ilBasicSkill($skillBaseId);
197  $levels = $skill->getLevelData();
198 
199  $reachedLevelId = null;
200 
201  foreach($levels as $level)
202  {
203  $threshold = $this->skillLevelThresholdList->getThreshold($skillBaseId, $skillTrefId, $level['id']);
204 
205  if( !($threshold instanceof ilTestSkillLevelThreshold) || !$threshold->getThreshold() )
206  {
207  continue;
208  }
209 
210  $reachedLevelId = $level['id'];
211 
212  if( $skillPoints <= $threshold->getThreshold() )
213  {
214  break;
215  }
216  }
217 
218  if( $reachedLevelId )
219  {
220  $this->reachedSkillLevels[] = array(
221  'usrId' => $userId, 'sklBaseId' => $skillBaseId,
222  'sklTrefId' => $skillTrefId, 'sklLevelId' => $reachedLevelId
223  );
224  }
225  }
226  }
227 
228  private function triggerSkillService()
229  {
230  foreach($this->getReachedSkillLevels() as $reachedSkillLevel)
231  {
233  $reachedSkillLevel['usrId'], $reachedSkillLevel['sklBaseId'],
234  $reachedSkillLevel['sklTrefId'], $reachedSkillLevel['sklLevelId']
235  );
236  }
237  }
238 
239  private function invokeSkillLevelTrigger($userId, $skillBaseId, $skillTrefId, $skillLevelId)
240  {
242  $skillLevelId, $userId, $this->testOBJ->getRefId(), $skillTrefId, ilBasicSkill::ACHIEVED, true
243  );
244 
245  //mail('bheyser@databay.de', "trigger skill $skillBaseId:$skillTrefId level $skillLevelId for user $userId", '');
246  }
247 
249  {
250  $reachedLevels = array();
251 
252  foreach($this->getReachedSkillLevels() as $reachedLevel)
253  {
254  $reachedLevels[$reachedLevel['sklBaseId']] = array(
255  $reachedLevel['sklTrefId'] => $reachedLevel['sklLevelId']
256  );
257  }
258 
259  return $reachedLevels;
260  }
261 
263  {
264  $uniqueSkills = array();
265 
266  foreach($this->skillQuestionAssignmentList->getUniqueAssignedSkills() as $skill)
267  {
268  $uniqueSkills[] = array(
269  'base_skill_id' => (int)$skill['skill_base_id'],
270  'tref_id' => (int)$skill['skill_tref_id']
271  );
272  }
273 
274  return $uniqueSkills;
275  }
276 
277  public function isAssignedSkill($skillBaseId, $skillTrefId)
278  {
279  $this->skillQuestionAssignmentList->isAssignedSkill($skillBaseId, $skillTrefId);
280  }
281 
283  {
284  $matchingSkillProfiles = array();
285 
286  include_once("./Services/Skill/classes/class.ilSkillProfile.php");
287  $usersProfiles = ilSkillProfile::getProfilesOfUser($usrId);
288 
289  foreach ($usersProfiles as $profileData)
290  {
291  $profile = new ilSkillProfile($profileData['id']);
292  $assignedSkillLevels = $profile->getSkillLevels();
293 
294  foreach($assignedSkillLevels as $assignedSkillLevel)
295  {
296  $skillBaseId = $assignedSkillLevel['base_skill_id'];
297  $skillTrefId = $assignedSkillLevel['tref_id'];
298 
299  if( $this->skillQuestionAssignmentList->isAssignedSkill($skillBaseId, $skillTrefId) )
300  {
301  $matchingSkillProfiles[$profileData['id']] = $profile->getTitle();
302  }
303  }
304  }
305 
306  return $matchingSkillProfiles;
307  }
308 
309  public function noProfileMatchingAssignedSkillExists($usrId, $availableSkillProfiles)
310  {
311  $noProfileMatchingSkills = $this->skillQuestionAssignmentList->getUniqueAssignedSkills();
312 
313  foreach($availableSkillProfiles as $skillProfileId => $skillProfileTitle)
314  {
315  $profile = new ilSkillProfile($skillProfileId);
316  $assignedSkillLevels = $profile->getSkillLevels();
317 
318  foreach($assignedSkillLevels as $assignedSkillLevel)
319  {
320  $skillBaseId = $assignedSkillLevel['base_skill_id'];
321  $skillTrefId = $assignedSkillLevel['tref_id'];
322 
323  if( $this->skillQuestionAssignmentList->isAssignedSkill($skillBaseId, $skillTrefId) )
324  {
325  unset($noProfileMatchingSkills["{$skillBaseId}:{$skillTrefId}"]);
326  }
327  }
328  }
329 
330  return count($noProfileMatchingSkills);
331  }
332 }