19 require_once
'./Modules/Test/classes/inc.AssessmentConstants.php';
54 $this->minAutoComplete = self::MIN_LENGTH_AUTOCOMPLETE;
56 $this->ilDB = $DIC->database();
57 $this->identical_scoring = 1;
157 return $this->minAutoComplete ? $this->minAutoComplete : self::MIN_LENGTH_AUTOCOMPLETE;
162 if (strlen($this->title)
164 && $this->long_menu_text
165 &&
sizeof($this->answers) > 0
166 &&
sizeof($this->correct_answers) > 0
201 if (!is_array($correct_answers_row[0]) ||
sizeof($correct_answers_row[0]) == 0) {
204 if ($correct_answers_row[1] > 0) {
205 array_push(
$points, $correct_answers_row[1]);
228 if (!in_array($answer, $answer_options)) {
248 $sum += (float) $add[1];
257 $this->ilDB->manipulateF(
260 array( $this->
getId() )
262 $this->ilDB->manipulateF(
264 ) .
" (question_fi, long_menu_text, feedback_setting, min_auto_complete, identical_scoring) VALUES (%s, %s, %s, %s, %s)",
265 array(
"integer",
"text",
"integer",
"integer",
"integer"),
284 foreach ($gap[0] as $position => $answer) {
285 if ($type_array == null) {
288 $type = $type_array[$gap_number];
293 'question_fi' => array(
'integer', $this->
getId()),
294 'gap_number' => array(
'integer', (
int) $gap_number),
295 'position' => array(
'integer', (
int) $position)
298 'answer_text' => array(
'text', $answer),
299 'points' => array(
'float', (
float) str_replace(
',',
'.', $gap[1])),
300 'type' => array(
'integer', (
int) $type)
304 $points += (float) str_replace(
',',
'.', $gap[1]);
313 foreach ($array as $gap => $values) {
315 if (is_array($values)) {
316 foreach ($values as
$key => $value) {
317 $file_content .= $value .
"\n";
319 $file_content = rtrim($file_content,
"\n");
321 fwrite($file, $file_content);
331 if ($files ===
false) {
337 foreach ($files as $file) {
338 $gap = str_replace(
'.txt',
'', basename($file));
339 $answers[(
int) $gap] = explode(
"\n", file_get_contents($file));
359 throw new ilException(
'Cannot create export directory');
363 !is_dir($folder_name) ||
364 !is_readable($folder_name) ||
365 !is_writable($folder_name)
367 throw new ilException(
'Cannot create export directory');
373 $result = $this->ilDB->queryF(
378 if ($result->numRows() == 1) {
379 $data = $this->ilDB->fetchAssoc($result);
380 $this->
setId($question_id);
384 $this->
setComment((
string) $data[
"description"]);
394 if (isset($data[
'feedback_setting'])) {
412 parent::loadFromDb($question_id);
417 $res = $this->db->queryF(
418 "SELECT * FROM {$this->getAnswerTableName()} WHERE question_fi = %s ORDER BY gap_number, position ASC",
424 while (
$data = $this->ilDB->fetchAssoc(
$res)) {
436 $res = $this->db->queryF(
437 'SELECT gap_number, answer_text FROM ' . $this->
getAnswerTableName() .
' WHERE question_fi = %s',
441 while (
$data = $this->ilDB->fetchAssoc(
$res)) {
455 $res = $this->db->queryF(
456 'SELECT answer_text FROM ' . $this->
getAnswerTableName() .
' WHERE question_fi = %s AND gap_number = %s',
457 array(
'integer',
'integer'),
458 array($question_id, $gap_id)
460 while (
$data = $this->ilDB->fetchAssoc(
$res)) {
469 $res = $this->db->queryF(
470 'SELECT points FROM ' . $this->
getAnswerTableName() .
' WHERE question_fi = %s AND gap_number = %s GROUP BY gap_number, points',
471 array(
'integer',
'integer'),
472 array($question_id, $gap_id)
474 while (
$data = $this->ilDB->fetchAssoc(
$res)) {
494 if ($this->
id <= 0) {
500 $this_id = $this->
getId();
505 $original_id = $this->questioninfo->getOriginalId($this->
id);
508 if ((
int) $testObjId > 0) {
509 $clone->setObjId($testObjId);
529 $clone->copyPageOfQuestion($this_id);
530 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
531 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
538 if ($this->
getId() <= 0) {
539 throw new RuntimeException(
'The question has not been saved. It cannot be duplicated');
544 $original_id = $this->questioninfo->getOriginalId($this->
id);
546 $source_questionpool_id = $this->
getObjId();
547 $clone->setObjId($target_questionpool_id);
556 $clone->onCopy($source_questionpool_id,
$original_id, $clone->getObjId(), $clone->getId());
563 if ($this->
getId() <= 0) {
564 throw new RuntimeException(
'The question has not been saved. It cannot be duplicated');
568 $sourceParentId = $this->
getObjId();
574 $clone->setObjId($targetParentId);
576 if ($targetQuestionTitle) {
577 $clone->setTitle($targetQuestionTitle);
581 $clone->copyPageOfQuestion($sourceQuestionId);
582 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
584 $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
601 public function calculateReachedPoints($active_id, $pass = null, $authorizedSolution =
true, $returndetails =
false): float
603 if ($returndetails) {
604 throw new ilTestException(
'return details not implemented for ' . __METHOD__);
607 $found_values = array();
608 if (is_null($pass)) {
612 while (
$data = $this->ilDB->fetchAssoc($result)) {
621 if ($found_values == null) {
625 $solution_values_text = array();
626 foreach ($found_values as
$key => $answer) {
633 if ((in_array($answer, $solution_values_text)) && (
$points > 0)) {
638 array_push($solution_values_text, $answer);
645 public function saveWorkingData(
int $active_id,
int $pass = null,
bool $authorized =
true): bool
647 if (is_null($pass)) {
653 $this->
getProcessLocker()->executeUserSolutionUpdateLockOperation(
function () use (&$entered_values, $active_id, $pass, $authorized) {
658 if (strlen($value)) {
665 if ($entered_values) {
669 "log_user_entered_values",
671 ), $active_id, $this->
getId());
677 "log_user_not_entered_values",
679 ), $active_id, $this->
getId());
693 $ilDB = $DIC[
'ilDB'];
696 'authorized' =>
false,
697 'intermediate' =>
false 701 SELECT authorized, COUNT(*) cnt 703 WHERE active_fi = " .
$ilDB->quote($activeId,
'integer') .
" 704 AND question_fi = " .
$ilDB->quote($this->
getId(),
'integer') .
" 705 AND pass = " .
$ilDB->quote($pass,
'integer') .
" 709 if ($this->
getStep() !== null) {
710 $query .=
" AND step = " .
$ilDB->quote((
int) $this->
getStep(),
'integer') .
" ";
717 $result =
$ilDB->query($query);
719 while ($row =
$ilDB->fetchAssoc($result)) {
720 if ($row[
'authorized']) {
721 $return[
'authorized'] = $row[
'cnt'] > 0;
723 $return[
'intermediate'] = $row[
'cnt'] > 0;
733 $solutionSubmit = array();
736 foreach ($answer as
$key => $value) {
737 $solutionSubmit[
$key] = $value;
740 return $solutionSubmit;
745 $answer = $_POST[
'answer'] ?? null;
746 if (is_array($answer)) {
747 $answer = array_map(
function ($value) {
761 return "assLongMenu";
766 return 'qpl_qst_lome';
783 parent::setExportDetailsXLSX($worksheet, $startrow, $col, $active_id, $pass);
789 $worksheet->
setCell($startrow + $i, $col, $this->
lng->txt(
'assLongMenu') .
" $i");
791 foreach ($solution as $solutionvalue) {
792 if ($gap_index == $solutionvalue[
"value1"]) {
794 case self::ANSWER_TYPE_SELECT_VAL:
795 $value = $solutionvalue[
"value2"];
799 $worksheet->
setCell($startrow + $i, $col + 2, $value);
801 case self::ANSWER_TYPE_TEXT_VAL:
802 $worksheet->
setCell($startrow + $i, $col + 2, $solutionvalue[
"value2"]);
810 return $startrow + $i + 1;
828 $result->setReachedPercentage((
$points / $max_points) * 100);
853 $this->ilDB->manipulateF(
856 array( $question_id )
860 public function delete(
int $question_id):
void 862 parent::delete($question_id);
880 $result[
'id'] = $this->
getId();
888 $result[
'feedback'] = array(
889 'onenotcorrect' => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
false)),
890 'allcorrect' => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
true))
896 $result[
'mobs'] = $mobs;
897 return json_encode($result);
902 return ($this->identical_scoring) ? 1 : 0;
910 $this->identical_scoring = ($a_identical_scoring) ? 1 : 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...
getSolutionValues($active_id, $pass=null, bool $authorized=true)
Loads solutions of a given user from the database an returns it.
setNrOfTries(int $a_nr_of_tries)
static getInstance($identifier)
static stripSlashesRecursive($a_data, bool $a_strip_html=true, string $a_allow="")
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...
Abstract basic class which is to be extended by the concrete assessment question type classes...
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
getColumnCoord(int $a_col)
Get column "name" from number.
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="")
float $points
The maximum available points for the question.
Base Exception for all Exceptions relating to Modules/Test.
setParticipantsSolution($participantSolution)
saveCurrentSolution(int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
setBold(string $a_coords)
Set cell(s) to bold.
static _enabledAssessmentLogging()
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...
static logAction(string $logtext, int $active_id, int $question_id)
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
string $question
The question text.
static getDataDir()
get data directory (outside webspace)
saveQuestionDataToDb(int $original_id=-1)
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="")