19 require_once
'./Modules/Test/classes/inc.AssessmentConstants.php';
51 $this->
object->loadFromDb(
$id);
65 $hasErrors = (!$always) ? $this->
editQuestion(
true) :
false;
86 $this->editForm = $form;
88 $form->setFormAction($this->
ctrl->getFormAction($this));
90 $form->setMultipart(
false);
91 $form->setTableWidth(
"100%");
92 $form->setId(
"orderinghorizontal");
105 $form->setValuesByPost();
106 $errors = !$form->checkInput();
107 $form->setValuesByPost();
114 $this->tpl->setVariable(
"QUESTION_DATA", $form->getHTML());
134 $graphicalOutput =
false,
135 $result_output =
false,
136 $show_question_only =
true,
137 $show_feedback =
false,
138 $show_correct_solution =
false,
139 $show_manual_scoring =
false,
140 $show_question_text =
true 143 $user_solutions = [];
144 if (($active_id > 0) && (!$show_correct_solution)) {
145 $user_solutions = $this->
object->getSolutionValues($active_id, $pass);
148 $show_inline_feedback =
false;
157 $show_correct_solution,
158 $show_manual_scoring,
161 $show_inline_feedback,
166 mixed $user_solutions,
169 bool $graphical_output =
false,
170 bool $result_output =
false,
171 bool $show_question_only =
true,
172 bool $show_feedback =
false,
173 bool $show_correct_solution =
false,
174 bool $show_manual_scoring =
false,
175 bool $show_question_text =
true,
176 bool $show_autosave_title =
false,
177 bool $show_inline_feedback =
false,
180 if (count($user_solutions) && strlen($user_solutions[0][
'value1'])) {
181 $elements = explode(
"{::}", $user_solutions[0][
'value1']);
184 if (!count($elements)) {
185 $elements = $show_correct_solution ? $this->
object->getOrderingElements() : $this->
object->getRandomOrderingElements();
188 $template =
new ilTemplate(
"tpl.il_as_qpl_orderinghorizontal_output_solution.html",
true,
true,
"Modules/TestQuestionPool");
189 foreach ($elements as
$id => $element) {
190 $template->setCurrentBlock(
"element");
191 $template->setVariable(
"ELEMENT_ID",
"sol_e_" . $this->
object->getId() .
"_$id");
193 $template->parseCurrentBlock();
196 if (($active_id > 0) && (!$show_correct_solution)) {
197 if ($this->
object->getStep() === null) {
198 $reached_points = $this->
object->getReachedPoints($active_id, $pass);
200 $reached_points = $this->
object->calculateReachedPoints($active_id, $pass);
202 if ($graphical_output) {
204 if ($reached_points == $this->
object->getMaximumPoints()) {
206 } elseif ($reached_points > 0) {
209 $template->setCurrentBlock(
"icon_ok");
210 $template->setVariable(
"ICON_OK", $correctness_icon);
211 $template->parseCurrentBlock();
214 $reached_points = $this->
object->getPoints();
217 if ($result_output) {
218 $resulttext = ($reached_points == 1) ?
"(%s " . $this->
lng->txt(
"point") .
")" :
"(%s " . $this->
lng->txt(
"points") .
")";
219 $template->setVariable(
"RESULT_OUTPUT", sprintf($resulttext, $reached_points));
221 if ($show_question_text ==
true) {
222 $template->setVariable(
"QUESTIONTEXT", $this->
object->getQuestionForHTMLOutput());
225 if ($this->
object->getTextSize() >= 10) {
226 $template->setVariable(
"STYLE",
" style=\"font-size: " . $this->
object->getTextSize() .
"%;\"");
229 $questionoutput = $template->get();
230 $solutiontemplate =
new ilTemplate(
"tpl.il_as_tst_solution_output.html",
true,
true,
"Modules/TestQuestionPool");
231 $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
235 if ($show_feedback) {
238 $feedback .= strlen($fb) ? $fb :
'';
241 if (strlen($feedback)) {
247 $solutiontemplate->setVariable(
"ILC_FB_CSS_CLASS", $cssClass);
250 $solutionoutput = $solutiontemplate->get();
251 if (!$show_question_only) {
255 return $solutionoutput;
259 public function getPreview($show_question_only =
false, $showInlineFeedback =
false): string
263 $elements = $this->
object->splitAndTrimOrderElementText($elements, $this->
object->getAnswerSeparator());
265 $elements = $this->
object->getRandomOrderingElements();
268 $template =
new ilTemplate(
"tpl.il_as_qpl_orderinghorizontal_preview.html",
true,
true,
"Modules/TestQuestionPool");
271 $(
'#horizontal_{QUESTION_ID}').ilHorizontalOrderingQuestion({
272 result_value_selector :
'.ilOrderingValue',
273 result_separator :
'{::}' 277 $js = str_replace(
'{QUESTION_ID}', $this->
object->getId(), $js);
278 $this->tpl->addOnLoadCode($js);
280 foreach ($elements as
$id => $element) {
281 $template->setCurrentBlock(
"element");
282 $template->setVariable(
"ELEMENT_ID",
"e_" . $this->
object->getId() .
"_$id");
285 $template->parseCurrentBlock();
287 $template->setVariable(
"QUESTION_ID", $this->
object->getId());
288 $template->setVariable(
"VALUE_ORDERRESULT",
' value="' . join(
'{::}', $elements) .
'"');
289 if ($this->
object->getTextSize() >= 10) {
290 $template->setVariable(
"STYLE",
" style=\"font-size: " . $this->
object->getTextSize() .
"%;\"");
292 $template->setVariable(
"QUESTIONTEXT", $this->
object->getQuestionForHTMLOutput());
293 $questionoutput = $template->get();
294 if (!$show_question_only) {
299 if ($DIC->http()->agent()->isMobile() || $DIC->http()->agent()->isIpad()) {
302 $this->tpl->addJavaScript(
'./node_modules/@andxor/jquery-ui-touch-punch-fix/jquery.ui.touch-punch.js');
304 $this->tpl->addJavascript(
"./Modules/TestQuestionPool/templates/default/orderinghorizontal.js");
305 return $questionoutput;
309 public function getTestOutput($active_id, $pass, $is_postponed =
false, $use_post_solutions =
false, $show_feedback =
false): string
313 $template =
new ilTemplate(
"tpl.il_as_qpl_orderinghorizontal_output.html",
true,
true,
"Modules/TestQuestionPool");
315 $().ready(
function() {
316 if (typeof $.fn.ilHorizontalOrderingQuestion !=
'undefined') {
317 $(
'#horizontal_{QUESTION_ID}').ilHorizontalOrderingQuestion({
318 result_value_selector:
'.ilOrderingValue',
319 result_separator:
'{::}' 324 $js = str_replace(
'{QUESTION_ID}', $this->
object->getId(), $js);
325 $this->tpl->addOnLoadCode($js);
328 $elements = $this->
object->getRandomOrderingElements();
331 $solutions = $this->
object->getTestOutputSolutions($active_id, $pass);
333 if (is_array($solutions) && count($solutions) == 1) {
334 $elements = explode(
"{::}", $solutions[0][
'value1']);
337 if (!is_array($solutions) || count($solutions) == 0) {
342 foreach ($elements as
$id => $element) {
343 $template->setCurrentBlock(
"element");
344 $template->setVariable(
"ELEMENT_ID",
"e_" . $this->
object->getId() .
"_$id");
347 $template->parseCurrentBlock();
349 $template->setVariable(
"QUESTION_ID", $this->
object->getId());
350 if ($this->
object->getTextSize() >= 10) {
351 $template->setVariable(
"STYLE",
" style=\"font-size: " . $this->
object->getTextSize() .
"%;\"");
353 $template->setVariable(
"VALUE_ORDERRESULT",
' value="' . join(
'{::}', $elements) .
'"');
354 $template->setVariable(
"QUESTIONTEXT", $this->
object->getQuestionForHTMLOutput());
355 $questionoutput = $template->get();
361 if ($DIC->http()->agent()->isMobile() || $DIC->http()->agent()->isIpad()) {
364 $this->tpl->addJavaScript(
'./node_modules/@andxor/jquery-ui-touch-punch-fix/jquery.ui.touch-punch.js');
366 $this->tpl->addJavascript(
"./Modules/TestQuestionPool/templates/default/orderinghorizontal.js");
367 $questionoutput = $template->get();
368 $pageoutput = $this->
outQuestionPage(
"", $is_postponed, $active_id, $questionoutput);
378 if ($DIC->http()->agent()->isMobile() || $DIC->http()->agent()->isIpad()) {
379 $files[] =
'./node_modules/@andxor/jquery-ui-touch-punch-fix/jquery.ui.touch-punch.js';
392 $this->
object->setTextSize((
float) str_replace(
',',
'.', $this->request->raw(
'textsize') ??
'0.0'));
393 $this->
object->setOrderText($this->request->raw(
'ordertext'));
394 $this->
object->setPoints((
float) str_replace(
',',
'.', $this->request->raw(
'points')));
415 $ordertext->
setValue((
string) self::prepareTextareaOutput($this->
object->getOrderText(),
false,
true));
416 $ordertext->setRequired(
true);
417 $ordertext->setInfo(sprintf($this->
lng->txt(
"ordertext_info"), $this->
object->getSeparator()));
418 $ordertext->setRows(10);
419 $ordertext->setCols(80);
423 $textsize->setValue($this->
object->getTextSize());
424 $textsize->setInfo($this->
lng->txt(
"textsize_info"));
425 $textsize->setSize(6);
426 $textsize->setMinValue(10);
427 $textsize->setRequired(
false);
432 $points->allowDecimals(
true);
435 if ($this->
object->getPoints() == null) {
436 $points->setValue(
"1");
438 $points->setValue($this->
object->getPoints());
440 $points->setRequired(
true);
442 $points->setMinValue(0.0);
443 $points->setMinvalueShouldBeGreater(
true);
461 public function aggregateAnswers($relevant_answers_chosen, $answer_defined_on_question): array
463 $aggregate = array();
464 foreach ($relevant_answers_chosen as $answer) {
465 $answer = str_replace($this->
object->getAnswerSeparator(),
' - ', $answer);
466 if (in_array($answer[
'value1'], $aggregate)) {
467 $aggregate[$answer[
'value1']] = $aggregate[$answer[
'value1']] + 1;
469 $aggregate[$answer[
'value1']] = 1;
483 $tpl =
new ilTemplate(
'tpl.il_as_aggregated_answers_table.html',
true,
true,
"Modules/TestQuestionPool");
485 foreach ($aggregate as
$key => $line_data) {
498 foreach ($relevantAnswers as $ans) {
499 $md5 = md5($ans[
'value1']);
501 if (!isset($answers[$md5])) {
502 $answer = str_replace(
503 $this->
object->getAnswerSeparator(),
504 ' - ',
508 $answers[$md5] = array(
509 'answer' => $answer,
'frequency' => 0
513 $answers[$md5][
'frequency']++;
524 $points->allowDecimals(
true);
525 $points->setValue($this->
object->getPoints());
526 $points->setRequired(
true);
528 $points->setMinValue(0.0);
529 $points->setMinvalueShouldBeGreater(
true);
538 $this->
object->setPoints((
float) str_replace(
',',
'.', $form->
getInput(
'points')));
isTestPresentationContext()
hasCorrectSolution($activeId, $passIndex)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
generateCorrectnessIconsForCorrectness(int $correctness)
getAggregatedAnswersView(array $relevant_answers)
Returns an html string containing a question specific representation of the answers so far given in t...
setCurrentBlock(string $blockname=self::DEFAULT_BLOCK)
Sets the template to the given block.
renderSolutionOutput(mixed $user_solutions, int $active_id, ?int $pass, bool $graphical_output=false, bool $result_output=false, bool $show_question_only=true, bool $show_feedback=false, bool $show_correct_solution=false, bool $show_manual_scoring=false, bool $show_question_text=true, bool $show_autosave_title=false, bool $show_inline_feedback=false,)
saveCorrectionsFormProperties(ilPropertyFormGUI $form)
addBasicQuestionFormProperties(ilPropertyFormGUI $form)
parseCurrentBlock(string $blockname=self::DEFAULT_BLOCK)
Parses the given block.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const CSS_CLASS_FEEDBACK_CORRECT
ilGlobalPageTemplate $tpl
renderAggregateView($aggregate)
populateTaxonomyFormSection(ilPropertyFormGUI $form)
addQuestionFormCommandButtons(ilPropertyFormGUI $form)
populateQuestionSpecificFormPart(\ilPropertyFormGUI $form)
setValue(string $a_value)
editQuestion($checkonly=false)
Creates an output of the edit form for the question.
setErrorMessage(string $errormessage)
writeQuestionGenericPostData()
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.
static initjQueryUI(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery-UI JS-File to the global template (see included_components.txt for included components)
aggregateAnswers($relevant_answers_chosen, $answer_defined_on_question)
const CSS_CLASS_FEEDBACK_WRONG
Basic GUI class for assessment questions.
populateCorrectionsFormProperties(ilPropertyFormGUI $form)
writeQuestionSpecificPostData(ilPropertyFormGUI $form)
Extracts the question specific values from $_POST and applies them to the data object.
saveTaxonomyAssignments()
getILIASPage(string $html="")
Returns the ILIAS Page around a question.
__construct($id=-1)
assOrderingHorizontalGUI constructor
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="", $inlineFeedbackEnabled=false)
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
getPresentationJavascripts()
This class represents a text area property in a property form.
getPreview($show_question_only=false, $showInlineFeedback=false)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
getAnswersFrequency($relevantAnswers, $questionIndex)
getAfterParticipationSuppressionQuestionPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
getSpecificFeedbackOutput(array $userSolution)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static clear(string $a_var)
setVariable(string $variable, $value='')
Sets the given variable to the given value.
static set(string $a_var, $a_val)
Set a value.
getTestOutput($active_id, $pass, $is_postponed=false, $use_post_solutions=false, $show_feedback=false)
writePostData(bool $always=false)
{}
getGenericFeedbackOutput(int $active_id, ?int $pass)