ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.assMatchingQuestionGUI.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';
7require_once './Modules/Test/classes/inc.AssessmentConstants.php';
8
24{
35 public function __construct($id = -1)
36 {
37 parent::__construct();
38 include_once "./Modules/TestQuestionPool/classes/class.assMatchingQuestion.php";
39 $this->object = new assMatchingQuestion();
40 $this->setErrorMessage($this->lng->txt("msg_form_save_error"));
41 if ($id >= 0) {
42 $this->object->loadFromDb($id);
43 }
44 }
45
49 protected function writePostData($always = false)
50 {
51 $hasErrors = (!$always) ? $this->editQuestion(true) : false;
52 if (!$hasErrors) {
53 require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
58 return 0;
59 }
60 return 1;
61 }
62
64 {
65 // Delete all existing answers and create new answers from the form data
66 $this->object->flushMatchingPairs();
67 $this->object->flushTerms();
68 $this->object->flushDefinitions();
69
70 // add terms
71 require_once './Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php';
72 foreach ($_POST['terms']['answer'] as $index => $answer) {
73 $filename = $_POST['terms']['imagename'][$index];
74 if (strlen($_FILES['terms']['name']['image'][$index])) {
75 // upload the new file
76 $name = $_FILES['terms']['name']['image'][$index];
77 if ($this->object->setImageFile(
78 $_FILES['terms']['tmp_name']['image'][$index],
79 $this->object->getEncryptedFilename($name)
80 )
81 ) {
82 $filename = $this->object->getEncryptedFilename($name);
83 } else {
84 $filename = "";
85 }
86 }
87 $this->object->addTerm(
88 new assAnswerMatchingTerm($answer, $filename, $_POST['terms']['identifier'][$index])
89 );
90 }
91 // add definitions
92 require_once './Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php';
93 foreach ($_POST['definitions']['answer'] as $index => $answer) {
94 $filename = $_POST['definitions']['imagename'][$index];
95 if (strlen($_FILES['definitions']['name']['image'][$index])) {
96 // upload the new file
97 $name = $_FILES['definitions']['name']['image'][$index];
98 if ($this->object->setImageFile(
99 $_FILES['definitions']['tmp_name']['image'][$index],
100 $this->object->getEncryptedFilename($name)
101 )
102 ) {
103 $filename = $this->object->getEncryptedFilename($name);
104 } else {
105 $filename = "";
106 }
107 }
108 $this->object->addDefinition(
109 new assAnswerMatchingDefinition($answer, $filename, $_POST['definitions']['identifier'][$index])
110 );
111 }
112
113 // add matching pairs
114 if (is_array($_POST['pairs']['points'])) {
115 require_once './Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php';
116 foreach ($_POST['pairs']['points'] as $index => $points) {
117 $term_id = $_POST['pairs']['term'][$index];
118 $definition_id = $_POST['pairs']['definition'][$index];
119 $this->object->addMatchingPair(
120 $this->object->getTermWithIdentifier($term_id),
121 $this->object->getDefinitionWithIdentifier($definition_id),
122 $points
123 );
124 }
125 }
126 }
127
129 {
130 if (!$this->object->getSelfAssessmentEditingMode()) {
131 $this->object->setShuffle($_POST["shuffle"]);
132 } else {
133 $this->object->setShuffle(1);
134 }
135 $this->object->setThumbGeometry($_POST["thumb_geometry"]);
136 $this->object->setMatchingMode($_POST['matching_mode']);
137 }
138
139 public function uploadterms()
140 {
141 $this->writePostData(true);
142 $this->editQuestion();
143 }
144
145 public function removeimageterms()
146 {
147 $this->writePostData(true);
148 $position = key($_POST['cmd']['removeimageterms']);
149 $this->object->removeTermImage($position);
150 $this->editQuestion();
151 }
152
153 public function uploaddefinitions()
154 {
155 $this->writePostData(true);
156 $this->editQuestion();
157 }
158
159 public function removeimagedefinitions()
160 {
161 $this->writePostData(true);
162 $position = key($_POST['cmd']['removeimagedefinitions']);
163 $this->object->removeDefinitionImage($position);
164 $this->editQuestion();
165 }
166
167 public function addterms()
168 {
169 $this->writePostData();
170 $position = key($_POST["cmd"]["addterms"]);
171 $this->object->insertTerm($position+1);
172 $this->editQuestion();
173 }
174
175 public function removeterms()
176 {
177 $this->writePostData();
178 $position = key($_POST["cmd"]["removeterms"]);
179 $this->object->deleteTerm($position);
180 $this->editQuestion();
181 }
182
183 public function adddefinitions()
184 {
185 $this->writePostData();
186 $position = key($_POST["cmd"]["adddefinitions"]);
187 $this->object->insertDefinition($position+1);
188 $this->editQuestion();
189 }
190
191 public function removedefinitions()
192 {
193 $this->writePostData();
194 $position = key($_POST["cmd"]["removedefinitions"]);
195 $this->object->deleteDefinition($position);
196 $this->editQuestion();
197 }
198
199 public function addpairs()
200 {
201 $this->writePostData();
202 $position = key($_POST["cmd"]["addpairs"]);
203 $this->object->insertMatchingPair($position+1);
204 $this->editQuestion();
205 }
206
207 public function removepairs()
208 {
209 $this->writePostData();
210 $position = key($_POST["cmd"]["removepairs"]);
211 $this->object->deleteMatchingPair($position);
212 $this->editQuestion();
213 }
214
215 public function editQuestion($checkonly = false)
216 {
217 $save = $this->isSaveCommand();
218 $this->getQuestionTemplate();
219
220 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
221 $form = new ilPropertyFormGUI();
222 $this->editForm = $form;
223
224 $form->setFormAction($this->ctrl->getFormAction($this));
225 $form->setTitle($this->outQuestionType());
226 $form->setMultipart(true);
227 $form->setTableWidth("100%");
228 $form->setId("matching");
229
230
231 // title, author, description, question, working time (assessment mode)
237
238 $errors = false;
239 if ($save) {
240 $form->setValuesByPost();
241 $errors = !$form->checkInput();
242 $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
243 if (!$errors && !$this->isValidTermAndDefinitionAmount($form) && !$this->object->getSelfAssessmentEditingMode()) {
244 $errors = true;
245 $terms = $form->getItemByPostVar('terms');
246 $terms->setAlert($this->lng->txt("msg_number_of_terms_too_low"));
247 ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
248 }
249 if ($errors) {
250 $checkonly = false;
251 }
252 }
253
254 if (!$checkonly) {
255 $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
256 }
257 return $errors;
258 }
259
260 private function isDefImgUploadCommand()
261 {
262 return $this->ctrl->getCmd() == 'uploaddefinitions';
263 }
264
265 private function isTermImgUploadCommand()
266 {
267 return $this->ctrl->getCmd() == 'uploadterms';
268 }
269
278 {
279 $matchingMode = $form->getItemByPostVar('matching_mode')->getValue();
280
281 if ($matchingMode == assMatchingQuestion::MATCHING_MODE_N_ON_N) {
282 return true;
283 }
284
285 $numTerms = count($form->getItemByPostVar('terms')->getValues());
286 $numDefinitions = count($form->getItemByPostVar('definitions')->getValues());
287
288 if ($numTerms >= $numDefinitions) {
289 return true;
290 }
291
292 return false;
293 }
294
296 {
297 // Definitions
298 include_once "./Modules/TestQuestionPool/classes/class.ilMatchingWizardInputGUI.php";
299 $definitions = new ilMatchingWizardInputGUI($this->lng->txt("definitions"), "definitions");
300 if ($this->object->getSelfAssessmentEditingMode()) {
301 $definitions->setHideImages(true);
302 }
303
304 $definitions->setRequired(true);
305 $definitions->setQuestionObject($this->object);
306 $definitions->setTextName($this->lng->txt('definition_text'));
307 $definitions->setImageName($this->lng->txt('definition_image'));
308 include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
309 if (!count($this->object->getDefinitions())) {
310 $this->object->addDefinition(new assAnswerMatchingDefinition());
311 }
312 $definitionvalues = $this->object->getDefinitions();
313 $definitions->setValues($definitionvalues);
314 if ($this->isDefImgUploadCommand()) {
315 $definitions->checkInput();
316 }
317 $form->addItem($definitions);
318
319 // Terms
320 include_once "./Modules/TestQuestionPool/classes/class.ilMatchingWizardInputGUI.php";
321 $terms = new ilMatchingWizardInputGUI($this->lng->txt("terms"), "terms");
322 if ($this->object->getSelfAssessmentEditingMode()) {
323 $terms->setHideImages(true);
324 }
325 $terms->setRequired(true);
326 $terms->setQuestionObject($this->object);
327 $terms->setTextName($this->lng->txt('term_text'));
328 $terms->setImageName($this->lng->txt('term_image'));
329 include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
330 if (!count($this->object->getTerms())) {
331 $this->object->addTerm(new assAnswerMatchingTerm());
332 }
333 $termvalues = $this->object->getTerms();
334 $terms->setValues($termvalues);
335 if ($this->isTermImgUploadCommand()) {
336 $terms->checkInput();
337 }
338 $form->addItem($terms);
339
340 // Matching Pairs
341 include_once "./Modules/TestQuestionPool/classes/class.ilMatchingPairWizardInputGUI.php";
342 $pairs = new ilMatchingPairWizardInputGUI($this->lng->txt('matching_pairs'), 'pairs');
343 $pairs->setRequired(true);
344 $pairs->setTerms($this->object->getTerms());
345 $pairs->setDefinitions($this->object->getDefinitions());
346 include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
347 if (count($this->object->getMatchingPairs()) == 0) {
348 $this->object->addMatchingPair(new assAnswerMatchingPair($termvalues[0], $definitionvalues[0], 0));
349 }
350 $pairs->setPairs($this->object->getMatchingPairs());
351 $form->addItem($pairs);
352
353 return $form;
354 }
355
357 {
358 // Edit mode
359 $hidden = new ilHiddenInputGUI("matching_type");
360 $hidden->setValue($matchingtype);
361 $form->addItem($hidden);
362
363 if (!$this->object->getSelfAssessmentEditingMode()) {
364 // shuffle
365 $shuffle = new ilSelectInputGUI($this->lng->txt("shuffle_answers"), "shuffle");
366 $shuffle_options = array(
367 0 => $this->lng->txt("no"),
368 1 => $this->lng->txt("matching_shuffle_terms_definitions"),
369 2 => $this->lng->txt("matching_shuffle_terms"),
370 3 => $this->lng->txt("matching_shuffle_definitions")
371 );
372 $shuffle->setOptions($shuffle_options);
373 $shuffle->setValue($this->object->getShuffle() != null ? $this->object->getShuffle() : 1);
374 $shuffle->setRequired(false);
375 $form->addItem($shuffle);
376
377 $geometry = new ilNumberInputGUI($this->lng->txt("thumb_geometry"), "thumb_geometry");
378 $geometry->setValue($this->object->getThumbGeometry());
379 $geometry->setRequired(true);
380 $geometry->setMaxLength(6);
381 $geometry->setMinValue(20);
382 $geometry->setSize(6);
383 $geometry->setInfo($this->lng->txt("thumb_geometry_info"));
384 $form->addItem($geometry);
385 }
386
387 // Matching Mode
388 $mode = new ilRadioGroupInputGUI($this->lng->txt('qpl_qst_inp_matching_mode'), 'matching_mode');
389 $mode->setRequired(true);
390
391 $modeONEonONE = new ilRadioOption(
392 $this->lng->txt('qpl_qst_inp_matching_mode_one_on_one'),
394 );
395 $mode->addOption($modeONEonONE);
396
397 $modeALLonALL = new ilRadioOption(
398 $this->lng->txt('qpl_qst_inp_matching_mode_all_on_all'),
400 );
401 $mode->addOption($modeALLonALL);
402
403 $mode->setValue($this->object->getMatchingMode());
404
405 $form->addItem($mode);
406 }
407
421 public function getSolutionOutput(
422 $active_id,
423 $pass = null,
424 $graphicalOutput = false,
425 $result_output = false,
426 $show_question_only = true,
427 $show_feedback = false,
428 $show_correct_solution = false,
429 $show_manual_scoring = false,
430 $show_question_text = true
431 ) {
432 // generate the question output
433 include_once "./Services/UICore/classes/class.ilTemplate.php";
434 $template = new ilTemplate("tpl.il_as_qpl_matching_output_solution.html", true, true, "Modules/TestQuestionPool");
435 $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html", true, true, "Modules/TestQuestionPool");
436
437 $solutions = array();
438 if (($active_id > 0) && (!$show_correct_solution)) {
439 include_once "./Modules/Test/classes/class.ilObjTest.php";
440 $solutions =&$this->object->getSolutionValues($active_id, $pass);
441 $solution_script .= "";
442 } else {
443 foreach ($this->object->getMaximumScoringMatchingPairs() as $pair) {
444 $solutions[] = array(
445 "value1" => $pair->term->identifier,
446 "value2" => $pair->definition->identifier,
447 'points' => $pair->points
448 );
449 }
450 }
451
452 $i = 0;
453
454 foreach ($solutions as $solution) {
455 $definition = $this->object->getDefinitionWithIdentifier($solution['value2']);
456 $term = $this->object->getTermWithIdentifier($solution['value1']);
457 $points = $solution['points'];
458
459 if (is_object($definition)) {
460 if (strlen($definition->picture)) {
461 if (strlen($definition->text)) {
462 $template->setCurrentBlock('definition_image_text');
463 $template->setVariable("TEXT_DEFINITION", ilUtil::prepareFormOutput($definition->text));
464 $template->parseCurrentBlock();
465 }
466
467 $answerImageSrc = ilWACSignedPath::signFile(
468 $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $definition->picture
469 );
470
471 $template->setCurrentBlock('definition_image');
472 $template->setVariable('ANSWER_IMAGE_URL', $answerImageSrc);
473 $template->setVariable('ANSWER_IMAGE_ALT', (strlen($definition->text)) ? ilUtil::prepareFormOutput($definition->text) : ilUtil::prepareFormOutput($definition->picture));
474 $template->setVariable('ANSWER_IMAGE_TITLE', (strlen($definition->text)) ? ilUtil::prepareFormOutput($definition->text) : ilUtil::prepareFormOutput($definition->picture));
475 $template->setVariable('URL_PREVIEW', $this->object->getImagePathWeb() . $definition->picture);
476 $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
477 $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.svg'));
478 $template->parseCurrentBlock();
479 } else {
480 $template->setCurrentBlock('definition_text');
481 $template->setVariable("DEFINITION", $this->object->prepareTextareaOutput($definition->text, true));
482 $template->parseCurrentBlock();
483 }
484 }
485 if (is_object($term)) {
486 if (strlen($term->picture)) {
487 if (strlen($term->text)) {
488 $template->setCurrentBlock('term_image_text');
489 $template->setVariable("TEXT_TERM", ilUtil::prepareFormOutput($term->text));
490 $template->parseCurrentBlock();
491 }
492
493 $answerImageSrc = ilWACSignedPath::signFile(
494 $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $term->picture
495 );
496
497 $template->setCurrentBlock('term_image');
498 $template->setVariable('ANSWER_IMAGE_URL', $answerImageSrc);
499 $template->setVariable('ANSWER_IMAGE_ALT', (strlen($term->text)) ? ilUtil::prepareFormOutput($term->text) : ilUtil::prepareFormOutput($term->picture));
500 $template->setVariable('ANSWER_IMAGE_TITLE', (strlen($term->text)) ? ilUtil::prepareFormOutput($term->text) : ilUtil::prepareFormOutput($term->picture));
501 $template->setVariable('URL_PREVIEW', $this->object->getImagePathWeb() . $term->picture);
502 $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
503 $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.svg'));
504 $template->parseCurrentBlock();
505 } else {
506 $template->setCurrentBlock('term_text');
507 $template->setVariable("TERM", $this->object->prepareTextareaOutput($term->text, true));
508 $template->parseCurrentBlock();
509 }
510 $i++;
511 }
512 if (($active_id > 0) && (!$show_correct_solution)) {
513 if ($graphicalOutput) {
514 // output of ok/not ok icons for user entered solutions
515 $ok = false;
516 foreach ($this->object->getMatchingPairs() as $pair) {
517 if ($this->isCorrectMatching($pair, $definition, $term)) {
518 $ok = true;
519 }
520 }
521
522 if ($ok) {
523 $template->setCurrentBlock("icon_ok");
524 $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.svg"));
525 $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
526 $template->parseCurrentBlock();
527 } else {
528 $template->setCurrentBlock("icon_ok");
529 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.svg"));
530 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
531 $template->parseCurrentBlock();
532 }
533 }
534 }
535
536 if ($result_output) {
537 $resulttext = ($points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
538 $template->setCurrentBlock("result_output");
539 $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $points));
540 $template->parseCurrentBlock();
541 }
542
543 $template->setCurrentBlock("row");
544 $template->setVariable("TEXT_MATCHES", $this->lng->txt("matches"));
545 $template->parseCurrentBlock();
546 }
547
548 $questiontext = $this->object->getQuestion();
549 if ($show_question_text==true) {
550 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, true));
551 }
552
553 $questionoutput = $template->get();
554
555 $feedback = '';
556 if ($show_feedback) {
557 if (!$this->isTestPresentationContext()) {
558 $fb = $this->getGenericFeedbackOutput($active_id, $pass);
559 $feedback .= strlen($fb) ? $fb : '';
560 }
561
562 $fb = $this->getSpecificFeedbackOutput($active_id, $pass);
563 $feedback .= strlen($fb) ? $fb : '';
564 }
565 if (strlen($feedback)) {
566 $cssClass = (
567 $this->hasCorrectSolution($active_id, $pass) ?
569 );
570
571 $solutiontemplate->setVariable("ILC_FB_CSS_CLASS", $cssClass);
572 $solutiontemplate->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($feedback, true));
573 }
574
575 $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
576
577 $solutionoutput = $solutiontemplate->get();
578 if (!$show_question_only) {
579 // get page object output
580 $solutionoutput = $this->getILIASPage($solutionoutput);
581 }
582 return $solutionoutput;
583 }
584
585 public function getPreview($show_question_only = false, $showInlineFeedback = false)
586 {
587 $solutions = is_object($this->getPreviewSession()) ? (array) $this->getPreviewSession()->getParticipantsSolution() : array();
588
589 if ($GLOBALS['ilBrowser']->isMobile() || $GLOBALS['ilBrowser']->isIpad()) {
590 require_once 'Services/jQuery/classes/class.iljQueryUtil.php';
593 $this->tpl->addJavaScript('./libs/bower/bower_components/jqueryui-touch-punch/jquery.ui.touch-punch.min.js');
594 } else {
595 $this->tpl->addJavaScript('Modules/TestQuestionPool/js/jquery-ui-1-10-3-fixed.js');
596 }
597 $this->tpl->addJavaScript('Modules/TestQuestionPool/js/ilMatchingQuestion.js');
598 $this->tpl->addCss(ilUtil::getStyleSheetLocation('output', 'test_javascript.css', 'Modules/TestQuestionPool'));
599
600 $template = new ilTemplate("tpl.il_as_qpl_matching_output.html", true, true, "Modules/TestQuestionPool");
601
602 foreach ($solutions as $defId => $terms) {
603 foreach ($terms as $termId) {
604 $template->setCurrentBlock("matching_data");
605 $template->setVariable("DEFINITION_ID", $defId);
606 $template->setVariable("TERM_ID", $termId);
607 $template->parseCurrentBlock();
608 }
609 }
610
611 // shuffle output
612 $terms = $this->object->getTerms();
613 $definitions = $this->object->getDefinitions();
614 switch ($this->object->getShuffle()) {
615 case 1:
616 $seed = $this->object->getShuffler()->getSeed();
617 $this->object->getShuffler()->setSeed($seed . '1');
618 $terms = $this->object->getShuffler()->shuffle($terms);
619 $this->object->getShuffler()->setSeed($seed . '2');
620 $definitions = $this->object->getShuffler()->shuffle($definitions);
621 $this->object->getShuffler()->setSeed($seed);
622 break;
623 case 2:
624 $terms = $this->object->getShuffler()->shuffle($terms);
625 break;
626 case 3:
627 $definitions = $this->object->getShuffler()->shuffle($definitions);
628 break;
629 }
630
631 // create definitions
632 $counter = 0;
633 foreach ($definitions as $definition) {
634 if (strlen($definition->picture)) {
635 $template->setCurrentBlock("definition_picture");
636 $template->setVariable("DEFINITION_ID", $definition->identifier);
637 $template->setVariable("IMAGE_HREF", $this->object->getImagePathWeb() . $definition->picture);
638 $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $definition->picture;
639 $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $definition->picture;
640 if (!@file_exists($thumb)) {
641 $this->object->rebuildThumbnails();
642 }
643 $template->setVariable("THUMBNAIL_HREF", $thumbweb);
644 $template->setVariable("THUMB_ALT", $this->lng->txt("image"));
645 $template->setVariable("THUMB_TITLE", $this->lng->txt("image"));
646 $template->setVariable("TEXT_DEFINITION", (strlen($definition->text)) ? $this->object->prepareTextareaOutput($definition->text, true, true) : '');
647 $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
648 $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.svg'));
649 $template->parseCurrentBlock();
650 } else {
651 $template->setCurrentBlock("definition_text");
652 $template->setVariable("DEFINITION", $this->object->prepareTextareaOutput($definition->text, true, true));
653 $template->parseCurrentBlock();
654 }
655
656 $template->setCurrentBlock("droparea");
657 $template->setVariable("ID_DROPAREA", $definition->identifier);
658 $template->setVariable("QUESTION_ID", $this->object->getId());
659 $template->parseCurrentBlock();
660
661 $template->setCurrentBlock("definition_data");
662 $template->setVariable("DEFINITION_ID", $definition->identifier);
663 $template->parseCurrentBlock();
664 }
665
666 // create terms
667 $counter = 0;
668 foreach ($terms as $term) {
669 if (strlen($term->picture)) {
670 $template->setCurrentBlock("term_picture");
671 $template->setVariable("TERM_ID", $term->identifier);
672 $template->setVariable("IMAGE_HREF", $this->object->getImagePathWeb() . $term->picture);
673 $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $term->picture;
674 $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $term->picture;
675 if (!@file_exists($thumb)) {
676 $this->object->rebuildThumbnails();
677 }
678 $template->setVariable("THUMBNAIL_HREF", $thumbweb);
679 $template->setVariable("THUMB_ALT", $this->lng->txt("image"));
680 $template->setVariable("THUMB_TITLE", $this->lng->txt("image"));
681 $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
682 $template->setVariable("TEXT_TERM", (strlen($term->text)) ? $this->object->prepareTextareaOutput($term->text, true, true) : '');
683 $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.svg'));
684 $template->parseCurrentBlock();
685 } else {
686 $template->setCurrentBlock("term_text");
687 $template->setVariable("TERM_TEXT", $this->object->prepareTextareaOutput($term->text, true, true));
688 $template->parseCurrentBlock();
689 }
690 $template->setCurrentBlock("draggable");
691 $template->setVariable("ID_DRAGGABLE", $term->identifier);
692 $template->parseCurrentBlock();
693
694 $template->setCurrentBlock("term_data");
695 $template->setVariable("TERM_ID", $term->identifier);
696 $template->parseCurrentBlock();
697 }
698
699 $template->setVariable('MATCHING_MODE', $this->object->getMatchingMode());
700
701 $template->setVariable("RESET_BUTTON", $this->lng->txt("reset_terms"));
702
703 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), true));
704
705 $questionoutput = $template->get();
706
707 if (!$show_question_only) {
708 // get page object output
709 $questionoutput = $this->getILIASPage($questionoutput);
710 }
711
712 return $questionoutput;
713 }
714
720 protected function sortDefinitionsBySolution(array $solution, array $definitions)
721 {
722 $neworder = array();
723 $handled_defintions = array();
724 foreach ($solution as $solution_values) {
725 $id = $solution_values['value2'];
726 if (!isset($handled_defintions[$id])) {
727 $neworder[] = $this->object->getDefinitionWithIdentifier($id);
728 $handled_defintions[$id] = $id;
729 }
730 }
731
732 foreach ($definitions as $definition) {
736 if (!isset($handled_defintions[$definition->identifier])) {
737 $neworder[] = $definition;
738 }
739 }
740
741 return $neworder;
742 }
743
744 // hey: prevPassSolutions - pass will be always available from now on
745 public function getTestOutput($active_id, $pass, $is_postponed = false, $user_post_solution = false, $inlineFeedback = false)
746 // hey.
747 {
748 if ($GLOBALS['ilBrowser']->isMobile() || $GLOBALS['ilBrowser']->isIpad()) {
749 require_once 'Services/jQuery/classes/class.iljQueryUtil.php';
752 $this->tpl->addJavaScript('./libs/bower/bower_components/jqueryui-touch-punch/jquery.ui.touch-punch.min.js');
753 } else {
754 $this->tpl->addJavaScript('Modules/TestQuestionPool/js/jquery-ui-1-10-3-fixed.js');
755 }
756 $this->tpl->addJavaScript('Modules/TestQuestionPool/js/ilMatchingQuestion.js');
757 $this->tpl->addCss(ilUtil::getStyleSheetLocation('output', 'test_javascript.css', 'Modules/TestQuestionPool'));
758
759 $template = new ilTemplate("tpl.il_as_qpl_matching_output.html", true, true, "Modules/TestQuestionPool");
760
761 if ($active_id) {
762 // hey: prevPassSolutions - obsolete due to central check
763 #$solutions = NULL;
764 #include_once "./Modules/Test/classes/class.ilObjTest.php";
765 #if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
766 #{
767 # if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
768 #}
769 // hey.
770 if (is_array($user_post_solution)) {
771 $solutions = array();
772 foreach ($user_post_solution['matching'][$this->object->getId()] as $definition => $term) {
773 array_push($solutions, array("value1" => $term, "value2" => $definition));
774 }
775 } else {
776 // hey: prevPassSolutions - obsolete due to central check
777 $solutions = $this->object->getTestOutputSolutions($active_id, $pass);
778 // hey.
779 }
780
781 $counter = 0;
782 foreach ($solutions as $idx => $solution_value) {
783 if (($solution_value["value2"] > -1) && ($solution_value["value1"] > -1)) {
784 $template->setCurrentBlock("matching_data");
785 $template->setVariable("TERM_ID", $solution_value["value1"]);
786 $template->setVariable("DEFINITION_ID", $solution_value["value2"]);
787 $template->parseCurrentBlock();
788 }
789
790 $counter++;
791 }
792 }
793
794 $terms = $this->object->getTerms();
795 $definitions = $this->object->getDefinitions();
796 switch ($this->object->getShuffle()) {
797 case 1:
798 $seed = $this->object->getShuffler()->getSeed();
799 $this->object->getShuffler()->setSeed($seed . '1');
800 $terms = $this->object->getShuffler()->shuffle($terms);
801 if (count($solutions)) {
802 $definitions = $this->sortDefinitionsBySolution($solutions, $definitions);
803 } else {
804 $this->object->getShuffler()->setSeed($seed . '2');
805 $definitions = $this->object->getShuffler()->shuffle($definitions);
806 }
807 $this->object->getShuffler()->setSeed($seed);
808 break;
809 case 2:
810 $terms = $this->object->getShuffler()->shuffle($terms);
811 break;
812 case 3:
813 if (count($solutions)) {
814 $definitions = $this->sortDefinitionsBySolution($solutions, $definitions);
815 } else {
816 $definitions = $this->object->getShuffler()->shuffle($definitions);
817 }
818 break;
819 }
820
821 // create definitions
822 $counter = 0;
823 foreach ($definitions as $definition) {
824 if (strlen($definition->picture)) {
825 $template->setCurrentBlock("definition_picture");
826 $template->setVariable("DEFINITION_ID", $definition->identifier);
827 $template->setVariable("IMAGE_HREF", $this->object->getImagePathWeb() . $definition->picture);
828 $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $definition->picture;
829 $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $definition->picture;
830 if (!@file_exists($thumb)) {
831 $this->object->rebuildThumbnails();
832 }
833 $template->setVariable("THUMBNAIL_HREF", $thumbweb);
834 $template->setVariable("THUMB_ALT", $this->lng->txt("image"));
835 $template->setVariable("THUMB_TITLE", $this->lng->txt("image"));
836 $template->setVariable("TEXT_DEFINITION", (strlen($definition->text)) ? $this->object->prepareTextareaOutput($definition->text, true, true) : '');
837 $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
838 $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.svg'));
839 $template->parseCurrentBlock();
840 } else {
841 $template->setCurrentBlock("definition_text");
842 $template->setVariable("DEFINITION", $this->object->prepareTextareaOutput($definition->text, true, true));
843 $template->parseCurrentBlock();
844 }
845
846 $template->setCurrentBlock("droparea");
847 $template->setVariable("ID_DROPAREA", $definition->identifier);
848 $template->setVariable("QUESTION_ID", $this->object->getId());
849 $template->parseCurrentBlock();
850
851 $template->setCurrentBlock("definition_data");
852 $template->setVariable("DEFINITION_ID", $definition->identifier);
853 $template->parseCurrentBlock();
854 }
855
856 // create terms
857 $counter = 0;
858 foreach ($terms as $term) {
859 if (strlen($term->picture)) {
860 $template->setCurrentBlock("term_picture");
861 $template->setVariable("TERM_ID", $term->identifier);
862 $template->setVariable("IMAGE_HREF", $this->object->getImagePathWeb() . $term->picture);
863 $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $term->picture;
864 $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $term->picture;
865 if (!@file_exists($thumb)) {
866 $this->object->rebuildThumbnails();
867 }
868 $template->setVariable("THUMBNAIL_HREF", $thumbweb);
869 $template->setVariable("THUMB_ALT", $this->lng->txt("image"));
870 $template->setVariable("THUMB_TITLE", $this->lng->txt("image"));
871 $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
872 $template->setVariable("TEXT_TERM", (strlen($term->text)) ? $this->object->prepareTextareaOutput($term->text, true, true) : '');
873 $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.svg'));
874 $template->parseCurrentBlock();
875 } else {
876 $template->setCurrentBlock("term_text");
877 $template->setVariable("TERM_TEXT", $this->object->prepareTextareaOutput($term->text, true, true));
878 $template->parseCurrentBlock();
879 }
880 $template->setCurrentBlock("draggable");
881 $template->setVariable("ID_DRAGGABLE", $term->identifier);
882 $template->parseCurrentBlock();
883
884 $template->setCurrentBlock('term_data');
885 $template->setVariable('TERM_ID', $term->identifier);
886 $template->parseCurrentBlock();
887 }
888
889 $template->setVariable('MATCHING_MODE', $this->object->getMatchingMode());
890
891 $template->setVariable("RESET_BUTTON", $this->lng->txt("reset_terms"));
892
893 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), true));
894
895 return $this->outQuestionPage("", $is_postponed, $active_id, $template->get());
896 }
897
901 public function checkInput()
902 {
903 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"])) {
904 return false;
905 }
906 return true;
907 }
908
916 public function setQuestionTabs()
917 {
918 global $rbacsystem, $ilTabs;
919
920 $ilTabs->clearTargets();
921
922 $this->ctrl->setParameterByClass("ilAssQuestionPageGUI", "q_id", $_GET["q_id"]);
923 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
924 $q_type = $this->object->getQuestionType();
925
926 if (strlen($q_type)) {
927 $classname = $q_type . "GUI";
928 $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
929 $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
930 }
931
932 if ($_GET["q_id"]) {
933 if ($rbacsystem->checkAccess('write', $_GET["ref_id"])) {
934 // edit page
935 $ilTabs->addTarget(
936 "edit_page",
937 $this->ctrl->getLinkTargetByClass("ilAssQuestionPageGUI", "edit"),
938 array("edit", "insert", "exec_pg"),
939 "",
940 "",
941 $force_active
942 );
943 }
944
945 $this->addTab_QuestionPreview($ilTabs);
946 }
947
948 $force_active = false;
949 if ($rbacsystem->checkAccess('write', $_GET["ref_id"])) {
950 $url = "";
951 if ($classname) {
952 $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
953 }
954 // edit question properties
955 $ilTabs->addTarget(
956 "edit_question",
957 $url,
958 array("editQuestion", "save", "saveEdit", "removeimageterms", "uploadterms", "removeimagedefinitions", "uploaddefinitions",
959 "addpairs", "removepairs", "addterms", "removeterms", "adddefinitions", "removedefinitions", "originalSyncForm"),
960 $classname,
961 "",
962 $force_active
963 );
964 }
965
966 // add tab for question feedback within common class assQuestionGUI
967 $this->addTab_QuestionFeedback($ilTabs);
968
969 // add tab for question hint within common class assQuestionGUI
970 $this->addTab_QuestionHints($ilTabs);
971
972 // add tab for question's suggested solution within common class assQuestionGUI
973 $this->addTab_SuggestedSolution($ilTabs, $classname);
974
975 // Assessment of questions sub menu entry
976 if ($_GET["q_id"]) {
977 $ilTabs->addTarget(
978 "statistics",
979 $this->ctrl->getLinkTargetByClass($classname, "assessment"),
980 array("assessment"),
981 $classname,
982 ""
983 );
984 }
985
986 $this->addBackTab($ilTabs);
987 }
988
989 public function getSpecificFeedbackOutput($active_id, $pass)
990 {
991 $userSolution = $this->object->fetchIndexedValuesFromValuePairs(
992 $this->object->getSolutionValues($active_id, $pass)
993 );
994
995 $matches = array_values($this->object->matchingpairs);
996
997 if (!$this->object->feedbackOBJ->specificAnswerFeedbackExists($matches)) {
998 return '';
999 }
1000
1001 $feedback = '<table class="test_specific_feedback"><tbody>';
1002
1003 foreach ($matches as $idx => $ans) {
1004 if ($active_id) {
1005 if (!isset($userSolution[$ans->definition->identifier])) {
1006 continue;
1007 }
1008
1009 if (!is_array($userSolution[$ans->definition->identifier])) {
1010 continue;
1011 }
1012
1013 if (!in_array($ans->term->identifier, $userSolution[$ans->definition->identifier])) {
1014 continue;
1015 }
1016 }
1017
1018 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
1019 $this->object->getId(),
1020 $idx
1021 );
1022 $feedback .= '<tr><td>"' . $ans->definition->text . '"&nbsp;' . $this->lng->txt("matches") . '&nbsp;"';
1023 $feedback .= $ans->term->text . '"</td><td>';
1024 $feedback .= $fb . '</td> </tr>';
1025 }
1026
1027 $feedback .= '</tbody></table>';
1028 return $this->object->prepareTextareaOutput($feedback, true);
1029 }
1030
1041 {
1042 return array();
1043 }
1044
1055 {
1056 return array();
1057 }
1058
1067 public function getAggregatedAnswersView($relevant_answers)
1068 {
1069 return ''; //print_r($relevant_answers,true);
1070 }
1071
1072 private function isCorrectMatching($pair, $definition, $term)
1073 {
1074 if (!($pair->points > 0)) {
1075 return false;
1076 }
1077
1078 if (!is_object($term)) {
1079 return false;
1080 }
1081
1082 if ($pair->definition->identifier != $definition->identifier) {
1083 return false;
1084 }
1085
1086 if ($pair->term->identifier != $term->identifier) {
1087 return false;
1088 }
1089
1090 return true;
1091 }
1092}
sprintf('%.4f', $callTime)
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Class for matching question definitions.
Class for matching question pairs.
Class for matching question terms.
Matching question GUI representation.
isValidTermAndDefinitionAmount(ilPropertyFormGUI $form)
for mode 1:1 terms count must not be less than definitions count for mode n:n this limitation is canc...
populateAnswerSpecificFormPart(\ilPropertyFormGUI $form)
writePostData($always=false)
{Evaluates a posted edit form and writes the form data in the question object.integer A positive valu...
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.
getSpecificFeedbackOutput($active_id, $pass)
Returns the answer specific feedback for the question.
isCorrectMatching($pair, $definition, $term)
getAfterParticipationSuppressionAnswerPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
getPreview($show_question_only=false, $showInlineFeedback=false)
getAfterParticipationSuppressionQuestionPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
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.
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, $user_post_solution=false, $inlineFeedback=false)
populateQuestionSpecificFormPart(\ilPropertyFormGUI $form)
__construct($id=-1)
assMatchingQuestionGUI constructor
Class for matching 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 hidden form property in a property form.
This class represents a key value pair wizard property in a property form.
This class represents a single choice wizard property in a property form.
This class represents a number property in a property form.
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
special template class to simplify handling of ITX/PEAR
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
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
static signFile($path_to_file)
static initjQueryUI($a_tpl=null)
inits and adds the jQuery-UI JS-File to the global template (see included_components....
static initjQuery($a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
$counter
$template
$i
Definition: disco.tpl.php:19
if(!array_key_exists('StateId', $_REQUEST)) $id
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
Interface ilGuiAnswerScoringAdjustable.
Interface ilGuiQuestionScoringAdjustable.
if($format !==null) $name
Definition: metadata.php:146
$index
Definition: metadata.php:60
$errors
Definition: index.php:6
$url
if(isset($_POST['submit'])) $form