ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTestNewScoringGUI.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 
24 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
25 include_once "./Modules/Test/classes/class.ilTestServiceGUI.php";
26 
37 {
38 
48 function ilTestNewScoringGUI($a_object)
49 {
50  parent::ilTestServiceGUI($a_object);
51  $this->ctrl->saveParameter($this, "active_id");
52  $this->ctrl->saveParameter($this, "userfilter");
53  $this->ctrl->saveParameter($this, "pass");
54 }
55 
59 function &executeCommand()
60 {
61  $cmd = $this->ctrl->getCmd();
62  $next_class = $this->ctrl->getNextClass($this);
63 
64  if (strlen($cmd) == 0)
65  {
66  $this->ctrl->redirect($this, "scoreQuestion");
67  }
68  $cmd = $this->getCommand($cmd);
69  switch($next_class)
70  {
71  default:
72  $ret =& $this->$cmd();
73  break;
74  }
75  return $ret;
76 }
77 
82 function scoreQuestion()
83 {
84  global $ilUser, $ilDB, $ilErr, $tpl;
85 
86  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
87  include_once "./Modules/Test/classes/class.ilTestNewScoring.php";
88 
89  $qtypes = array();
90  array_push($qtypes, "assClozeTest", "assMultipleChoice", "assNumeric", "assTextSubset", "assSingleChoice", "assMatchingQuestion", "assOrderingQuestion", "assOrderingHorizontal");
91  $obj_scoring = new ilTestNewScoring($this->object);
92  $questionId = $_POST["id"];
93  $command = $_GET["command"];
94  if ($_REQUEST["export"])
95  {
96  $testquestions =& $this->object->getTestQuestions();
97  $qnum = 1;
98  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_stat_questions.html", "Modules/Test/newscoring");
99 
100  foreach ($testquestions as $question)
101  {
102  $obj_scoring->loadTempTable($question["question_id"]);
103  $qtype = assQuestion::_getQuestionType($question["question_id"]);
104  if (in_array($qtype, $qtypes))
105  {
106  $output .= $this->getQuestionStat($question["question_id"], FALSE, $qnum++);
107  }
108  }
109  $this->tpl->setVariable("QUESTION_EXPORT", $output);
110  }
111  else
112  {
113  if ($_GET["sync"]) // original-synchronisation
114  {
115  if ($_GET["sync"] == "yes")
116  ilUtil::sendInfo("Die Frage wurde im Test und im Fragenpool gespeichert und alle Testteilnehmer wurden neu bewertet.");
117  elseif ($_GET["sync"] == "no")
118  ilUtil::sendInfo("Die Frage wurde im Test gespeichert und alle Testteilnehmer wurden neu bewertet.");
119  $command = "list";
120  }
121  // Question save and participants score
122 
123  $save_qst = 2;
124  if ($_REQUEST["score"])
125  {
126  $obj_scoring->saveQuestionAndUserResults($_POST);
127  $question = $this->object->createQuestionGUI("", $_POST["id"]);
128  $qtype = assQuestion::_getQuestionType($_POST["id"]);
129  if ($qtype == "assOrderingQuestion")
130  {
131  $save_qst = $obj_scoring->saveOrderingItemPoints($_POST);
132  }
133  $originalexists = $question->object->_questionExists($question->object->original_id);
134  if ($originalexists && assQuestion::_isWriteable($question->object->original_id, $ilUser->getId()))
135  {
136  if (($qtype == "assOrderingQuestion") && !$save_qst)
137  {
138  $command = "list";
139  }
140  else
141  {
142  $this->ctrl->setParameter($this, "q_id", $_POST["id"]);
143  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_qpl_sync_original.html", "Modules/TestQuestionPool");
144  $this->tpl->setCurrentBlock("adm_content");
145  $this->tpl->setVariable("BUTTON_YES", $this->lng->txt("yes"));
146  $this->tpl->setVariable("BUTTON_NO", $this->lng->txt("no"));
147  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
148  $this->tpl->setVariable("TEXT_SYNC", $this->lng->txt("confirm_sync_questions"));
149  $this->tpl->parseCurrentBlock();
150  }
151  }
152  elseif($save_qst)
153  {
154  ilUtil::sendInfo("Die Frage wurde im Test gespeichert und alle Testteilnehmer wurden neu bewertet.");
155  }
156  $this->ctrl->setParameter($this, "q_id", $qid);
157  $this->ctrl->setParameter($this, "command", "list");
158  }
159  if ($_REQUEST["add"] || $_REQUEST["del"])
160  {
161  $question = $this->object->createQuestionGUI("", $_POST["id"]);
162  $qtype = assQuestion::_getQuestionType($_POST["id"]);
163 
164  if ($_REQUEST["add"] && $_POST["chb_add"])
165  {
166  $checkb = $_POST["chb_add"];
167  $par = $_POST["params1"];
168  $hint = $this->lng->txt("regrading_new_answers_hint");
169  $command = "add";
170  }
171  elseif ($_REQUEST["del"] && ($_POST["chb_del"] || $_POST["chb_del_subset"]))
172  {
173  if ($_POST["chb_del"])
174  $checkb = $_POST["chb_del"];
175  else
176  $checkb = $_POST["chb_del_subset"];
177  $par = $_POST["params2"];
178  $hint = "Um die Punkte zu aktualisieren, druecken Sie auf Frage und Punkte speichern.";
179  $command = "del";
180  }
181  $cnt = 0;
182  if (count($checkb))
183  foreach($par as $key => $value)
184  {
185  if ($checkb[$key] == "on")
186  {
187  if (preg_match("/(\d+)_(\d+)_(\d+)/", $value, $matches))
188 
189  if ($command == "add")
190  {
191  if (preg_match("/(\d+)_(\d+)_(\d+)/", $value, $matches))
192  $gap_id = $matches[1];
193  $order = $matches[2];
194  $solutionId = $matches[3];
195 
196  $answer_item = $obj_scoring->addQuestionAnswer($solutionId, $qtype);
197  if ($qtype == "assClozeTest")
198  {
199  include_once "./Modules/TestQuestionPool/classes/class.assAnswerCloze.php";
200  $answer = new assAnswerCloze($answer_item, 0, $order);
201  $question->object->gaps[$gap_id]->addItem($answer);
202  }
203  if ($qtype == "assTextSubset")
204  {
205  $order = $matches[2] + $cnt;
206  $question->object->addAnswer($answer_item, 0, $order);
207  }
208  }
209  if ($command == "del")
210  {
211  if (preg_match("/(\d+)_(\d+)/", $value, $matches))
212  $gap_id = $matches[1];
213  $order = $matches[2];
214 
215  if ($qtype == "assClozeTest")
216  {
217  $question->object->gaps[$gap_id]->deleteItem($order);
218  }
219  if ($qtype == "assTextSubset")
220  {
221  $order = $order - $cnt;
222  $question->object->deleteAnswer($order);
223  }
224  }
225  $cnt++;
226  }
227  }
228  $question->object->saveToDb();
229 
230  $this->ctrl->setParameter($this, "q_id", $_POST["id"]);
231  $this->ctrl->setParameter($this, "command", "list");
232  $this->ctrl->setParameter($this, "warn", $hint);
233  $this->ctrl->redirect($this, "scoreQuestion");
234  }
235  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_newscoring_question.html", "Modules/Test/newscoring");
236 
237  $this->tpl->setVariable("FORMACTION", $this->ctrl->getLinkTarget($this, "scoreQuestion"));
238  if ($_GET["warn"])
239  $this->tpl->setVariable("WARNING", $_GET["warn"]);
240 
241  // display question list
242 
243  if ($command == "" OR ($_REQUEST["back"] > ""))
244  {
245  if ($this->object->isRandomTest())
246  {
247  $this->tpl->setCurrentBlock("qlist");
248  $this->tpl->setVariable("HINT", $this->lng->txt("regrading_random"));
249  $this->tpl->ParseCurrentBlock();
250  return;
251  }
252  $data =& $this->object->getCompleteEvaluationData(FALSE);
253  if (count($data->getParticipants()) == 0)
254  {
255  ilUtil::sendInfo($this->lng->txt("tst_no_evaluation_data"), true);
256  return;
257  }
258  $this->tpl->setCurrentBlock("qlist");
259  $this->tpl->setVariable("HINT", "<em>" . $this->lng->txt("regrading_hint") . "</em>");
260  $this->tpl->setVariable("HEADING", $this->lng->txt("regrading_list_of_questions"));
261  $this->tpl->setVariable("TXT_NUMBER", $this->lng->txt("regrading_number"));
262  $this->tpl->setVariable("TXT_QUESTION_TITLE", $this->lng->txt("regrading_question_title"));
263  $this->tpl->setVariable("TXT_QUESTION_TYPE", $this->lng->txt("regrading_question_type"));
264  $this->tpl->setVariable("TXT_SHOW_QUESTION_STATS", $this->lng->txt("regrading_show_question_stats"));
265  $testquestions =& $this->object->getTestQuestions();
266  $qnum = 1;
267  foreach ($testquestions as $quest)
268  {
269  $questionId = $quest["question_id"];
270  $qtype = assQuestion::_getQuestionType($questionId);
271  if (in_array($qtype, $qtypes))
272  {
273  $questionTitle = $quest["title"];
274  $question = $this->object->createQuestionGUI("", $questionId);
275  $this->tpl->setCurrentBlock("question");
276  $this->tpl->setVariable("QNUM", $qnum++);
277  $this->tpl->setVariable("TITLE", $questionTitle);
278  $href= $this->ctrl->getLinkTarget($this, "scoreQuestion")."&command=list&q_id=".$questionId;
279  $this->tpl->setVariable("HREF",$href);
280  $this->tpl->setVariable("QTYPE",$this->lng->txt($qtype));
281  $this->tpl->ParseCurrentBlock();
282  }
283  }
284  $this->tpl->ParseCurrentBlock();
285  }
286  elseif ($command == "list") // display selected question
287  {
288  $q_id = $_GET["q_id"] ? $_GET["q_id"] : $questionId;
289  $obj_scoring->loadTempTable($q_id);
290  $qtype = assQuestion::_getQuestionType($q_id);
291 
292  if ($qtype == "assOrderingQuestion")
293  {
294  if ($save_qst == 0)
295  {
296  $mess = $this->lng->txt("regrading_maxpoints_error");
297  }
298  if ($save_qst == 2)
299  {
300  $itemPoints = $obj_scoring->loadOrderingItemPoints($q_id);
301  if (!$itemPoints[0])
302  {
303  $mess = $this->lng->txt("regrading_newstyle_help");
304  }
305  else
306  {
307  $mess = $this->lng->txt("regrading_oldstyle_help");
308  }
309  }
310  }
311  ilUtil::sendInfo($mess);
312  $out = $this->getQuestionStat($q_id, true);
313  $this->tpl->setVariable("QUESTION", $out);
314  }
315  }
316 }
317 
323 function getQuestionStat($qid, $save = FALSE, $qnum = "")
324 {
325  global $ilUser, $ilDB;
326 
327  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
328  include_once "./Modules/Test/classes/class.ilTestNewScoring.php";
329 
330  $obj_scoring = new ilTestNewScoring($this->object);
331  $questionId = $qid;
332 
333  // show QuestionText
334 
335  $question = $this->object->createQuestionGUI("", $questionId);
336  $qtype = assQuestion::_getQuestionType($questionId);
337  $qText = $question->getSolutionOutput("", NULL, FALSE, TRUE, FALSE);
338  $qText = preg_replace("/<pre>/", "", $qText);
339  $qText = preg_replace("/<\/pre>/", "", $qText);
340 
341  $template = new ilTemplate("tpl.il_as_tst_stat_question.html", TRUE, TRUE, "Modules/Test/newscoring");
342  if (!$save)
343  {
344  $qnum .= ". ";
345  }
346  $title = $qnum. $question->object->getTitle(). " - ". $this->lng->txt($qtype);
347 
348  $template->setCurrentBlock("qtable");
349  $template->setVariable("QUESTION_HEADING", $title);
350  $template->setVariable("TXT_QUESTION_PREVIEW", $this->lng->txt("regrading_question_preview"));
351  $template->setVariable("TXT_CORRECT_ANSWERS_AND_POINTS", $this->lng->txt("regrading_correct_answers_and_points"));
352  $template->setVariable("TXT_STATS_USER_ANSWERS", $this->lng->txt("regrading_stats_user_answers"));
353  $template->setVariable("QUESTION_TEXT", $qText);
354  $template->setVariable("QUESTION_ID", $questionId);
355  switch ($qtype)
356  {
357  case "assClozeTest":
358  $template->setCurrentBlock("identical_scoring");
359  $identical_scoring = $question->object->getIdenticalScoring();
360  if ($identical_scoring) $template->setVariable("CHECKED_IDENT_SCORING", " checked=\"checked\"");
361  $template->setVariable("TEXT_IDENT_SCORING", $this->lng->txt("identical_scoring"));
362 
363  // Add textgap rating options
364 
365  $textgap_options = array(
366  array("ci", $this->lng->txt("cloze_textgap_case_insensitive")),
367  array("cs", $this->lng->txt("cloze_textgap_case_sensitive")),
368  array("l1", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "1")),
369  array("l2", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "2")),
370  array("l3", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "3")),
371  array("l4", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "4")),
372  array("l5", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "5"))
373  );
374  $textgap_rating = $question->object->getTextgapRating();
375  $template->setVariable("TEXTGAP_RATING", "Text-Bewertung");
376  foreach ($textgap_options as $textgap_option)
377  {
378  $template->setCurrentBlock("textgap_rating");
379  $template->setVariable("TEXTGAP_VALUE", $textgap_option[0]);
380  $template->setVariable("TEXTGAP_TEXT", $textgap_option[1]);
381  if (strcmp($textgap_rating, $textgap_option[0]) == 0)
382  {
383  $template->setVariable("SELECTED_TEXTGAP_VALUE", " selected=\"selected\"");
384  }
385  $template->parseCurrentBlock();
386  }
387  $template->ParseCurrentBlock();
388  $gapTextArray=array();
389  $clozeText = $question->object->getClozeText();
390  $gapTextArray = split ("/gap", $clozeText);
391  $textgap = 0;
392  $cnt1=0;
393  $cnt2=0;
394  foreach ($question->object->gaps as $gap_id => $value)
395  {
396  $origItemCount = 0;
397  $gap_text = strstr($gapTextArray[$gap_id], "[gap]");
398  while($pos = strpos($gap_text, ","))
399  {
400  $origItemCount++;
401  $gap_text = strstr(",", $gap_text);
402  }
403  $answerarray = array();
404  for ($order = 0; $order < $question->object->gaps[$gap_id]->getItemCount(); $order++)
405  {
406  // correct answers
407 
408  $answer = $question->object->gaps[$gap_id]->getItem($order);
409 
410  // numeric-gap
411 
412  if ($question->object->gaps[$gap_id]->getType() == CLOZE_NUMERIC)
413  {
414  $template->setCurrentBlock("correct_ranges");
415  $template->setVariable("LOWNAME",$gap_id."_1");
416  $template->setVariable("UPPERNAME", $gap_id."_2");
417  $template->setVariable("TEXT_RANGE_LOWER_LIMIT", ($gap_id+1).".2. ".$this->lng->txt("range_lower_limit"));
418  $template->setVariable("VALUE_LOWER_LIMIT", " value=\"" . $answer->getLowerBound() . "\"");
419  $template->setVariable("TEXT_RANGE_UPPER_LIMIT", ($gap_id+1).".3. ".$this->lng->txt("range_upper_limit"));
420  $template->setVariable("VALUE_UPPER_LIMIT", " value=\"" . $answer->getUpperBound() . "\"");
421  $template->setVariable("VALUENAME", $gap_id."_3"); // Wert angeben
422  $template->setVariable("TEXT_VALUE", ($gap_id+1).".1. ".$this->lng->txt("value"));
423  $template->setVariable("VALUE_VALUE", " value=\"" . $answer->getAnswertext() . "\"");
424  $template->setVariable("POINTNAME",$gap_id."_0");
425  $template->setVariable("TEXT_POINTS", ($gap_id+1).".4. ". $this->lng->txt("points"));
426  $template->setVariable("VALUE_POINTS", "\"". " value=\"" . $answer->getPoints() . "\"");
427  $template->parseCurrentBlock();
428  }
429  else // textgap
430  {
431  $template->setCurrentBlock("correct_cloze");
432  $template->setVariable("CORRECT_ANSWER", ($gap_id+1). ".". ($order+1). ".". $answer->getAnswertext());
433  $template->setVariable("POINTS", $answer->getPoints());
434  $template->setVariable("FIELDNAME", $gap_id."_".$order);
435  if (($question->object->gaps[$gap_id]->getType() == CLOZE_TEXT) && ($order > $origItemCount))
436  {
437  $template->setVariable("PARAMS", ($gap_id."_".$order));
438  $template->setVariable("DELETE", "0");
439  $template->setVariable("COUNTER", $cnt1++);
440  $textgap = 1;
441  }
442  $template->ParseCurrentBlock();
443  array_push($answerarray, $answer->getAnswertext()."_".$answer->getPoints());
444  }
445  }
446  //Statistik of UserAnswers (from temp_solutions!!!)
447 
448  $values = array();
449  $values = ilTestNewScoring::getSolutionStat($questionId, $gap_id);
450  foreach ($values as $value2)
451  {
452  $template->setCurrentBlock("answer_stat");
453  $userans = $value2;
454  $stat = ilTestNewScoring::getUserAnswers($questionId, $userans, $gap_id);
455  $template->setVariable("STUD", ($gap_id+1). ". (". $stat["count"]. ") ". $userans);
456  $solutionId = $stat["val"];
457 
458  // SelectGap
459 
460  if ($question->object->gaps[$gap_id]->getType() == CLOZE_SELECT)
461  {
462  for ($order = 0; $order < $question->object->gaps[$gap_id]->getItemCount(); $order++)
463  {
464  $answer = $question->object->gaps[$gap_id]->getItem($order);
465  if ($answer->getOrder() == $userans)
466  {
467  $userans_val = $answer->getAnswertext();
468  $template->setVariable("STUD", ($gap_id+1). ".". ($order+1). ". (". $stat["count"]. ") ". $userans_val);
469  }
470  }
471  }
472  // TextGap
473 
474  if ($userans AND ($question->object->gaps[$gap_id]->getType() == CLOZE_TEXT))
475  {
476  // Check with Levenshtein etc, $answerarray contains the correct answers (answerText_Points)
477 
478  $OK = $obj_scoring->checkLevenstein($question, $answerarray, $userans);
479  if (!$OK )
480  {
481  $maxItem = $question->object->gaps[$gap_id]->getItemCount();
482  $template->setVariable("PARAMS", ($gap_id."_".$maxItem. "_".$solutionId));
483  $template->setVariable("ADD", "0");
484  $template->setVariable("COUNTER", $cnt2++);
485  }
486  $textgap = 1;
487  }
488  $template->ParseCurrentBlock();
489 
490  } // end of User-Statistik
491  }
492  break;
493 
494  case "assMatchingQuestion":
495  $order = 1;
496  foreach ($question->object->matchingpairs as $key => $value)
497  {
498  $template->setCurrentBlock("correct_matching");
499  $question->object->loadFromDb($questionId);
500  $matching_obj = $question->object->matchingpairs[$key];
501  $template->setVariable("ORDER", $order);
502  $template->setVariable("POINTS", $matching_obj->__get("points"));
503 
504  $definition = $matching_obj->__get("definition");
505  $term = $matching_obj->__get("term");
506 
507  if (strlen($definition->text))
508  {
509  $template->setVariable("DEFINITION", $definition->text);
510  }
511  elseif (strlen($definition->picture))
512  {
513  $def_thumb = $question->object->getImagePathWeb(). $question->object->getThumbPrefix() . $definition->picture;
514  $template->setVariable("DEFINITION", "<img src=\"$def_thumb\" />");
515  }
516  if (strlen($term->text))
517  {
518  $template->setVariable("TERM", $term->text);
519  }
520  elseif (strlen($term->picture))
521  {
522  $term_thumb = $question->object->getImagePathWeb(). $question->object->getThumbPrefix() . $term->picture;
523  $template->setVariable("TERM", "<img src=\"$term_thumb\" />");
524  }
525  $template->setVariable("TERMID", "0_". $term->identifier);
526  $template->ParseCurrentBlock();
527 
528  // Statistik der Benutzer-Antworten
529 
530  if (strlen($definition->text))
531  {
532  $def = $definition->text;
533  }
534  elseif (strlen($definition->picture))
535  {
536  $def = $definition->picture;
537  }
538  $temp = $obj_scoring->getSolutionStat($questionId, $def);
539  $order2 = 0;
540  foreach ($temp as $val1)
541  {
542  if ($order2 == 0)
543  {
544  $value2 = $val1;
545  $order2++;
546  }
547  else
548  {
549  $stat = $obj_scoring->getUserAnswers($questionId, $val1, $value2);
550  $template->setCurrentBlock("answer_stat");
551  if (!strlen($definition->text) && strlen($definition->picture))
552  {
553  $def = "<img src=\"$def_thumb\" />";
554  }
555  if (strlen($term->text))
556  {
557  $terms = $stat["val"];
558  }
559  elseif (strlen($term->picture))
560  {
561  $terms = "<img src=\"$term_thumb\" />";
562  }
563  if ($terms)
564  {
565  $template->setVariable("STUD", $order. ".". $order2. ". (". $stat["count"]. ") ". $def. "-". $terms);
566  }
567  $template->ParseCurrentBlock();
568  $order2++;
569  }
570  }
571  $order++;
572  }
573  break;
574 
575  case "assOrderingQuestion":
576  case "assOrderingHorizontal":
577 
578  // correct answer
579 
580  $template->setCurrentBlock("correct_ordering");
581 
582  $itemPoints = $obj_scoring->loadOrderingItemPoints($questionId);
583  if ($qtype == "assOrderingHorizontal")
584  {
585  $template->setVariable("CORRECT_HORIZONTAL", $question->object->getOrderText());
586  }
587  else
588  foreach ($question->object->answers as $idx => $answer)
589  {
590  $template->setCurrentBlock("correct_ordering_row");
591  if ($question->object->getOrderingType() == OQ_PICTURES)
592  {
593  $filename = "thumb.".$answer->getAnswertext();
594  $imagepath = $question->object->getImagePathWeb() .$filename;
595  $template->setVariable("CORRECT_ANSWER", "<img src=\"$imagepath\" />");
596  }
597  else
598  {
599  $template->setVariable("CORRECT_ANSWER", $answer->getAnswertext());
600  }
601  $template->setVariable("POSITION", ($idx+1));
602  $template->setVariable("POINTS_TEXTNAME", "0_". ($idx+1));
603  if (count($itemPoints))
604  {
605  $template->setVariable("POINTS_VALUE", $itemPoints[$idx]);
606  }
607  $template->ParseCurrentBlock();
608  }
609  $template->setCurrentBlock("max_points");
610  $maxpoints = $question->object->getMaximumPoints();
611  $template->setVariable("POINTS_TEXTNAME", ("0_0"));
612  $template->setVariable("MAX_POINTS", $maxpoints);
613  $template->ParseCurrentBlock();
614 
615  if ($qtype == "assOrderingQuestion")
616  {
617  foreach ($question->object->answers as $idx => $answer)
618  {
619  // Statistik der Benutzer-Antworten
620 
621  $value1 = $idx;
622  $temp = $obj_scoring->getSolutionStat($questionId, $value1);
623  $template->setCurrentBlock("answer_stat");
624  $cnt = 0;
625  foreach ($temp as $val2)
626  {
627  $stat = $obj_scoring->getUserAnswers($questionId, $value1, $val2);
628  $template->setCurrentBlock("answer_stat");
629  if ($question->object->getOrderingType() == OQ_PICTURES)
630  {
631  $filename = "thumb.".$answer->getAnswertext();
632  $imagepath = $question->object->getImagePathWeb(). $filename;
633  $template->setVariable("STUD", ($value1+1). ". (". $stat["count"]. ") ". $val2. " - ". "<img src=\"$imagepath\" />");
634  }
635  else
636  {
637  $template->setVariable("STUD", ($value1+1). ". (". $stat["count"]. ") ". $val2. " - ". $answer->getAnswertext());
638  }
639  $template->ParseCurrentBlock();
640  }
641  }
642  }
643  else
644  {
645  $temp = $obj_scoring->getSolutionStat($questionId);
646  $template->setCurrentBlock("answer_stat");
647  $template->ParseCurrentBlock();
648  $cnt = 1;
649  foreach ($temp as $val2)
650  {
651  $stat = $obj_scoring->getUserAnswers($questionId, 0, $val2);
652  $template->setCurrentBlock("answer_stat");
653  $val = preg_replace('/{::}/', ' ', $val2);
654  $template->setVariable("STUD", $cnt++. ". (". $stat["count"]. ") ". $val);
655  $template->ParseCurrentBlock();
656  }
657  }
658  break;
659 
660  case "assMultipleChoice":
661  case "assSingleChoice":
662 
663  // korrekte Antworten
664 
665  foreach ($question->object->answers as $answer)
666  {
667  if ($qtype == "assMultipleChoice")
668  {
669  $template->setCurrentBlock("correct_mult");
670  $template->setVariable("POINTS-UNCHECKED", $answer->getPointsUnchecked());
671  $template->setVariable("FIELDNAME_U", "1_".$answer->getOrder());
672  }
673  else
674  {
675  $template->setCurrentBlock("correct_single");
676  }
677  $template->setVariable("CORRECT_ANSWER", ($answer->getOrder()+1). ". ". $answer->getAnswertext());
678  $template->setVariable("POINTS", $answer->getPoints());
679  $template->setVariable("FIELDNAME", "0_".$answer->getOrder());
680  $template->ParseCurrentBlock();
681 
682  // Statistik der Benutzer-Antworten
683 
684  $value1 = $answer->getOrder();
685  $temp = $obj_scoring->getSolutionStat($questionId, $value1);
686  $template->setCurrentBlock("answer_stat");
687  $template->setVariable("STUD", ($value1+1). ". (". count($temp). ") ". $answer->getAnswertext());
688  $template->ParseCurrentBlock();
689  }
690  break;
691 
692  case "assNumeric":
693 
694  // korrekte Antworten
695 
696  $template->setCurrentBlock("correct_ranges");
697  $template->setVariable("TEXT_POINTS", $this->lng->txt("points"));
698  $template->setVariable("VALUE_POINTS", "\"". " value=\"" . $question->object->getPoints() . "\"");
699  $template->setVariable("POINTNAME","0_0");
700  $template->setVariable("LOWNAME","1_0");
701  $template->setVariable("UPPERNAME", "2_0");
702  $template->setVariable("TEXT_RANGE_LOWER_LIMIT", $this->lng->txt("range_lower_limit"));
703  $template->setVariable("VALUE_LOWER_LIMIT", " value=\"" . $question->object->getLowerLimit() . "\"");
704  $template->setVariable("TEXT_RANGE_UPPER_LIMIT", $this->lng->txt("range_upper_limit"));
705  $template->setVariable("VALUE_UPPER_LIMIT", " value=\"" . $question->object->getUpperLimit() . "\"");
706  $template->parseCurrentBlock();
707 
708  // Statistik der Benutzer-Antworten
709 
710  $temp = $obj_scoring->getSolutionStat($questionId);
711  $counter = 1;
712  foreach ($temp as $value1)
713  {
714  $stat = $obj_scoring->getUserAnswers($questionId, $value1);
715  $template->setCurrentBlock("answer_stat");
716  $template->setVariable("STUD", $counter++. ". (". $stat["count"]. ") ". $value1);
717  $template->ParseCurrentBlock();
718  }
719  break;
720 
721  case "assTextSubset":
722 
723  // korrekte Antworten
724  // "allanswers" (new Question-Parameter) needs to be initialized
725 
726  if (!$question->object->allanswers)
727  {
728  $question->object->setAllAnswers(count($question->object->answers));
729  $question->object->saveToDb();
730  }
731  $cnt = 0;
732  foreach ($question->object->answers as $answer)
733  {
734  $template->setCurrentBlock("correct_subset");
735  $template->setVariable("CORRECT_ANSWER", ($answer->getOrder()+1). ". ". $answer->getAnswertext());
736  $template->setVariable("POINTS", $answer->getPoints());
737  $template->setVariable("FIELDNAME", "0_".$answer->getOrder());
738  if (($answer->getOrder()+1) > $question->object->allanswers)
739  {
740  $template->setVariable("PARAMS", ("0_".$answer->getOrder()));
741  $template->setVariable("DELETE", "0");
742  $template->setVariable("COUNTER", $cnt++);
743  }
744  $template->ParseCurrentBlock();
745  }
746 
747  // Add textgap rating options
748 
749  $text_options = array(
750  array("ci", $this->lng->txt("cloze_textgap_case_insensitive")),
751  array("cs", $this->lng->txt("cloze_textgap_case_sensitive")),
752  array("l1", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "1")),
753  array("l2", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "2")),
754  array("l3", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "3")),
755  array("l4", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "4")),
756  array("l5", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "5"))
757  );
758  $text_rating = $question->object->getTextRating();
759  foreach ($text_options as $text_option)
760  {
761  $template->setCurrentBlock("text_rating");
762  $template->setVariable("TEXT_VALUE", $text_option[0]);
763  $template->setVariable("TEXT_TEXT", $text_option[1]);
764  if (strcmp($text_rating, $text_option[0]) == 0)
765  {
766  $template->setVariable("SELECTED_TEXT_VALUE", " selected=\"selected\"");
767  }
768  $template->parseCurrentBlock();
769  }
770 
771  // Statistik der Benutzer-Antworten
772 
773  $temp = $obj_scoring->getSolutionStat($questionId);
774  $cnt = 0;
775  foreach ($temp as $value1)
776  {
777  if (!$value1)
778  continue;
779  $stat = $obj_scoring->getUserAnswers($questionId, $value1);
780 
781  // Check userAnswer with Levenshtein
782 
783  $template->setCurrentBlock("answer_stat");
784  $available_answers =& $question->object->getAvailableAnswers();
785  $index = $question->object->isAnswerCorrect($available_answers, $value1);
786  if ($index !== FALSE)
787  {
788  $template->setVariable("STUD", ($index+1). ". (". $stat["count"]. ") ". $value1);
789  }
790  else
791  {
792  $template->setVariable("STUD", "0. (". $stat["count"]. ") ". $value1);
793  $template->setVariable("PARAMS", ("0_". $question->object->getAnswerCount()."_".$stat["val"]));
794  $template->setVariable("ADD", "0");
795  $template->setVariable("COUNTER", $cnt++);
796  }
797  $template->ParseCurrentBlock();
798  }
799  break;
800 
801  } // end of case
802 
803  $template->ParseCurrentBlock();
804  if ($save)
805  {
806  $template->setVariable("SAVEPOINTS", $this->lng->txt("regrading_save"));
807  if ($textgap || ($qtype == "assTextSubset"))
808  {
809  $template->setVariable("COLSPAN", 1);
810  $template->setVariable("DEL_ANSWER", $this->lng->txt("regrading_remove_answer"));
811  $template->setVariable("ADD_ANSWER", $this->lng->txt("regrading_add_answer"));
812  }
813  else
814  {
815  $template->setVariable("COLSPAN", 3);
816  }
817  }
818  return $template->get();
819 }
820 
825 function sync()
826 {
827  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
828 
829  $question = $this->object->createQuestionGUI("", $_GET["q_id"]);
830  $original_id = $question->object->original_id;
831  if ($original_id)
832  {
833  $question->object->syncWithOriginal();
834  $qtype = assQuestion::_getQuestionType($original_id);
835  if ($qtype == "assClozeTest")
836  {
837  $orig_question = $this->object->createQuestionGUI("", $original_id);
838  $orig_question->object->updateClozeTextFromGaps();
839  $orig_question->object->saveToDb();
840  }
841  }
842  $this->ctrl->setParameter($this, "q_id", $_GET["q_id"]);
843  $this->ctrl->setParameter($this, "sync", "yes");
844  $this->ctrl->redirect($this, "scoreQuestion");
845 }
846 
851 function cancelSync()
852 {
853  $this->ctrl->setParameter($this, "q_id", $_GET["q_id"]);
854  $this->ctrl->setParameter($this, "sync", "no");
855  $this->ctrl->redirect($this, "scoreQuestion");
856 }
857 }
858 ?>