Class for text questions. More...
Inheritance diagram for assTextQuestion:
Collaboration diagram for assTextQuestion:Public Member Functions | |
| assTextQuestion ($title="", $comment="", $author="", $owner=-1, $question="") | |
| assTextQuestion constructor | |
| isComplete () | |
| Returns true, if a multiple choice question is complete for use. | |
| saveToDb ($original_id="") | |
| Saves a assTextQuestion object to a database. | |
| loadFromDb ($question_id) | |
| Loads a assTextQuestion object from a database. | |
| duplicate ($for_test=true, $title="", $author="", $owner="") | |
| Duplicates an assTextQuestion. | |
| copyObject ($target_questionpool, $title="") | |
| Copies an assTextQuestion object. | |
| getMaxNumOfChars () | |
| Gets the maximum number of characters for the text solution. | |
| setMaxNumOfChars ($maxchars=0) | |
| Sets the maximum number of characters for the text solution. | |
| getMaximumPoints () | |
| Returns the maximum points, a learner can reach answering 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. | |
| calculateReachedPoints ($active_id, $pass=NULL) | |
| Returns the points, a learner has reached answering the question. | |
| saveWorkingData ($active_id, $pass=NULL) | |
| Saves the learners input of the question to the database. | |
| createRandomSolution ($test_id, $user_id) | |
| getQuestionType () | |
| Returns the question type of the question. | |
| getKeywords () | |
| Returns the keywords of the question. | |
| setKeywords ($a_keywords) | |
| Sets the keywords of the question. | |
| & | getKeywordList () |
| Returns the keywords of the question in an array. | |
| getTextRating () | |
| Returns the rating option for text comparisons. | |
| setTextRating ($a_text_rating) | |
| Sets the rating option for text comparisons. | |
| getAdditionalTableName () | |
| Returns the name of the additional question data table in the database. | |
| getRTETextWithMediaObjects () | |
| Collects all text in the question which could contain media objects which were created with the Rich Text Editor. | |
Data Fields | |
| $maxNumOfChars | |
| $keywords | |
| $text_rating | |
Class for text questions.
assTextQuestion is a class for text questions
Definition at line 35 of file class.assTextQuestion.php.
| assTextQuestion::assTextQuestion | ( | $ | title = "", |
|
| $ | comment = "", |
|||
| $ | author = "", |
|||
| $ | owner = -1, |
|||
| $ | question = "" | |||
| ) |
assTextQuestion constructor
The constructor takes possible arguments an creates an instance of the assTextQuestion object.
| string | $title A title string to describe the question | |
| string | $comment A comment string to describe the question | |
| string | $author A string containing the name of the questions author | |
| integer | $owner A numerical ID to identify the owner/creator | |
| string | $question The question string of the text question public |
Definition at line 78 of file class.assTextQuestion.php.
References assQuestion::$author, assQuestion::$comment, assQuestion::$owner, assQuestion::$question, assQuestion::$title, and assQuestion::assQuestion().
{
$this->assQuestion($title, $comment, $author, $owner, $question);
$this->maxNumOfChars = 0;
$this->points = 0;
$this->keywords = "";
}
Here is the call graph for this function:| assTextQuestion::calculateReachedPoints | ( | $ | active_id, | |
| $ | pass = NULL | |||
| ) |
Returns the points, a learner has reached answering the question.
Returns the points, a learner has reached answering the question The points are calculated from the given answers including checks for all special scoring options in the test container.
| integer | $user_id The database ID of the learner | |
| integer | $test_id The database Id of the test containing the question public |
Definition at line 495 of file class.assTextQuestion.php.
References $keywords, assQuestion::$points, assQuestion::getId(), getKeywordList(), getMaximumPoints(), assQuestion::getSolutionMaxPass(), and isKeywordMatching().
{
global $ilDB;
$points = 0;
if (is_null($pass))
{
$pass = $this->getSolutionMaxPass($active_id);
}
$query = sprintf("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
$ilDB->quote($active_id . ""),
$ilDB->quote($this->getId() . ""),
$ilDB->quote($pass . "")
);
$result = $ilDB->query($query);
if ($result->numRows() == 1)
{
$row = $result->fetchRow(DB_FETCHMODE_ASSOC);
if ($row["points"])
{
$points = $row["points"];
}
else
{
$keywords =& $this->getKeywordList();
if (count($keywords))
{
$foundkeyword = false;
foreach ($keywords as $keyword)
{
if (!$foundkeyword)
{
if ($this->isKeywordMatching($row["value1"], $keyword))
{
$foundkeyword = true;
}
}
}
if ($foundkeyword) $points = $this->getMaximumPoints();
}
}
}
$points = parent::calculateReachedPoints($active_id, $pass = NULL, $points);
return $points;
}
Here is the call graph for this function:| assTextQuestion::copyObject | ( | $ | target_questionpool, | |
| $ | title = "" | |||
| ) |
Copies an assTextQuestion object.
Copies an assTextQuestion object
public
Definition at line 313 of file class.assTextQuestion.php.
References assQuestion::$title, assQuestion::_getOriginalId(), and assQuestion::getObjId().
{
if ($this->id <= 0)
{
// The question has not been saved. It cannot be duplicated
return;
}
// duplicate the question in database
$clone = $this;
include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
$original_id = assQuestion::_getOriginalId($this->id);
$clone->id = -1;
$source_questionpool = $this->getObjId();
$clone->setObjId($target_questionpool);
if ($title)
{
$clone->setTitle($title);
}
$clone->saveToDb();
// copy question page content
$clone->copyPageOfQuestion($original_id);
// copy XHTML media objects
$clone->copyXHTMLMediaObjectsOfQuestion($original_id);
// duplicate the generic feedback
$clone->duplicateFeedbackGeneric($original_id);
return $clone->id;
}
Here is the call graph for this function:| assTextQuestion::createRandomSolution | ( | $ | test_id, | |
| $ | user_id | |||
| ) |
| assTextQuestion::duplicate | ( | $ | for_test = true, |
|
| $ | title = "", |
|||
| $ | author = "", |
|||
| $ | owner = "" | |||
| ) |
Duplicates an assTextQuestion.
Duplicates an assTextQuestion
public
Definition at line 260 of file class.assTextQuestion.php.
References assQuestion::$author, assQuestion::$owner, assQuestion::$title, assQuestion::_getOriginalId(), and assQuestion::getId().
{
if ($this->id <= 0)
{
// The question has not been saved. It cannot be duplicated
return;
}
// duplicate the question in database
$this_id = $this->getId();
$clone = $this;
include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
$original_id = assQuestion::_getOriginalId($this->id);
$clone->id = -1;
if ($title)
{
$clone->setTitle($title);
}
if ($author)
{
$clone->setAuthor($author);
}
if ($owner)
{
$clone->setOwner($owner);
}
if ($for_test)
{
$clone->saveToDb($original_id);
}
else
{
$clone->saveToDb();
}
// copy question page content
$clone->copyPageOfQuestion($this_id);
// copy XHTML media objects
$clone->copyXHTMLMediaObjectsOfQuestion($this_id);
// duplicate the generic feedback
$clone->duplicateFeedbackGeneric($this_id);
return $clone->id;
}
Here is the call graph for this function:| assTextQuestion::getAdditionalTableName | ( | ) |
Returns the name of the additional question data table in the database.
Returns the name of the additional question data table in the database
Reimplemented from assQuestion.
Definition at line 722 of file class.assTextQuestion.php.
{
return "qpl_question_essay";
}
| & assTextQuestion::getKeywordList | ( | ) |
Returns the keywords of the question in an array.
Returns the keywords of the question in an array
Definition at line 659 of file class.assTextQuestion.php.
References $keywords.
Referenced by calculateReachedPoints().
{
$keywords = array();
if (preg_match_all("/([^\s]+)/", $this->keywords, $matches))
{
foreach ($matches[1] as $keyword)
{
array_push($keywords, trim($keyword));
}
}
return $keywords;
}
Here is the caller graph for this function:| assTextQuestion::getKeywords | ( | ) |
Returns the keywords of the question.
Returns the keywords of the question
Definition at line 633 of file class.assTextQuestion.php.
Referenced by saveToDb().
{
return $this->keywords;
}
Here is the caller graph for this function:| assTextQuestion::getMaximumPoints | ( | ) |
Returns the maximum points, a learner can reach answering the question.
Returns the maximum points, a learner can reach answering the question
public
Reimplemented from assQuestion.
Definition at line 386 of file class.assTextQuestion.php.
Referenced by calculateReachedPoints(), and isComplete().
{
return $this->points;
}
Here is the caller graph for this function:| assTextQuestion::getMaxNumOfChars | ( | ) |
Gets the maximum number of characters for the text solution.
Gets the maximum number of characters for the text solution
Definition at line 352 of file class.assTextQuestion.php.
Referenced by saveToDb(), and saveWorkingData().
{
if (strcmp($this->maxNumOfChars, "") == 0)
{
return 0;
}
else
{
return $this->maxNumOfChars;
}
}
Here is the caller graph for this function:| assTextQuestion::getQuestionType | ( | ) |
Returns the question type of the question.
Returns the question type of the question
Reimplemented from assQuestion.
Definition at line 620 of file class.assTextQuestion.php.
{
return "assTextQuestion";
}
| assTextQuestion::getRTETextWithMediaObjects | ( | ) |
Collects all text in the question which could contain media objects which were created with the Rich Text Editor.
Reimplemented from assQuestion.
Definition at line 731 of file class.assTextQuestion.php.
{
return parent::getRTETextWithMediaObjects();
}
| assTextQuestion::getTextRating | ( | ) |
Returns the rating option for text comparisons.
Returns the rating option for text comparisons
Definition at line 681 of file class.assTextQuestion.php.
Referenced by isKeywordMatching(), and saveToDb().
{
return $this->text_rating;
}
Here is the caller graph for this function:| assTextQuestion::isComplete | ( | ) |
Returns true, if a multiple choice question is complete for use.
Returns true, if a multiple choice question is complete for use
Reimplemented from assQuestion.
Definition at line 100 of file class.assTextQuestion.php.
References getMaximumPoints().
Referenced by saveToDb().
{
if (($this->title) and ($this->author) and ($this->question) and ($this->getMaximumPoints() > 0))
{
return true;
}
else
{
return false;
}
}
Here is the call graph for this function:
Here is the caller graph for this function:| assTextQuestion::isKeywordMatching | ( | $ | answertext, | |
| $ | a_keyword | |||
| ) |
Checks if one of the keywords matches the answertext.
Checks if one of the keywords matches the answertext
| string | $answertext The answertext of the user | |
| string | $a_keyword The keyword which should be checked |
Definition at line 438 of file class.assTextQuestion.php.
References getTextRating(), ilStr::strPos(), and ilStr::strToLower().
Referenced by calculateReachedPoints().
{
$result = FALSE;
$textrating = $this->getTextRating();
include_once "./Services/Utilities/classes/class.ilStr.php";
switch ($textrating)
{
case TEXTGAP_RATING_CASEINSENSITIVE:
if (ilStr::strPos(ilStr::strToLower($answertext), ilStr::strToLower($a_keyword)) !== false) return TRUE;
break;
case TEXTGAP_RATING_CASESENSITIVE:
if (ilStr::strPos($answertext, $a_keyword) !== false) return TRUE;
break;
}
$answerwords = array();
if (preg_match_all("/([^\s.]+)/", $answertext, $matches))
{
foreach ($matches[1] as $answerword)
{
array_push($answerwords, trim($answerword));
}
}
foreach ($answerwords as $a_original)
{
switch ($textrating)
{
case TEXTGAP_RATING_LEVENSHTEIN1:
if (levenshtein($a_original, $a_keyword) <= 1) return TRUE;
break;
case TEXTGAP_RATING_LEVENSHTEIN2:
if (levenshtein($a_original, $a_keyword) <= 2) return TRUE;
break;
case TEXTGAP_RATING_LEVENSHTEIN3:
if (levenshtein($a_original, $a_keyword) <= 3) return TRUE;
break;
case TEXTGAP_RATING_LEVENSHTEIN4:
if (levenshtein($a_original, $a_keyword) <= 4) return TRUE;
break;
case TEXTGAP_RATING_LEVENSHTEIN5:
if (levenshtein($a_original, $a_keyword) <= 5) return TRUE;
break;
}
}
return $result;
}
Here is the call graph for this function:
Here is the caller graph for this function:| assTextQuestion::loadFromDb | ( | $ | question_id | ) |
Loads a assTextQuestion object from a database.
Loads a assTextQuestion object from a database
| object | $db A pear DB object | |
| integer | $question_id A unique key which defines the text question in the database public |
Reimplemented from assQuestion.
Definition at line 220 of file class.assTextQuestion.php.
References $data, ilRTE::_replaceMediaObjectImageSrc(), and assQuestion::setEstimatedWorkingTime().
{
global $ilDB;
$query = sprintf("SELECT qpl_questions.*, qpl_question_essay.* FROM qpl_questions, qpl_question_essay WHERE question_id = %s AND qpl_questions.question_id = qpl_question_essay.question_fi",
$ilDB->quote($question_id)
);
$result = $ilDB->query($query);
if (strcmp(strtolower(get_class($result)), db_result) == 0)
{
if ($result->numRows() == 1)
{
$data = $result->fetchRow(DB_FETCHMODE_OBJECT);
$this->id = $question_id;
$this->title = $data->title;
$this->comment = $data->comment;
$this->solution_hint = $data->solution_hint;
$this->original_id = $data->original_id;
$this->obj_id = $data->obj_fi;
$this->author = $data->author;
$this->owner = $data->owner;
include_once("./Services/RTE/classes/class.ilRTE.php");
$this->question = ilRTE::_replaceMediaObjectImageSrc($data->question_text, 1);
$this->maxNumOfChars = $data->maxNumOfChars;
$this->keywords = $data->keywords;
$this->text_rating = $data->textgap_rating;
$this->points = $data->points;
$this->setEstimatedWorkingTime(substr($data->working_time, 0, 2), substr($data->working_time, 3, 2), substr($data->working_time, 6, 2));
}
}
parent::loadFromDb($question_id);
}
Here is the call graph for this function:| assTextQuestion::saveToDb | ( | $ | original_id = "" |
) |
Saves a assTextQuestion object to a database.
Saves a assTextQuestion object to a database
| object | $db A pear DB object public |
Reimplemented from assQuestion.
Definition at line 120 of file class.assTextQuestion.php.
References ilRTE::_replaceMediaObjectImageSrc(), assQuestion::createPageObject(), assQuestion::getEstimatedWorkingTime(), getKeywords(), getMaxNumOfChars(), assQuestion::getPoints(), assQuestion::getQuestionTypeID(), assQuestion::getTestId(), getTextRating(), assQuestion::insertIntoTest(), and isComplete().
{
global $ilDB;
$complete = 0;
if ($this->isComplete())
{
$complete = 1;
}
$estw_time = $this->getEstimatedWorkingTime();
$estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
if ($original_id)
{
$original_id = $ilDB->quote($original_id);
}
else
{
$original_id = "NULL";
}
// cleanup RTE images which are not inserted into the question text
include_once("./Services/RTE/classes/class.ilRTE.php");
if ($this->id == -1)
{
// Neuen Datensatz schreiben
$now = getdate();
$question_type = $this->getQuestionTypeID();
$created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
$query = sprintf("INSERT INTO qpl_questions (question_id, question_type_fi, obj_fi, title, comment, author, owner, points, question_text, working_time, complete, created, original_id, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
$ilDB->quote($question_type),
$ilDB->quote($this->obj_id),
$ilDB->quote($this->title),
$ilDB->quote($this->comment),
$ilDB->quote($this->author),
$ilDB->quote($this->owner),
$ilDB->quote($this->getPoints() . ""),
$ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->question, 0)),
$ilDB->quote($estw_time),
$ilDB->quote("$complete"),
$ilDB->quote($created),
$original_id
);
$result = $ilDB->query($query);
if ($result == DB_OK)
{
$this->id = $ilDB->getLastInsertId();
$query = sprintf("INSERT INTO qpl_question_essay (question_fi, maxNumOfChars, keywords, textgap_rating) VALUES (%s, %s, %s, %s)",
$ilDB->quote($this->id . ""),
$ilDB->quote($this->getMaxNumOfChars()),
$ilDB->quote($this->getKeywords() . ""),
$ilDB->quote($this->getTextRating() . "")
);
$ilDB->query($query);
// create page object of question
$this->createPageObject();
if ($this->getTestId() > 0)
{
$this->insertIntoTest($this->getTestId());
}
}
}
else
{
// Vorhandenen Datensatz aktualisieren
$query = sprintf("UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, author = %s, points = %s, question_text = %s, working_time=%s, complete = %s WHERE question_id = %s",
$ilDB->quote($this->obj_id. ""),
$ilDB->quote($this->title),
$ilDB->quote($this->comment),
$ilDB->quote($this->author),
$ilDB->quote($this->getPoints() . ""),
$ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->question, 0)),
$ilDB->quote($estw_time),
$ilDB->quote("$complete"),
$ilDB->quote($this->id)
);
$result = $ilDB->query($query);
$query = sprintf("UPDATE qpl_question_essay SET maxNumOfChars = %s, keywords = %s, textgap_rating = %s WHERE question_fi = %s",
$ilDB->quote($this->getMaxNumOfChars()),
$ilDB->quote($this->getKeywords() . ""),
$ilDB->quote($this->getTextRating() . ""),
$ilDB->quote($this->id . "")
);
$result = $ilDB->query($query);
}
parent::saveToDb($original_id);
}
Here is the call graph for this function:| assTextQuestion::saveWorkingData | ( | $ | active_id, | |
| $ | pass = NULL | |||
| ) |
Saves the learners input of the question to the database.
Saves the learners input of the question to the database
| integer | $test_id The database id of the test containing this question |
Reimplemented from assQuestion.
Definition at line 552 of file class.assTextQuestion.php.
References ilObjAssessmentFolder::_enabledAssessmentLogging(), ilObjAssessmentFolder::_getLogLanguage(), ilObjTest::_getPass(), assQuestion::getId(), getMaxNumOfChars(), assQuestion::logAction(), ilUtil::stripSlashes(), and ilStr::subStr().
{
global $ilDB;
global $ilUser;
if (is_null($pass))
{
include_once "./Modules/Test/classes/class.ilObjTest.php";
$pass = ilObjTest::_getPass($active_id);
}
$query = sprintf("DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
$ilDB->quote($active_id . ""),
$ilDB->quote($this->getId() . ""),
$ilDB->quote($pass . "")
);
$result = $ilDB->query($query);
$text = ilUtil::stripSlashes($_POST["TEXT"], FALSE);
if ($this->getMaxNumOfChars())
{
include_once "./Services/Utilities/classes/class.ilStr.php";
$text = ilStr::subStr($text, 0, $this->getMaxNumOfChars());
}
$entered_values = 0;
if (strlen($text))
{
$query = sprintf("INSERT INTO tst_solutions (solution_id, active_fi, question_fi, value1, value2, pass, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL, %s, NULL)",
$ilDB->quote($active_id . ""),
$ilDB->quote($this->getId() . ""),
$ilDB->quote(trim($text) . ""),
$ilDB->quote($pass . "")
);
$result = $ilDB->query($query);
$entered_values++;
}
if ($entered_values)
{
include_once ("./classes/class.ilObjAssessmentFolder.php");
if (ilObjAssessmentFolder::_enabledAssessmentLogging())
{
$this->logAction($this->lng->txtlng("assessment", "log_user_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
}
}
else
{
include_once ("./classes/class.ilObjAssessmentFolder.php");
if (ilObjAssessmentFolder::_enabledAssessmentLogging())
{
$this->logAction($this->lng->txtlng("assessment", "log_user_not_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
}
}
parent::saveWorkingData($active_id, $pass);
return true;
}
Here is the call graph for this function:| assTextQuestion::setKeywords | ( | $ | a_keywords | ) |
Sets the keywords of the question.
Sets the keywords of the question
| string | $a_keywords The keywords of the question public |
Definition at line 646 of file class.assTextQuestion.php.
{
$this->keywords = $a_keywords;
}
| assTextQuestion::setMaxNumOfChars | ( | $ | maxchars = 0 |
) |
Sets the maximum number of characters for the text solution.
Sets the maximum number of characters for the text solution
| integer | $maxchars The maximum number of characters for the text solution public |
Definition at line 373 of file class.assTextQuestion.php.
{
$this->maxNumOfChars = $maxchars;
}
| assTextQuestion::setReachedPoints | ( | $ | active_id, | |
| $ | points, | |||
| $ | pass = NULL | |||
| ) |
Sets the points, a learner has reached answering the question.
Sets the points, a learner has reached answering the question
| integer | $user_id The database ID of the learner | |
| integer | $test_id The database Id of the test containing the question | |
| integer | $points The points the user has reached answering the question |
Definition at line 402 of file class.assTextQuestion.php.
References assQuestion::$points, assQuestion::_updateTestPassResults(), assQuestion::getId(), assQuestion::getPoints(), and assQuestion::getSolutionMaxPass().
{
global $ilDB;
if (($points > 0) && ($points <= $this->getPoints()))
{
if (is_null($pass))
{
$pass = $this->getSolutionMaxPass($active_id);
}
$query = sprintf("UPDATE tst_test_result SET points = %s WHERE active_fi = %s AND question_fi = %s AND pass = %s",
$ilDB->quote($points . ""),
$ilDB->quote($active_id . ""),
$ilDB->quote($this->getId() . ""),
$ilDB->quote($pass . "")
);
$result = $ilDB->query($query);
$this->_updateTestPassResults($active_id, $pass);
return TRUE;
}
else
{
return TRUE;
}
}
Here is the call graph for this function:| assTextQuestion::setTextRating | ( | $ | a_text_rating | ) |
Sets the rating option for text comparisons.
Sets the rating option for text comparisons
| string | $a_textgap_rating The rating option for text comparisons |
Definition at line 695 of file class.assTextQuestion.php.
{
switch ($a_text_rating)
{
case TEXTGAP_RATING_CASEINSENSITIVE:
case TEXTGAP_RATING_CASESENSITIVE:
case TEXTGAP_RATING_LEVENSHTEIN1:
case TEXTGAP_RATING_LEVENSHTEIN2:
case TEXTGAP_RATING_LEVENSHTEIN3:
case TEXTGAP_RATING_LEVENSHTEIN4:
case TEXTGAP_RATING_LEVENSHTEIN5:
$this->text_rating = $a_text_rating;
break;
default:
$this->text_rating = TEXTGAP_RATING_CASEINSENSITIVE;
break;
}
}
| assTextQuestion::$keywords |
Definition at line 54 of file class.assTextQuestion.php.
Referenced by calculateReachedPoints(), and getKeywordList().
| assTextQuestion::$maxNumOfChars |
Definition at line 44 of file class.assTextQuestion.php.
| assTextQuestion::$text_rating |
Definition at line 63 of file class.assTextQuestion.php.
1.7.1