19require_once
'./Modules/Test/classes/inc.AssessmentConstants.php';
78 $this->answers = array();
79 $this->correctanswers = 0;
94 count($this->answers) >= $this->correctanswers
134 $result =
$ilDB->queryF(
139 if ($result->numRows() == 1) {
141 $this->
setId($question_id);
145 $this->
setComment((
string) $data[
"description"]);
150 include_once(
"./Services/RTE/classes/class.ilRTE.php");
168 $result =
$ilDB->queryF(
169 "SELECT * FROM qpl_a_textsubset WHERE question_fi = %s ORDER BY aorder ASC",
173 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
174 if ($result->numRows() > 0) {
180 parent::loadFromDb($question_id);
190 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
191 if (array_key_exists($order, $this->answers)) {
194 $newchoices = array();
195 for (
$i = 0;
$i < $order;
$i++) {
196 $newchoices[] = $this->answers[
$i];
198 $newchoices[] = $answer;
199 for (
$i = $order, $iMax = count($this->answers);
$i < $iMax;
$i++) {
200 $changed = $this->answers[
$i];
201 $changed->setOrder(
$i + 1);
202 $newchoices[] = $changed;
204 $this->answers = $newchoices;
218 if ($this->
id <= 0) {
223 $this_id = $this->
getId();
227 include_once(
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
231 if ((
int) $testObjId > 0) {
232 $clone->setObjId($testObjId);
253 $clone->copyPageOfQuestion($this_id);
255 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
257 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
269 if ($this->
getId() <= 0) {
270 throw new RuntimeException(
'The question has not been saved. It cannot be duplicated');
274 include_once(
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
277 $source_questionpool_id = $this->
getObjId();
278 $clone->setObjId($target_questionpool_id);
288 $clone->onCopy($source_questionpool_id,
$original_id, $clone->getObjId(), $clone->getId());
295 if ($this->
getId() <= 0) {
296 throw new RuntimeException(
'The question has not been saved. It cannot be duplicated');
299 include_once(
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
302 $sourceParentId = $this->
getObjId();
308 $clone->setObjId($targetParentId);
310 if ($targetQuestionTitle) {
311 $clone->setTitle($targetQuestionTitle);
316 $clone->copyPageOfQuestion($sourceQuestionId);
318 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
320 $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
334 return count($this->answers);
351 if (count($this->answers) < 1) {
354 if (
$index >= count($this->answers)) {
358 return $this->answers[
$index];
374 if (count($this->answers) < 1) {
377 if (
$index >= count($this->answers)) {
380 unset($this->answers[
$index]);
381 $this->answers = array_values($this->answers);
382 for (
$i = 0, $iMax = count($this->answers);
$i < $iMax;
$i++) {
383 if ($this->answers[
$i]->getOrder() >
$index) {
384 $this->answers[
$i]->setOrder(
$i);
397 $this->answers = array();
409 foreach ($this->answers as $answer) {
410 if ($answer->getPoints() > 0) {
411 $points[] = $answer->getPoints();
417 if (isset(
$points[$counter])) {
418 $maxpoints +=
$points[$counter];
432 $available_answers = array();
433 foreach ($this->answers as $answer) {
434 $available_answers[] = $answer->getAnswertext();
436 return $available_answers;
451 include_once
"./Services/Utilities/classes/class.ilStr.php";
460 $value = html_entity_decode($value); #SB
461 switch ($textrating) {
468 if (strcmp($value, $answer) == 0) {
473 $transformation =
$refinery->string()->levenshtein()->standard($answer, 1);
476 $transformation =
$refinery->string()->levenshtein()->standard($answer, 2);
479 $transformation =
$refinery->string()->levenshtein()->standard($answer, 3);
482 $transformation =
$refinery->string()->levenshtein()->standard($answer, 4);
485 $transformation =
$refinery->string()->levenshtein()->standard($answer, 5);
490 if (isset($transformation) && $transformation->transform($value) >= 0) {
518 switch ($a_text_rating) {
526 $this->text_rating = $a_text_rating;
546 if ($returndetails) {
547 throw new ilTestException(
'return details not implemented for ' . __METHOD__);
554 if (is_null($pass)) {
559 $enteredTexts = array();
561 $enteredTexts[] =
$data[
"value1"];
575 $this->correctanswers = $a_correct_answers;
603 if (is_null($pass)) {
604 include_once
"./Modules/Test/classes/class.ilObjTest.php";
611 $this->
getProcessLocker()->executeUserSolutionUpdateLockOperation(
function () use (&$entered_values, $solutionSubmit, $active_id, $pass, $authorized) {
614 foreach ($solutionSubmit as $value) {
615 if (strlen($value)) {
622 if ($entered_values) {
626 "log_user_entered_values",
628 ), $active_id, $this->getId());
633 "log_user_not_entered_values",
635 ), $active_id, $this->getId());
651 array( $this->
getId() )
656 ) .
" (question_fi, textgap_rating, correctanswers) VALUES (%s, %s, %s)",
657 array(
"integer",
"text",
"integer" ),
672 "DELETE FROM qpl_a_textsubset WHERE question_fi = %s",
674 array( $this->
getId() )
677 foreach ($this->answers as
$key => $value) {
678 $answer_obj = $this->answers[
$key];
679 $next_id =
$ilDB->nextId(
'qpl_a_textsubset');
681 "INSERT INTO qpl_a_textsubset (answer_id, question_fi, answertext, points, aorder, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
682 array(
'integer',
'integer',
'text',
'float',
'integer',
'integer' ),
686 $answer_obj->getAnswertext(),
687 $answer_obj->getPoints(),
688 $answer_obj->getOrder(),
703 return "assTextSubset";
713 foreach ($this->answers as $answer) {
714 $key = $answer->getPoints() .
'';
716 if (!isset($join[
$key]) || !is_array($join[
$key])) {
720 $join[
$key][] = $answer->getAnswertext();
735 foreach ($this->answers as $answer) {
736 $len = strlen($answer->getAnswertext());
737 if ($len > $maxwidth) {
741 return $maxwidth + 3;
752 return "qpl_qst_textsubset";
763 return "qpl_a_textsubset";
772 return parent::getRTETextWithMediaObjects();
780 parent::setExportDetailsXLS($worksheet, $startrow, $active_id, $pass);
785 foreach ($solutions as $solution) {
786 $worksheet->
setCell($startrow +
$i, 2, $solution[
"value1"]);
790 return $startrow +
$i + 1;
803 include_once(
"./Services/RTE/classes/class.ilRTE.php");
805 $result[
'id'] = $this->
getId();
811 $result[
'feedback'] = array(
812 'onenotcorrect' => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
false)),
813 'allcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
true))
819 "answertext" => (
string) $answer_obj->getAnswertext(),
820 "points" => (
float) $answer_obj->getPoints(),
821 "order" => (
int) $answer_obj->getOrder()
824 $result[
'correct_answers'] =
$answers;
835 $result[
'mobs'] =
$mobs;
837 return json_encode($result);
846 $post = $this->dic->http()->wrapper()->post();
848 $solutionSubmit = [];
850 if (
$post->has(
"TEXTSUBSET_$index")) {
851 $value =
$post->retrieve(
853 $this->dic->refinery()->kindlyTo()->string()
857 $value = $purifier->purify($value);
858 $solutionSubmit[] = $value;
863 return $solutionSubmit;
871 $enteredTexts ??= [];
874 foreach ($enteredTexts as $enteredtext) {
877 unset($available_answers[
$index]);
928 if ($maxStep !==
null) {
930 "SELECT value1 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step = %s ORDER BY solution_id",
931 array(
"integer",
"integer",
"integer",
"integer"),
932 array($active_id, $pass, $this->
getId(), $maxStep)
936 "SELECT value1 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s ORDER BY solution_id",
937 array(
"integer",
"integer",
"integer"),
938 array($active_id, $pass, $this->
getId())
944 $result->addKeyValue(
$index, $row[
"value1"]);
950 $result->setReachedPercentage((
$points / $max_points) * 100);
975 if ($answerOptionValue !== $item->getAnswerText()) {
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.
float $points
The maximum available points for the question.
setOriginalId(?int $original_id)
string $question
The question text.
static logAction(string $logtext, int $active_id, int $question_id)
setAdditionalContentEditingMode(?string $additionalContentEditingMode)
saveCurrentSolution(int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
getSolutionValues($active_id, $pass=null, bool $authorized=true)
Loads solutions of a given user from the database an returns it.
static extendedTrim(string $value)
Trim non-printable characters from the beginning and end of a string.
getHtmlUserSolutionPurifier()
ILIAS Refinery Factory $refinery
setQuestion(string $question="")
getCurrentSolutionResultSet(int $active_id, int $pass, bool $authorized=true)
static _getOriginalId(int $question_id)
saveQuestionDataToDb(int $original_id=-1)
setAuthor(string $author="")
setComment(string $comment="")
getSolutionMaxPass(int $active_id)
setNrOfTries(int $a_nr_of_tries)
setLifecycle(ilAssQuestionLifecycle $lifecycle)
setTitle(string $title="")
removeCurrentSolution(int $active_id, int $pass, bool $authorized=true)
lookupMaxStep(int $active_id, int $pass)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getExpressionTypes()
Get all available expression types for a specific question.
getMaxTextboxWidth()
Returns the maximum width needed for the answer textboxes.
setCorrectAnswers(int $a_correct_answers)
Sets the number of correct answers needed to solve the question.
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
getAdditionalTableName()
Returns the name of the additional question data table in the database.
isAnswerCorrect($answers, $answer)
Returns the index of the found answer, if the given answer is in the set of correct answers and match...
& joinAnswers()
Returns the answers of the question as a comma separated string.
toJSON()
Returns a JSON representation of the question.
deleteAnswer($index=0)
Deletes an answer with a given index.
addAnswerOptionValue(int $qIndex, string $answerOptionValue, float $points)
isComplete()
Returns true, if a TextSubset question is complete for use.
duplicate(bool $for_test=true, string $title="", string $author="", string $owner="", $testObjId=null)
Duplicates an assTextSubsetQuestion.
createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle="")
setTextRating($a_text_rating)
Sets the rating option for text comparisons.
saveToDb($original_id="")
Saves a assTextSubset object to a database.
calculateReachedPointsForSolution($enteredTexts)
addAnswer($answertext, $points, $order)
Adds an answer to 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.
getOperators($expression)
Get all available operations for a specific question.
copyObject($target_questionpool_id, $title="")
Copies an assTextSubset object.
& getAvailableAnswers()
Returns the available answers for the question.
getTextRating()
Returns the rating option for text comparisons.
loadFromDb($question_id)
Loads a assTextSubset object from a database.
getQuestionType()
Returns the question type of the question.
getCorrectAnswers()
Returns the number of correct answers needed to solve the question.
getAnswerCount()
Returns the number of answers.
flushAnswers()
Deletes all answers.
getAvailableAnswerOptions($index=null)
If index is null, the function returns an array with all anwser options Else it returns the specific ...
__construct( $title="", $comment="", $author="", $owner=-1, $question="")
assTextSubset constructor
getRTETextWithMediaObjects()
Collects all text in the question which could contain media objects which were created with the Rich ...
isAddableAnswerOptionValue(int $qIndex, string $answerOptionValue)
setExportDetailsXLS(ilAssExcelFormatHelper $worksheet, int $startrow, int $active_id, int $pass)
{}
getAnswer($index=0)
Returns an answer with a given index.
calculateReachedPoints($active_id, $pass=null, $authorizedSolution=true, $returndetails=false)
Returns the points, a learner has reached answering the question.
static getDraftInstance()
static getInstance($identifier)
static _enabledAssessmentLogging()
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
static getOperatorsByExpression($expression)
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...
static strToLower(string $a_string)
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...
const TEXTGAP_RATING_LEVENSHTEIN5
const TEXTGAP_RATING_LEVENSHTEIN4
const TEXTGAP_RATING_LEVENSHTEIN3
const TEXTGAP_RATING_CASESENSITIVE
const TEXTGAP_RATING_LEVENSHTEIN2
const TEXTGAP_RATING_CASEINSENSITIVE
const TEXTGAP_RATING_LEVENSHTEIN1
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const PercentageResultExpression
getUserQuestionResult($active_id, $pass)
Get the user solution for a question by active_id and the test pass.
const StringResultExpression
const NumericResultExpression
const EmptyAnswerExpression
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
saveAnswerSpecificDataToDb()
Saves the answer specific records into a question types answer table.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples