19require_once
'./Modules/TestQuestionPool/classes/class.assQuestion.php';
20require_once
'./Modules/Test/classes/inc.AssessmentConstants.php';
21require_once
'./Modules/TestQuestionPool/interfaces/interface.ilObjQuestionScoringAdjustable.php';
22require_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)
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) {
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__);
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"];
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"]);
702 array( $this->
getId()
707 'question_fi' => array(
'integer', $this->
getId()),
710 'keywords' => array(
'text',
null),
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;
896 return $this->answers;
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();
973 if (isset($answers[
'answer'])) {
974 $count = count($answers[
'answer']);
977 $count = count($answers);
981 $this->flushAnswers();
983 for (
$i = 0;
$i < $count;
$i++) {
985 $this->addAnswer($answers[
'answer'][
$i], $answers[
'points'][
$i]);
987 $this->addAnswer($answers[
$i], 0);
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"])
1017 return $this->keyword_relation;
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'];
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)
setShuffle(?bool $shuffle=true)
getSolutionValues($active_id, $pass=null, bool $authorized=true)
Loads solutions of a given user from the database an returns it.
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)
static getNumExistingSolutionRecords(int $activeId, int $pass, int $questionId)
setTitle(string $title="")
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...
setMaxNumOfChars($maxchars=0)
Sets the maximum number of characters for the text solution.
isAnswered(int $active_id, int $pass)
returns boolean wether the question is answered during test pass or not
setExportDetailsXLS(ilAssExcelFormatHelper $worksheet, int $startrow, int $active_id, int $pass)
{}
isKeywordMatching($answertext, $a_keyword)
Checks if one of the keywords matches the answertext.
getLatestAutosaveContent(int $active_id, int $pass)
saveToDb($original_id="")
Saves a assTextQuestion object to a database.
loadFromDb($question_id)
Loads a assTextQuestion object from a database.
addAnswer( $answertext="", $points=0.0, $points_unchecked=0.0, $order=0, $answerimage="")
Adds a possible answer for a multiple choice question.
saveWorkingData($active_id, $pass=null, $authorized=true)
Saves the learners input of the question to the database.
const HAS_SPECIFIC_FEEDBACK
static isObligationPossible(int $questionId)
returns boolean wether it is possible to set this question type as obligatory or not considering the ...
getRTETextWithMediaObjects()
Collects all text in the question which could contain media objects which were created with the Rich ...
isComplete()
Returns true, if a multiple choice question is complete for use.
setKeywordRelation($a_relation)
This method implements a default behaviour.
calculateReachedPoints($active_id, $pass=null, $authorizedSolution=true, $returndetails=false)
Returns the points, a learner has reached answering the question.
getAnswer($index=0)
Returns an answer with a given index.
setMatchcondition(int $matchcondition)
getAdditionalTableName()
Returns the name of the additional question data table in the database.
static getScoringModesWithPointsByKeyword()
setWordCounterEnabled($wordCounterEnabled)
toJSON()
Returns a JSON representation of the question.
flushAnswers()
Deletes all answers.
setTextRating($a_text_rating)
Sets the rating option for text comparisons.
static getValidScoringModes()
copyObject($target_questionpool_id, $title="")
Copies an assTextQuestion object.
getQuestionType()
Returns the question type of the question.
deleteAnswer($index=0)
Deletes an answer with a given index.
getMaxNumOfChars()
Gets the maximum number of characters for the text solution.
calculateReachedPointsForSolution($solution)
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
isValidTextRating($textRating)
duplicate(bool $for_test=true, string $title="", string $author="", string $owner="", $testObjId=null)
Duplicates an assTextQuestion.
createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle="")
setReachedPoints($active_id, $points, $pass=null)
Sets the points, a learner has reached answering the question.
__construct( $title="", $comment="", $author="", $owner=-1, $question="")
assTextQuestion constructor
static getScoringModesWithPointsByQuestion()
getTextRating()
Returns the rating option for text comparisons.
duplicateAnswers($original_id)
static getDraftInstance()
static getInstance($identifier)
setBold(string $a_coords)
Set cell(s) to bold.
getColumnCoord(int $a_col)
Get column "name" from number.
static _getRichTextEditor()
Returns the identifier for the Rich Text Editor.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _enabledAssessmentLogging()
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
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 strPos(string $a_haystack, string $a_needle, ?int $a_offset=null)
static strToLower(string $a_string)
static strLen(string $a_string)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static isHTML(string $a_text)
Checks if a given string contains HTML or not.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
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...
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