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 $hasErrors = (!$always) ? $this->
editQuestion(
true) :
false;
49 require_once
'Services/Form/classes/class.ilPropertyFormGUI.php';
70 return (
$_POST[
'types'] == 0) ? true :
false;
73 $lastChange = $this->
object->getLastChange();
74 if (empty($lastChange) && !isset(
$_POST[
'types'])) {
76 return $this->
object->getMultilineAnswerSetting() ? false :
true;
79 return $this->
object->isSingleline;
92 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
94 $this->editForm =
$form;
96 $form->setFormAction($this->ctrl->getFormAction($this));
100 $form->setMultipart(
true);
102 $form->setMultipart(
false);
104 $form->setTableWidth(
"100%");
105 $form->setId(
"asssinglechoice");
119 $form->setValuesByPost();
121 $form->setValuesByPost();
128 $this->tpl->setVariable(
"QUESTION_DATA",
$form->getHTML());
139 $position = key(
$_POST[
'cmd'][
'uploadchoice']);
149 $position = key(
$_POST[
'cmd'][
'removeimagechoice']);
151 $this->
object->removeAnswerImage($position);
161 $position = key(
$_POST[
'cmd'][
'addchoice']);
162 $this->
object->addAnswer(
"", 0, $position+1);
172 $position = key(
$_POST[
'cmd'][
'removechoice']);
173 $this->
object->deleteAnswer($position);
193 $graphicalOutput =
false,
194 $result_output =
false,
195 $show_question_only =
true,
196 $show_feedback =
false,
197 $show_correct_solution =
false,
198 $show_manual_scoring =
false,
199 $show_question_text =
true 206 if (($active_id > 0) && (!$show_correct_solution)) {
207 $solutions =&$this->
object->getSolutionValues($active_id,
$pass);
208 foreach ($solutions as $idx => $solution_value) {
209 $user_solution = $solution_value[
"value1"];
215 if ($answer->getPoints() > $max_points) {
216 $max_points = $answer->getPoints();
220 $user_solution = $found_index;
223 include_once
"./Services/UICore/classes/class.ilTemplate.php";
224 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_sr_output_solution.html",
true,
true,
"Modules/TestQuestionPool");
225 $solutiontemplate =
new ilTemplate(
"tpl.il_as_tst_solution_output.html",
true,
true,
"Modules/TestQuestionPool");
226 foreach (
$keys as $answer_id) {
227 $answer = $this->
object->answers[$answer_id];
228 if (($active_id > 0) && (!$show_correct_solution)) {
229 if ($graphicalOutput) {
232 if (strcmp($user_solution, $answer_id) == 0) {
233 if ($answer->getPoints() == $this->
object->getMaximumPoints()) {
241 $template->setVariable(
"TEXT_OK", $this->lng->txt(
"answer_is_right"));
244 $template->setCurrentBlock(
"icon_not_ok");
245 if ($answer->getPoints() > 0) {
247 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_not_correct_but_positive"));
250 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_wrong"));
255 if (strlen($user_solution) == 0) {
256 $template->setCurrentBlock(
"icon_not_ok");
258 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_wrong"));
263 if (strlen($answer->getImage())) {
264 $template->setCurrentBlock(
"answer_image");
265 if ($this->
object->getThumbSize()) {
266 $template->setVariable(
"ANSWER_IMAGE_URL", $this->
object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
268 $template->setVariable(
"ANSWER_IMAGE_URL", $this->
object->getImagePathWeb() . $answer->getImage());
270 $alt = $answer->getImage();
271 if (strlen($answer->getAnswertext())) {
272 $alt = $answer->getAnswertext();
274 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
279 if ($show_feedback) {
282 $template->setCurrentBlock(
"answer_row");
283 $template->setVariable(
"ANSWER_TEXT", $this->
object->prepareTextareaOutput($answer->getAnswertext(),
true));
286 if (strcmp($user_solution, $answer_id) == 0) {
288 $template->setVariable(
"SOLUTION_ALT", $this->lng->txt(
"checked"));
291 $template->setVariable(
"SOLUTION_ALT", $this->lng->txt(
"unchecked"));
295 $template->setVariable(
'SUFFIX', $show_correct_solution ?
'bestsolution' :
'usersolution');
296 $template->setVariable(
'SOLUTION_VALUE', $answer_id);
297 if (strcmp($user_solution, $answer_id) == 0) {
298 $template->setVariable(
'SOLUTION_CHECKED',
'checked');
302 if ($result_output) {
303 $points = $this->
object->answers[$answer_id]->getPoints();
304 $resulttext = ($points == 1) ?
"(%s " . $this->lng->txt(
"point") .
")" :
"(%s " . $this->lng->txt(
"points") .
")";
305 $template->setVariable(
"RESULT_OUTPUT", sprintf($resulttext, $points));
309 $questiontext = $this->
object->getQuestion();
310 if ($show_question_text==
true) {
311 $template->setVariable(
"QUESTIONTEXT", $this->
object->prepareTextareaOutput($questiontext,
true));
315 if (strlen($feedback)) {
321 $solutiontemplate->setVariable(
"ILC_FB_CSS_CLASS", $cssClass);
322 $solutiontemplate->setVariable(
"FEEDBACK", $this->
object->prepareTextareaOutput($feedback,
true));
324 $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
326 $solutionoutput = $solutiontemplate->get();
327 if (!$show_question_only) {
331 return $solutionoutput;
334 public function getPreview($show_question_only =
false, $showInlineFeedback =
false)
339 include_once
"./Services/UICore/classes/class.ilTemplate.php";
340 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_sr_output.html",
true,
true,
"Modules/TestQuestionPool");
341 foreach (
$keys as $answer_id) {
342 $answer = $this->
object->answers[$answer_id];
343 if (strlen($answer->getImage())) {
344 if ($this->
object->getThumbSize()) {
346 $template->setVariable(
"URL_PREVIEW", $this->
object->getImagePathWeb() . $answer->getImage());
347 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
349 $template->setVariable(
"ANSWER_IMAGE_URL", $this->
object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
350 list($width, $height,
$type, $attr) = getimagesize($this->
object->getImagePath() . $answer->getImage());
351 $alt = $answer->getImage();
352 if (strlen($answer->getAnswertext())) {
353 $alt = $answer->getAnswertext();
355 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
360 $template->setCurrentBlock(
"answer_image");
361 $template->setVariable(
"ANSWER_IMAGE_URL", $this->
object->getImagePathWeb() . $answer->getImage());
362 list($width, $height,
$type, $attr) = getimagesize($this->
object->getImagePath() . $answer->getImage());
363 $alt = $answer->getImage();
364 if (strlen($answer->getAnswertext())) {
365 $alt = $answer->getAnswertext();
367 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
377 $template->setCurrentBlock(
"answer_row");
379 $template->setVariable(
"ANSWER_ID", $answer_id);
380 $template->setVariable(
"ANSWER_TEXT", $this->
object->prepareTextareaOutput($answer->getAnswertext(),
true));
384 if (strcmp($user_solution, $answer_id) == 0) {
385 $template->setVariable(
"CHECKED_ANSWER",
" checked=\"checked\"");
391 $questiontext = $this->
object->getQuestion();
392 $template->setVariable(
"QUESTIONTEXT", $this->
object->prepareTextareaOutput($questiontext,
true));
394 if (!$show_question_only) {
398 return $questionoutput;
402 public function getTestOutput($active_id,
$pass, $is_postponed =
false, $use_post_solutions =
false, $show_feedback =
false)
412 #include_once "./Modules/Test/classes/class.ilObjTest.php"; 413 #if (!ilObjTest::_getUsePreviousAnswers($active_id, true)) 415 # if (is_null($pass)) $pass = ilObjTest::_getPass($active_id); 418 $solutions = $this->
object->getTestOutputSolutions($active_id,
$pass);
419 foreach ($solutions as $idx => $solution_value) {
420 $user_solution = $solution_value[
"value1"];
425 include_once
"./Services/UICore/classes/class.ilTemplate.php";
426 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_sr_output.html",
true,
true,
"Modules/TestQuestionPool");
427 foreach (
$keys as $answer_id) {
428 $answer = $this->
object->answers[$answer_id];
429 if (strlen($answer->getImage())) {
430 if ($this->
object->getThumbSize()) {
432 $template->setVariable(
"URL_PREVIEW", $this->
object->getImagePathWeb() . $answer->getImage());
433 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
435 $template->setVariable(
"ANSWER_IMAGE_URL", $this->
object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
436 list($width, $height,
$type, $attr) = getimagesize($this->
object->getImagePath() . $answer->getImage());
437 $alt = $answer->getImage();
438 if (strlen($answer->getAnswertext())) {
439 $alt = $answer->getAnswertext();
441 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
446 $template->setCurrentBlock(
"answer_image");
447 $template->setVariable(
"ANSWER_IMAGE_URL", $this->
object->getImagePathWeb() . $answer->getImage());
448 list($width, $height,
$type, $attr) = getimagesize($this->
object->getImagePath() . $answer->getImage());
449 $alt = $answer->getImage();
450 if (strlen($answer->getAnswertext())) {
451 $alt = $answer->getAnswertext();
453 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
460 if ($show_feedback) {
461 $feedbackOutputRequired =
false;
463 switch ($this->
object->getSpecificFeedbackSetting()) {
465 $feedbackOutputRequired =
true;
469 if (strcmp($user_solution, $answer_id) == 0) {
470 $feedbackOutputRequired =
true;
475 if ($this->
object->getAnswer($answer_id)->getPoints() > 0) {
476 $feedbackOutputRequired =
true;
481 if ($feedbackOutputRequired) {
482 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
488 $template->setVariable(
"FEEDBACK", $this->
object->prepareTextareaOutput($fb,
true));
493 $template->setCurrentBlock(
"answer_row");
494 $template->setVariable(
"ANSWER_ID", $answer_id);
495 $template->setVariable(
"ANSWER_TEXT", $this->
object->prepareTextareaOutput($answer->getAnswertext(),
true));
496 if (strcmp($user_solution, $answer_id) == 0) {
497 $template->setVariable(
"CHECKED_ANSWER",
" checked=\"checked\"");
501 $questiontext = $this->
object->getQuestion();
502 $template->setVariable(
"QUESTIONTEXT", $this->
object->prepareTextareaOutput($questiontext,
true));
504 $pageoutput = $this->
outQuestionPage(
"", $is_postponed, $active_id, $questionoutput);
517 global $rbacsystem, $ilTabs;
519 $ilTabs->clearTargets();
521 $this->ctrl->setParameterByClass(
"ilAssQuestionPageGUI",
"q_id",
$_GET[
"q_id"]);
522 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
523 $q_type = $this->
object->getQuestionType();
525 if (strlen($q_type)) {
526 $classname = $q_type .
"GUI";
527 $this->ctrl->setParameterByClass(strtolower($classname),
"sel_question_types", $q_type);
528 $this->ctrl->setParameterByClass(strtolower($classname),
"q_id",
$_GET[
"q_id"]);
532 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"])) {
536 $this->ctrl->getLinkTargetByClass(
"ilAssQuestionPageGUI",
"edit"),
537 array(
"edit",
"insert",
"exec_pg"),
547 $force_active =
false;
548 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"])) {
551 $url = $this->ctrl->getLinkTargetByClass($classname,
"editQuestion");
557 array(
"editQuestion",
"save",
"saveEdit",
"addchoice",
"removechoice",
"removeimagechoice",
"uploadchoice",
"originalSyncForm"),
577 $this->ctrl->getLinkTargetByClass($classname,
"assessment"),
594 $choiceKeys = array_keys($this->
object->answers);
596 if ($this->
object->getShuffle()) {
597 $choiceKeys = $this->
object->getShuffler()->shuffle($choiceKeys);
607 return $this->
object->prepareTextareaOutput(
$output,
true);
612 $this->
object->setShuffle(
$_POST[
"shuffle"]);
613 $this->
object->setMultilineAnswerSetting(
$_POST[
"types"]);
614 if (is_array(
$_POST[
'choice'][
'imagename']) &&
$_POST[
"types"] == 1) {
615 $this->
object->isSingleline =
true;
618 $this->
object->isSingleline = (
$_POST[
"types"] == 0) ?
true :
false;
620 $this->
object->setThumbSize((strlen(
$_POST[
"thumb_size"])) ?
$_POST[
"thumb_size"] :
"");
629 $shuffle->setChecked($this->
object->getShuffle());
630 $shuffle->setRequired(
false);
633 if ($this->
object->getId()) {
635 $hidden->setValue($this->
object->getId());
639 if (!$this->
object->getSelfAssessmentEditingMode()) {
643 $types->setValue(($isSingleline) ? 0 : 1);
646 0 => $this->lng->txt(
'answers_singleline'),
647 1 => $this->lng->txt(
'answers_multiline'),
655 $thumb_size =
new ilNumberInputGUI($this->lng->txt(
"thumb_size"),
"thumb_size");
656 $thumb_size->
setSuffix($this->lng->txt(
"thumb_size_unit_pixel"));
657 $thumb_size->setMinValue(20);
658 $thumb_size->setDecimals(0);
659 $thumb_size->setSize(6);
660 $thumb_size->setInfo($this->lng->txt(
'thumb_size_info'));
661 $thumb_size->setValue($this->
object->getThumbSize());
662 $thumb_size->setRequired(
false);
685 $this->
object->flushAnswers();
686 if ($this->
object->isSingleline) {
687 foreach (
$_POST[
'choice'][
'answer'] as
$index => $answertext) {
691 $file_org_name = $_FILES[
'choice'][
'name'][
'image'][
$index];
692 $file_temp_name = $_FILES[
'choice'][
'tmp_name'][
'image'][
$index];
694 if (strlen($file_temp_name)) {
696 $suffix = strtolower(array_pop(explode(
".", $file_org_name)));
697 if (in_array($suffix,
array(
"jpg",
"jpeg",
"png",
"gif" ))) {
699 $filename = $this->
object->buildHashedImageFilename($file_org_name);
706 $this->
object->addAnswer($answertext,
$_POST[
'choice'][
'points'][
$index], $index, $picturefile);
709 foreach (
$_POST[
'choice'][
'answer'] as
$index => $answer) {
710 $answertext = $answer;
711 $this->
object->addAnswer($answertext,
$_POST[
'choice'][
'points'][
$index], $index);
721 include_once
"./Modules/TestQuestionPool/classes/class.ilSingleChoiceWizardInputGUI.php";
724 $choices->setQuestionObject($this->
object);
725 $choices->setSingleline($isSingleline);
726 $choices->setAllowMove(
false);
727 if ($this->
object->getSelfAssessmentEditingMode()) {
728 $choices->setSize(40);
730 $choices->setMaxLength(800);
731 if ($this->
object->getAnswerCount() == 0) {
732 $this->
object->addAnswer(
"", 0, 0);
734 $choices->setValues($this->
object->getAnswers());
769 $aggregate =
array();
770 foreach ($answers_defined_on_question as $answer) {
771 $aggregated_info_for_answer =
array();
772 $aggregated_info_for_answer[
'answertext'] = $answer->getAnswerText();
773 $aggregated_info_for_answer[
'count_checked'] = 0;
775 foreach ($relevant_answers_chosen as $relevant_answer) {
776 if ($relevant_answer[
'value1'] == $answer->getOrder()) {
777 $aggregated_info_for_answer[
'count_checked']++;
780 $aggregated_info_for_answer[
'count_unchecked'] =
781 ceil(count($relevant_answers_chosen) / count($answers_defined_on_question))
782 - $aggregated_info_for_answer[
'count_checked'];
784 $aggregate[] = $aggregated_info_for_answer;
796 $tpl =
new ilTemplate(
'tpl.il_as_aggregated_answers_table.html',
true,
true,
"Modules/TestQuestionPool");
798 $tpl->setCurrentBlock(
'headercell');
799 $tpl->setVariable(
'HEADER', $this->lng->txt(
'tst_answer_aggr_answer_header'));
800 $tpl->parseCurrentBlock();
802 $tpl->setCurrentBlock(
'headercell');
803 $tpl->setVariable(
'HEADER', $this->lng->txt(
'tst_answer_aggr_frequency_header'));
804 $tpl->parseCurrentBlock();
806 foreach ($aggregate as $line_data) {
807 $tpl->setCurrentBlock(
'aggregaterow');
808 $tpl->setVariable(
'OPTION', $line_data[
'answertext']);
809 $tpl->setVariable(
'COUNT', $line_data[
'count_checked']);
810 $tpl->parseCurrentBlock();
817 $feedbackOutputRequired =
false;
819 switch ($this->
object->getSpecificFeedbackSetting()) {
821 $feedbackOutputRequired =
true;
825 if (strcmp($user_solution, $answer_id) == 0) {
826 $feedbackOutputRequired =
true;
831 if ($this->
object->getAnswer($answer_id)->getPoints() > 0) {
832 $feedbackOutputRequired =
true;
837 if ($feedbackOutputRequired) {
838 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->
object->getId(), $answer_id);
841 $template->setVariable(
"FEEDBACK", $this->
object->prepareTextareaOutput($fb,
true));
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)
if(!array_key_exists('StateId', $_REQUEST)) $id
renderAggregateView($aggregate)
populateQuestionSpecificFormPart(\ilPropertyFormGUI $form)
getQuestionTemplate()
get question template
const CSS_CLASS_FEEDBACK_CORRECT
populateTaxonomyFormSection(ilPropertyFormGUI $form)
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
getTestOutput($active_id, $pass, $is_postponed=false, $use_post_solutions=false, $show_feedback=false)
writeQuestionGenericPostData()
if(isset($_POST['submit'])) $form
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
Create styles array
The data for the language used.
getAnswerFeedbackOutput($active_id, $pass)
Returns the answer generic feedback depending on the results of the question.
populateAnswerSpecificFormPart(\ilPropertyFormGUI $form)
saveTaxonomyAssignments()
addchoice()
Add a new answer.
Create new PHPExcel object
obj_idprivate
addBackTab(ilTabsGUI $ilTabs)
static secureString($a_str, $a_strip_html=true, $a_allow="")
Remove unsecure tags.
isRenderPurposePrintPdf()
Interface ilGuiAnswerScoringAdjustable.
Single choice question GUI representation.
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="")
output question page
getSpecificFeedbackOutput($active_id, $pass)
__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()