4 require_once
'./Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
5 require_once
'./Modules/TestQuestionPool/interfaces/interface.ilGuiQuestionScoringAdjustable.php';
6 require_once
'./Modules/TestQuestionPool/interfaces/interface.ilGuiAnswerScoringAdjustable.php';
7 require_once
'./Modules/Test/classes/inc.AssessmentConstants.php';
34 parent::__construct();
35 include_once
"./Modules/TestQuestionPool/classes/class.assSingleChoice.php";
38 $this->
object->loadFromDb(
$id);
47 return $this->
object->feedbackOBJ->isSpecificAnswerFeedbackAvailable($this->object->getId());
55 $hasErrors = (!$always) ? $this->
editQuestion(
true) :
false;
57 require_once
'Services/Form/classes/class.ilPropertyFormGUI.php';
78 return (
$_POST[
'types'] == 0) ? true :
false;
81 $lastChange = $this->
object->getLastChange();
82 if (empty($lastChange) && !isset(
$_POST[
'types'])) {
84 return $this->
object->getMultilineAnswerSetting() ? false :
true;
87 return $this->
object->isSingleline;
100 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
102 $this->editForm =
$form;
104 $form->setFormAction($this->ctrl->getFormAction($this));
108 $form->setMultipart(
true);
110 $form->setMultipart(
false);
112 $form->setTableWidth(
"100%");
113 $form->setId(
"asssinglechoice");
127 $form->setValuesByPost();
129 $form->setValuesByPost();
136 $this->tpl->setVariable(
"QUESTION_DATA",
$form->getHTML());
147 $position = key(
$_POST[
'cmd'][
'uploadchoice']);
157 $position = key(
$_POST[
'cmd'][
'removeimagechoice']);
159 $this->
object->removeAnswerImage($position);
169 $position = key(
$_POST[
'cmd'][
'addchoice']);
170 $this->
object->addAnswer(
"", 0, $position + 1);
180 $position = key(
$_POST[
'cmd'][
'removechoice']);
181 $this->
object->deleteAnswer($position);
211 $graphicalOutput =
false,
212 $result_output =
false,
213 $show_question_only =
true,
214 $show_feedback =
false,
215 $show_correct_solution =
false,
216 $show_manual_scoring =
false,
217 $show_question_text =
true 224 if (($active_id > 0) && (!$show_correct_solution)) {
226 foreach ($solutions as $idx => $solution_value) {
227 $user_solution = $solution_value[
"value1"];
232 foreach ($this->object->answers as
$index => $answer) {
233 if ($answer->getPoints() > $max_points) {
234 $max_points = $answer->getPoints();
238 $user_solution = $found_index;
241 include_once
"./Services/UICore/classes/class.ilTemplate.php";
242 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_sr_output_solution.html",
true,
true,
"Modules/TestQuestionPool");
243 $solutiontemplate =
new ilTemplate(
"tpl.il_as_tst_solution_output.html",
true,
true,
"Modules/TestQuestionPool");
244 foreach (
$keys as $answer_id) {
245 $answer = $this->
object->answers[$answer_id];
246 if (($active_id > 0) && (!$show_correct_solution)) {
247 if ($graphicalOutput) {
250 if (strcmp($user_solution, $answer_id) == 0) {
251 if ($answer->getPoints() == $this->
object->getMaximumPoints()) {
259 $template->setVariable(
"TEXT_OK", $this->lng->txt(
"answer_is_right"));
262 $template->setCurrentBlock(
"icon_not_ok");
263 if ($answer->getPoints() > 0) {
265 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_not_correct_but_positive"));
268 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_wrong"));
273 if (strlen($user_solution) == 0) {
274 $template->setCurrentBlock(
"icon_not_ok");
276 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_wrong"));
281 if (strlen($answer->getImage())) {
282 $template->setCurrentBlock(
"answer_image");
283 if ($this->object->getThumbSize()) {
284 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
286 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
288 $alt = $answer->getImage();
289 if (strlen($answer->getAnswertext())) {
290 $alt = $answer->getAnswertext();
292 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
297 if ($show_feedback) {
300 $template->setCurrentBlock(
"answer_row");
301 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(),
true));
304 if (strcmp($user_solution, $answer_id) == 0) {
306 $template->setVariable(
"SOLUTION_ALT", $this->lng->txt(
"checked"));
309 $template->setVariable(
"SOLUTION_ALT", $this->lng->txt(
"unchecked"));
312 $template->setVariable(
'QID', $this->object->getId());
313 $template->setVariable(
'SUFFIX', $show_correct_solution ?
'bestsolution' :
'usersolution');
314 $template->setVariable(
'SOLUTION_VALUE', $answer_id);
315 if (strcmp($user_solution, $answer_id) == 0) {
316 $template->setVariable(
'SOLUTION_CHECKED',
'checked');
320 if ($result_output) {
321 $points = $this->
object->answers[$answer_id]->getPoints();
322 $resulttext = ($points == 1) ?
"(%s " . $this->lng->txt(
"point") .
")" :
"(%s " . $this->lng->txt(
"points") .
")";
323 $template->setVariable(
"RESULT_OUTPUT", sprintf($resulttext, $points));
327 $questiontext = $this->
object->getQuestion();
328 if ($show_question_text ==
true) {
329 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext,
true));
333 if (strlen($feedback)) {
339 $solutiontemplate->setVariable(
"ILC_FB_CSS_CLASS", $cssClass);
340 $solutiontemplate->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput($feedback,
true));
342 $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
344 $solutionoutput = $solutiontemplate->get();
350 if (!$show_question_only) {
354 return $solutionoutput;
357 public function getPreview($show_question_only =
false, $showInlineFeedback =
false)
362 include_once
"./Services/UICore/classes/class.ilTemplate.php";
363 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_sr_output.html",
true,
true,
"Modules/TestQuestionPool");
364 foreach (
$keys as $answer_id) {
365 $answer = $this->
object->answers[$answer_id];
366 if (strlen($answer->getImage())) {
367 if ($this->object->getThumbSize()) {
369 $template->setVariable(
"URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
370 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
372 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
373 list($width, $height,
$type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
374 $alt = $answer->getImage();
375 if (strlen($answer->getAnswertext())) {
376 $alt = $answer->getAnswertext();
378 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
383 $template->setCurrentBlock(
"answer_image");
384 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
385 list($width, $height,
$type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
386 $alt = $answer->getImage();
387 if (strlen($answer->getAnswertext())) {
388 $alt = $answer->getAnswertext();
390 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
400 $template->setCurrentBlock(
"answer_row");
401 $template->setVariable(
"QID", $this->object->getId() .
'ID');
402 $template->setVariable(
"ANSWER_ID", $answer_id);
403 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(),
true));
407 if (strcmp($user_solution, $answer_id) == 0) {
408 $template->setVariable(
"CHECKED_ANSWER",
" checked=\"checked\"");
414 $questiontext = $this->
object->getQuestion();
415 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext,
true));
417 if (!$show_question_only) {
421 return $questionoutput;
425 public function getTestOutput($active_id,
$pass, $is_postponed =
false, $use_post_solutions =
false, $show_feedback =
false)
435 #include_once "./Modules/Test/classes/class.ilObjTest.php"; 436 #if (!ilObjTest::_getUsePreviousAnswers($active_id, true)) 438 # if (is_null($pass)) $pass = ilObjTest::_getPass($active_id); 441 $solutions = $this->
object->getTestOutputSolutions($active_id,
$pass);
442 foreach ($solutions as $idx => $solution_value) {
443 $user_solution = $solution_value[
"value1"];
448 include_once
"./Services/UICore/classes/class.ilTemplate.php";
449 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_sr_output.html",
true,
true,
"Modules/TestQuestionPool");
450 foreach (
$keys as $answer_id) {
451 $answer = $this->
object->answers[$answer_id];
452 if (strlen($answer->getImage())) {
453 if ($this->object->getThumbSize()) {
455 $template->setVariable(
"URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
456 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
458 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
459 list($width, $height,
$type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
460 $alt = $answer->getImage();
461 if (strlen($answer->getAnswertext())) {
462 $alt = $answer->getAnswertext();
464 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
469 $template->setCurrentBlock(
"answer_image");
470 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
471 list($width, $height,
$type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
472 $alt = $answer->getImage();
473 if (strlen($answer->getAnswertext())) {
474 $alt = $answer->getAnswertext();
476 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
483 if ($show_feedback) {
484 $feedbackOutputRequired =
false;
486 switch ($this->object->getSpecificFeedbackSetting()) {
488 $feedbackOutputRequired =
true;
492 if (strcmp($user_solution, $answer_id) == 0) {
493 $feedbackOutputRequired =
true;
498 if ($this->object->getAnswer($answer_id)->getPoints() > 0) {
499 $feedbackOutputRequired =
true;
504 if ($feedbackOutputRequired) {
505 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
506 $this->object->getId(),
512 $template->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput($fb,
true));
517 $template->setCurrentBlock(
"answer_row");
518 $template->setVariable(
"ANSWER_ID", $answer_id);
519 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(),
true));
520 if (strcmp($user_solution, $answer_id) == 0) {
521 $template->setVariable(
"CHECKED_ANSWER",
" checked=\"checked\"");
525 $questiontext = $this->
object->getQuestion();
526 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext,
true));
528 $pageoutput = $this->
outQuestionPage(
"", $is_postponed, $active_id, $questionoutput, $show_feedback);
542 $rbacsystem = $DIC[
'rbacsystem'];
543 $ilTabs = $DIC[
'ilTabs'];
545 $ilTabs->clearTargets();
547 $this->ctrl->setParameterByClass(
"ilAssQuestionPageGUI",
"q_id",
$_GET[
"q_id"]);
548 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
549 $q_type = $this->
object->getQuestionType();
551 if (strlen($q_type)) {
552 $classname = $q_type .
"GUI";
553 $this->ctrl->setParameterByClass(strtolower($classname),
"sel_question_types", $q_type);
554 $this->ctrl->setParameterByClass(strtolower($classname),
"q_id",
$_GET[
"q_id"]);
558 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"])) {
562 $this->ctrl->getLinkTargetByClass(
"ilAssQuestionPageGUI",
"edit"),
563 array(
"edit",
"insert",
"exec_pg"),
573 $force_active =
false;
574 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"])) {
577 $url = $this->ctrl->getLinkTargetByClass($classname,
"editQuestion");
583 array(
"editQuestion",
"save",
"saveEdit",
"addchoice",
"removechoice",
"removeimagechoice",
"uploadchoice",
"originalSyncForm"),
603 $this->ctrl->getLinkTargetByClass($classname,
"assessment"),
620 $choiceKeys = array_keys($this->object->answers);
622 if ($this->object->getShuffle()) {
623 $choiceKeys = $this->
object->getShuffler()->shuffle($choiceKeys);
633 return $this->
object->prepareTextareaOutput(
$output,
true);
638 $this->
object->setShuffle(
$_POST[
"shuffle"]);
639 $this->
object->setMultilineAnswerSetting(
$_POST[
"types"]);
640 if (is_array(
$_POST[
'choice'][
'imagename']) &&
$_POST[
"types"] == 1) {
641 $this->
object->isSingleline =
true;
644 $this->
object->isSingleline = (
$_POST[
"types"] == 0) ?
true :
false;
646 $this->
object->setThumbSize((strlen(
$_POST[
"thumb_size"])) ?
$_POST[
"thumb_size"] :
"");
655 $shuffle->setChecked($this->object->getShuffle());
656 $shuffle->setRequired(
false);
659 if ($this->object->getId()) {
661 $hidden->setValue($this->object->getId());
665 if (!$this->object->getSelfAssessmentEditingMode()) {
669 $types->setValue(($isSingleline) ? 0 : 1);
672 0 => $this->lng->txt(
'answers_singleline'),
673 1 => $this->lng->txt(
'answers_multiline'),
681 $thumb_size =
new ilNumberInputGUI($this->lng->txt(
"thumb_size"),
"thumb_size");
682 $thumb_size->
setSuffix($this->lng->txt(
"thumb_size_unit_pixel"));
683 $thumb_size->setMinValue(20);
684 $thumb_size->setDecimals(0);
685 $thumb_size->setSize(6);
686 $thumb_size->setInfo($this->lng->txt(
'thumb_size_info'));
687 $thumb_size->setValue($this->object->getThumbSize());
688 $thumb_size->setRequired(
false);
711 $this->
object->flushAnswers();
712 if ($this->object->isSingleline) {
713 foreach (
$_POST[
'choice'][
'answer'] as
$index => $answertext) {
717 $file_org_name = $_FILES[
'choice'][
'name'][
'image'][
$index];
718 $file_temp_name = $_FILES[
'choice'][
'tmp_name'][
'image'][
$index];
720 if (strlen($file_temp_name)) {
722 $suffix = strtolower(array_pop(explode(
".", $file_org_name)));
723 if (in_array($suffix, array(
"jpg",
"jpeg",
"png",
"gif" ))) {
725 $filename = $this->
object->buildHashedImageFilename($file_org_name);
726 if ($this->object->setImageFile(
$filename, $file_temp_name) == 0) {
732 $this->
object->addAnswer($answertext,
$_POST[
'choice'][
'points'][
$index], $index, $picturefile);
735 foreach (
$_POST[
'choice'][
'answer'] as
$index => $answer) {
736 $answertext = $answer;
737 $this->
object->addAnswer($answertext,
$_POST[
'choice'][
'points'][
$index], $index);
747 include_once
"./Modules/TestQuestionPool/classes/class.ilSingleChoiceWizardInputGUI.php";
750 $choices->setQuestionObject($this->
object);
751 $choices->setSingleline($isSingleline);
752 $choices->setAllowMove(
false);
753 if ($this->object->getSelfAssessmentEditingMode()) {
754 $choices->setSize(40);
756 $choices->setMaxLength(800);
757 if ($this->object->getAnswerCount() == 0) {
758 $this->
object->addAnswer(
"", 0, 0);
760 $choices->setValues($this->object->getAnswers());
795 $aggregate = array();
796 foreach ($answers_defined_on_question as $answer) {
797 $aggregated_info_for_answer = array();
798 $aggregated_info_for_answer[
'answertext'] = $answer->getAnswerText();
799 $aggregated_info_for_answer[
'count_checked'] = 0;
801 foreach ($relevant_answers_chosen as $relevant_answer) {
802 if ($relevant_answer[
'value1'] == $answer->getOrder()) {
803 $aggregated_info_for_answer[
'count_checked']++;
806 $aggregated_info_for_answer[
'count_unchecked'] =
807 ceil(count($relevant_answers_chosen) / count($answers_defined_on_question))
808 - $aggregated_info_for_answer[
'count_checked'];
810 $aggregate[] = $aggregated_info_for_answer;
822 $tpl =
new ilTemplate(
'tpl.il_as_aggregated_answers_table.html',
true,
true,
"Modules/TestQuestionPool");
824 $tpl->setCurrentBlock(
'headercell');
825 $tpl->setVariable(
'HEADER', $this->lng->txt(
'tst_answer_aggr_answer_header'));
826 $tpl->parseCurrentBlock();
828 $tpl->setCurrentBlock(
'headercell');
829 $tpl->setVariable(
'HEADER', $this->lng->txt(
'tst_answer_aggr_frequency_header'));
830 $tpl->parseCurrentBlock();
832 foreach ($aggregate as $line_data) {
833 $tpl->setCurrentBlock(
'aggregaterow');
834 $tpl->setVariable(
'OPTION', $line_data[
'answertext']);
835 $tpl->setVariable(
'COUNT', $line_data[
'count_checked']);
836 $tpl->parseCurrentBlock();
843 $feedbackOutputRequired =
false;
845 switch ($this->object->getSpecificFeedbackSetting()) {
847 $feedbackOutputRequired =
true;
851 if (strcmp($user_solution, $answer_id) == 0) {
852 $feedbackOutputRequired =
true;
857 if ($this->object->getAnswer($answer_id)->getPoints() > 0) {
858 $feedbackOutputRequired =
true;
863 if ($feedbackOutputRequired) {
864 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), 0, $answer_id);
867 $template->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput($fb,
true));
875 $agg = $this->
aggregateAnswers($relevantAnswers, $this->object->getAnswers());
879 foreach ($agg as $ans) {
881 'answer' => $ans[
'answertext'],
882 'frequency' => $ans[
'count_checked']
891 require_once
'Modules/TestQuestionPool/classes/forms/class.ilAssSingleChoiceCorrectionsInputGUI.php';
894 $choices->setQuestionObject($this->
object);
895 $choices->setValues($this->object->getAnswers());
904 $points = $form->
getInput(
'choice')[
'points'];
906 foreach ($this->object->getAnswers() as
$index => $answer) {
908 $answer->setPoints((
float) $points[$index]);
isTestPresentationContext()
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
hasCorrectSolution($activeId, $passIndex)
addTab_QuestionPreview(ilTabsGUI $tabsGUI)
aggregateAnswers($relevant_answers_chosen, $answers_defined_on_question)
addBasicQuestionFormProperties($form)
Add basic question form properties: assessment: title, author, description, question, working time.
getAggregatedAnswersView($relevant_answers)
Returns an html string containing a question specific representation of the answers so far given in t...
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.
writePostData($always=false)
{}
addTab_QuestionHints(ilTabsGUI $tabs)
adds the hints tab to ilTabsGUI
setQuestionTabs()
Sets the ILIAS tabs for this question type.
writeAnswerSpecificPostData(ilPropertyFormGUI $form)
Extracts the answer specific values from $_POST and applies them to the data object.
populateInlineFeedback($template, $answer_id, $user_solution)
supportsIntermediateSolutionOutput()
Question type specific support of intermediate solution output The function getSolutionOutput respect...
if(!array_key_exists('StateId', $_REQUEST)) $id
renderAggregateView($aggregate)
populateQuestionSpecificFormPart(\ilPropertyFormGUI $form)
getQuestionTemplate()
get question template
const CSS_CLASS_FEEDBACK_CORRECT
getAnswersFrequency($relevantAnswers, $questionIndex)
populateTaxonomyFormSection(ilPropertyFormGUI $form)
getUseIntermediateSolution()
Get if intermediate solution should be used for solution output.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
getTestOutput($active_id, $pass, $is_postponed=false, $use_post_solutions=false, $show_feedback=false)
writeQuestionGenericPostData()
if(isset($_POST['submit'])) $form
getSpecificFeedbackOutput($userSolution)
getPreview($show_question_only=false, $showInlineFeedback=false)
getAfterParticipationSuppressionAnswerPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
getILIASPage($html="")
Returns the ILIAS Page around a question.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
Class for single choice questions.
special template class to simplify handling of ITX/PEAR
getAfterParticipationSuppressionQuestionPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
addTab_QuestionFeedback(ilTabsGUI $tabs)
adds the feedback tab to ilTabsGUI
removechoice()
Remove an answer.
const CSS_CLASS_FEEDBACK_WRONG
Basic GUI class for assessment questions.
static getHtmlPath($relative_path)
get url of path
getAnswerFeedbackOutput($active_id, $pass)
Returns the answer generic feedback depending on the results of the question.
populateAnswerSpecificFormPart(\ilPropertyFormGUI $form)
populateCorrectionsFormProperties(ilPropertyFormGUI $form)
saveTaxonomyAssignments()
addchoice()
Add a new answer.
saveCorrectionsFormProperties(ilPropertyFormGUI $form)
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="", $inlineFeedbackEnabled=false)
output question page
addBackTab(ilTabsGUI $ilTabs)
static secureString($a_str, $a_strip_html=true, $a_allow="")
Remove unsecure tags.
isRenderPurposePrintPdf()
Interface ilGuiAnswerScoringAdjustable.
Single choice question GUI representation.
__construct($id=-1)
assSingleChoiceGUI constructor
editQuestion($checkonly=false)
Creates an output of the edit form for the question.
removeimagechoice()
Remove an image.
Interface ilGuiQuestionScoringAdjustable.
getEditAnswersSingleLine($checkonly=false)
Get the single/multiline editing of answers.
uploadchoice()
Upload an image.
addTab_SuggestedSolution(ilTabsGUI $tabs, $classname)
addQuestionFormCommandButtons($form)
Add the command buttons of a question properties form.
writeQuestionSpecificPostData(ilPropertyFormGUI $form)
Extracts the question specific values from $_POST and applies them to the data object.
renderPurposeSupportsFormHtml()