ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.assErrorTextGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once './Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
5require_once './Modules/TestQuestionPool/interfaces/interface.ilGuiQuestionScoringAdjustable.php';
6require_once './Modules/TestQuestionPool/interfaces/interface.ilGuiAnswerScoringAdjustable.php';
7
8require_once './Modules/Test/classes/inc.AssessmentConstants.php';
9
25{
34 public function __construct($id = -1)
35 {
36 parent::__construct();
37 include_once "./Modules/TestQuestionPool/classes/class.assErrorText.php";
38 $this->object = new assErrorText();
39 $this->setErrorMessage($this->lng->txt("msg_form_save_error"));
40 if ($id >= 0)
41 {
42 $this->object->loadFromDb($id);
43 }
44 }
45
54 function writePostData($always = false)
55 {
56 $hasErrors = (!$always) ? $this->editQuestion(true) : false;
57 if (!$hasErrors)
58 {
59 require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
64 return 0;
65 }
66 return 1;
67 }
68
70 {
71 if (is_array( $_POST['errordata']['key'] ))
72 {
73 $this->object->flushErrorData();
74 foreach ($_POST['errordata']['key'] as $idx => $val)
75 {
76 $this->object->addErrorData( $val,
77 $_POST['errordata']['value'][$idx],
78 $_POST['errordata']['points'][$idx]
79 );
80 }
81 }
82 }
83
85 {
86 $questiontext = $_POST["question"];
87 $this->object->setQuestion( $questiontext );
88 $this->object->setErrorText( $_POST["errortext"] );
89 $points_wrong = str_replace( ",", ".", $_POST["points_wrong"] );
90 if (strlen( $points_wrong ) == 0)
91 $points_wrong = -1.0;
92 $this->object->setPointsWrong( $points_wrong );
93
94 if (!$this->object->getSelfAssessmentEditingMode())
95 {
96 $this->object->setTextSize( $_POST["textsize"] );
97 }
98 }
99
107 public function editQuestion($checkonly = FALSE)
108 {
109 $save = $this->isSaveCommand();
110 $this->getQuestionTemplate();
111
112 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
113 $form = new ilPropertyFormGUI();
114 $form->setFormAction($this->ctrl->getFormAction($this));
115 $form->setTitle($this->outQuestionType());
116 $form->setMultipart(FALSE);
117 $form->setTableWidth("100%");
118 $form->setId("orderinghorizontal");
119
120 $this->addBasicQuestionFormProperties( $form );
121
122 $this->populateQuestionSpecificFormPart( $form );
123
124 if (count($this->object->getErrorData()) || $checkonly)
125 {
126 $this->populateAnswerSpecificFormPart( $form );
127 }
128
129 $this->populateTaxonomyFormSection($form);
130
131 $form->addCommandButton("analyze", $this->lng->txt('analyze_errortext'));
132 $this->addQuestionFormCommandButtons($form);
133
134 $errors = false;
135
136 if ($save)
137 {
138 $form->setValuesByPost();
139 $errors = !$form->checkInput();
140 $form->setValuesByPost(); // again, because checkInput now performs the whole stripSlashes handling and we need this if we don't want to have duplication of backslashes
141 if ($errors) $checkonly = false;
142 }
143
144 if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
145 return $errors;
146 }
147
153 {
155 $header->setTitle( $this->lng->txt( "errors_section" ) );
156 $form->addItem( $header );
157
158 include_once "./Modules/TestQuestionPool/classes/class.ilErrorTextWizardInputGUI.php";
159 $errordata = new ilErrorTextWizardInputGUI($this->lng->txt( "errors" ), "errordata");
160 $errordata->setKeyName( $this->lng->txt( 'text_wrong' ) );
161 $errordata->setValueName( $this->lng->txt( 'text_correct' ) );
162 $errordata->setValues( $this->object->getErrorData() );
163 $form->addItem( $errordata );
164
165 // points for wrong selection
166 $points_wrong = new ilNumberInputGUI($this->lng->txt( "points_wrong" ), "points_wrong");
167 $points_wrong->allowDecimals(true);
168 $points_wrong->setValue( $this->object->getPointsWrong() );
169 $points_wrong->setInfo( $this->lng->txt( "points_wrong_info" ) );
170 $points_wrong->setSize( 6 );
171 $points_wrong->setRequired( true );
172 $form->addItem( $points_wrong );
173 return $form;
174 }
175
181 {
182 // errortext
183 $errortext = new ilTextAreaInputGUI($this->lng->txt( "errortext" ), "errortext");
184 $errortext->setValue( $this->object->getErrorText() );
185 $errortext->setRequired( TRUE );
186 $errortext->setInfo( $this->lng->txt( "errortext_info" ) );
187 $errortext->setRows( 10 );
188 $errortext->setCols( 80 );
189 $form->addItem( $errortext );
190
191 if (!$this->object->getSelfAssessmentEditingMode())
192 {
193 // textsize
194 $textsize = new ilNumberInputGUI($this->lng->txt( "textsize" ), "textsize");
195 $textsize->setValue( strlen( $this->object->getTextSize() ) ? $this->object->getTextSize() : 100.0 );
196 $textsize->setInfo( $this->lng->txt( "textsize_errortext_info" ) );
197 $textsize->setSize( 6 );
198 $textsize->setSuffix( "%" );
199 $textsize->setMinValue( 10 );
200 $textsize->setRequired( true );
201 $form->addItem( $textsize );
202 }
203 }
204
208 public function analyze()
209 {
210 $this->writePostData(true);
211 $this->object->setErrorData($this->object->getErrorsFromText($_POST['errortext']));
212 $this->editQuestion();
213 }
214
234 $active_id, $pass = NULL,
235 $graphicalOutput = FALSE,
236 $result_output = FALSE,
237 $show_question_only = TRUE,
238 $show_feedback = FALSE,
239 $show_correct_solution = FALSE,
240 $show_manual_scoring = FALSE,
241 $show_question_text = TRUE
242 )
243 {
244 // get the solution of the user for the active pass or from the last pass if allowed
245 $template = new ilTemplate("tpl.il_as_qpl_errortext_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
246
247 $selections = array();
248 if (($active_id > 0) && (!$show_correct_solution)) {
249
250 /* Retrieve tst_solutions entries. */
251 $reached_points = $this->object->getReachedPoints($active_id, $pass);
252 $solutions =& $this->object->getSolutionValues($active_id, $pass);
253 if (is_array($solutions)) {
254 foreach ($solutions as $solution) {
255 array_push($selections, (int) $solution['value1']);
256 }
257 $errortext_value = join(",", $selections);
258 }
259 }
260 else {
261 $selections = $this->object->getBestSelection();
262 $reached_points = $this->object->getPoints();
263 }
264
265 if ($result_output) {
266 $resulttext = ($reached_points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
267 $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $reached_points));
268 }
269
270 if ($this->object->getTextSize() >= 10)
271 $template->setVariable("STYLE", " style=\"font-size: " . $this->object->getTextSize() . "%;\"");
272
273 if ($show_question_text==true)
274 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
275
276 $errortext = $this->object->createErrorTextOutput($selections, $graphicalOutput, $show_correct_solution, false);
277
278 $template->setVariable("ERRORTEXT", $errortext);
279 $questionoutput = $template->get();
280
281 $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
282
283 $feedback = '';
284 if($show_feedback)
285 {
286 if( !$this->isTestPresentationContext() )
287 {
288 $fb = $this->getGenericFeedbackOutput($active_id, $pass);
289 $feedback .= strlen($fb) ? $fb : '';
290 }
291
292 $fb = $this->getSpecificFeedbackOutput($active_id, $pass);
293 $feedback .= strlen($fb) ? $fb : '';
294 }
295 if (strlen($feedback))
296 {
297 $cssClass = ( $this->hasCorrectSolution($active_id, $pass) ?
299 );
300
301 $solutiontemplate->setVariable("ILC_FB_CSS_CLASS", $cssClass);
302 $solutiontemplate->setVariable("FEEDBACK", $this->object->prepareTextareaOutput( $feedback, true ));
303 }
304
305 $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
306
307 $solutionoutput = $solutiontemplate->get();
308 if (!$show_question_only)
309 {
310 // get page object output
311 $solutionoutput = $this->getILIASPage($solutionoutput);
312 }
313 return $solutionoutput;
314 }
315
316 function getPreview($show_question_only = FALSE, $showInlineFeedback = false)
317 {
318 $selections = is_object($this->getPreviewSession()) ? (array)$this->getPreviewSession()->getParticipantsSolution() : array();
319
320 $template = new ilTemplate("tpl.il_as_qpl_errortext_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
321 if ($this->object->getTextSize() >= 10) $template->setVariable("STYLE", " style=\"font-size: " . $this->object->getTextSize() . "%;\"");
322 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
323 $errortext = $this->object->createErrorTextOutput($selections);
324 $template->setVariable("ERRORTEXT", $errortext);
325 $template->setVariable("ERRORTEXT_ID", "qst_" . $this->object->getId());
326 $questionoutput = $template->get();
327 if (!$show_question_only)
328 {
329 // get page object output
330 $questionoutput = $this->getILIASPage($questionoutput);
331 }
332 $this->tpl->addJavascript("./Modules/TestQuestionPool/templates/default/errortext.js");
333 return $questionoutput;
334 }
335
337 $active_id,
338 // hey: prevPassSolutions - will be always available from now on
339 $pass,
340 // hey.
341 $is_postponed = FALSE,
342 $use_post_solutions = FALSE,
343 $show_feedback = FALSE
344 )
345 {
346 // generate the question output
347 $template = new ilTemplate("tpl.il_as_qpl_errortext_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
348 if ($active_id)
349 {
350 // hey: prevPassSolutions - obsolete due to central check
351 #$solutions = NULL;
352 #include_once "./Modules/Test/classes/class.ilObjTest.php";
353 #if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
354 #{
355 # if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
356 #}
357 $solutions = $this->getTestOutputSolutions($active_id, $pass);
358 // hey.
359 }
360 $errortext_value = "";
361 $selections = array();
362 if (is_array($solutions))
363 {
364 foreach ($solutions as $solution)
365 {
366 array_push($selections, $solution['value1']);
367 }
368 $errortext_value = join(",", $selections);
369 }
370 if ($this->object->getTextSize() >= 10) $template->setVariable("STYLE", " style=\"font-size: " . $this->object->getTextSize() . "%;\"");
371 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
372 $errortext = $this->object->createErrorTextOutput($selections);
373 $this->ctrl->setParameterByClass($this->getTargetGuiClass(), 'errorvalue', '');
374 $template->setVariable("ERRORTEXT", $errortext);
375 $template->setVariable("ERRORTEXT_ID", "qst_" . $this->object->getId());
376 $template->setVariable("ERRORTEXT_VALUE", $errortext_value);
377
378 $questionoutput = $template->get();
379 if (!$show_question_only)
380 {
381 // get page object output
382 $questionoutput = $this->getILIASPage($questionoutput);
383 }
384 $this->tpl->addJavascript("./Modules/TestQuestionPool/templates/default/errortext.js");
385 $questionoutput = $template->get();
386 $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
387 return $pageoutput;
388 }
389
398 {
399 global $rbacsystem, $ilTabs;
400
401 $ilTabs->clearTargets();
402
403 $this->ctrl->setParameterByClass("ilAssQuestionPageGUI", "q_id", $_GET["q_id"]);
404 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
405 $q_type = $this->object->getQuestionType();
406
407 if (strlen($q_type))
408 {
409 $classname = $q_type . "GUI";
410 $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
411 $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
412 }
413
414 if ($_GET["q_id"])
415 {
416 if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
417 {
418 // edit page
419 $ilTabs->addTarget("edit_page",
420 $this->ctrl->getLinkTargetByClass("ilAssQuestionPageGUI", "edit"),
421 array("edit", "insert", "exec_pg"),
422 "", "", $force_active);
423 }
424
425 $this->addTab_QuestionPreview($ilTabs);
426 }
427
428 $force_active = false;
429 if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
430 {
431 $url = "";
432 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
433 // edit question properties
434 $ilTabs->addTarget("edit_question",
435 $url,
436 array("editQuestion", "save", "saveEdit", "analyze", "originalSyncForm"),
437 $classname, "", $force_active);
438 }
439
440 // add tab for question feedback within common class assQuestionGUI
441 $this->addTab_QuestionFeedback($ilTabs);
442
443 // add tab for question hint within common class assQuestionGUI
444 $this->addTab_QuestionHints($ilTabs);
445
446 // add tab for question's suggested solution within common class assQuestionGUI
447 $this->addTab_SuggestedSolution($ilTabs, $classname);
448
449 // Assessment of questions sub menu entry
450 if ($_GET["q_id"])
451 {
452 $ilTabs->addTarget("statistics",
453 $this->ctrl->getLinkTargetByClass($classname, "assessment"),
454 array("assessment"),
455 $classname, "");
456 }
457
458 $this->addBackTab($ilTabs);
459 }
460
461 function getSpecificFeedbackOutput($active_id, $pass)
462 {
463 $selection = $this->object->getBestSelection(false);
464
465 if( !$this->object->feedbackOBJ->specificAnswerFeedbackExists(array_keys($selection)) )
466 {
467 return '';
468 }
469
470 $feedback = '<table class="test_specific_feedback"><tbody>';
471
472 $elements = array();
473 foreach(preg_split("/[\n\r]+/", $this->object->errortext) as $line)
474 {
475 $elements = array_merge( $elements, preg_split("/\s+/", $line));
476 }
477
478 $matchedIndexes = array();
479
480 $i = 0;
481 foreach ($selection as $index => $answer)
482 {
483 $element = array();
484 foreach($answer as $answerPartIndex)
485 {
486 $element[] = $elements[$answerPartIndex];
487 }
488
489 $element = implode(' ', $element);
490 $element = str_replace(array('((', '))', '#'), array('', '', ''), $element);
491
492 $ordinal = $index + 1;
493
494 $feedback .= '<tr>';
495
496 $feedback .= '<td class="text-nowrap">' . $ordinal . '. ' . $element . ':</td>';
497
498 foreach ($this->object->getErrorData() as $idx => $ans)
499 {
500 if( isset($matchedIndexes[$idx]) )
501 {
502 continue;
503 }
504
505 if ( preg_match('/'.preg_quote($ans->text_wrong, '/').'/', $element) )
506 {
507 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
508 $this->object->getId(), $idx
509 );
510
511 $feedback .= '<td>'. $fb . '</td>';
512
513 $matchedIndexes[$idx] = $idx;
514
515 break;
516 }
517 }
518
519 $feedback .= '</tr>';
520 }
521
522 $feedback .= '</tbody></table>';
523
524 return $this->object->prepareTextareaOutput($feedback, TRUE);
525 }
526
537 {
538 return array();
539 }
540
551 {
552 return array();
553 }
554
563 public function getAggregatedAnswersView($relevant_answers)
564 {
565 $errortext = $this->object->getErrorText();
566
567 $passdata = array(); // Regroup answers into units of passes.
568 foreach($relevant_answers as $answer_chosen)
569 {
570 $passdata[$answer_chosen['active_fi'].'-'. $answer_chosen['pass']][$answer_chosen['value2']][] = $answer_chosen['value1'];
571 }
572
573 $html = '';
574 foreach($passdata as $key => $pass)
575 {
576 $passdata[$key] = $this->object->createErrorTextOutput($pass);
577 $html .= $passdata[$key] . '<hr /><br />';
578 }
579
580 return $html;
581 }
582}
$_GET["client_id"]
The assErrorTextGUI class encapsulates the GUI representation for error text questions.
setQuestionTabs()
Sets the ILIAS tabs for this question type.
getAggregatedAnswersView($relevant_answers)
Returns an html string containing a question specific representation of the answers so far given in t...
getTestOutput( $active_id, $pass, $is_postponed=FALSE, $use_post_solutions=FALSE, $show_feedback=FALSE)
getAfterParticipationSuppressionQuestionPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
populateQuestionSpecificFormPart(ilPropertyFormGUI $form)
getPreview($show_question_only=FALSE, $showInlineFeedback=false)
writeQuestionSpecificPostData(ilPropertyFormGUI $form)
Extracts the question specific values from $_POST and applies them to the data object.
writeAnswerSpecificPostData(ilPropertyFormGUI $form)
Extracts the answer specific values from $_POST and applies them to the data object.
getAfterParticipationSuppressionAnswerPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
populateAnswerSpecificFormPart(ilPropertyFormGUI $form)
writePostData($always=false)
Evaluates a posted edit form and writes the form data in the question object.
__construct($id=-1)
assErrorTextGUI constructor
getSolutionOutput( $active_id, $pass=NULL, $graphicalOutput=FALSE, $result_output=FALSE, $show_question_only=TRUE, $show_feedback=FALSE, $show_correct_solution=FALSE, $show_manual_scoring=FALSE, $show_question_text=TRUE)
Get the question solution output.
editQuestion($checkonly=FALSE)
Creates an output of the edit form for the question.
getSpecificFeedbackOutput($active_id, $pass)
Returns the answer specific feedback for the question.
analyze()
Parse the error text.
Class for error text questions.
Basic GUI class for assessment questions.
populateTaxonomyFormSection(ilPropertyFormGUI $form)
setErrorMessage($errormessage)
addTab_QuestionHints(ilTabsGUI $tabs)
adds the hints tab to ilTabsGUI
addQuestionFormCommandButtons($form)
Add the command buttons of a question properties form.
getILIASPage($html="")
Returns the ILIAS Page around a question.
getQuestionTemplate()
get question template
writePostData()
Evaluates a posted edit form and writes the form data in the question object.
addTab_SuggestedSolution(ilTabsGUI $tabs, $classname)
getTestOutputSolutions($activeId, $pass)
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="")
output question page
addBackTab(ilTabsGUI $ilTabs)
hasCorrectSolution($activeId, $passIndex)
addTab_QuestionFeedback(ilTabsGUI $tabs)
adds the feedback tab to ilTabsGUI
addBasicQuestionFormProperties($form)
Add basic question form properties: assessment: title, author, description, question,...
addTab_QuestionPreview(ilTabsGUI $tabsGUI)
getGenericFeedbackOutput($active_id, $pass)
Returns the answer specific feedback for the question.
This class represents a key value pair wizard property in a property form.
This class represents a section header in a property form.
This class represents a number property in a property form.
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
special template class to simplify handling of ITX/PEAR
This class represents a text area property in a property form.
$_POST['username']
Definition: cron.php:12
$html
Definition: example_001.php:87
$header
Interface ilGuiAnswerScoringAdjustable.
Interface ilGuiQuestionScoringAdjustable.
$url
Definition: shib_logout.php:72
$errors