4 require_once
'./Modules/TestQuestionPool/classes/class.assQuestion.php';
5 require_once
'./Modules/Test/classes/inc.AssessmentConstants.php';
6 require_once
'./Modules/TestQuestionPool/interfaces/interface.ilObjQuestionScoringAdjustable.php';
7 require_once
'./Modules/TestQuestionPool/interfaces/interface.ilObjAnswerScoringAdjustable.php';
82 $this->wordCounterEnabled =
false;
83 $this->maxNumOfChars = 0;
85 $this->answers = array();
86 $this->matchcondition = 0;
96 if (strlen($this->title)
129 $ilDB = $DIC[
'ilDB'];
138 $this->
setId($question_id);
147 include_once(
"./Services/RTE/classes/class.ilRTE.php");
153 $this->matchcondition = (strlen($data[
'matchcondition'])) ? $data[
'matchcondition'] : 0;
154 $this->
setEstimatedWorkingTime(substr($data[
"working_time"], 0, 2), substr($data[
"working_time"], 3, 2), substr($data[
"working_time"], 6, 2));
170 "SELECT * FROM qpl_a_essay WHERE question_fi = %s",
172 array($this->
getId())
177 $this->
addAnswer($row[
'answertext'], $row[
'points']);
180 parent::loadFromDb($question_id);
190 if ($this->
id <= 0) {
195 $this_id = $this->
getId();
199 include_once(
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
203 if ((
int) $testObjId > 0) {
204 $clone->setObjId($testObjId);
225 $clone->copyPageOfQuestion($this_id);
227 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
228 #$clone->duplicateAnswers($this_id); 230 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
242 if ($this->
id <= 0) {
248 include_once(
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
251 $source_questionpool_id = $this->
getObjId();
252 $clone->setObjId($target_questionpool_id);
262 #$clone->duplicateAnswers($original_id); 264 $clone->onCopy($source_questionpool_id,
$original_id, $clone->getObjId(), $clone->getId());
271 if ($this->
id <= 0) {
276 include_once(
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
279 $sourceParentId = $this->
getObjId();
285 $clone->setObjId($targetParentId);
287 if ($targetQuestionTitle) {
288 $clone->setTitle($targetQuestionTitle);
293 $clone->copyPageOfQuestion($sourceQuestionId);
295 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
297 #$clone->duplicateAnswers($sourceQuestionId); 299 $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
313 if (strcmp($this->maxNumOfChars,
"") == 0) {
329 $this->maxNumOfChars = $maxchars;
356 if (in_array($this->
getKeywordRelation(), self::getScoringModesWithPointsByQuestion())) {
357 return parent::getPoints();
362 foreach ($this->answers as $answer) {
363 if ($answer->getPoints() > 0) {
373 if (in_array($this->
getKeywordRelation(), self::getScoringModesWithPointsByQuestion())) {
379 foreach ($this->answers as $answer) {
380 if ($answer->getPoints() < 0) {
399 $ilDB = $DIC[
'ilDB'];
402 if (is_null(
$pass)) {
405 $affectedRows =
$ilDB->manipulateF(
406 "UPDATE tst_test_result SET points = %s WHERE active_fi = %s AND question_fi = %s AND pass = %s",
407 array(
'float',
'integer',
'integer',
'integer'),
410 self::_updateTestPassResults($active_id,
$pass);
419 switch ($textRating) {
445 include_once
"./Services/Utilities/classes/class.ilStr.php";
446 switch ($textrating) {
460 $answertext = strip_tags($answertext);
462 $answerwords = array();
463 if (preg_match_all(
"/([^\s.]+)/", $answertext, $matches)) {
464 foreach ($matches[1] as $answerword) {
465 array_push($answerwords, trim($answerword));
468 foreach ($answerwords as $a_original) {
469 switch ($textrating) {
471 if (levenshtein($a_original, $a_keyword) <= 1) {
476 if (levenshtein($a_original, $a_keyword) <= 2) {
481 if (levenshtein($a_original, $a_keyword) <= 3) {
486 if (levenshtein($a_original, $a_keyword) <= 4) {
491 if (levenshtein($a_original, $a_keyword) <= 5) {
520 $qst_answer = $answer->getAnswertext();
521 $user_answer =
' ' . $solution;
524 $points += $answer->getPoints();
535 $qst_answer = $answer->getAnswertext();
536 $user_answer =
' ' . $solution;
551 $qst_answer = $answer->getAnswertext();
552 $user_answer =
' ' . $solution;
578 if ($returndetails) {
579 throw new ilTestException(
'return details not implemented for ' . __METHOD__);
583 $ilDB = $DIC[
'ilDB'];
586 if (is_null(
$pass)) {
599 if ($row[
"points"] != null) {
600 return $row[
"points"];
617 $ilDB = $DIC[
'ilDB'];
620 include_once
"./Services/Utilities/classes/class.ilStr.php";
621 if (is_null(
$pass)) {
622 include_once
"./Modules/Test/classes/class.ilObjTest.php";
629 $this->
getProcessLocker()->executeUserSolutionUpdateLockOperation(
function () use (&$entered_values, $active_id,
$pass, $authorized, $text) {
638 if ($entered_values) {
639 include_once(
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
644 include_once(
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
671 $ilDB = $DIC[
'ilDB'];
675 array( $this->
getId()
680 'question_fi' => array(
'integer', $this->
getId()),
683 'keywords' => array(
'text', null),
685 'matchcondition' => array(
'integer', $this->matchcondition),
696 $ilDB = $DIC[
'ilDB'];
699 "DELETE FROM qpl_a_essay WHERE question_fi = %s",
701 array( $this->
getId() )
704 foreach ($this->answers as $answer) {
706 $nextID =
$ilDB->nextId(
'qpl_a_essay');
708 "INSERT INTO qpl_a_essay (answer_id, question_fi, answertext, points) VALUES (%s, %s, %s, %s)",
709 array(
"integer",
"integer",
"text",
'float' ),
713 $answer->getAnswertext(),
728 return "assTextQuestion";
752 switch ($a_text_rating) {
760 $this->text_rating = $a_text_rating;
776 return "qpl_qst_essay";
785 return parent::getRTETextWithMediaObjects();
793 parent::setExportDetailsXLS($worksheet, $startrow, $active_id,
$pass);
798 $worksheet->setCell($startrow +
$i, 0, $this->lng->txt(
"result"));
799 $worksheet->setBold($worksheet->getColumnCoord(0) . ($startrow +
$i));
801 require_once
'Modules/Test/classes/class.ilObjAssessmentFolder.php';
804 $string_escaping_org_value = $worksheet->getStringEscaping();
805 if ($assessment_folder->getExportEssayQuestionsWithHtml() == 1) {
806 $worksheet->setStringEscaping(
false);
809 if (strlen($solutions[0][
"value1"])) {
810 $worksheet->setCell($startrow +
$i, 1, $solutions[0][
"value1"]);
814 $worksheet->setStringEscaping($string_escaping_org_value);
815 return $startrow +
$i + 1;
823 include_once(
"./Services/RTE/classes/class.ilRTE.php");
837 return count($this->answers);
856 $points_unchecked = 0.0,
860 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
864 $this->answers[] = $answer;
886 if (count($this->answers) < 1) {
889 if (
$index >= count($this->answers)) {
893 return $this->answers[
$index];
909 if (count($this->answers) < 1) {
912 if (
$index >= count($this->answers)) {
915 $answer = $this->answers[
$index];
916 if (strlen($answer->getImage())) {
917 $this->deleteImage($answer->getImage());
919 unset($this->answers[
$index]);
920 $this->answers = array_values($this->answers);
921 for (
$i = 0;
$i < count($this->answers);
$i++) {
922 if ($this->answers[
$i]->getOrder() >
$index) {
923 $this->answers[
$i]->setOrder(
$i);
930 return 'qpl_a_essay';
941 $this->answers = array();
956 for (
$i = 0;
$i < $count;
$i++) {
968 $ilDB = $DIC[
'ilDB'];
971 "SELECT * FROM qpl_a_essay WHERE question_fi = %s",
977 $next_id =
$ilDB->nextId(
'qpl_a_essay');
978 $affectedRows =
$ilDB->manipulateF(
979 "INSERT INTO qpl_a_essay (answer_id, question_fi, answertext, points) 980 VALUES (%s, %s, %s, %s)",
981 array(
'integer',
'integer',
'text',
'float'),
982 array($next_id, $this->
getId(), $row[
"answertext"], $row[
"points"])
999 $this->keyword_relation = $a_relation;
1004 return array_merge(self::getScoringModesWithPointsByQuestion(), self::getScoringModesWithPointsByKeyword());
1009 return array(
'non',
'all',
'one');
1014 return array(
'any');
1032 return $numExistingSolutionRecords > 0;
1052 $text = strip_tags($text);
1054 $text = str_replace(
'>',
'>', $text);
1055 $text = str_replace(
'<',
'<', $text);
1056 $text = str_replace(
' ',
' ', $text);
1057 $text = str_replace(
'&',
'&', $text);
1059 $text = str_replace(
"\r\n",
"\n", $text);
1060 $text = str_replace(
"\n",
"", $text);
1067 $text = str_replace(
' ',
' ', $text);
1069 $text = preg_replace(
'/[.,:;!?\-_#\'"+*\\/=()&%§$]/m',
'', $text);
1071 $text = preg_replace(
'/^\s*/m',
'', $text);
1072 $text = preg_replace(
'/\s*$/m',
'', $text);
1073 $text = preg_replace(
'/\s+/m',
' ', $text);
1075 return count(explode(
' ', $text));
1080 $question_fi = $this->
getId();
1083 $cntresult = $this->db->query(
' 1084 SELECT count(solution_id) cnt 1086 WHERE active_fi = ' . $this->db->quote($active_id,
'int') .
' 1087 AND question_fi = ' . $this->db->quote($this->
getId(),
'int') .
' 1088 AND authorized = ' . $this->db->quote(0,
'int')
1090 $row = $this->db->fetchAssoc($cntresult);
1091 if($row[
'cnt'] > 0 ) {
1092 $tresult = $this->db->query(
' 1095 WHERE active_fi = ' . $this->db->quote($active_id,
'int') .
' 1096 AND question_fi = ' . $this->db->quote($this->
getId(),
'int') .
' 1097 AND authorized = ' . $this->db->quote(0,
'int')
1099 $trow = $this->db->fetchAssoc($tresult);
1100 return $trow[
'value1'];
duplicate($for_test=true, $title="", $author="", $owner="", $testObjId=null)
Duplicates an assTextQuestion.
static logAction($logtext="", $active_id="", $question_id="")
Logs an action into the Test&Assessment log.
getId()
Gets the id of the assQuestion object.
setExportDetailsXLS($worksheet, $startrow, $active_id, $pass)
{}
static getInstance($identifier)
static _getOriginalId($question_id)
Returns the original id of a question.
formatSAQuestion($a_q)
Format self assessment question.
const TEXTGAP_RATING_LEVENSHTEIN5
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
static getScoringModesWithPointsByKeyword()
static getNumExistingSolutionRecords($activeId, $pass, $questionId)
returns the number of existing solution records for the given test active / pass and given question i...
static strPos($a_haystack, $a_needle, $a_offset=null)
isAnswered($active_id, $pass=null)
returns boolean wether the question is answered during test pass or not
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.
getPoints()
Returns the maximum available points for 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...
isComplete()
Returns true, if a multiple choice question is complete for use.
createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle="")
ASS_AnswerBinaryStateImage is a class for answers with a binary state indicator (checked/unchecked, set/unset) and an image file.
getSolutionValues($active_id, $pass=null, $authorized=true)
Loads solutions of a given user from the database an returns it.
setId($id=-1)
Sets the id of the assQuestion object.
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.
getSolutionMaxPass($active_id)
Returns the maximum pass a users question solution.
setEstimatedWorkingTime($hour=0, $min=0, $sec=0)
Sets the estimated working time of a question from given hour, minute and second. ...
static strToLower($a_string)
static getValidScoringModes()
toJSON()
Returns a JSON representation of the question.
setNrOfTries($a_nr_of_tries)
setAdditionalContentEditingMode($additinalContentEditingMode)
setter for additional content editing mode for this question
setShuffle($shuffle=true)
Sets the shuffle flag.
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
getObjId()
Get the object id of the container object.
setWordCounterEnabled($wordCounterEnabled)
getShuffle()
Gets the shuffle flag.
Base Exception for all Exceptions relating to Modules/Test.
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
static _getLogLanguage()
retrieve the log language for assessment logging
__construct( $title="", $comment="", $author="", $owner=-1, $question="")
assTextQuestion constructor
setAuthor($author="")
Sets the authors name of the assQuestion object.
static _enabledAssessmentLogging()
check wether assessment logging is enabled or not
isValidTextRating($textRating)
const TEXTGAP_RATING_LEVENSHTEIN3
Class for text questions.
calculateReachedPointsForSolution($solution)
duplicateAnswers($original_id)
flushAnswers()
Deletes all answers.
saveCurrentSolution($active_id, $pass, $value1, $value2, $authorized=true, $tstamp=null)
Class ilObjAssessmentFolder.
static getScoringModesWithPointsByQuestion()
const TEXTGAP_RATING_CASESENSITIVE
setKeywordRelation($a_relation)
This method implements a default behaviour.
Interface ilObjAnswerScoringAdjustable.
setTextRating($a_text_rating)
Sets the rating option for text comparisons.
getQuestion()
Gets the question string of the question object.
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.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
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.
setPoints($a_points)
Sets the maximum available points for the question.
addAnswer( $answertext="", $points=0.0, $points_unchecked=0.0, $order=0, $answerimage="")
Adds a possible answer for a multiple choice question.
saveQuestionDataToDb($original_id="")
getMaxNumOfChars()
Gets the maximum number of characters for the text solution.
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 ...
setQuestion($question="")
Sets the question string of the question object.
Interface ilObjQuestionScoringAdjustable.
removeCurrentSolution($active_id, $pass, $authorized=true)
__construct(Container $dic, ilPlugin $plugin)
const TEXTGAP_RATING_LEVENSHTEIN4
setOriginalId($original_id)
getCurrentSolutionResultSet($active_id, $pass, $authorized=true)
Get a restulset for the current user solution for a this question by active_id and pass...
setLifecycle(ilAssQuestionLifecycle $lifecycle)
getTitle()
Gets the title string of the assQuestion object.
static isHTML($a_text)
Checks if a given string contains HTML or not.
getTextRating()
Returns the rating option for text comparisons.
setTitle($title="")
Sets the title string of the assQuestion object.
setObjId($obj_id=0)
Set the object id of the container object.
setComment($comment="")
Sets the comment string of the assQuestion object.
getLatestAutosaveContent($active_id)
static getDraftInstance()
static isObligationPossible($questionId)
returns boolean wether it is possible to set this question type as obligatory or not considering the ...
setOwner($owner="")
Sets the creator/owner ID of the assQuestion object.
const TEXTGAP_RATING_CASEINSENSITIVE