ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.assOrderingHorizontalGUI.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/Test/classes/inc.AssessmentConstants.php';
7
22{
31 function __construct($id = -1)
32 {
33 parent::__construct();
34 include_once "./Modules/TestQuestionPool/classes/class.assOrderingHorizontal.php";
35 $this->object = new assOrderingHorizontal();
36 $this->setErrorMessage($this->lng->txt("msg_form_save_error"));
37 if ($id >= 0)
38 {
39 $this->object->loadFromDb($id);
40 }
41 }
42
43 function getCommand($cmd)
44 {
45 return $cmd;
46 }
47
55 public function writePostData($always = false)
56 {
57 $hasErrors = (!$always) ? $this->editQuestion(true) : false;
58 if (!$hasErrors)
59 {
60 require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
64 return 0;
65 }
66 return 1;
67 }
68
74 public function editQuestion($checkonly = FALSE)
75 {
76 $save = $this->isSaveCommand();
77 $this->getQuestionTemplate();
78
79 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
80 $form = new ilPropertyFormGUI();
81 $form->setFormAction($this->ctrl->getFormAction($this));
82 $form->setTitle($this->outQuestionType());
83 $form->setMultipart(FALSE);
84 $form->setTableWidth("100%");
85 $form->setId("orderinghorizontal");
86
87 $this->addBasicQuestionFormProperties( $form );
89
90
91 $this->populateTaxonomyFormSection($form);
92
94
95 $errors = false;
96
97 if ($save)
98 {
99 $form->setValuesByPost();
100 $errors = !$form->checkInput();
101 $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
102 if ($errors) $checkonly = false;
103 }
104
105 if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
106 return $errors;
107 }
108
123 $active_id,
124 $pass = NULL,
125 $graphicalOutput = FALSE,
126 $result_output = FALSE,
127 $show_question_only = TRUE,
128 $show_feedback = FALSE,
129 $show_correct_solution = FALSE,
130 $show_manual_scoring = FALSE,
131 $show_question_text = TRUE
132 )
133 {
134 // get the solution of the user for the active pass or from the last pass if allowed
135 $template = new ilTemplate("tpl.il_as_qpl_orderinghorizontal_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
136
137 $solutionvalue = "";
138 if (($active_id > 0) && (!$show_correct_solution))
139 {
140 $solutions =& $this->object->getSolutionValues($active_id, $pass);
141 if (strlen($solutions[0]["value1"]))
142 {
143 $elements = split("{::}", $solutions[0]["value1"]);
144 foreach ($elements as $id => $element)
145 {
146 $template->setCurrentBlock("element");
147 $template->setVariable("ELEMENT_ID", "sol_e_" . $this->object->getId() . "_$id");
148 $template->setVariable("ELEMENT_VALUE", ilUtil::prepareFormOutput($element));
149 $template->parseCurrentBlock();
150 }
151 }
152 $solutionvalue = str_replace("{::}", " ", $solutions[0]["value1"]);
153 }
154 else
155 {
156 $elements = $this->object->getOrderingElements();
157 foreach ($elements as $id => $element)
158 {
159 $template->setCurrentBlock("element");
160 $template->setVariable("ELEMENT_ID", "sol_e_" . $this->object->getId() . "_$id");
161 $template->setVariable("ELEMENT_VALUE", ilUtil::prepareFormOutput($element));
162 $template->parseCurrentBlock();
163 }
164 $solutionvalue = join($this->object->getOrderingElements(), " ");
165 }
166
167 if (($active_id > 0) && (!$show_correct_solution))
168 {
169 if($this->object->getStep() === NULL)
170 {
171 $reached_points = $this->object->getReachedPoints($active_id, $pass);
172 }
173 else
174 {
175 $reached_points = $this->object->calculateReachedPoints($active_id, $pass);
176 }
177 if ($graphicalOutput)
178 {
179 // output of ok/not ok icons for user entered solutions
180 if ($reached_points == $this->object->getMaximumPoints())
181 {
182 $template->setCurrentBlock("icon_ok");
183 $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.svg"));
184 $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
185 $template->parseCurrentBlock();
186 }
187 else
188 {
189 $template->setCurrentBlock("icon_ok");
190 if ($reached_points > 0)
191 {
192 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.svg"));
193 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
194 }
195 else
196 {
197 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.svg"));
198 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
199 }
200 $template->parseCurrentBlock();
201 }
202 }
203 }
204 else
205 {
206 $reached_points = $this->object->getPoints();
207 }
208
209 if ($result_output)
210 {
211 $resulttext = ($reached_points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
212 $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $reached_points));
213 }
214 if($show_question_text==true)
215 {
216 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
217 }
218// $template->setVariable("SOLUTION_TEXT", ilUtil::prepareFormOutput($solutionvalue));
219 if ($this->object->textsize >= 10) $template->setVariable("STYLE", " style=\"font-size: " . $this->object->textsize . "%;\"");
220
221 $questionoutput = $template->get();
222 $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
223 $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
224
225
226 $feedback = '';
227 if($show_feedback)
228 {
229 $fb = $this->getGenericFeedbackOutput($active_id, $pass);
230 $feedback .= strlen($fb) ? $fb : '';
231
232 $fb = $this->getSpecificFeedbackOutput($active_id, $pass);
233 $feedback .= strlen($fb) ? $fb : '';
234 }
235 if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $this->object->prepareTextareaOutput( $feedback, true ));
236 $solutionoutput = $solutiontemplate->get();
237 if (!$show_question_only)
238 {
239 // get page object output
240 $solutionoutput = $this->getILIASPage($solutionoutput);
241 }
242 return $solutionoutput;
243 }
244
245 function getPreview($show_question_only = FALSE, $showInlineFeedback = false)
246 {
247 if( is_object($this->getPreviewSession()) && strlen((string)$this->getPreviewSession()->getParticipantsSolution()) )
248 {
249 $elements = (string)$this->getPreviewSession()->getParticipantsSolution();
250 $elements = $this->object->splitAndTrimOrderElementText($elements, $this->object->getAnswerSeparator());
251 }
252 else
253 {
254 $elements = $this->object->getRandomOrderingElements();
255 }
256
257 $template = new ilTemplate("tpl.il_as_qpl_orderinghorizontal_preview.html",TRUE, TRUE, "Modules/TestQuestionPool");
258 foreach ($elements as $id => $element)
259 {
260 $template->setCurrentBlock("element");
261 $template->setVariable("ELEMENT_ID", "e_" . $this->object->getId() . "_$id");
262 $template->setVariable("ORDERING_VALUE", ilUtil::prepareFormOutput($element));
263 $template->setVariable("ELEMENT_VALUE", ilUtil::prepareFormOutput($element));
264 $template->parseCurrentBlock();
265 }
266 $template->setVariable("QUESTION_ID", $this->object->getId());
267 $template->setVariable("VALUE_ORDERRESULT", ' value="' . join($elements, '{::}') . '"');
268 if ($this->object->textsize >= 10) $template->setVariable("STYLE", " style=\"font-size: " . $this->object->textsize . "%;\"");
269 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
270 $questionoutput = $template->get();
271 if (!$show_question_only)
272 {
273 // get page object output
274 $questionoutput = $this->getILIASPage($questionoutput);
275 }
276 $this->tpl->addJavascript("./Modules/TestQuestionPool/templates/default/orderinghorizontal.js");
277 return $questionoutput;
278 }
279
280 function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
281 {
282 // generate the question output
283 $template = new ilTemplate("tpl.il_as_qpl_orderinghorizontal_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
284 $elements = $this->object->getRandomOrderingElements();
285
286 if ($active_id)
287 {
288 $solutions = NULL;
289 include_once "./Modules/Test/classes/class.ilObjTest.php";
290 if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
291 {
292 if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
293 }
294 $solutions =& $this->object->getSolutionValues($active_id, $pass);
295 if (count($solutions) == 1)
296 {
297 $elements = split("{::}", $solutions[0]["value1"]);
298 }
299 }
300 if (count($solutions) == 0)
301 {
302 $_SESSION['qst_ordering_horizontal_elements'] = $elements;
303 }
304 else
305 {
306 unset($_SESSION['qst_ordering_horizontal_elements']);
307 }
308 foreach ($elements as $id => $element)
309 {
310 $template->setCurrentBlock("element");
311 $template->setVariable("ELEMENT_ID", "e_" . $this->object->getId() . "_$id");
312 $template->setVariable("ORDERING_VALUE", ilUtil::prepareFormOutput($element));
313 $template->setVariable("ELEMENT_VALUE", ilUtil::prepareFormOutput($element));
314 $template->parseCurrentBlock();
315 }
316 $template->setVariable("QUESTION_ID", $this->object->getId());
317 if ($this->object->textsize >= 10) $template->setVariable("STYLE", " style=\"font-size: " . $this->object->textsize . "%;\"");
318 $template->setVariable("VALUE_ORDERRESULT", ' value="' . join($elements, '{::}') . '"');
319 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
320 $questionoutput = $template->get();
321 if (!$show_question_only)
322 {
323 // get page object output
324 $questionoutput = $this->getILIASPage($questionoutput);
325 }
326 $this->tpl->addJavascript("./Modules/TestQuestionPool/templates/default/orderinghorizontal.js");
327 $questionoutput = $template->get();
328 $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
329 return $pageoutput;
330 }
331
337 function saveFeedback()
338 {
339 include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
340 $errors = $this->feedback(true);
341 $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
342 $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
343 $this->object->cleanupMediaObjectUsage();
344 parent::saveFeedback();
345 }
346
355 {
356 global $rbacsystem, $ilTabs;
357
358 $ilTabs->clearTargets();
359
360 $this->ctrl->setParameterByClass("ilAssQuestionPageGUI", "q_id", $_GET["q_id"]);
361 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
362 $q_type = $this->object->getQuestionType();
363
364 if (strlen($q_type))
365 {
366 $classname = $q_type . "GUI";
367 $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
368 $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
369 }
370
371 if ($_GET["q_id"])
372 {
373 if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
374 {
375 // edit page
376 $ilTabs->addTarget("edit_page",
377 $this->ctrl->getLinkTargetByClass("ilAssQuestionPageGUI", "edit"),
378 array("edit", "insert", "exec_pg"),
379 "", "", $force_active);
380 }
381
382 $this->addTab_QuestionPreview($ilTabs);
383 }
384
385 $force_active = false;
386 if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
387 {
388 $url = "";
389 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
390 $commands = $_POST["cmd"];
391 if (is_array($commands))
392 {
393 foreach ($commands as $key => $value)
394 {
395 if (preg_match("/^suggestrange_.*/", $key, $matches))
396 {
397 $force_active = true;
398 }
399 }
400 }
401 // edit question properties
402 $ilTabs->addTarget("edit_question",
403 $url,
404 array("editQuestion", "save", "saveEdit", "originalSyncForm"),
405 $classname, "", $force_active);
406 }
407
408 // add tab for question feedback within common class assQuestionGUI
409 $this->addTab_QuestionFeedback($ilTabs);
410
411 // add tab for question hint within common class assQuestionGUI
412 $this->addTab_QuestionHints($ilTabs);
413
414 // add tab for question's suggested solution within common class assQuestionGUI
415 $this->addTab_SuggestedSolution($ilTabs, $classname);
416
417 // Assessment of questions sub menu entry
418 if ($_GET["q_id"])
419 {
420 $ilTabs->addTarget("statistics",
421 $this->ctrl->getLinkTargetByClass($classname, "assessment"),
422 array("assessment"),
423 $classname, "");
424 }
425
426 $this->addBackTab($ilTabs);
427 }
428
429 function getSpecificFeedbackOutput($active_id, $pass)
430 {
431 if(strpos($this->object->getOrderText(),'::'))
432 {
433 $answers = explode('::', $this->object->getOrderText());
434 } else {
435 $answers = explode(' ', $this->object->getOrderText());
436 }
437
438 if( !$this->object->feedbackOBJ->specificAnswerFeedbackExists(array_values($answers)) )
439 {
440 return '';
441 }
442
443 $output = '<table class="test_specific_feedback"><tbody>';
444
445 foreach($answers as $idx => $answer)
446 {
447 $feedback = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
448 $this->object->getId(), $idx
449 );
450
451 $output .= "<tr><td>{$answer}</td><td>{$feedback}</td></tr>";
452 }
453
454 $output .= '</tbody></table>';
455
456 return $this->object->prepareTextareaOutput($output, TRUE);
457 }
458
460 {
461 $this->object->setTextSize( $_POST["textsize"] );
462 $this->object->setOrderText( $_POST["ordertext"] );
463 $this->object->setPoints( $_POST["points"] );
464 }
465
476 {
477 return array();
478 }
479
481 {
482 // ordertext
483 $ordertext = new ilTextAreaInputGUI($this->lng->txt( "ordertext" ), "ordertext");
484 $ordertext->setValue( $this->object->prepareTextareaOutput( $this->object->getOrderText() ) );
485 $ordertext->setRequired( TRUE );
486 $ordertext->setInfo( sprintf( $this->lng->txt( "ordertext_info" ), $this->object->separator ) );
487 $ordertext->setRows( 10 );
488 $ordertext->setCols( 80 );
489 $form->addItem( $ordertext );
490 // textsize
491 $textsize = new ilNumberInputGUI($this->lng->txt( "textsize" ), "textsize");
492 $textsize->setValue( $this->object->getTextSize() );
493 $textsize->setInfo( $this->lng->txt( "textsize_info" ) );
494 $textsize->setSize( 6 );
495 $textsize->setMinValue( 10 );
496 $textsize->setRequired( FALSE );
497 $form->addItem( $textsize );
498 // points
499 $points = new ilNumberInputGUI($this->lng->txt( "points" ), "points");
500
501 $points->allowDecimals( true );
502 // mbecker: Fix for mantis bug 7866: Predefined values schould make sense.
503 // This implements a default value of "1" for this question type.
504 if ($this->object->getPoints() == null)
505 {
506 $points->setValue( "1" );
507 }
508 else
509 {
510 $points->setValue( $this->object->getPoints() );
511 }
512 $points->setRequired( TRUE );
513 $points->setSize( 3 );
514 $points->setMinValue( 0.0 );
515 $points->setMinvalueShouldBeGreater( true );
516 $form->addItem( $points );
517 }
518
527 public function getAggregatedAnswersView($relevant_answers)
528 {
529 return $this->renderAggregateView(
530 $this->aggregateAnswers( $relevant_answers, $this->object->getOrderText() ) )->get();
531 }
532
533 public function aggregateAnswers($relevant_answers_chosen, $answer_defined_on_question)
534 {
535 $aggregate = array();
536 foreach($relevant_answers_chosen as $answer)
537 {
538 $answer = str_replace($this->object->getAnswerSeparator(), '&nbsp;&nbsp;-&nbsp;&nbsp;', $answer);
539 if (in_array($answer['value1'], $aggregate))
540 {
541 $aggregate[$answer['value1']] = $aggregate[$answer['value1']]+1;
542 }
543 else
544 {
545 $aggregate[$answer['value1']] = 1;
546 }
547 }
548
549 return $aggregate;
550 }
551
557 public function renderAggregateView($aggregate)
558 {
559 $tpl = new ilTemplate('tpl.il_as_aggregated_answers_table.html', true, true, "Modules/TestQuestionPool");
560
561 foreach ($aggregate as $key => $line_data)
562 {
563 $tpl->setCurrentBlock( 'aggregaterow' );
564 $tpl->setVariable( 'COUNT', $line_data );
565 $tpl->setVariable( 'OPTION', $key );
566 $tpl->parseCurrentBlock();
567 }
568 return $tpl;
569 }
570}
$_GET["client_id"]
The assOrderingHorizontalGUI class encapsulates the GUI representation for horizontal ordering questi...
getTestOutput($active_id, $pass=NULL, $is_postponed=FALSE, $use_post_solutions=FALSE, $show_feedback=FALSE)
aggregateAnswers($relevant_answers_chosen, $answer_defined_on_question)
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.
getPreview($show_question_only=FALSE, $showInlineFeedback=false)
writePostData($always=false)
Evaluates a posted edit form and writes the form data in the question object.
getSpecificFeedbackOutput($active_id, $pass)
Returns the answer specific feedback for the question.
getAggregatedAnswersView($relevant_answers)
Returns an html string containing a question specific representation of the answers so far given in t...
setQuestionTabs()
Sets the ILIAS tabs for this question type.
writeQuestionSpecificPostData(ilPropertyFormGUI $form)
Extracts the question specific values from $_POST and applies them to the data object.
populateQuestionSpecificFormPart(\ilPropertyFormGUI $form)
editQuestion($checkonly=FALSE)
Creates an output of the edit form for the question.
saveFeedback()
Saves the feedback for a single choice question.
__construct($id=-1)
assOrderingHorizontalGUI constructor
getAfterParticipationSuppressionQuestionPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
Class for horizontal ordering 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
addTab_SuggestedSolution(ilTabsGUI $tabs, $classname)
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="")
output question page
addBackTab(ilTabsGUI $ilTabs)
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 number property in a property form.
_getUsePreviousAnswers($active_id, $user_active_user_setting=false)
Returns if the previous results should be hidden for a learner.
_getPass($active_id)
Retrieves the actual pass of a given user for a given test.
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.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
$_POST['username']
Definition: cron.php:12
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
Interface ilGuiQuestionScoringAdjustable.
$cmd
Definition: sahs_server.php:35
$errors