19 require_once
'./Modules/Test/classes/inc.AssessmentConstants.php';
95 $this->wordCounterEnabled =
false;
96 $this->maxNumOfChars = 0;
99 $this->matchcondition = 0;
119 if (strlen($this->title)
157 $ilDB = $DIC[
'ilDB'];
159 $result =
$ilDB->queryF(
164 if (
$ilDB->numRows($result) == 1) {
166 $this->
setId($question_id);
169 $this->
setComment((
string) $data[
"description"]);
173 $this->
setPoints((
float) $data[
"points"]);
180 $this->matchcondition = (isset($data[
'matchcondition'])) ? (
int) $data[
'matchcondition'] : 0;
195 $result =
$ilDB->queryF(
196 "SELECT * FROM qpl_a_essay WHERE question_fi = %s",
202 while ($row =
$ilDB->fetchAssoc($result)) {
203 $this->
addAnswer($row[
'answertext'], $row[
'points']);
206 parent::loadFromDb($question_id);
216 if ($this->
id <= 0) {
221 $this_id = $this->
getId();
226 $original_id = $this->questioninfo->getOriginalId($this->
id);
229 if ((
int) $testObjId > 0) {
230 $clone->setObjId($testObjId);
251 $clone->copyPageOfQuestion($this_id);
253 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
254 #$clone->duplicateAnswers($this_id); 256 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
268 if ($this->
getId() <= 0) {
269 throw new RuntimeException(
'The question has not been saved. It cannot be duplicated');
274 $original_id = $this->questioninfo->getOriginalId($this->
id);
276 $source_questionpool_id = $this->
getObjId();
277 $clone->setObjId($target_questionpool_id);
287 #$clone->duplicateAnswers($original_id); 289 $clone->onCopy($source_questionpool_id,
$original_id, $clone->getObjId(), $clone->getId());
296 if ($this->
getId() <= 0) {
297 throw new RuntimeException(
'The question has not been saved. It cannot be duplicated');
301 $sourceParentId = $this->
getObjId();
307 $clone->setObjId($targetParentId);
309 if ($targetQuestionTitle) {
310 $clone->setTitle($targetQuestionTitle);
315 $clone->copyPageOfQuestion($sourceQuestionId);
317 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
319 #$clone->duplicateAnswers($sourceQuestionId); 321 $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
347 $this->maxNumOfChars = $maxchars;
374 if (in_array($this->
getKeywordRelation(), self::getScoringModesWithPointsByQuestion())) {
375 return parent::getPoints();
380 foreach ($this->answers as $answer) {
381 if ($answer->getPoints() > 0) {
391 if (in_array($this->
getKeywordRelation(), self::getScoringModesWithPointsByQuestion())) {
397 foreach ($this->answers as $answer) {
398 if ($answer->getPoints() < 0) {
408 switch ($textRating) {
437 switch ($textrating) {
451 $answertext = strip_tags($answertext);
453 if (preg_match_all(
"/([^\s.]+)/", $answertext, $matches)) {
454 foreach ($matches[1] as $answerword) {
455 array_push($answerwords, trim($answerword));
460 switch ($textrating) {
462 $transformation =
$refinery->string()->levenshtein()->standard($a_keyword, 1);
465 $transformation =
$refinery->string()->levenshtein()->standard($a_keyword, 2);
468 $transformation =
$refinery->string()->levenshtein()->standard($a_keyword, 3);
471 $transformation =
$refinery->string()->levenshtein()->standard($a_keyword, 4);
474 $transformation =
$refinery->string()->levenshtein()->standard($a_keyword, 5);
479 foreach ($answerwords as $a_original) {
480 if (isset($transformation) && $transformation->transform($a_original) >= 0) {
489 $solution = html_entity_decode($solution);
506 $qst_answer = $answer->getAnswertext();
507 $user_answer =
' ' . $solution;
509 $points += $answer->getPoints();
517 $qst_answer = $answer->getAnswertext();
518 $user_answer =
' ' . $solution;
529 $qst_answer = $answer->getAnswertext();
530 $user_answer =
' ' . $solution;
552 public function calculateReachedPoints($active_id, $pass = null, $authorizedSolution =
true, $returndetails =
false): float
554 if ($returndetails) {
555 throw new ilTestException(
'return details not implemented for ' . __METHOD__);
559 $ilDB = $DIC[
'ilDB'];
561 if (is_null($pass)) {
568 if (
$ilDB->numRows($result) == 0) {
573 $row =
$ilDB->fetchAssoc($result);
574 if ($row[
"points"] != null) {
575 return (
float) $row[
"points"];
592 $ilDB = $DIC[
'ilDB'];
593 $ilUser = $DIC[
'ilUser'];
595 if (is_null($pass)) {
602 $this->
getProcessLocker()->executeUserSolutionUpdateLockOperation(
function () use (&$entered_values, $active_id, $pass, $authorized, $text) {
611 if ($entered_values) {
615 "log_user_entered_values",
617 ), $active_id, $this->
getId());
623 "log_user_not_entered_values",
625 ), $active_id, $this->
getId());
640 $text = htmlentities($_POST[
"TEXT"]);
654 $ilDB = $DIC[
'ilDB'];
662 'question_fi' => [
'integer', $this->
getId()],
665 'keywords' => [
'text', null],
678 $ilDB = $DIC[
'ilDB'];
681 "DELETE FROM qpl_a_essay WHERE question_fi = %s",
686 foreach ($this->answers as $answer) {
688 $nextID =
$ilDB->nextId(
'qpl_a_essay');
690 "INSERT INTO qpl_a_essay (answer_id, question_fi, answertext, points) VALUES (%s, %s, %s, %s)",
691 [
'integer',
'integer',
'text',
'float'],
695 $answer->getAnswertext(),
710 return "assTextQuestion";
734 switch ($a_text_rating) {
742 $this->text_rating = $a_text_rating;
758 return "qpl_qst_essay";
767 return parent::getRTETextWithMediaObjects();
775 parent::setExportDetailsXLSX($worksheet, $startrow, $col, $active_id, $pass);
780 $worksheet->
setCell($startrow + $i, $col, $this->
lng->txt(
"result"));
786 if ($assessment_folder->getExportEssayQuestionsWithHtml()) {
790 if (array_key_exists(0, $solutions) && strlen($solutions[0][
"value1"])) {
791 $worksheet->
setCell($startrow + $i, $col + 2, html_entity_decode($solutions[0][
"value1"]));
796 return $startrow + $i + 1;
805 $result[
'id'] = $this->
getId();
812 return json_encode($result);
817 return count($this->answers);
836 $points_unchecked = 0.0,
841 $this->answers[] = $answer;
863 if (count($this->answers) < 1) {
866 if ($index >= count($this->answers)) {
870 return $this->answers[$index];
886 if (count($this->answers) < 1) {
889 if ($index >= count($this->answers)) {
892 $answer = $this->answers[$index];
896 unset($this->answers[$index]);
897 $this->answers = array_values($this->answers);
898 for ($i = 0, $iMax = count($this->answers); $i < $iMax; $i++) {
899 if ($this->answers[$i]->
getOrder() > $index) {
900 $this->answers[$i]->setOrder($i);
907 return 'qpl_a_essay';
933 for ($i = 0; $i < $count; $i++) {
945 $ilDB = $DIC[
'ilDB'];
947 $result =
$ilDB->queryF(
948 "SELECT * FROM qpl_a_essay WHERE question_fi = %s",
952 if ($result->numRows()) {
953 while ($row =
$ilDB->fetchAssoc($result)) {
954 $next_id =
$ilDB->nextId(
'qpl_a_essay');
955 $affectedRows =
$ilDB->manipulateF(
956 "INSERT INTO qpl_a_essay (answer_id, question_fi, answertext, points) 957 VALUES (%s, %s, %s, %s)",
958 [
'integer',
'integer',
'text',
'float'],
959 [$next_id, $this->
getId(), $row[
"answertext"], $row[
"points"]]
976 if ($relation !== null) {
983 return array_merge(self::getScoringModesWithPointsByQuestion(), self::getScoringModesWithPointsByKeyword());
988 return [
'non',
'all',
'one'];
1013 $text = strip_tags($text);
1015 $text = str_replace(
'>',
'>', $text);
1016 $text = str_replace(
'<',
'<', $text);
1017 $text = str_replace(
' ',
' ', $text);
1018 $text = str_replace(
'&',
'&', $text);
1020 $text = str_replace(
"\r\n",
"\n", $text);
1021 $text = str_replace(
"\n",
"", $text);
1031 $text = str_replace(
' ',
' ', $text);
1033 $text = preg_replace(
'/[.,:;!?\-_#\'"+*\\/=()&%§$]/m',
'', $text);
1035 $text = preg_replace(
'/^\s*/m',
'', $text);
1036 $text = preg_replace(
'/\s*$/m',
'', $text);
1037 $text = preg_replace(
'/\s+/m',
' ', $text);
1039 return count(explode(
' ', $text));
1044 $question_fi = $this->
getId();
1047 $cntresult = $this->db->query(
1049 SELECT count(solution_id) cnt 1051 WHERE active_fi = ' . $this->db->quote($active_id,
'int') .
' 1052 AND question_fi = ' . $this->db->quote($this->
getId(),
'int') .
' 1053 AND authorized = ' . $this->db->quote(0,
'int')
1054 .
' AND pass = ' . $this->db->quote($pass,
'int')
1056 $row = $this->db->fetchAssoc($cntresult);
1057 if ($row[
'cnt'] > 0) {
1058 $tresult = $this->db->query(
1062 WHERE active_fi = ' . $this->db->quote($active_id,
'int') .
' 1063 AND question_fi = ' . $this->db->quote($this->
getId(),
'int') .
' 1064 AND authorized = ' . $this->db->quote(0,
'int')
1065 .
' AND pass = ' . $this->db->quote($pass,
'int')
1067 $trow = $this->db->fetchAssoc($tresult);
1068 return $trow[
'value1'];
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)
const TEXTGAP_RATING_LEVENSHTEIN5
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
static getScoringModesWithPointsByKeyword()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static isObligationPossible(int $questionId)
returns boolean wether it is possible to set this question type as obligatory or not considering the ...
getLatestAutosaveContent(int $active_id, int $pass)
static _getRichTextEditor()
Returns the identifier for the Rich Text Editor.
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.
const TEXTGAP_RATING_LEVENSHTEIN2
static isHTML(string $a_text)
Checks if a given string contains HTML or not.
const TEXTGAP_RATING_LEVENSHTEIN1
Abstract basic class which is to be extended by the concrete assessment question type classes...
static strPos(string $a_haystack, string $a_needle, int $a_offset=0)
isComplete()
Returns true, if a multiple choice question is complete for use.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
setMaxNumOfChars(int $maxchars=0)
Sets the maximum number of characters for the text solution.
createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle="")
getColumnCoord(int $a_col)
Get column "name" from number.
ASS_AnswerBinaryStateImage is a class for answers with a binary state indicator (checked/unchecked, set/unset) and an image file.
loadFromDb($question_id)
Loads a assTextQuestion object from a database.
saveToDb($original_id="")
Saves a assTextQuestion object to a database.
saveWorkingData($active_id, $pass=null, $authorized=true)
Saves the learners input of the question to the database.
copyObject($target_questionpool_id, $title="")
Copies an assTextQuestion object.
static getValidScoringModes()
toJSON()
Returns a JSON representation of the question.
setComment(string $comment="")
duplicate(bool $for_test=true, string $title="", string $author="", int $owner=-1, $testObjId=null)
Duplicates an assTextQuestion.
setWordCounterEnabled($wordCounterEnabled)
float $points
The maximum available points for the question.
Base Exception for all Exceptions relating to Modules/Test.
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
static strLen(string $a_string)
__construct( $title="", $comment="", $author="", $owner=-1, $question="")
assTextQuestion constructor
saveCurrentSolution(int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
setBold(string $a_coords)
Set cell(s) to bold.
static _enabledAssessmentLogging()
isValidTextRating($textRating)
const TEXTGAP_RATING_LEVENSHTEIN3
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...
calculateReachedPointsForSolution($solution)
setMatchcondition(int $matchcondition)
duplicateAnswers($original_id)
flushAnswers()
Deletes all answers.
static logAction(string $logtext, int $active_id, int $question_id)
Class ilObjAssessmentFolder.
static getScoringModesWithPointsByQuestion()
const TEXTGAP_RATING_CASESENSITIVE
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setTextRating($a_text_rating)
Sets the rating option for text comparisons.
getHtmlUserSolutionPurifier()
getQuestionType()
Returns the question type of the question.
isKeywordMatching($answertext, $a_keyword)
Checks if one of the keywords matches the answertext.
getAdditionalTableName()
Returns the name of the additional question data table in the database.
string $question
The question text.
const HAS_SPECIFIC_FEEDBACK
getAnswer($index=0)
Returns an answer with a given index.
deleteAnswer($index=0)
Deletes an answer with a given index.
saveAnswerSpecificDataToDb()
Saves the answer specific records into a question types answer table.
addAnswer( $answertext="", $points=0.0, $points_unchecked=0.0, $order=0, $answerimage="")
Adds a possible answer for a multiple choice question.
setKeywordRelation(?string $relation)
This method implements a default behaviour.
saveQuestionDataToDb(int $original_id=-1)
getMaxNumOfChars()
Gets the maximum number of characters for the text solution.
getSolutionMaxPass(int $active_id)
removeCurrentSolution(int $active_id, int $pass, bool $authorized=true)
calculateReachedPoints($active_id, $pass=null, $authorizedSolution=true, $returndetails=false)
Returns the points, a learner has reached answering the question.
getRTETextWithMediaObjects()
Collects all text in the question which could contain media objects which were created with the Rich ...
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)
setLifecycle(ilAssQuestionLifecycle $lifecycle)
getCurrentSolutionResultSet(int $active_id, int $pass, bool $authorized=true)
getTextRating()
Returns the rating option for text comparisons.
setExportDetailsXLSX(ilAssExcelFormatHelper $worksheet, int $startrow, int $col, int $active_id, int $pass)
{}
setAuthor(string $author="")
setShuffle(?bool $shuffle=true)
setAdditionalContentEditingMode(?string $additionalContentEditingMode)
static getDraftInstance()
ILIAS Refinery Factory $refinery
const TEXTGAP_RATING_CASEINSENSITIVE
setQuestion(string $question="")