ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
23{
32 public function __construct($id = -1)
33 {
34 parent::__construct();
35 include_once "./Modules/TestQuestionPool/classes/class.assOrderingHorizontal.php";
36 $this->object = new assOrderingHorizontal();
37 $this->setErrorMessage($this->lng->txt("msg_form_save_error"));
38 if ($id >= 0) {
39 $this->object->loadFromDb($id);
40 }
41 }
42
43 public function getCommand($cmd)
44 {
45 return $cmd;
46 }
47
51 protected function writePostData($always = false)
52 {
53 $hasErrors = (!$always) ? $this->editQuestion(true) : false;
54 if (!$hasErrors) {
55 require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
59 return 0;
60 }
61 return 1;
62 }
63
69 public function editQuestion($checkonly = false)
70 {
71 $save = $this->isSaveCommand();
72 $this->getQuestionTemplate();
73
74 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
76 $this->editForm = $form;
77
78 $form->setFormAction($this->ctrl->getFormAction($this));
79 $form->setTitle($this->outQuestionType());
80 $form->setMultipart(false);
81 $form->setTableWidth("100%");
82 $form->setId("orderinghorizontal");
83
86
87
89
91
92 $errors = false;
93
94 if ($save) {
95 $form->setValuesByPost();
96 $errors = !$form->checkInput();
97 $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
98 if ($errors) {
99 $checkonly = false;
100 }
101 }
102
103 if (!$checkonly) {
104 $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
105 }
106 return $errors;
107 }
108
122 public function getSolutionOutput(
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 // get the solution of the user for the active pass or from the last pass if allowed
134 $template = new ilTemplate("tpl.il_as_qpl_orderinghorizontal_output_solution.html", true, true, "Modules/TestQuestionPool");
135
136 //$solutionvalue = "";
137 if (($active_id > 0) && (!$show_correct_solution)) {
138 $solutions =&$this->object->getSolutionValues($active_id, $pass);
139 if (strlen($solutions[0]["value1"])) {
140 $elements = explode("{::}", $solutions[0]["value1"]);
141 }
142
143 if (!count($elements)) {
144 $elements = $this->object->getRandomOrderingElements();
145 }
146
147 foreach ($elements as $id => $element) {
148 $template->setCurrentBlock("element");
149 $template->setVariable("ELEMENT_ID", "sol_e_" . $this->object->getId() . "_$id");
150 $template->setVariable("ELEMENT_VALUE", ilUtil::prepareFormOutput($element));
151 $template->parseCurrentBlock();
152 }
153
154 //$solutionvalue = str_replace("{::}", " ", $solutions[0]["value1"]);
155 } else {
156 $elements = $this->object->getOrderingElements();
157 foreach ($elements as $id => $element) {
158 $template->setCurrentBlock("element");
159 $template->setVariable("ELEMENT_ID", "sol_e_" . $this->object->getId() . "_$id");
160 $template->setVariable("ELEMENT_VALUE", ilUtil::prepareFormOutput($element));
161 $template->parseCurrentBlock();
162 }
163 //$solutionvalue = join($this->object->getOrderingElements(), " ");
164 }
165
166 if (($active_id > 0) && (!$show_correct_solution)) {
167 if ($this->object->getStep() === null) {
168 $reached_points = $this->object->getReachedPoints($active_id, $pass);
169 } else {
170 $reached_points = $this->object->calculateReachedPoints($active_id, $pass);
171 }
172 if ($graphicalOutput) {
173 // output of ok/not ok icons for user entered solutions
174 if ($reached_points == $this->object->getMaximumPoints()) {
175 $template->setCurrentBlock("icon_ok");
176 $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.svg"));
177 $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
178 $template->parseCurrentBlock();
179 } else {
180 $template->setCurrentBlock("icon_ok");
181 if ($reached_points > 0) {
182 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.svg"));
183 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
184 } else {
185 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.svg"));
186 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
187 }
188 $template->parseCurrentBlock();
189 }
190 }
191 } else {
192 $reached_points = $this->object->getPoints();
193 }
194
195 if ($result_output) {
196 $resulttext = ($reached_points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
197 $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $reached_points));
198 }
199 if ($show_question_text==true) {
200 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), true));
201 }
202 // $template->setVariable("SOLUTION_TEXT", ilUtil::prepareFormOutput($solutionvalue));
203 if ($this->object->textsize >= 10) {
204 $template->setVariable("STYLE", " style=\"font-size: " . $this->object->textsize . "%;\"");
205 }
206
207 $questionoutput = $template->get();
208 $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html", true, true, "Modules/TestQuestionPool");
209 $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
210
211
212 $feedback = '';
213 if ($show_feedback) {
214 if (!$this->isTestPresentationContext()) {
215 $fb = $this->getGenericFeedbackOutput($active_id, $pass);
216 $feedback .= strlen($fb) ? $fb : '';
217 }
218
219 $fb = $this->getSpecificFeedbackOutput($active_id, $pass);
220 $feedback .= strlen($fb) ? $fb : '';
221 }
222 if (strlen($feedback)) {
223 $cssClass = (
224 $this->hasCorrectSolution($active_id, $pass) ?
226 );
227
228 $solutiontemplate->setVariable("ILC_FB_CSS_CLASS", $cssClass);
229 $solutiontemplate->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($feedback, true));
230 }
231 $solutionoutput = $solutiontemplate->get();
232 if (!$show_question_only) {
233 // get page object output
234 $solutionoutput = $this->getILIASPage($solutionoutput);
235 }
236 return $solutionoutput;
237 }
238
239 public function getPreview($show_question_only = false, $showInlineFeedback = false)
240 {
241 if (is_object($this->getPreviewSession()) && strlen((string) $this->getPreviewSession()->getParticipantsSolution())) {
242 $elements = (string) $this->getPreviewSession()->getParticipantsSolution();
243 $elements = $this->object->splitAndTrimOrderElementText($elements, $this->object->getAnswerSeparator());
244 } else {
245 $elements = $this->object->getRandomOrderingElements();
246 }
247
248 $template = new ilTemplate("tpl.il_as_qpl_orderinghorizontal_preview.html", true, true, "Modules/TestQuestionPool");
249 foreach ($elements as $id => $element) {
250 $template->setCurrentBlock("element");
251 $template->setVariable("ELEMENT_ID", "e_" . $this->object->getId() . "_$id");
252 $template->setVariable("ORDERING_VALUE", ilUtil::prepareFormOutput($element));
253 $template->setVariable("ELEMENT_VALUE", ilUtil::prepareFormOutput($element));
254 $template->parseCurrentBlock();
255 }
256 $template->setVariable("QUESTION_ID", $this->object->getId());
257 $template->setVariable("VALUE_ORDERRESULT", ' value="' . join($elements, '{::}') . '"');
258 if ($this->object->textsize >= 10) {
259 $template->setVariable("STYLE", " style=\"font-size: " . $this->object->textsize . "%;\"");
260 }
261 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), true));
262 $questionoutput = $template->get();
263 if (!$show_question_only) {
264 // get page object output
265 $questionoutput = $this->getILIASPage($questionoutput);
266 }
267 $this->tpl->addJavascript("./Modules/TestQuestionPool/templates/default/orderinghorizontal.js");
268 return $questionoutput;
269 }
270
271 // hey: prevPassSolutions - pass will be always available from now on
272 public function getTestOutput($active_id, $pass, $is_postponed = false, $use_post_solutions = false, $show_feedback = false)
273 // hey.
274 {
275 // generate the question output
276 $template = new ilTemplate("tpl.il_as_qpl_orderinghorizontal_output.html", true, true, "Modules/TestQuestionPool");
277 $elements = $this->object->getRandomOrderingElements();
278
279 if ($active_id) {
280 // hey: prevPassSolutions - obsolete due to central check
281 #$solutions = NULL;
282 #include_once "./Modules/Test/classes/class.ilObjTest.php";
283 #if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
284 #{
285 # if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
286 #}
287 $solutions = $this->object->getTestOutputSolutions($active_id, $pass);
288 // hey.
289 if (count($solutions) == 1) {
290 $elements = explode("{::}", $solutions[0]["value1"]);
291 }
292 }
293 if (count($solutions) == 0) {
294 $_SESSION['qst_ordering_horizontal_elements'] = $elements;
295 } else {
296 unset($_SESSION['qst_ordering_horizontal_elements']);
297 }
298 foreach ($elements as $id => $element) {
299 $template->setCurrentBlock("element");
300 $template->setVariable("ELEMENT_ID", "e_" . $this->object->getId() . "_$id");
301 $template->setVariable("ORDERING_VALUE", ilUtil::prepareFormOutput($element));
302 $template->setVariable("ELEMENT_VALUE", ilUtil::prepareFormOutput($element));
303 $template->parseCurrentBlock();
304 }
305 $template->setVariable("QUESTION_ID", $this->object->getId());
306 if ($this->object->textsize >= 10) {
307 $template->setVariable("STYLE", " style=\"font-size: " . $this->object->textsize . "%;\"");
308 }
309 $template->setVariable("VALUE_ORDERRESULT", ' value="' . join($elements, '{::}') . '"');
310 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), true));
311 $questionoutput = $template->get();
312 if (!$show_question_only) {
313 // get page object output
314 $questionoutput = $this->getILIASPage($questionoutput);
315 }
316 $this->tpl->addJavascript("./Modules/TestQuestionPool/templates/default/orderinghorizontal.js");
317 $questionoutput = $template->get();
318 $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
319 return $pageoutput;
320 }
321
327 public function saveFeedback()
328 {
329 include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
330 $errors = $this->feedback(true);
331 $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
332 $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
333 $this->object->cleanupMediaObjectUsage();
334 parent::saveFeedback();
335 }
336
344 public function setQuestionTabs()
345 {
346 global $rbacsystem, $ilTabs;
347
348 $ilTabs->clearTargets();
349
350 $this->ctrl->setParameterByClass("ilAssQuestionPageGUI", "q_id", $_GET["q_id"]);
351 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
352 $q_type = $this->object->getQuestionType();
353
354 if (strlen($q_type)) {
355 $classname = $q_type . "GUI";
356 $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
357 $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
358 }
359
360 if ($_GET["q_id"]) {
361 if ($rbacsystem->checkAccess('write', $_GET["ref_id"])) {
362 // edit page
363 $ilTabs->addTarget(
364 "edit_page",
365 $this->ctrl->getLinkTargetByClass("ilAssQuestionPageGUI", "edit"),
366 array("edit", "insert", "exec_pg"),
367 "",
368 "",
369 $force_active
370 );
371 }
372
373 $this->addTab_QuestionPreview($ilTabs);
374 }
375
376 $force_active = false;
377 if ($rbacsystem->checkAccess('write', $_GET["ref_id"])) {
378 $url = "";
379 if ($classname) {
380 $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
381 }
382 $commands = $_POST["cmd"];
383 if (is_array($commands)) {
384 foreach ($commands as $key => $value) {
385 if (preg_match("/^suggestrange_.*/", $key, $matches)) {
386 $force_active = true;
387 }
388 }
389 }
390 // edit question properties
391 $ilTabs->addTarget(
392 "edit_question",
393 $url,
394 array("editQuestion", "save", "saveEdit", "originalSyncForm"),
395 $classname,
396 "",
397 $force_active
398 );
399 }
400
401 // add tab for question feedback within common class assQuestionGUI
402 $this->addTab_QuestionFeedback($ilTabs);
403
404 // add tab for question hint within common class assQuestionGUI
405 $this->addTab_QuestionHints($ilTabs);
406
407 // add tab for question's suggested solution within common class assQuestionGUI
408 $this->addTab_SuggestedSolution($ilTabs, $classname);
409
410 // Assessment of questions sub menu entry
411 if ($_GET["q_id"]) {
412 $ilTabs->addTarget(
413 "statistics",
414 $this->ctrl->getLinkTargetByClass($classname, "assessment"),
415 array("assessment"),
416 $classname,
417 ""
418 );
419 }
420
421 $this->addBackTab($ilTabs);
422 }
423
424 public function getSpecificFeedbackOutput($active_id, $pass)
425 {
426 if (strpos($this->object->getOrderText(), '::')) {
427 $answers = explode('::', $this->object->getOrderText());
428 } else {
429 $answers = explode(' ', $this->object->getOrderText());
430 }
431
432 if (!$this->object->feedbackOBJ->specificAnswerFeedbackExists(array_values($answers))) {
433 return '';
434 }
435
436 $output = '<table class="test_specific_feedback"><tbody>';
437
438 foreach ($answers as $idx => $answer) {
439 $feedback = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
440 $this->object->getId(),
441 $idx
442 );
443
444 $output .= "<tr><td>{$answer}</td><td>{$feedback}</td></tr>";
445 }
446
447 $output .= '</tbody></table>';
448
449 return $this->object->prepareTextareaOutput($output, true);
450 }
451
453 {
454 $this->object->setTextSize($_POST["textsize"]);
455 $this->object->setOrderText($_POST["ordertext"]);
456 $this->object->setPoints($_POST["points"]);
457 }
458
469 {
470 return array();
471 }
472
474 {
475 // ordertext
476 $ordertext = new ilTextAreaInputGUI($this->lng->txt("ordertext"), "ordertext");
477 $ordertext->setValue($this->object->prepareTextareaOutput($this->object->getOrderText()));
478 $ordertext->setRequired(true);
479 $ordertext->setInfo(sprintf($this->lng->txt("ordertext_info"), $this->object->separator));
480 $ordertext->setRows(10);
481 $ordertext->setCols(80);
482 $form->addItem($ordertext);
483 // textsize
484 $textsize = new ilNumberInputGUI($this->lng->txt("textsize"), "textsize");
485 $textsize->setValue($this->object->getTextSize());
486 $textsize->setInfo($this->lng->txt("textsize_info"));
487 $textsize->setSize(6);
488 $textsize->setMinValue(10);
489 $textsize->setRequired(false);
490 $form->addItem($textsize);
491 // points
492 $points = new ilNumberInputGUI($this->lng->txt("points"), "points");
493
494 $points->allowDecimals(true);
495 // mbecker: Fix for mantis bug 7866: Predefined values schould make sense.
496 // This implements a default value of "1" for this question type.
497 if ($this->object->getPoints() == null) {
498 $points->setValue("1");
499 } else {
500 $points->setValue($this->object->getPoints());
501 }
502 $points->setRequired(true);
503 $points->setSize(3);
504 $points->setMinValue(0.0);
505 $points->setMinvalueShouldBeGreater(true);
506 $form->addItem($points);
507 }
508
517 public function getAggregatedAnswersView($relevant_answers)
518 {
519 return $this->renderAggregateView(
520 $this->aggregateAnswers($relevant_answers, $this->object->getOrderText())
521 )->get();
522 }
523
524 public function aggregateAnswers($relevant_answers_chosen, $answer_defined_on_question)
525 {
526 $aggregate = array();
527 foreach ($relevant_answers_chosen as $answer) {
528 $answer = str_replace($this->object->getAnswerSeparator(), '&nbsp;&nbsp;-&nbsp;&nbsp;', $answer);
529 if (in_array($answer['value1'], $aggregate)) {
530 $aggregate[$answer['value1']] = $aggregate[$answer['value1']]+1;
531 } else {
532 $aggregate[$answer['value1']] = 1;
533 }
534 }
535
536 return $aggregate;
537 }
538
544 public function renderAggregateView($aggregate)
545 {
546 $tpl = new ilTemplate('tpl.il_as_aggregated_answers_table.html', true, true, "Modules/TestQuestionPool");
547
548 foreach ($aggregate as $key => $line_data) {
549 $tpl->setCurrentBlock('aggregaterow');
550 $tpl->setVariable('COUNT', $line_data);
551 $tpl->setVariable('OPTION', $key);
552 $tpl->parseCurrentBlock();
553 }
554 return $tpl;
555 }
556}
sprintf('%.4f', $callTime)
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
The assOrderingHorizontalGUI class encapsulates the GUI representation for horizontal ordering questi...
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.integer A positive valu...
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.
getTestOutput($active_id, $pass, $is_postponed=false, $use_post_solutions=false, $show_feedback=false)
editQuestion($checkonly=false)
Creates an output of the edit form for the question.
writeQuestionSpecificPostData(ilPropertyFormGUI $form)
Extracts the question specific values from $_POST and applies them to the data object.
populateQuestionSpecificFormPart(\ilPropertyFormGUI $form)
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)
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 number property in a property form.
This class represents a property form user interface.
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
$template
$key
Definition: croninfo.php:18
if(!array_key_exists('StateId', $_REQUEST)) $id
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\s+" &#(? foreach( $entity_files as $file) $output
Interface ilGuiQuestionScoringAdjustable.
$errors
Definition: index.php:6
$url
if(isset($_POST['submit'])) $form