19 require_once
'./Modules/TestQuestionPool/classes/class.assQuestion.php';
20 require_once
'./Modules/Test/classes/inc.AssessmentConstants.php';
21 require_once
'./Modules/TestQuestionPool/interfaces/interface.ilObjQuestionScoringAdjustable.php';
22 require_once
'./Modules/TestQuestionPool/interfaces/interface.ilObjAnswerScoringAdjustable.php';
98 $this->wordCounterEnabled =
false;
99 $this->maxNumOfChars = 0;
101 $this->answers = array();
102 $this->matchcondition = 0;
122 if (strlen($this->title)
160 $ilDB = $DIC[
'ilDB'];
162 $result =
$ilDB->queryF(
167 if (
$ilDB->numRows($result) == 1) {
169 $this->
setId($question_id);
172 $this->
setComment((
string) $data[
"description"]);
176 $this->
setPoints((
float) $data[
"points"]);
178 include_once(
"./Services/RTE/classes/class.ilRTE.php");
184 $this->matchcondition = (strlen($data[
'matchcondition'])) ? (
int) $data[
'matchcondition'] : 0;
199 $result =
$ilDB->queryF(
200 "SELECT * FROM qpl_a_essay WHERE question_fi = %s",
202 array($this->
getId())
206 while ($row =
$ilDB->fetchAssoc($result)) {
207 $this->
addAnswer($row[
'answertext'], $row[
'points']);
210 parent::loadFromDb($question_id);
220 if ($this->
id <= 0) {
225 $this_id = $this->
getId();
229 include_once(
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
233 if ((
int) $testObjId > 0) {
234 $clone->setObjId($testObjId);
255 $clone->copyPageOfQuestion($this_id);
257 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
258 #$clone->duplicateAnswers($this_id); 260 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
272 if ($this->
getId() <= 0) {
273 throw new RuntimeException(
'The question has not been saved. It cannot be duplicated');
277 include_once(
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
280 $source_questionpool_id = $this->
getObjId();
281 $clone->setObjId($target_questionpool_id);
291 #$clone->duplicateAnswers($original_id); 293 $clone->onCopy($source_questionpool_id,
$original_id, $clone->getObjId(), $clone->getId());
300 if ($this->
getId() <= 0) {
301 throw new RuntimeException(
'The question has not been saved. It cannot be duplicated');
304 include_once(
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
307 $sourceParentId = $this->
getObjId();
313 $clone->setObjId($targetParentId);
315 if ($targetQuestionTitle) {
316 $clone->setTitle($targetQuestionTitle);
321 $clone->copyPageOfQuestion($sourceQuestionId);
323 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
325 #$clone->duplicateAnswers($sourceQuestionId); 327 $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
341 if (strcmp($this->maxNumOfChars,
"") == 0) {
357 $this->maxNumOfChars = $maxchars;
384 if (in_array($this->
getKeywordRelation(), self::getScoringModesWithPointsByQuestion())) {
385 return parent::getPoints();
390 foreach ($this->answers as $answer) {
391 if ($answer->getPoints() > 0) {
401 if (in_array($this->
getKeywordRelation(), self::getScoringModesWithPointsByQuestion())) {
407 foreach ($this->answers as $answer) {
408 if ($answer->getPoints() < 0) {
427 $ilDB = $DIC[
'ilDB'];
430 if (is_null($pass)) {
433 $affectedRows =
$ilDB->manipulateF(
434 "UPDATE tst_test_result SET points = %s WHERE active_fi = %s AND question_fi = %s AND pass = %s",
435 array(
'float',
'integer',
'integer',
'integer'),
438 self::_updateTestPassResults($active_id, $pass);
447 switch ($textRating) {
475 include_once
"./Services/Utilities/classes/class.ilStr.php";
477 switch ($textrating) {
491 $answertext = strip_tags($answertext);
492 $answerwords = array();
493 if (preg_match_all(
"/([^\s.]+)/", $answertext, $matches)) {
494 foreach ($matches[1] as $answerword) {
495 array_push($answerwords, trim($answerword));
500 switch ($textrating) {
502 $transformation =
$refinery->string()->levenshtein()->standard($a_keyword, 1);
505 $transformation =
$refinery->string()->levenshtein()->standard($a_keyword, 2);
508 $transformation =
$refinery->string()->levenshtein()->standard($a_keyword, 3);
511 $transformation =
$refinery->string()->levenshtein()->standard($a_keyword, 4);
514 $transformation =
$refinery->string()->levenshtein()->standard($a_keyword, 5);
519 foreach ($answerwords as $a_original) {
520 if (isset($transformation) && $transformation->transform($a_original) >= 0) {
529 $solution = html_entity_decode($solution);
546 $qst_answer = $answer->getAnswertext();
547 $user_answer =
' ' . $solution;
549 $points += $answer->getPoints();
557 $qst_answer = $answer->getAnswertext();
558 $user_answer =
' ' . $solution;
569 $qst_answer = $answer->getAnswertext();
570 $user_answer =
' ' . $solution;
594 if ($returndetails) {
595 throw new ilTestException(
'return details not implemented for ' . __METHOD__);
599 $ilDB = $DIC[
'ilDB'];
601 if (is_null($pass)) {
608 if (
$ilDB->numRows($result) == 0) {
613 $row =
$ilDB->fetchAssoc($result);
614 if ($row[
"points"] != null) {
615 return $row[
"points"];
632 $ilDB = $DIC[
'ilDB'];
635 include_once
"./Services/Utilities/classes/class.ilStr.php";
636 if (is_null($pass)) {
637 include_once
"./Modules/Test/classes/class.ilObjTest.php";
644 $this->
getProcessLocker()->executeUserSolutionUpdateLockOperation(
function () use (&$entered_values, $active_id, $pass, $authorized, $text) {
653 if ($entered_values) {
654 include_once(
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
658 "log_user_entered_values",
660 ), $active_id, $this->
getId());
663 include_once(
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
667 "log_user_not_entered_values",
669 ), $active_id, $this->
getId());
684 $text = htmlentities($_POST[
"TEXT"]);
698 $ilDB = $DIC[
'ilDB'];
702 array( $this->
getId()
707 'question_fi' => array(
'integer', $this->
getId()),
710 'keywords' => array(
'text', null),
723 $ilDB = $DIC[
'ilDB'];
726 "DELETE FROM qpl_a_essay WHERE question_fi = %s",
728 array( $this->
getId() )
731 foreach ($this->answers as $answer) {
733 $nextID =
$ilDB->nextId(
'qpl_a_essay');
735 "INSERT INTO qpl_a_essay (answer_id, question_fi, answertext, points) VALUES (%s, %s, %s, %s)",
736 array(
"integer",
"integer",
"text",
'float' ),
740 $answer->getAnswertext(),
755 return "assTextQuestion";
779 switch ($a_text_rating) {
787 $this->text_rating = $a_text_rating;
803 return "qpl_qst_essay";
812 return parent::getRTETextWithMediaObjects();
820 parent::setExportDetailsXLS($worksheet, $startrow, $active_id, $pass);
825 $worksheet->
setCell($startrow +
$i, 0, $this->
lng->txt(
"result"));
828 require_once
'Modules/Test/classes/class.ilObjAssessmentFolder.php';
832 if ($assessment_folder->getExportEssayQuestionsWithHtml()) {
836 if (array_key_exists(0, $solutions) && strlen($solutions[0][
"value1"])) {
837 $worksheet->
setCell($startrow +
$i, 2, html_entity_decode($solutions[0][
"value1"]));
842 return $startrow +
$i + 1;
850 include_once(
"./Services/RTE/classes/class.ilRTE.php");
852 $result[
'id'] = $this->
getId();
859 return json_encode($result);
864 return count($this->answers);
883 $points_unchecked = 0.0,
887 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
891 $this->answers[] = $answer;
913 if (count($this->answers) < 1) {
916 if (
$index >= count($this->answers)) {
920 return $this->answers[
$index];
936 if (count($this->answers) < 1) {
939 if (
$index >= count($this->answers)) {
942 $answer = $this->answers[
$index];
946 unset($this->answers[
$index]);
947 $this->answers = array_values($this->answers);
948 for (
$i = 0, $iMax = count($this->answers);
$i < $iMax;
$i++) {
949 if ($this->answers[
$i]->getOrder() > $index) {
950 $this->answers[
$i]->setOrder(
$i);
957 return 'qpl_a_essay';
968 $this->answers = array();
983 for (
$i = 0;
$i < $count;
$i++) {
995 $ilDB = $DIC[
'ilDB'];
997 $result =
$ilDB->queryF(
998 "SELECT * FROM qpl_a_essay WHERE question_fi = %s",
1002 if ($result->numRows()) {
1003 while ($row =
$ilDB->fetchAssoc($result)) {
1004 $next_id =
$ilDB->nextId(
'qpl_a_essay');
1005 $affectedRows =
$ilDB->manipulateF(
1006 "INSERT INTO qpl_a_essay (answer_id, question_fi, answertext, points) 1007 VALUES (%s, %s, %s, %s)",
1008 array(
'integer',
'integer',
'text',
'float'),
1009 array($next_id, $this->
getId(), $row[
"answertext"], $row[
"points"])
1026 $this->keyword_relation = $a_relation;
1031 return array_merge(self::getScoringModesWithPointsByQuestion(), self::getScoringModesWithPointsByKeyword());
1036 return array(
'non',
'all',
'one');
1041 return array(
'any');
1059 return $numExistingSolutionRecords > 0;
1079 $text = strip_tags($text);
1081 $text = str_replace(
'>',
'>', $text);
1082 $text = str_replace(
'<',
'<', $text);
1083 $text = str_replace(
' ',
' ', $text);
1084 $text = str_replace(
'&',
'&', $text);
1086 $text = str_replace(
"\r\n",
"\n", $text);
1087 $text = str_replace(
"\n",
"", $text);
1097 $text = str_replace(
' ',
' ', $text);
1099 $text = preg_replace(
'/[.,:;!?\-_#\'"+*\\/=()&%§$]/m',
'', $text);
1101 $text = preg_replace(
'/^\s*/m',
'', $text);
1102 $text = preg_replace(
'/\s*$/m',
'', $text);
1103 $text = preg_replace(
'/\s+/m',
' ', $text);
1105 return count(explode(
' ', $text));
1111 $cntresult = $this->db->query(
1113 SELECT count(solution_id) cnt 1115 WHERE active_fi = ' . $this->db->quote($active_id,
'int') .
' 1116 AND question_fi = ' . $this->db->quote($this->
getId(),
'int') .
' 1117 AND authorized = ' . $this->db->quote(0,
'int')
1118 .
' AND pass = ' . $this->db->quote($pass,
'int')
1120 $row = $this->db->fetchAssoc($cntresult);
1121 if ($row[
'cnt'] > 0) {
1122 $tresult = $this->db->query(
1126 WHERE active_fi = ' . $this->db->quote($active_id,
'int') .
' 1127 AND question_fi = ' . $this->db->quote($this->
getId(),
'int') .
' 1128 AND authorized = ' . $this->db->quote(0,
'int')
1129 .
' AND pass = ' . $this->db->quote($pass,
'int')
1131 $trow = $this->db->fetchAssoc($tresult);
1132 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()
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...
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="")
createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle="")
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...
setExportDetailsXLS(ilAssExcelFormatHelper $worksheet, int $startrow, int $active_id, int $pass)
{}
loadFromDb($question_id)
Loads a assTextQuestion object from a database.
saveToDb($original_id="")
Saves a assTextQuestion object to a database.
static strPos(string $a_haystack, string $a_needle, ?int $a_offset=null)
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 _getOriginalId(int $question_id)
static getNumExistingSolutionRecords(int $activeId, int $pass, int $questionId)
static getValidScoringModes()
toJSON()
Returns a JSON representation of the question.
setComment(string $comment="")
setWordCounterEnabled($wordCounterEnabled)
float $points
The maximum available points for the question.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
static strLen(string $a_string)
duplicate(bool $for_test=true, string $title="", string $author="", string $owner="", $testObjId=null)
Duplicates an assTextQuestion.
__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...
calculateReachedPointsForSolution($solution)
setMatchcondition(int $matchcondition)
duplicateAnswers($original_id)
flushAnswers()
Deletes all answers.
static logAction(string $logtext, int $active_id, int $question_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getScoringModesWithPointsByQuestion()
const TEXTGAP_RATING_CASESENSITIVE
setKeywordRelation($a_relation)
This method implements a default behaviour.
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.
setMaxNumOfChars($maxchars=0)
Sets the maximum number of characters for the text solution.
getHtmlUserSolutionPurifier()
getQuestionType()
Returns the question type of the question.
setReachedPoints($active_id, $points, $pass=null)
Sets the points, a learner has reached answering 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.
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...
__construct(Container $dic, ilPlugin $plugin)
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)
isAnswered(int $active_id, int $pass)
returns boolean wether the question is answered during test pass or not
getTextRating()
Returns the rating option for text comparisons.
setAuthor(string $author="")
setShuffle(?bool $shuffle=true)
setAdditionalContentEditingMode(?string $additionalContentEditingMode)
static getDraftInstance()
ILIAS Refinery Factory $refinery
const TEXTGAP_RATING_CASEINSENSITIVE
setQuestion(string $question="")