ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTestEvaluationData.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
35 {
42 
48  private $test;
49 
56 
63 
70 
75  var $datasets;
76 
77  public function __sleep()
78  {
79  return array('questionTitles', 'participants', 'statistics', 'arrFilter', 'datasets', 'test');
80  }
81 
87  function __construct($test = "")
88  {
89  $this->participants = array();
90  $this->questionTitles = array();
91  if (is_object($test)) $this->test =& $test;
92  if (is_object($test))
93  {
94  $this->generateOverview();
95  }
96  }
97 
98  function __destruct()
99  {
100  unset($this->participants);
101  $this->participants = array();
102  unset($this->questionTitles);
103  $this->questionTitles = array();
104  unset($this->test);
105  unset($this->statistics);
106  }
107 
108  function generateOverview()
109  {
110  $this->participants = array();
111  global $ilDB;
112  include_once "./Modules/Test/classes/class.ilTestEvaluationPassData.php";
113  include_once "./Modules/Test/classes/class.ilTestEvaluationUserData.php";
114  $result = $ilDB->queryF("SELECT usr_data.usr_id, usr_data.firstname, usr_data.lastname, usr_data.title, usr_data.login, " .
115  "tst_pass_result.* FROM tst_pass_result, tst_active " .
116  "LEFT JOIN usr_data ON tst_active.user_fi = usr_data.usr_id " .
117  "WHERE tst_active.active_id = tst_pass_result.active_fi " .
118  "AND tst_active.test_fi = %s " .
119  "ORDER BY usr_data.lastname, usr_data.firstname, tst_pass_result.active_fi, tst_pass_result.pass, tst_pass_result.tstamp",
120  array('integer'),
121  array($this->getTest()->getTestId())
122  );
123  $pass = NULL;
124  $checked = array();
125  $thissets = 0;
126  while ($row = $ilDB->fetchAssoc($result))
127  {
128  $thissets++;
129  $remove = FALSE;
130  if (!$this->participantExists($row["active_fi"]))
131  {
132  $this->addParticipant($row["active_fi"], new ilTestEvaluationUserData($this->getTest()->getPassScoring()));
133  $this->getParticipant($row["active_fi"])->setName($this->getTest()->buildName($row["usr_id"], $row["firstname"], $row["lastname"], $row["title"]));
134  $this->getParticipant($row["active_fi"])->setLogin($row["login"]);
135  $this->getParticipant($row["active_fi"])->setUserID($row["usr_id"]);
136  }
137  if (!is_object($this->getParticipant($row["active_fi"])->getPass($row["pass"])))
138  {
140  $pass->setPass($row["pass"]);
141  $this->getParticipant($row["active_fi"])->addPass($row["pass"], $pass);
142  }
143  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setReachedPoints($row["points"]);
144  if ($row["questioncount"] == 0)
145  {
147  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setMaxPoints($data['points']);
148  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setQuestionCount($data['count']);
149  }
150  else
151  {
152  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setMaxPoints($row["maxpoints"]);
153  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setQuestionCount($row["questioncount"]);
154  }
155  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setNrOfAnsweredQuestions($row["answeredquestions"]);
156  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setWorkingTime($row["workingtime"]);
157  }
158  }
159 
160  function unsetParticipant($active_id)
161  {
162  unset($this->participants[$active_id]);
163  }
164 
165  function getCompleteDataForParticipant($active_id)
166  {
167  global $ilDB;
168 
169  $result = $ilDB->queryF("SELECT tst_test_result.*, qpl_questions.original_id, qpl_questions.title questiontitle, " .
170  "qpl_questions.points maxpoints " .
171  "FROM tst_test_result, qpl_questions, tst_active " .
172  "WHERE tst_active.active_id = tst_test_result.active_fi " .
173  "AND qpl_questions.question_id = tst_test_result.question_fi " .
174  "AND tst_active.test_fi = %s AND tst_active.active_id = %s " .
175  "ORDER BY tst_active.active_id, tst_test_result.pass, tst_test_result.tstamp",
176  array('integer', 'integer'),
177  array($this->getTest()->getTestId(), $active_id)
178  );
179  $pass = NULL;
180  $checked = array();
181  $datasets = 0;
182  while ($row = $ilDB->fetchAssoc($result))
183  {
184  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->addAnsweredQuestion($row["question_fi"], $row["maxpoints"], $row["points"]);
185  }
186 
187  if ($this->getTest()->isRandomTest())
188  {
189  for ($testpass = 0; $testpass <= $this->getParticipant($active_id)->getLastPass(); $testpass++)
190  {
191  $ilDB->setLimit($this->getTest()->getQuestionCount(), 0);
192  $result = $ilDB->queryF("SELECT tst_test_rnd_qst.sequence, tst_test_rnd_qst.question_fi, qpl_questions.original_id, " .
193  "tst_test_rnd_qst.pass, qpl_questions.points, qpl_questions.title " .
194  "FROM tst_test_rnd_qst, qpl_questions " .
195  "WHERE tst_test_rnd_qst.question_fi = qpl_questions.question_id " .
196  "AND tst_test_rnd_qst.pass = %s " .
197  "AND tst_test_rnd_qst.active_fi = %s ORDER BY tst_test_rnd_qst.sequence",
198  array('integer','integer'),
199  array($testpass, $active_id)
200  );
201  if ($result->numRows())
202  {
203  while ($row = $ilDB->fetchAssoc($result))
204  {
205  $tpass = array_key_exists("pass", $row) ? $row["pass"] : 0;
206  $this->getParticipant($active_id)->addQuestion($row["original_id"] ? $row["original_id"] : $row["question_fi"], $row["question_fi"], $row["points"], $row["sequence"], $tpass);
207  $this->addQuestionTitle($row["question_fi"], $row["title"]);
208  }
209  }
210  }
211  }
212  else
213  {
214  $result = $ilDB->queryF("SELECT tst_test_question.sequence, tst_test_question.question_fi, " .
215  "qpl_questions.points, qpl_questions.title, qpl_questions.original_id " .
216  "FROM tst_test_question, tst_active, qpl_questions " .
217  "WHERE tst_test_question.question_fi = qpl_questions.question_id " .
218  "AND tst_active.active_id = %s AND tst_active.test_fi = tst_test_question.test_fi ORDER BY tst_test_question.sequence",
219  array('integer'),
220  array($active_id)
221  );
222  if ($result->numRows())
223  {
224  $questionsbysequence = array();
225  while ($row = $ilDB->fetchAssoc($result))
226  {
227  $questionsbysequence[$row["sequence"]] = $row;
228  }
229  $seqresult = $ilDB->queryF("SELECT * FROM tst_sequence WHERE active_fi = %s",
230  array('integer'),
231  array($active_id)
232  );
233  while ($seqrow = $ilDB->fetchAssoc($seqresult))
234  {
235  $questionsequence = unserialize($seqrow["sequence"]);
236  foreach ($questionsequence as $sidx => $seq)
237  {
238  $qsid = $questionsbysequence[$seq]["original_id"] ? $questionsbysequence[$seq]["original_id"] : $questionsbysequence[$seq]["question_fi"];
239  $this->getParticipant($active_id)->addQuestion($qsid, $questionsbysequence[$seq]["question_fi"], $questionsbysequence[$seq]["points"], $sidx + 1, $seqrow["pass"]);
240  $this->addQuestionTitle($questionsbysequence[$seq]["question_fi"], $questionsbysequence[$seq]["title"]);
241  }
242  }
243  }
244  }
245 
246  if ($this->getTest()->getECTSOutput())
247  {
248  $passed_array =& $this->getTest()->getTotalPointsPassedArray();
249  }
250 
251  $percentage = $this->getParticipant($active_id)->getReachedPointsInPercent();
252  $mark = $this->getTest()->getMarkSchema()->getMatchingMark($percentage);
253  if (is_object($mark))
254  {
255  $this->getParticipant($active_id)->setMark($mark->getShortName());
256  $this->getParticipant($active_id)->setMarkOfficial($mark->getOfficialName());
257  $this->getParticipant($active_id)->setPassed($mark->getPassed());
258  }
259  if ($this->getTest()->getECTSOutput())
260  {
261  $ects_mark = $this->getTest()->getECTSGrade($passed_array, $this->getParticipant($active_id)->getReached(), $this->getParticipant($active_id)->getMaxPoints());
262  $this->getParticipant($active_id)->setECTSMark($ects_mark);
263  }
264  $visitingTime =& $this->getTest()->getVisitTimeOfParticipant($active_id);
265  $this->getParticipant($active_id)->setFirstVisit($visitingTime["firstvisit"]);
266  $this->getParticipant($active_id)->setLastVisit($visitingTime["lastvisit"]);
267  }
268 
269  function getTest()
270  {
271  return $this->test;
272  }
273 
274  function setTest($test)
275  {
276  $this->test =& $test;
277  }
278 
280  {
281  $this->datasets = $datasets;
282  }
283 
284  function getDatasets()
285  {
286  return $this->datasets;
287  }
288 
289  function addQuestionTitle($question_id, $question_title)
290  {
291  $this->questionTitles[$question_id] = $question_title;
292  }
293 
294  function getQuestionTitles()
295  {
296  return $this->questionTitles;
297  }
298 
299  function getQuestionTitle($question_id)
300  {
301  if (array_key_exists($question_id, $this->questionTitles))
302  {
303  return $this->questionTitles[$question_id];
304  }
305  else
306  {
307  return "";
308  }
309  }
310 
312  {
313  include_once "./Modules/Test/classes/class.ilTestStatistics.php";
314  $this->statistics = new ilTestStatistics($this);
315  }
316 
317  function getParticipants()
318  {
319  if (count($this->arrFilter))
320  {
321  $filteredParticipants = array();
322  $courseids = array();
323  $groupids = array();
324  global $ilDB;
325  if (array_key_exists('group', $this->arrFilter))
326  {
327  $ids = ilObject::_getIdsForTitle($this->arrFilter['group'], 'grp', true);
328  $groupids = array_merge($groupids, $ids);
329  }
330  if (array_key_exists('course', $this->arrFilter))
331  {
332  $ids = ilObject::_getIdsForTitle($this->arrFilter['course'], 'crs', true);
333  $courseids = array_merge($courseids, $ids);
334  }
335  foreach ($this->participants as $active_id => $participant)
336  {
337  $remove = FALSE;
338  if (array_key_exists('name', $this->arrFilter))
339  {
340  if (!(strpos(strtolower($participant->getName()), strtolower($this->arrFilter['name'])) !== FALSE)) $remove = TRUE;
341  }
342  if (!$remove)
343  {
344  if (array_key_exists('group', $this->arrFilter))
345  {
346  include_once "./Services/Membership/classes/class.ilParticipants.php";
347  $groups = ilParticipants::_getMembershipByType($participant->getUserID(), "grp");
348  $foundfilter = FALSE;
349  if (count(array_intersect($groupids, $groups))) $foundfilter = TRUE;
350  if (!$foundfilter) $remove = TRUE;
351  }
352  }
353  if (!$remove)
354  {
355  if (array_key_exists('course', $this->arrFilter))
356  {
357  include_once "./Services/Membership/classes/class.ilParticipants.php";
358  $courses = ilParticipants::_getMembershipByType($participant->getUserID(), "crs");
359  $foundfilter = FALSE;
360  if (count(array_intersect($courseids, $courses))) $foundfilter = TRUE;
361  if (!$foundfilter) $remove = TRUE;
362  }
363  }
364  if (!$remove)
365  {
366  if (array_key_exists('active_id', $this->arrFilter))
367  {
368  if ($active_id != $this->arrFilter['active_id']) $remove = TRUE;
369  }
370  }
371  if (!$remove) $filteredParticipants[$active_id] = $participant;
372  }
373  return $filteredParticipants;
374  }
375  else
376  {
377  return $this->participants;
378  }
379  }
380 
381  function resetFilter()
382  {
383  $this->arrFilter = array();
384  }
385 
386  /*
387  * Set an output filter for getParticipants
388  *
389  * @param string $by name, course, group
390  * @param string $text Filter text
391  */
392  function setFilter($by, $text)
393  {
394  $this->arrFilter = array($by => $text);
395  }
396 
397  /*
398  * Set an output filter for getParticipants
399  *
400  * @param array $arrFilter filter values
401  */
403  {
404  $this->arrFilter = $arrFilter;
405  }
406 
407  function addParticipant($active_id, $participant)
408  {
409  $this->participants[$active_id] = $participant;
410  }
411 
412  function &getParticipant($active_id)
413  {
414  return $this->participants[$active_id];
415  }
416 
417  function participantExists($active_id)
418  {
419  return array_key_exists($active_id, $this->participants);
420  }
421 
422  function removeParticipant($active_id)
423  {
424  unset($this->participants[$active_id]);
425  }
426 
427  function &getStatistics()
428  {
429  return $this->statistics;
430  }
431 
432  function getParticipantIds()
433  {
434  return array_keys($this->participants);
435  }
436 
437  public static function _getTimeStatsForParticipant($active_id, $pass = null)
438  {
439  global $ilDB;
440  if (is_numeric($pass))
441  {
442  $result = $ilDB->queryF("SELECT * FROM tst_times WHERE active_fi = %s AND pass = %s",
443  array('integer', 'integer'),
444  array($active_id, $pass)
445  );
446  }
447  else
448  {
449  $result = $ilDB->queryF("SELECT * FROM tst_times WHERE active_fi = %s",
450  array('integer'),
451  array($active_id)
452  );
453  }
455  }
456 
457  public static function _getTimeStatsForTest($test_id)
458  {
459  global $ilDB;
460  $result = $ilDB->queryF("SELECT tst_times.* FROM tst_times, tst_active WHERE tst_times.active_fi = tst_active.active_id AND tst_active.test_fi = %s",
461  array('integer'),
462  array($test_id)
463  );
465  }
466 
467  public static function _getTimeStatsForQueryResult($result)
468  {
469  global $ilDB;
470  $data = array();
471  while ($row = $ilDB->fetchAssoc($result))
472  {
473  if (!array_key_exists($row['question_fi'], $data))
474  {
475  $data[$row['question_fi']] = array();
476  }
477  if (!array_key_exists($row['pass'], $data[$row['question_fi']]))
478  {
479  $data[$row['question_fi']][$row['pass']] = array();
480  }
481  if (!array_key_exists($row['active_fi'], $data[$row['question_fi']][$row['pass']]))
482  {
483  $data[$row['question_fi']][$row['pass']][$row['active_fi']] = array();
484  }
485  preg_match("/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/", $row["started"], $matches);
486  $epoch_1 = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
487  preg_match("/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/", $row["finished"], $matches);
488  $epoch_2 = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
489  $timeInSeconds = ($epoch_2 - $epoch_1);
490  array_push($data[$row['question_fi']][$row['pass']][$row['active_fi']], $timeInSeconds);
491  }
492  return $data;
493  }
494 } // END ilTestEvaluationData
495 
496 ?>