19 declare(strict_types=1);
138 $this->minAutoComplete = $min_auto_complete;
148 if (strlen($this->title)
150 && $this->long_menu_text
151 &&
sizeof($this->answers) > 0
152 &&
sizeof($this->correct_answers) > 0
177 if ($correct_answers ===
null 178 || $correct_answers === []
179 || $hidden_text_files ===
null 180 || $hidden_text_files === []) {
183 if (
sizeof($correct_answers) !=
sizeof($hidden_text_files)) {
186 foreach ($correct_answers as $key => $correct_answers_row) {
190 if (!is_array($correct_answers_row[0]) || $correct_answers_row[0] === []) {
193 if ($correct_answers_row[1] > 0) {
194 array_push(
$points, $correct_answers_row[1]);
197 if (
sizeof($correct_answers) !=
sizeof(
$points)) {
216 foreach ($answers[0] as $key => $answer) {
217 if (!in_array($answer, $answer_options)) {
237 $sum += (float) $add[1];
246 $this->db->manipulateF(
251 $this->db->manipulateF(
253 ) .
" (question_fi, long_menu_text, feedback_setting, min_auto_complete, identical_scoring) VALUES (%s, %s, %s, %s, %s)",
254 [
"integer",
"text",
"integer",
"integer",
"integer"],
273 foreach ($gap[0] as $position => $answer) {
274 if ($type_array ==
null) {
277 $type = $type_array[$gap_number];
282 'question_fi' => [
'integer', $this->
getId()],
283 'gap_number' => [
'integer', (
int) $gap_number],
284 'position' => [
'integer', (
int) $position]
287 'answer_text' => [
'text', $answer],
288 'points' => [
'float', $gap[1]],
289 'type' => [
'integer', (
int) $type]
302 foreach ($array as $gap => $values) {
304 if (is_array($values)) {
305 foreach ($values as $key => $value) {
306 $file_content .= $value .
"\n";
308 $file_content = rtrim($file_content,
"\n");
310 fwrite($file, $file_content);
320 if ($files ===
false) {
326 foreach ($files as $file) {
327 $gap = str_replace(
'.txt',
'', basename($file));
328 $answers[(
int) $gap] = explode(
"\n", file_get_contents($file));
348 throw new ilException(
'Cannot create export directory');
352 !is_dir($folder_name) ||
353 !is_readable($folder_name) ||
354 !is_writable($folder_name)
356 throw new ilException(
'Cannot create export directory');
362 $result = $this->db->queryF(
367 if ($result->numRows() == 1) {
368 $data = $this->db->fetchAssoc($result);
369 $this->
setId($question_id);
373 $this->
setComment((
string) $data[
'description']);
381 $this->
setMinAutoComplete($data[
'min_auto_complete'] ?? self::MIN_LENGTH_AUTOCOMPLETE);
382 if (isset($data[
'feedback_setting'])) {
400 parent::loadFromDb($question_id);
405 $res = $this->db->queryF(
406 "SELECT * FROM {$this->getAnswerTableName()} WHERE question_fi = %s ORDER BY gap_number, position ASC",
411 $correct_answers = [];
412 while (
$data = $this->db->fetchAssoc(
$res)) {
413 $correct_answers[
$data[
'gap_number']][0][
$data[
'position']] = rtrim($data[
'answer_text']);
414 $correct_answers[$data[
'gap_number']][1] = $data[
'points'];
415 $correct_answers[$data[
'gap_number']][2] = $data[
'type'];
423 $correct_answers = [];
424 $res = $this->db->queryF(
425 'SELECT gap_number, answer_text FROM ' . $this->
getAnswerTableName() .
' WHERE question_fi = %s',
429 while (
$data = $this->db->fetchAssoc(
$res)) {
430 if (array_key_exists(
$data[
'gap_number'], $correct_answers)) {
431 $correct_answers[
$data[
'gap_number']] .=
' ' . $this->
lng->txt(
"or") .
' ';
432 $correct_answers[
$data[
'gap_number']] .= rtrim(
$data[
'answer_text']);
434 $correct_answers[
$data[
'gap_number']] = rtrim($data[
'answer_text']);
442 $correct_answers = [];
443 $res = $this->db->queryF(
444 'SELECT answer_text FROM ' . $this->
getAnswerTableName() .
' WHERE question_fi = %s AND gap_number = %s',
445 [
'integer',
'integer'],
446 [$question_id, $gap_id]
448 while (
$data = $this->db->fetchAssoc(
$res)) {
449 $correct_answers[] = rtrim(
$data[
'answer_text']);
457 $res = $this->db->queryF(
458 'SELECT points FROM ' . $this->
getAnswerTableName() .
' WHERE question_fi = %s AND gap_number = %s GROUP BY gap_number, points',
459 [
'integer',
'integer'],
460 [$question_id, $gap_id]
462 while (
$data = $this->db->fetchAssoc(
$res)) {
483 bool $authorized_solution =
true 486 if (is_null($pass)) {
490 while (
$data = $this->db->fetchAssoc($result)) {
499 if ($found_values ==
null) {
503 $solution_values_text = [];
504 foreach ($found_values as $key => $answer) {
505 if ($answer ===
'') {
510 if (!in_array($answer, $correct_answers)) {
516 && in_array($answer, $solution_values_text)
522 array_push($solution_values_text, $answer);
531 bool $authorized =
true 533 if (is_null($pass)) {
539 function () use ($answer, $active_id, $pass, $authorized) {
542 foreach ($answer as $key => $value) {
562 'authorized' =>
false,
563 'intermediate' => false
567 SELECT authorized, COUNT(*) cnt 569 WHERE active_fi = " . $this->db->quote($activeId,
'integer') .
" 570 AND question_fi = " . $this->db->quote($this->
getId(),
'integer') .
" 571 AND pass = " . $this->db->quote($pass,
'integer') .
" 576 $query .=
" AND step = " . $this->db->quote((
int) $this->
getStep(),
'integer') .
" ";
583 $result = $this->db->query($query);
585 while ($row = $this->db->fetchAssoc($result)) {
586 if ($row[
'authorized']) {
587 $return[
'authorized'] = $row[
'cnt'] > 0;
589 $return[
'intermediate'] = $row[
'cnt'] > 0;
599 $solution_submit = [];
600 foreach ($this->questionpool_request->strArray(
'answer') as $key => $value) {
601 $solution_submit[$key] = $value;
603 return $solution_submit;
608 $answer = $this->questionpool_request->strArray(
'answer');
619 return "assLongMenu";
624 return 'qpl_qst_lome';
651 $result->setReachedPercentage((
$points / $max_points) * 100);
676 $this->db->manipulateF(
683 public function delete(
int $question_id):
void 685 parent::delete($question_id);
703 $result[
'id'] = $this->
getId();
711 $result[
'feedback'] = [
712 'onenotcorrect' => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
false)),
713 'allcorrect' => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
true))
719 $result[
'mobs'] = $mobs;
720 return json_encode($result);
736 AdditionalInformationGenerator::KEY_QUESTION_TYPE => (string) $this->
getQuestionType(),
740 AdditionalInformationGenerator::KEY_QUESTION_SHUFFLE_ANSWER_OPTIONS => $additional_info
742 AdditionalInformationGenerator::KEY_FEEDBACK => [
743 AdditionalInformationGenerator::KEY_QUESTION_FEEDBACK_ON_INCOMPLETE => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
false)),
744 AdditionalInformationGenerator::KEY_QUESTION_FEEDBACK_ON_COMPLETE => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
true))
746 AdditionalInformationGenerator::KEY_QUESTION_ANSWER_OPTIONS => $this->
getAnswersForLog($additional_info),
747 AdditionalInformationGenerator::KEY_QUESTION_CORRECT_ANSWER_OPTIONS => $this->
getCorrectAnswersForLog($additional_info)
756 static function (
string $c, array $v) use ($additional_info, &$i):
string {
758 .
' ' . $i++ .
': ' . implode(
',', $v) .
'; ';
767 self::ANSWER_TYPE_SELECT_VAL => $additional_info->
getTagForLangVar(
'answers_select'),
768 self::ANSWER_TYPE_TEXT_VAL => $additional_info->
getTagForLangVar(
'answers_text_box')
774 static function (
string $c, array $v) use ($additional_info, $answer_types, &$i):
string {
776 .
' ' . $i++ .
': ' . implode(
',', $v[0]) .
', ' 778 . $additional_info->
getTagForLangVar(
'type') .
': ' . $answer_types[$v[2]] .
'; ';
786 array $solution_values
788 $parsed_solution = [];
790 foreach ($solution_values as $solution) {
791 if ($gap_index !== (
int) $solution[
'value1']) {
794 $value = $solution[
'value2'];
795 if ($gap[2] === self::ANSWER_TYPE_SELECT_VAL
796 && $value ===
'-1') {
799 $parsed_solution[$gap_index + 1] = $value;
803 return $parsed_solution;
808 $parsed_solution = [];
811 foreach ($solution_values as $solution) {
812 if ($gap_index !== (
int) $solution[
'value1']) {
815 $value = $solution[
'value2'];
816 if ($gap[2] === self::ANSWER_TYPE_SELECT_VAL
817 && $value ===
'-1') {
820 $parsed_solution[] = $this->
lng->txt(
'gap') .
' ' . $gap_index + 1 .
': ' . $value;
824 return $parsed_solution;
829 $correct_answers = [];
831 $correct_answers[] = $this->
lng->txt(
'gap')
832 .
' ' . $gap_index .
': ' . implode(
',', $gap[0]);
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
setNrOfTries(int $a_nr_of_tries)
static getInstance($identifier)
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
migrateToLmContent($content)
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
setComment(string $comment="")
setParticipantsSolution($participantSolution)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
saveCurrentSolution(int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
saveQuestionDataToDb(?int $original_id=null)
static getDataDir()
get data directory (outside webspace)
getSolutionMaxPass(int $active_id)
removeCurrentSolution(int $active_id, int $pass, bool $authorized=true)
const FEEDBACK_SETTING_ALL
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setOriginalId(?int $original_id)
setTitle(string $title="")
setLifecycle(ilAssQuestionLifecycle $lifecycle)
getCurrentSolutionResultSet(int $active_id, int $pass, bool $authorized=true)
getHtmlQuestionContentPurifier()
setAuthor(string $author="")
setAdditionalContentEditingMode(?string $additionalContentEditingMode)
static getDraftInstance()
setQuestion(string $question="")