19 require_once
'./Modules/Test/classes/inc.AssessmentConstants.php';
78 $this->answers = array();
79 $this->correctanswers = 0;
94 count($this->answers) >= $this->correctanswers
132 $ilDB = $DIC[
'ilDB'];
134 $result =
$ilDB->queryF(
139 if ($result->numRows() == 1) {
141 $this->
setId($question_id);
145 $this->
setComment((
string) $data[
"description"]);
167 $result =
$ilDB->queryF(
168 "SELECT * FROM qpl_a_textsubset WHERE question_fi = %s ORDER BY aorder ASC",
172 if ($result->numRows() > 0) {
178 parent::loadFromDb($question_id);
188 if (array_key_exists($order, $this->answers)) {
191 $newchoices = array();
192 for ($i = 0; $i < $order; $i++) {
193 $newchoices[] = $this->answers[$i];
195 $newchoices[] = $answer;
196 for ($i = $order, $iMax = count($this->answers); $i < $iMax; $i++) {
197 $changed = $this->answers[$i];
198 $changed->setOrder($i + 1);
199 $newchoices[] = $changed;
201 $this->answers = $newchoices;
215 if ($this->
id <= 0) {
220 $this_id = $this->
getId();
225 $original_id = $this->questioninfo->getOriginalId($this->
id);
228 if ((
int) $testObjId > 0) {
229 $clone->setObjId($testObjId);
250 $clone->copyPageOfQuestion($this_id);
252 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
254 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
266 if ($this->
getId() <= 0) {
267 throw new RuntimeException(
'The question has not been saved. It cannot be duplicated');
272 $original_id = $this->questioninfo->getOriginalId($this->
id);
274 $source_questionpool_id = $this->
getObjId();
275 $clone->setObjId($target_questionpool_id);
285 $clone->onCopy($source_questionpool_id,
$original_id, $clone->getObjId(), $clone->getId());
292 if ($this->
getId() <= 0) {
293 throw new RuntimeException(
'The question has not been saved. It cannot be duplicated');
297 $sourceParentId = $this->
getObjId();
303 $clone->setObjId($targetParentId);
305 if ($targetQuestionTitle) {
306 $clone->setTitle($targetQuestionTitle);
311 $clone->copyPageOfQuestion($sourceQuestionId);
313 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
315 $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
329 return count($this->answers);
346 if (count($this->answers) < 1) {
349 if ($index >= count($this->answers)) {
353 return $this->answers[$index];
369 if (count($this->answers) < 1) {
372 if ($index >= count($this->answers)) {
375 unset($this->answers[$index]);
376 $this->answers = array_values($this->answers);
377 for ($i = 0, $iMax = count($this->answers); $i < $iMax; $i++) {
378 if ($this->answers[$i]->
getOrder() > $index) {
379 $this->answers[$i]->setOrder($i);
392 $this->answers = array();
404 foreach ($this->answers as $answer) {
405 if ($answer->getPoints() > 0) {
406 $points[] = $answer->getPoints();
412 if (isset(
$points[$counter])) {
413 $maxpoints +=
$points[$counter];
427 $available_answers = array();
428 foreach ($this->answers as $answer) {
429 $available_answers[] = $answer->getAnswertext();
431 return $available_answers;
454 $value = html_entity_decode($value); #SB
455 switch ($textrating) {
462 if (strcmp($value, $answer) == 0) {
467 $transformation =
$refinery->string()->levenshtein()->standard($answer, 1);
470 $transformation =
$refinery->string()->levenshtein()->standard($answer, 2);
473 $transformation =
$refinery->string()->levenshtein()->standard($answer, 3);
476 $transformation =
$refinery->string()->levenshtein()->standard($answer, 4);
479 $transformation =
$refinery->string()->levenshtein()->standard($answer, 5);
484 if (isset($transformation) && $transformation->transform($value) >= 0) {
512 switch ($a_text_rating) {
520 $this->text_rating = $a_text_rating;
538 public function calculateReachedPoints($active_id, $pass = null, $authorizedSolution =
true, $returndetails =
false): float
540 if ($returndetails) {
541 throw new ilTestException(
'return details not implemented for ' . __METHOD__);
545 $ilDB = $DIC[
'ilDB'];
548 if (is_null($pass)) {
553 $enteredTexts = array();
555 $enteredTexts[] =
$data[
"value1"];
569 $this->correctanswers = $a_correct_answers;
594 $ilDB = $DIC[
'ilDB'];
595 $ilUser = $DIC[
'ilUser'];
597 if (is_null($pass)) {
604 $this->
getProcessLocker()->executeUserSolutionUpdateLockOperation(
function () use (&$entered_values, $solutionSubmit, $active_id, $pass, $authorized) {
607 foreach ($solutionSubmit as $value) {
608 if (strlen($value)) {
615 if ($entered_values) {
619 "log_user_entered_values",
621 ), $active_id, $this->
getId());
626 "log_user_not_entered_values",
628 ), $active_id, $this->
getId());
638 $ilDB = $DIC[
'ilDB'];
644 array( $this->
getId() )
649 ) .
" (question_fi, textgap_rating, correctanswers) VALUES (%s, %s, %s)",
650 array(
"integer",
"text",
"integer" ),
663 $ilDB = $DIC[
'ilDB'];
665 "DELETE FROM qpl_a_textsubset WHERE question_fi = %s",
667 array( $this->
getId() )
670 foreach ($this->answers as
$key => $value) {
671 $answer_obj = $this->answers[
$key];
672 $next_id =
$ilDB->nextId(
'qpl_a_textsubset');
674 "INSERT INTO qpl_a_textsubset (answer_id, question_fi, answertext, points, aorder, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
675 array(
'integer',
'integer',
'text',
'float',
'integer',
'integer' ),
679 $answer_obj->getAnswertext(),
680 $answer_obj->getPoints(),
681 $answer_obj->getOrder(),
696 return "assTextSubset";
706 foreach ($this->answers as $answer) {
707 $key = $answer->getPoints() .
'';
709 if (!isset($join[
$key]) || !is_array($join[$key])) {
713 $join[
$key][] = $answer->getAnswertext();
728 foreach ($this->answers as $answer) {
729 $len = strlen($answer->getAnswertext());
730 if ($len > $maxwidth) {
734 return $maxwidth + 3;
745 return "qpl_qst_textsubset";
756 return "qpl_a_textsubset";
765 return parent::getRTETextWithMediaObjects();
773 parent::setExportDetailsXLSX($worksheet, $startrow, $col, $active_id, $pass);
778 foreach ($solutions as $solution) {
779 $worksheet->
setCell($startrow + $i, $col + 2, $solution[
"value1"]);
783 return $startrow + $i + 1;
797 $result[
'id'] = $this->
getId();
803 $result[
'feedback'] = array(
804 'onenotcorrect' => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
false)),
805 'allcorrect' => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
true))
811 "answertext" => (
string) $answer_obj->getAnswertext(),
812 "points" => (float) $answer_obj->getPoints(),
813 "order" => (
int) $answer_obj->getOrder()
816 $result[
'correct_answers'] =
$answers;
827 $result[
'mobs'] = $mobs;
829 return json_encode($result);
838 $post = $this->dic->http()->wrapper()->post();
840 $solutionSubmit = [];
842 if (
$post->has(
"TEXTSUBSET_$index")) {
843 $value =
$post->retrieve(
845 $this->dic->refinery()->kindlyTo()->string()
849 $value = $purifier->purify($value);
850 $solutionSubmit[] = $value;
855 return $solutionSubmit;
864 $enteredTexts ??= [];
867 foreach ($enteredTexts as $enteredtext) {
868 $index = $this->
isAnswerCorrect($available_answers, html_entity_decode($enteredtext));
869 if ($index !==
false) {
870 unset($available_answers[$index]);
871 $points += $this->answers[$index]->getPoints();
916 $ilDB = $DIC[
'ilDB'];
923 "SELECT value1 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step = %s ORDER BY solution_id",
924 array(
"integer",
"integer",
"integer",
"integer"),
925 array($active_id, $pass, $this->
getId(), $maxStep)
929 "SELECT value1 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s ORDER BY solution_id",
930 array(
"integer",
"integer",
"integer"),
931 array($active_id, $pass, $this->
getId())
935 for ($index = 1; $index <=
$ilDB->numRows(
$data); ++$index) {
937 $result->addKeyValue($index, $row[
"value1"]);
943 $result->setReachedPercentage((
$points / $max_points) * 100);
956 if ($index !== null) {
968 if ($answerOptionValue !== $item->getAnswerText()) {
981 $this->
addAnswer($answerOptionValue, $points, $qIndex);
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...
calculateReachedPointsForSolution($enteredTexts)
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)
addAnswer($answertext, $points, $order)
Adds an answer to the question.
setExportDetailsXLSX(ilAssExcelFormatHelper $worksheet, int $startrow, int $col, int $active_id, int $pass)
{}
static getInstance($identifier)
getCorrectAnswers()
Returns the number of correct answers needed to solve the question.
const TEXTGAP_RATING_LEVENSHTEIN5
const PercentageResultExpression
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
flushAnswers()
Deletes all answers.
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.
setCorrectAnswers(int $a_correct_answers)
Sets the number of correct answers needed to solve the question.
const TEXTGAP_RATING_LEVENSHTEIN2
const TEXTGAP_RATING_LEVENSHTEIN1
Abstract basic class which is to be extended by the concrete assessment question type classes...
Class for answers with a binary state indicator.
getOperators($expression)
Get all available operations for a specific question.
copyObject($target_questionpool_id, $title="")
Copies an assTextSubset object.
calculateReachedPoints($active_id, $pass=null, $authorizedSolution=true, $returndetails=false)
Returns the points, a learner has reached answering the question.
& joinAnswers()
Returns the answers of the question as a comma separated string.
getTextRating()
Returns the rating option for text comparisons.
setTextRating($a_text_rating)
Sets the rating option for text comparisons.
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
toJSON()
Returns a JSON representation of the question.
getAnswerTableName()
Returns the name of the answer table in the database.
saveWorkingData($active_id, $pass=null, $authorized=true)
Saves the learners input of the question to the database.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isComplete()
Returns true, if a TextSubset question is complete for use.
getUserQuestionResult($active_id, $pass)
Get the user solution for a question by active_id and the test pass.
const StringResultExpression
setComment(string $comment="")
duplicate(bool $for_test=true, string $title="", string $author="", int $owner=-1, $testObjId=null)
Duplicates an assTextSubsetQuestion.
float $points
The maximum available points for the question.
getRTETextWithMediaObjects()
Collects all text in the question which could contain media objects which were created with the Rich ...
getAvailableAnswerOptions($index=null)
If index is null, the function returns an array with all anwser options Else it returns the specific ...
getQuestionType()
Returns the question type of the question.
Base Exception for all Exceptions relating to Modules/Test.
__construct( $title="", $comment="", $author="", $owner=-1, $question="")
assTextSubset constructor
saveCurrentSolution(int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
saveToDb($original_id="")
Saves a assTextSubset object to a database.
static _enabledAssessmentLogging()
const TEXTGAP_RATING_LEVENSHTEIN3
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addAnswerOptionValue(int $qIndex, string $answerOptionValue, float $points)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
loadFromDb($question_id)
Loads a assTextSubset object from a database.
createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle="")
& getAvailableAnswers()
Returns the available answers for the question.
static logAction(string $logtext, int $active_id, int $question_id)
const NumericResultExpression
const TEXTGAP_RATING_CASESENSITIVE
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getAnswerCount()
Returns the number of answers.
getHtmlUserSolutionPurifier()
getAdditionalTableName()
Returns the name of the additional question data table in the database.
string $question
The question text.
static getOperatorsByExpression($expression)
getExpressionTypes()
Get all available expression types for a specific question.
isAddableAnswerOptionValue(int $qIndex, string $answerOptionValue)
saveAnswerSpecificDataToDb()
Saves the answer specific records into a question types answer table.
saveQuestionDataToDb(int $original_id=-1)
getAnswer($index=0)
Returns an answer with a given index.
getSolutionMaxPass(int $active_id)
static extendedTrim(string $value)
Trim non-printable characters from the beginning and end of a string.
removeCurrentSolution(int $active_id, int $pass, bool $authorized=true)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setOriginalId(?int $original_id)
const TEXTGAP_RATING_LEVENSHTEIN4
setTitle(string $title="")
static strToLower(string $a_string)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
setLifecycle(ilAssQuestionLifecycle $lifecycle)
getCurrentSolutionResultSet(int $active_id, int $pass, bool $authorized=true)
deleteAnswer($index=0)
Deletes an answer with a given index.
getMaxTextboxWidth()
Returns the maximum width needed for the answer textboxes.
lookupMaxStep(int $active_id, int $pass)
setAuthor(string $author="")
setAdditionalContentEditingMode(?string $additionalContentEditingMode)
isAnswerCorrect($answers, $answer)
Returns the index of the found answer, if the given answer is in the set of correct answers and match...
static getDraftInstance()
ILIAS Refinery Factory $refinery
const TEXTGAP_RATING_CASEINSENSITIVE
setQuestion(string $question="")
const EmptyAnswerExpression