Class for cloze tests. More...
Inheritance diagram for ASS_ClozeTest:
Collaboration diagram for ASS_ClozeTest:Public Member Functions | |
| ASS_ClozeTest ($title="", $comment="", $author="", $owner=-1, $cloze_text="") | |
| ASS_ClozeTest constructor. | |
| isComplete () | |
| Returns true, if a cloze test is complete for use. | |
| & | createCloseTextArray () |
| Creates an associative array from the close text. | |
| createCloseTextFromArray ($assoc_array) | |
| Re-creates the close text from an an associative array. | |
| saveToDb ($original_id="") | |
| Saves a ASS_ClozeTest object to a database. | |
| loadFromDb ($question_id) | |
| Loads a ASS_ClozeTest object from a database. | |
| addAnswer ($gap, $answertext, $points, $answerorder, $correctness, $clozetype, $name, $shuffle, $answer_id=-1) | |
| Adds an answer to the question. | |
| duplicate ($for_test=true, $title="", $author="", $owner="") | |
| Duplicates an ASS_ClozeTest. | |
| copyObject ($target_questionpool, $title="") | |
| Copies an ASS_ClozeTest object. | |
| to_xml ($a_include_header=true, $a_include_binary=true, $a_shuffle=false, $test_output=false, $force_image_references=false) | |
| Returns a QTI xml representation of the question. | |
| set_cloze_text ($cloze_text="") | |
| Evaluates the text gap solutions from the cloze text. | |
| get_cloze_text () | |
| Returns the cloze text. | |
| get_start_tag () | |
| Returns the start tag of a cloze gap. | |
| get_end_tag () | |
| Returns the end tag of a cloze gap. | |
| set_start_tag ($start_tag="<gap>") | |
| Sets the start tag of a cloze gap. | |
| set_end_tag ($end_tag="</gap>") | |
| Sets the end tag of a cloze gap. | |
| rebuild_cloze_text () | |
| Replaces the gap values with the values of the gaps array. | |
| get_gap ($index=0) | |
| Returns an array of gap answers. | |
| get_gap_count () | |
| Returns the number of gaps. | |
| get_gap_text_list ($index=0, $separator=",") | |
| Returns a separated string of all answers for a given text gap. | |
| get_gap_text_count ($index=0) | |
| Returns a count of all answers of a gap. | |
| delete_gap ($index=0) | |
| Deletes a gap. | |
| flush_gaps () | |
| Deletes all gaps without changing the cloze text. | |
| delete_answertext_by_index ($gap_index=0, $answertext_index=0) | |
| Deletes an answer text of a gap. | |
| set_answertext ($index=0, $answertext_index=0, $answertext="", $add_gaptext=0) | |
| Sets an answer text of a gap. | |
| update_all_gap_params () | |
| Updates the cloze text setting the cloze type for every gap. | |
| set_cloze_type ($index, $cloze_type=CLOZE_TEXT) | |
| Sets the cloze type of the gap. | |
| set_gap_points ($index=0, $points=0.0) | |
| Sets the points of a gap. | |
| set_gap_shuffle ($index=0, $shuffle=1) | |
| Sets the shuffle state of a gap. | |
| set_single_answer_points ($index_gaps=0, $index_answerobject=0, $points=0.0) | |
| Sets the points of a gap answer. | |
| set_single_answer_state ($index_gaps=0, $index_answerobject=0, $state=0) | |
| Sets the state of a gap answer. | |
| getTextgapPoints ($a_original, $a_entered, $max_points) | |
| Returns the points for a text gap. | |
| calculateReachedPoints ($user_id, $test_id, $pass=NULL) | |
| Returns the points, a learner has reached answering the question. | |
| getReachedInformation ($user_id, $test_id, $pass=NULL) | |
| Returns the evaluation data, a learner has entered to answer the question. | |
| getMaximumPoints () | |
| Returns the maximum points, a learner can reach answering the question. | |
| saveWorkingData ($test_id, $pass=NULL) | |
| Saves the learners input of the question to the database. | |
| syncWithOriginal () | |
| getQuestionType () | |
| Returns the question type of the question. | |
| getColumnSize ($gap) | |
| Returns the maximum number of text columns within which a user can type their answer. | |
| getTextgapRating () | |
| Returns the rating option for text gaps. | |
| setTextgapRating ($a_textgap_rating) | |
| Sets the rating option for text gaps. | |
Data Fields | |
| $cloze_text | |
| $gaps | |
| $start_tag | |
| $end_tag | |
| $textgap_rating | |
Class for cloze tests.
ASS_ClozeText is a class for cloze tests using text or select gaps.
class.assClozeTest.php Assessment
Definition at line 37 of file class.assClozeTest.php.
| ASS_ClozeTest::addAnswer | ( | $ | gap, | |
| $ | answertext, | |||
| $ | points, | |||
| $ | answerorder, | |||
| $ | correctness, | |||
| $ | clozetype, | |||
| $ | name, | |||
| $ | shuffle, | |||
| $ | answer_id = -1 | |||
| ) |
Adds an answer to the question.
Adds an answer to the question
public
Definition at line 458 of file class.assClozeTest.php.
References ASS_Question::$points, and ASS_Question::$shuffle.
{
include_once "./assessment/classes/class.assAnswerCloze.php";
if (!is_array($this->gaps[$gap]))
{
$this->gaps[$gap] = array();
}
array_push($this->gaps[$gap], new ASS_AnswerCloze($answertext, $points, $answerorder, $correctness, $clozetype, $name, $shuffle, $answer_id));
}
| ASS_ClozeTest::ASS_ClozeTest | ( | $ | title = "", |
|
| $ | comment = "", |
|||
| $ | author = "", |
|||
| $ | owner = -1, |
|||
| $ | cloze_text = "" | |||
| ) |
ASS_ClozeTest constructor.
The constructor takes possible arguments an creates an instance of the ASS_ClozeTest 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 | $cloze_text The question string of the cloze test public |
Definition at line 100 of file class.assClozeTest.php.
References ASS_Question::$author, $cloze_text, ASS_Question::$comment, ASS_Question::$owner, ASS_Question::$title, ASS_Question::ASS_Question(), and set_cloze_text().
{
$this->start_tag = "<gap>";
$this->end_tag = "</gap>";
$this->ASS_Question($title, $comment, $author, $owner);
$this->gaps = array();
$this->set_cloze_text($cloze_text);
}
Here is the call graph for this function:| ASS_ClozeTest::calculateReachedPoints | ( | $ | user_id, | |
| $ | test_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 1431 of file class.assClozeTest.php.
References $counter, $data, ASS_Question::$points, $query, $result, $row, ASS_Question::$test_id, $user_id, ASS_Question::getId(), getMaximumPoints(), ASS_Question::getSolutionMaxPass(), and getTextgapPoints().
{
global $ilDB;
$found_value1 = array();
$found_value2 = array();
if (is_null($pass))
{
$pass = $this->getSolutionMaxPass($user_id, $test_id);
}
$query = sprintf("SELECT * FROM tst_solutions WHERE user_fi = %s AND test_fi = %s AND question_fi = %s AND pass = %s",
$ilDB->quote($user_id . ""),
$ilDB->quote($test_id . ""),
$ilDB->quote($this->getId() . ""),
$ilDB->quote($pass . "")
);
$result = $ilDB->query($query);
$user_result = array();
while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
{
if (strcmp($data->value2, "") != 0)
{
$user_result[$data->value1] = array(
"gap_id" => $data->value1,
"value" => $data->value2
);
}
}
$points = 0;
$counter = 0;
foreach ($user_result as $gap_id => $value)
{
if ($this->gaps[$gap_id][0]->get_cloze_type() == CLOZE_TEXT)
{
$gappoints = 0;
foreach ($this->gaps[$gap_id] as $k => $v)
{
$gotpoints = $this->getTextgapPoints($v->get_answertext(), $value["value"], $v->get_points());
if ($gotpoints > $gappoints) $gappoints = $gotpoints;
}
$points += $gappoints;
}
else
{
if ($value["value"] >= 0)
{
foreach ($this->gaps[$gap_id] as $answerkey => $answer)
{
if ($value["value"] == $answerkey)
{
$points += $answer->get_points();
}
}
}
}
}
// check for special scoring options in test
$query = sprintf("SELECT * FROM tst_tests WHERE test_id = %s",
$ilDB->quote($test_id)
);
$result = $ilDB->query($query);
if ($result->numRows() == 1)
{
$row = $result->fetchRow(DB_FETCHMODE_ASSOC);
if ($row["count_system"] == 1)
{
if ($points != $this->getMaximumPoints())
{
$points = 0;
}
}
}
else
{
$points = 0;
}
return $points;
}
Here is the call graph for this function:| ASS_ClozeTest::copyObject | ( | $ | target_questionpool, | |
| $ | title = "" | |||
| ) |
Copies an ASS_ClozeTest object.
Copies an ASS_ClozeTest object
public
Definition at line 522 of file class.assClozeTest.php.
References ASS_Question::$title, ASS_Question::_getOriginalId(), and ASS_Question::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 ("./assessment/classes/class.assQuestion.php");
$original_id = ASS_Question::_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);
return $clone->id;
}
Here is the call graph for this function:| & ASS_ClozeTest::createCloseTextArray | ( | ) |
Creates an associative array from the close text.
Creates an associative array from the close text
Definition at line 143 of file class.assClozeTest.php.
References $gaps, $key, $params, and $result.
Referenced by delete_answertext_by_index(), delete_gap(), rebuild_cloze_text(), set_cloze_text(), set_cloze_type(), and update_all_gap_params().
{
$result = array();
$search_pattern = "|<gap([^>]*?)>(.*?)</gap>|i";
preg_match_all($search_pattern, $this->cloze_text, $gaps);
if (count($gaps[0]))
{
// found at least one gap
$delimiters = preg_split($search_pattern, $this->cloze_text, -1, PREG_SPLIT_OFFSET_CAPTURE);
$result["gaps"] = array();
foreach ($gaps[0] as $index => $gap)
{
$result["gaps"][$index] = array();
$result["gaps"][$index]["gap"] = $gap;
$result["gaps"][$index]["params"] = array();
$result["gaps"][$index]["params"]["text"] = $gaps[1][$index];
// separate gap params
if (preg_match("/name\=\"([^\"]*?)\"/", $gaps[1][$index], $params))
{
$result["gaps"][$index]["params"]["name"] = $params[1];
}
else
{
$result["gaps"][$index]["params"]["name"] = $this->lng->txt("gap") . " " . ($index+1);
}
if (preg_match("/type\=\"([^\"]*?)\"/", $gaps[1][$index], $params))
{
$result["gaps"][$index]["params"]["type"] = $params[1];
}
else
{
$result["gaps"][$index]["params"]["type"] = "text";
}
if (preg_match("/shuffle\=\"([^\"]*?)\"/", $gaps[1][$index], $params))
{
$result["gaps"][$index]["params"]["shuffle"] = $params[1];
}
else
{
if (strcmp(strtolower($result["gaps"][$index]["params"]["type"]), "select") == 0)
{
$result["gaps"][$index]["params"]["shuffle"] = "yes";
}
}
$result["gaps"][$index]["text"] = array();
$result["gaps"][$index]["text"]["text"] = $gaps[2][$index];
$textparams = preg_split("/(?<!\\\\),/", $gaps[2][$index]);
foreach ($textparams as $key => $value)
{
$result["gaps"][$index]["text"][$key] = $value;
}
}
$result["delimiters"] = $delimiters;
}
else
{
$result["gaps"] = array();
$result["delimiters"] =
array(
array(0 => $this->cloze_text, 1 => "0")
);
}
//echo str_replace("\n", "<br />", str_replace(" ", " ", ilUtil::prepareFormOutput(print_r($result, true))));
return $result;
}
Here is the caller graph for this function:| ASS_ClozeTest::createCloseTextFromArray | ( | $ | assoc_array | ) |
Re-creates the close text from an an associative array.
Re-creates the close text from an an associative array
| array | $assoc_array Associative array containing all separated close text parts public |
Definition at line 217 of file class.assClozeTest.php.
References $key, and ASS_Question::$shuffle.
Referenced by delete_answertext_by_index(), delete_gap(), rebuild_cloze_text(), set_cloze_type(), and update_all_gap_params().
{
$this->cloze_text = "";
if (count($assoc_array))
{
$gap = 0;
foreach ($assoc_array["delimiters"] as $key => $value)
{
if (($key > 0) && ($key < count($assoc_array["delimiters"])))
{
if (strcmp($assoc_array["gaps"][$gap]["params"]["shuffle"], "") == 0)
{
$shuffle = "";
}
else
{
$shuffle = " shuffle=\"" . $assoc_array["gaps"][$gap]["params"]["shuffle"] . "\"";
}
$textarray = array();
if (is_array($assoc_array["gaps"][$gap]["text"]))
{
foreach ($assoc_array["gaps"][$gap]["text"] as $textindex => $textvalue)
{
if (preg_match("/\d+/", $textindex))
{
array_push($textarray, $textvalue);
}
}
}
if (count($textarray))
{
$this->cloze_text .= sprintf("<gap name=\"%s\" type=\"%s\"%s>%s</gap>",
$assoc_array["gaps"][$gap]["params"]["name"],
$assoc_array["gaps"][$gap]["params"]["type"],
$shuffle,
join(",", $textarray)
);
}
$gap++;
}
$this->cloze_text .= $value[0];
}
}
}
Here is the caller graph for this function:| ASS_ClozeTest::delete_answertext_by_index | ( | $ | gap_index = 0, |
|
| $ | answertext_index = 0 | |||
| ) |
Deletes an answer text of a gap.
Deletes an answer text of a gap with a given index. The index of the first gap is 0, the index of the second gap is 1 and so on.
| integer | $index A nonnegative index of the n-th gap | |
| string | $answertext The answer text that should be deleted public |
Definition at line 1147 of file class.assClozeTest.php.
References createCloseTextArray(), createCloseTextFromArray(), delete_gap(), and get_gap_text_list().
{
if ($gap_index < 0) return;
if (count($this->gaps) < 1) return;
if ($gap_index >= count($this->gaps)) return;
$old_text = $this->get_gap_text_list($gap_index);
if (count($this->gaps[$gap_index]) == 1) {
$this->delete_gap($gap_index);
} else {
$close = $this->createCloseTextArray();
unset($this->gaps[$gap_index][$answertext_index]);
$this->gaps[$gap_index] = array_values($this->gaps[$gap_index]);
unset($close["gaps"][$gap_index]["text"][$answertext_index]);
$this->createCloseTextFromArray($close);
}
}
Here is the call graph for this function:| ASS_ClozeTest::delete_gap | ( | $ | index = 0 |
) |
Deletes a gap.
Deletes a gap with a given index. The index of the first gap is 0, the index of the second gap is 1 and so on.
| integer | $index A nonnegative index of the n-th gap public |
Definition at line 1113 of file class.assClozeTest.php.
References createCloseTextArray(), and createCloseTextFromArray().
Referenced by delete_answertext_by_index().
{
if ($index < 0) return;
if (count($this->gaps) < 1) return;
if ($index >= count($this->gaps)) return;
$close = $this->createCloseTextArray();
unset($close["gaps"][$index]);
$this->createCloseTextFromArray($close);
unset($this->gaps[$index]);
$this->gaps = array_values($this->gaps);
}
Here is the call graph for this function:
Here is the caller graph for this function:| ASS_ClozeTest::duplicate | ( | $ | for_test = true, |
|
| $ | title = "", |
|||
| $ | author = "", |
|||
| $ | owner = "" | |||
| ) |
Duplicates an ASS_ClozeTest.
Duplicates an ASS_ClozeTest
public
Definition at line 475 of file class.assClozeTest.php.
References ASS_Question::$author, ASS_Question::$owner, ASS_Question::$title, ASS_Question::_getOriginalId(), and ASS_Question::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 ("./assessment/classes/class.assQuestion.php");
$original_id = ASS_Question::_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);
return $clone->id;
}
Here is the call graph for this function:| ASS_ClozeTest::flush_gaps | ( | ) |
Deletes all gaps without changing the cloze text.
Deletes all gaps without changing the cloze text
public
Definition at line 1132 of file class.assClozeTest.php.
{
$this->gaps = array();
}
| ASS_ClozeTest::get_cloze_text | ( | ) |
Returns the cloze text.
Returns the cloze text
Definition at line 950 of file class.assClozeTest.php.
Referenced by to_xml().
{
return $this->cloze_text;
}
Here is the caller graph for this function:| ASS_ClozeTest::get_end_tag | ( | ) |
Returns the end tag of a cloze gap.
Returns the end tag of a cloze gap
Definition at line 976 of file class.assClozeTest.php.
{
return $this->end_tag;
}
| ASS_ClozeTest::get_gap | ( | $ | index = 0 |
) |
Returns an array of gap answers.
Returns the array of gap answers with a given index. The index of the first gap is 0, the index of the second gap is 1 and so on.
| integer | $index A nonnegative index of the n-th gap |
Definition at line 1046 of file class.assClozeTest.php.
Referenced by saveWorkingData(), and to_xml().
{
if ($index < 0) return array();
if (count($this->gaps) < 1) return array();
if ($index >= count($this->gaps)) return array();
return $this->gaps[$index];
}
Here is the caller graph for this function:| ASS_ClozeTest::get_gap_count | ( | ) |
Returns the number of gaps.
Returns the number of gaps
Definition at line 1062 of file class.assClozeTest.php.
Referenced by to_xml(), and update_all_gap_params().
{
return count($this->gaps);
}
Here is the caller graph for this function:| ASS_ClozeTest::get_gap_text_count | ( | $ | index = 0 |
) |
Returns a count of all answers of a gap.
Returns a count of all answers of a gap
| integer | $index A nonnegative index of the n-th gap public |
Definition at line 1097 of file class.assClozeTest.php.
{
if ($index < 0) return 0;
if (count($this->gaps) < 1) return 0;
if ($index >= count($this->gaps)) return 0;
return count($this->gaps[$index]);
}
| ASS_ClozeTest::get_gap_text_list | ( | $ | index = 0, |
|
| $ | separator = "," | |||
| ) |
Returns a separated string of all answers for a given text gap.
Returns a separated string of all answers for a given gap. The index of the first gap is 0, the index of the second gap is 1 and so on.
| integer | $index A nonnegative index of the n-th gap | |
| string | $separator A string that separates the answer strings |
Definition at line 1078 of file class.assClozeTest.php.
References $key, $result, and $separator.
Referenced by delete_answertext_by_index(), rebuild_cloze_text(), and update_all_gap_params().
{
if ($index < 0) return "";
if (count($this->gaps) < 1) return "";
if ($index >= count($this->gaps)) return "";
$result = array();
foreach ($this->gaps[$index] as $key => $value) {
array_push($result, str_replace(",", "\,", $value->get_answertext()));
}
return join($separator, $result);
}
Here is the caller graph for this function:| ASS_ClozeTest::get_start_tag | ( | ) |
Returns the start tag of a cloze gap.
Returns the start tag of a cloze gap
Definition at line 963 of file class.assClozeTest.php.
{
return $this->start_tag;
}
| ASS_ClozeTest::getColumnSize | ( | $ | gap | ) |
Returns the maximum number of text columns within which a user can type their answer.
Returns the maximum number of text columns within which a user can type their answer
Definition at line 1778 of file class.assClozeTest.php.
References $size.
Referenced by to_xml().
{
$size = 0;
foreach ($gap as $answer)
{
$answertextsize = strlen($answer->get_answertext());
if ($answertextsize > $size) $size = $answertextsize;
}
return $size;
}
Here is the caller graph for this function:| ASS_ClozeTest::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 ASS_Question.
Definition at line 1594 of file class.assClozeTest.php.
References $key, and ASS_Question::$points.
Referenced by calculateReachedPoints(), isComplete(), saveToDb(), and syncWithOriginal().
{
$points = 0;
foreach ($this->gaps as $key => $value) {
if ($value[0]->get_cloze_type() == CLOZE_TEXT)
{
$gap_max_points = 0;
foreach ($value as $key2 => $value2)
{
if ($value2->get_points() > $gap_max_points)
{
$gap_max_points = $value2->get_points();
}
}
$points += $gap_max_points;
} else
{
$points_arr = array("set" => 0, "unset" => 0);
foreach ($value as $key2 => $value2)
{
if ($value2->get_points() > $points_arr["set"])
{
$points_arr["set"] = $value2->get_points();
}
}
$points += $points_arr["set"];
}
}
return $points;
}
Here is the caller graph for this function:| ASS_ClozeTest::getQuestionType | ( | ) |
Returns the question type of the question.
Returns the question type of the question
Definition at line 1765 of file class.assClozeTest.php.
{
return 3;
}
| ASS_ClozeTest::getReachedInformation | ( | $ | user_id, | |
| $ | test_id, | |||
| $ | pass = NULL | |||
| ) |
Returns the evaluation data, a learner has entered to answer the question.
Returns the evaluation data, a learner has entered to answer the question
| 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 1520 of file class.assClozeTest.php.
References $counter, $data, $key, $query, $result, ASS_Question::$test_id, $user_id, ASS_Question::getId(), and ASS_Question::getSolutionMaxPass().
{
$found_value1 = array();
$found_value2 = array();
$pass = array();
if (is_null($pass))
{
$pass = $this->getSolutionMaxPass($user_id, $test_id);
}
$query = sprintf("SELECT * FROM tst_solutions WHERE user_fi = %s AND test_fi = %s AND question_fi = %s AND pass = %s",
$this->ilias->db->quote($user_id . ""),
$this->ilias->db->quote($test_id . ""),
$this->ilias->db->quote($this->getId() . ""),
$this->ilias->db->quote($pass . "")
);
$result = $this->ilias->db->query($query);
while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
{
array_push($found_value1, $data->value1);
array_push($found_value2, $data->value2);
}
$counter = 1;
$user_result = array();
foreach ($found_value1 as $key => $value)
{
if ($this->gaps[$value][0]->get_cloze_type() == CLOZE_TEXT)
{
$solution = array(
"gap" => "$counter",
"points" => 0,
"true" => 0,
"value" => $found_value2[$key]
);
foreach ($this->gaps[$value] as $k => $v)
{
if (strcmp(strtolower($v->get_answertext()), strtolower($found_value2[$key])) == 0)
{
$solution = array(
"gap" => "$counter",
"points" => $v->get_points(),
"true" => 1,
"value" => $found_value2[$key]
);
}
}
}
else
{
$solution = array(
"gap" => "$counter",
"points" => 0,
"true" => 0,
"value" => $found_value2[$key]
);
if ($this->gaps[$value][$found_value1[$key]]->isStateSet())
{
$solution["points"] = $this->gaps[$value][$found_value1[$key]]->get_points();
$solution["true"] = 1;
}
}
$counter++;
$user_result[$value] = $solution;
}
return $user_result;
}
Here is the call graph for this function:| ASS_ClozeTest::getTextgapPoints | ( | $ | a_original, | |
| $ | a_entered, | |||
| $ | max_points | |||
| ) |
Returns the points for a text gap.
Returns the points for a text gap and compares the given solution with the entered solution using the text gap rating options.
| string | $a_original The original (correct) text | |
| string | $a_entered The text entered by the user | |
| integer | $max_points The maximum number of points for the solution public |
Definition at line 1389 of file class.assClozeTest.php.
References $result, and getTextgapRating().
Referenced by calculateReachedPoints().
{
$result = 0;
$gaprating = $this->getTextgapRating();
switch ($gaprating)
{
case TEXTGAP_RATING_CASEINSENSITIVE:
if (strcmp(strtolower(utf8_decode($a_original)), strtolower(utf8_decode($a_entered))) == 0) $result = $max_points;
break;
case TEXTGAP_RATING_CASESENSITIVE:
if (strcmp(utf8_decode($a_original), utf8_decode($a_entered)) == 0) $result = $max_points;
break;
case TEXTGAP_RATING_LEVENSHTEIN1:
if (levenshtein(utf8_decode($a_original), utf8_decode($a_entered)) <= 1) $result = $max_points;
break;
case TEXTGAP_RATING_LEVENSHTEIN2:
if (levenshtein(utf8_decode($a_original), utf8_decode($a_entered)) <= 2) $result = $max_points;
break;
case TEXTGAP_RATING_LEVENSHTEIN3:
if (levenshtein(utf8_decode($a_original), utf8_decode($a_entered)) <= 3) $result = $max_points;
break;
case TEXTGAP_RATING_LEVENSHTEIN4:
if (levenshtein(utf8_decode($a_original), utf8_decode($a_entered)) <= 4) $result = $max_points;
break;
case TEXTGAP_RATING_LEVENSHTEIN5:
if (levenshtein(utf8_decode($a_original), utf8_decode($a_entered)) <= 5) $result = $max_points;
break;
}
return $result;
}
Here is the call graph for this function:
Here is the caller graph for this function:| ASS_ClozeTest::getTextgapRating | ( | ) |
Returns the rating option for text gaps.
Returns the rating option for text gaps
Definition at line 1798 of file class.assClozeTest.php.
Referenced by getTextgapPoints(), and to_xml().
{
return $this->textgap_rating;
}
Here is the caller graph for this function:| ASS_ClozeTest::isComplete | ( | ) |
Returns true, if a cloze test is complete for use.
Returns true, if a cloze test is complete for use
Reimplemented from ASS_Question.
Definition at line 123 of file class.assClozeTest.php.
References getMaximumPoints().
Referenced by saveToDb(), and syncWithOriginal().
{
if (($this->title) and ($this->author) and ($this->cloze_text) and (count($this->gaps)) 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:| ASS_ClozeTest::loadFromDb | ( | $ | question_id | ) |
Loads a ASS_ClozeTest object from a database.
Loads a ASS_ClozeTest object from a database
| object | $db A pear DB object | |
| integer | $question_id A unique key which defines the cloze test in the database public |
Reimplemented from ASS_Question.
Definition at line 395 of file class.assClozeTest.php.
References $counter, $data, ASS_Question::$ilias, $query, $result, ASS_Question::setEstimatedWorkingTime(), and setTextgapRating().
{
global $ilias;
$db =& $ilias->db;
include_once "./assessment/classes/class.assAnswerCloze.php";
$query = sprintf("SELECT * FROM qpl_questions WHERE question_id = %s",
$db->quote($question_id)
);
$result = $db->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->obj_id = $data->obj_fi;
$this->title = $data->title;
$this->comment = $data->comment;
$this->solution_hint = $data->solution_hint;
$this->original_id = $data->original_id;
$this->author = $data->author;
$this->points = $data->points;
$this->owner = $data->owner;
$this->cloze_text = $data->question_text;
$this->setTextgapRating($data->textgap_rating);
$this->shuffle = $data->shuffle;
$this->setEstimatedWorkingTime(substr($data->working_time, 0, 2), substr($data->working_time, 3, 2), substr($data->working_time, 6, 2));
}
$query = sprintf("SELECT * FROM qpl_answers WHERE question_fi = %s ORDER BY gap_id, aorder ASC",
$db->quote($question_id)
);
$result = $db->query($query);
if (strcmp(strtolower(get_class($result)), db_result) == 0) {
$counter = -1;
while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT)) {
if ($data->gap_id != $counter) {
$answer_array = array();
array_push($this->gaps, $answer_array);
$counter = $data->gap_id;
}
if ($data->cloze_type == CLOZE_SELECT)
{
if ($data->correctness == 0)
{
// fix for older single response answers where points could be given for unchecked answers
$data->correctness = 1;
$data->points = 0;
}
}
array_push($this->gaps[$counter], new ASS_AnswerCloze($data->answertext, $data->points, $data->aorder, $data->correctness, $data->cloze_type, $data->name, $data->shuffle, $data->answer_id));
}
}
}
parent::loadFromDb($question_id);
}
Here is the call graph for this function:| ASS_ClozeTest::rebuild_cloze_text | ( | ) |
Replaces the gap values with the values of the gaps array.
Replaces the gap values with the values of the gaps array
public
Definition at line 1015 of file class.assClozeTest.php.
References $key, createCloseTextArray(), createCloseTextFromArray(), and get_gap_text_list().
Referenced by set_answertext().
{
$close =& $this->createCloseTextArray();
if (count($close))
{
for ($i = 0; $i < count($this->gaps); $i++)
{
$gaptext = $this->get_gap_text_list($i);
$textparams = preg_split("/(?<!\\\\),/", $gaptext);
$close["gaps"][$i]["text"] = array();
$close["gaps"][$i]["text"]["text"] = $gaptext;
foreach ($textparams as $key => $value)
{
$close["gaps"][$i]["text"][$key] = $value;
}
}
}
$this->createCloseTextFromArray($close);
}
Here is the call graph for this function:
Here is the caller graph for this function:| ASS_ClozeTest::saveToDb | ( | $ | original_id = "" |
) |
Saves a ASS_ClozeTest object to a database.
Saves a ASS_ClozeTest object to a database (experimental)
| object | $db A pear DB object public |
Reimplemented from ASS_Question.
Definition at line 270 of file class.assClozeTest.php.
References ASS_Question::$ilias, $key, $query, $result, ASS_Question::$shuffle, ASS_Question::createPageObject(), ASS_Question::getEstimatedWorkingTime(), getMaximumPoints(), ASS_Question::getTestId(), ASS_Question::insertIntoTest(), and isComplete().
{
global $ilias;
$db =& $ilias->db;
$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']);
$shuffle = 1;
if (!$this->shuffle)
{
$shuffle = 0;
}
if ($original_id)
{
$original_id = $db->quote($original_id);
}
else
{
$original_id = "NULL";
}
if ($this->id == -1)
{
// Neuen Datensatz schreiben
$now = getdate();
$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, points, author, owner, question_text, working_time, shuffle, complete, created, original_id, textgap_rating, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
$db->quote($this->getQuestionType()),
$db->quote($this->obj_id),
$db->quote($this->title),
$db->quote($this->comment),
$db->quote($this->getMaximumPoints() . ""),
$db->quote($this->author),
$db->quote($this->owner),
$db->quote($this->cloze_text),
$db->quote($estw_time),
$db->quote("$this->shuffle"),
$db->quote("$complete"),
$db->quote($created),
$original_id,
$db->quote($this->textgap_rating)
);
$result = $db->query($query);
if ($result == DB_OK)
{
$this->id = $this->ilias->db->getLastInsertId();
// create page object of question
$this->createPageObject();
// Falls die Frage in einen Test eingef�gt werden soll, auch diese Verbindung erstellen
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, points = %s, author = %s, question_text = %s, working_time = %s, shuffle = %s, complete = %s, textgap_rating = %s WHERE question_id = %s",
$db->quote($this->obj_id. ""),
$db->quote($this->title),
$db->quote($this->comment),
$db->quote($this->getMaximumPoints() . ""),
$db->quote($this->author),
$db->quote($this->cloze_text),
$db->quote($estw_time),
$db->quote("$this->shuffle"),
$db->quote("$complete"),
$db->quote($this->textgap_rating),
$db->quote($this->id)
);
$result = $db->query($query);
}
if ($result == DB_OK)
{
// Antworten schreiben
// delete old answers
$query = sprintf("DELETE FROM qpl_answers WHERE question_fi = %s",
$db->quote($this->id)
);
$result = $db->query($query);
// Anworten wegschreiben
foreach ($this->gaps as $key => $value)
{
foreach ($value as $answer_id => $answer_obj)
{
$query = sprintf("INSERT INTO qpl_answers (answer_id, question_fi, gap_id, answertext, points, aorder, cloze_type, name, shuffle, correctness, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
$db->quote($this->id),
$db->quote($key),
$db->quote($answer_obj->get_answertext() . ""),
$db->quote($answer_obj->get_points() . ""),
$db->quote($answer_obj->get_order() . ""),
$db->quote($answer_obj->get_cloze_type() . ""),
$db->quote($answer_obj->get_name() . ""),
$db->quote($answer_obj->get_shuffle() . ""),
$db->quote($answer_obj->getState() . "")
);
$answer_result = $db->query($query);
}
}
}
parent::saveToDb($original_id);
}
Here is the call graph for this function:| ASS_ClozeTest::saveWorkingData | ( | $ | test_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 ASS_Question.
Definition at line 1634 of file class.assClozeTest.php.
References $_POST, $ilUser, $key, $query, $result, ASS_Question::$test_id, ilObjAssessmentFolder::_enabledAssessmentLogging(), ilObjAssessmentFolder::_getLogLanguage(), ilObjTest::_getPass(), get_gap(), ASS_Question::getId(), ASS_Question::logAction(), and ilUtil::stripSlashes().
{
global $ilDB;
global $ilUser;
$db =& $ilDB->db;
include_once "./assessment/classes/class.ilObjTest.php";
$activepass = ilObjTest::_getPass($ilUser->id, $test_id);
$query = sprintf("DELETE FROM tst_solutions WHERE user_fi = %s AND test_fi = %s AND question_fi = %s AND pass = %s",
$db->quote($ilUser->id),
$db->quote($test_id),
$db->quote($this->getId()),
$db->quote($activepass . "")
);
$result = $db->query($query);
$entered_values = 0;
foreach ($_POST as $key => $value) {
if (preg_match("/^gap_(\d+)/", $key, $matches))
{
$value = ilUtil::stripSlashes($value);
if (strlen($value))
{
$gap = $this->get_gap($matches[1]);
if (!(($gap[0]->get_cloze_type() == CLOZE_SELECT) && ($value == -1)))
{
$query = sprintf("INSERT INTO tst_solutions (solution_id, user_fi, test_fi, question_fi, value1, value2, pass, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, NULL)",
$db->quote($ilUser->id),
$db->quote($test_id),
$db->quote($this->getId()),
$db->quote($matches[1]),
$db->quote($value),
$db->quote($activepass . "")
);
$result = $db->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()), $test_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()), $test_id, $this->getId());
}
}
parent::saveWorkingData($test_id, $pass);
return true;
}
Here is the call graph for this function:| ASS_ClozeTest::set_answertext | ( | $ | index = 0, |
|
| $ | answertext_index = 0, |
|||
| $ | answertext = "", |
|||
| $ | add_gaptext = 0 | |||
| ) |
Sets an answer text of a gap.
Sets an answer text of a gap with a given index. The index of the first gap is 0, the index of the second gap is 1 and so on.
| integer | $index A nonnegative index of the n-th gap | |
| integer | $answertext_index A nonnegative index of the n-th answertext | |
| string | $answertext The answer text that should be deleted public |
Definition at line 1175 of file class.assClozeTest.php.
References rebuild_cloze_text().
{
$answertext = str_replace("\,", ",", $answertext);
if ($add_gaptext == 1)
{
$arr = $this->gaps[$index][0];
if (strlen($this->gaps[$index][count($this->gaps[$index])-1]->get_answertext()) != 0)
{
$default_state = 0;
$default_points = 0;
if ($arr->get_cloze_type() == CLOZE_TEXT)
{
$default_state = 1;
if ($answertext_index > 0) $default_points = $this->gaps[$index][0]->get_points();
}
include_once "./assessment/classes/class.assAnswerCloze.php";
array_push($this->gaps[$index], new ASS_AnswerCloze($answertext, $default_points, count($this->gaps[$index]),
$default_state, $arr->get_cloze_type(),
$arr->get_name(), $arr->get_shuffle()));
$this->rebuild_cloze_text();
}
return;
}
if ($index < 0) return;
if (count($this->gaps) < 1) return;
if ($index >= count($this->gaps)) return;
if ($answertext_index < 0) return;
if (count($this->gaps[$index]) < 1) return;
if ($answertext_index >= count($this->gaps[$index])) return;
if (strlen($answertext) == 0)
{
// delete the answertext
$this->delete_answertext($index, $this->gaps[$index][$answertext_index]->get_answertext());
}
else
{
$this->gaps[$index][$answertext_index]->set_answertext($answertext);
$this->rebuild_cloze_text();
}
}
Here is the call graph for this function:| ASS_ClozeTest::set_cloze_text | ( | $ | cloze_text = "" |
) |
Evaluates the text gap solutions from the cloze text.
Evaluates the text gap solutions from the cloze text. A single or multiple text gap solutions could be entered using the following syntax in the cloze text: solution1 [, solution2, ..., solutionN] enclosed in the text gap selector *[]
| string | $cloze_text The cloze text with all gaps and gap gaps public |
Definition at line 892 of file class.assClozeTest.php.
References $cloze_text, $key, ASS_Question::$shuffle, $type, and createCloseTextArray().
Referenced by ASS_ClozeTest().
{
$this->gaps = array();
$this->cloze_text =& $cloze_text;
$close = $this->createCloseTextArray();
if (count($close))
{
foreach ($close["gaps"] as $key => $value)
{
if (strcmp(strtolower($value["params"]["type"]), "select") == 0)
{
$type = CLOZE_SELECT;
}
else
{
$type = CLOZE_TEXT;
}
if ($type == CLOZE_TEXT)
{
$default_state = 1;
}
else
{
$default_state = 0;
}
$name = $value["params"]["name"];
if (strcmp(strtolower($value["params"]["shuffle"]), "no") == 0)
{
$shuffle = 0;
}
else
{
$shuffle = 1;
}
$answer_array = array();
include_once "./assessment/classes/class.assAnswerCloze.php";
foreach ($value["text"] as $index => $textvalue)
{
if (preg_match("/\d+/", $index))
{
$textvalue = str_replace("\,", ",", $textvalue);
array_push($answer_array, new ASS_AnswerCloze($textvalue, 0, $index, $default_state, $type, $name, $shuffle));
}
}
array_push($this->gaps, $answer_array);
}
}
}
Here is the call graph for this function:
Here is the caller graph for this function:| ASS_ClozeTest::set_cloze_type | ( | $ | index, | |
| $ | cloze_type = CLOZE_TEXT | |||
| ) |
Sets the cloze type of the gap.
Sets the cloze type of the gap
| integer | $index The index of the chosen gap | |
| integer | $cloze_type The cloze type of the gap public |
Definition at line 1272 of file class.assClozeTest.php.
References $key, $type, createCloseTextArray(), and createCloseTextFromArray().
{
if ($index < 0) return;
if (count($this->gaps) < 1) return;
if ($index >= count($this->gaps)) return;
$close = $this->createCloseTextArray();
foreach ($this->gaps[$index] as $key => $value) {
$this->gaps[$index][$key]->set_cloze_type($cloze_type);
$this->gaps[$index][$key]->setState(1);
}
if ($cloze_type == CLOZE_TEXT)
{
$type = "text";
}
else
{
$type = "select";
}
$close["gaps"][$index]["type"] = $type;
$this->createCloseTextFromArray($close);
}
Here is the call graph for this function:| ASS_ClozeTest::set_end_tag | ( | $ | end_tag = "</gap>" |
) |
Sets the end tag of a cloze gap.
Sets the end tag of a cloze gap
| string | $end_tag The end tag for a cloze gap public |
Definition at line 1003 of file class.assClozeTest.php.
References $end_tag.
{
$this->end_tag = $end_tag;
}
| ASS_ClozeTest::set_gap_points | ( | $ | index = 0, |
|
| $ | points = 0.0 | |||
| ) |
Sets the points of a gap.
Sets the points of a gap with a given index. The index of the first gap is 0, the index of the second gap is 1 and so on.
| integer | $index A nonnegative index of the n-th gap | |
| double | $points The points for the correct solution of the gap public |
Definition at line 1304 of file class.assClozeTest.php.
References $key, and ASS_Question::$points.
| ASS_ClozeTest::set_gap_shuffle | ( | $ | index = 0, |
|
| $ | shuffle = 1 | |||
| ) |
Sets the shuffle state of a gap.
Sets the shuffle state of a gap with a given index. The index of the first gap is 0, the index of the second gap is 1 and so on.
| integer | $index A nonnegative index of the n-th gap | |
| integer | $shuffle Turn shuffle on (=1) or off (=0) public |
Definition at line 1324 of file class.assClozeTest.php.
References $key, and ASS_Question::$shuffle.
| ASS_ClozeTest::set_single_answer_points | ( | $ | index_gaps = 0, |
|
| $ | index_answerobject = 0, |
|||
| $ | points = 0.0 | |||
| ) |
Sets the points of a gap answer.
Sets the points of a gap answer with a given index. The index of the first gap is 0, the index of the second gap is 1 and so on.
| integer | $index_gaps A nonnegative index of the n-th gap | |
| integer | $index_answerobject A nonnegative index of the n-th answer in the specified gap | |
| double | $points The points for the correct solution of the answer public |
Definition at line 1346 of file class.assClozeTest.php.
References ASS_Question::$points.
{
if ($index_gaps < 0) return;
if (count($this->gaps) < 1) return;
if ($index_gaps >= count($this->gaps)) return;
if ($index_answerobject < 0) return;
if (count($this->gaps[$index_gaps]) < 1) return;
if ($index_answerobject >= count($this->gaps[$index_gaps])) return;
$this->gaps[$index_gaps][$index_answerobject]->set_points($points);
}
| ASS_ClozeTest::set_single_answer_state | ( | $ | index_gaps = 0, |
|
| $ | index_answerobject = 0, |
|||
| $ | state = 0 | |||
| ) |
Sets the state of a gap answer.
Sets the state of a gap answer with a given index. The index of the first gap is 0, the index of the second gap is 1 and so on.
| integer | $index_gaps A nonnegative index of the n-th gap | |
| integer | $index_answerobject A nonnegative index of the n-th answer in the specified gap | |
| boolean | $state The state of the answer public |
Definition at line 1368 of file class.assClozeTest.php.
{
if ($index_gaps < 0) return;
if (count($this->gaps) < 1) return;
if ($index_gaps >= count($this->gaps)) return;
if ($index_answerobject < 0) return;
if (count($this->gaps[$index_gaps]) < 1) return;
if ($index_answerobject >= count($this->gaps[$index_gaps])) return;
$this->gaps[$index_gaps][$index_answerobject]->setState($state);
}
| ASS_ClozeTest::set_start_tag | ( | $ | start_tag = "<gap>" |
) |
Sets the start tag of a cloze gap.
Sets the start tag of a cloze gap
| string | $start_tag The start tag for a cloze gap public |
Definition at line 989 of file class.assClozeTest.php.
References $start_tag.
{
$this->start_tag = $start_tag;
}
| ASS_ClozeTest::setTextgapRating | ( | $ | a_textgap_rating | ) |
Sets the rating option for text gaps.
Sets the rating option for text gaps
| string | $a_textgap_rating The rating option for text gaps |
Definition at line 1812 of file class.assClozeTest.php.
Referenced by loadFromDb().
{
switch ($a_textgap_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->textgap_rating = $a_textgap_rating;
break;
default:
$this->textgap_rating = TEXTGAP_RATING_CASEINSENSITIVE;
break;
}
}
Here is the caller graph for this function:| ASS_ClozeTest::syncWithOriginal | ( | ) |
Reimplemented from ASS_Question.
Definition at line 1695 of file class.assClozeTest.php.
References ASS_Question::$ilias, $key, $query, $result, ASS_Question::getEstimatedWorkingTime(), getMaximumPoints(), and isComplete().
{
global $ilias;
if ($this->original_id)
{
$complete = 0;
if ($this->isComplete())
{
$complete = 1;
}
$db = & $ilias->db;
$estw_time = $this->getEstimatedWorkingTime();
$estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
$query = sprintf("UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, points = %s, author = %s, question_text = %s, working_time = %s, shuffle = %s, textgap_rating = %s, complete = %s WHERE question_id = %s",
$db->quote($this->obj_id. ""),
$db->quote($this->title . ""),
$db->quote($this->comment . ""),
$db->quote($this->getMaximumPoints() . ""),
$db->quote($this->author . ""),
$db->quote($this->cloze_text . ""),
$db->quote($estw_time . ""),
$db->quote($this->shuffle . ""),
$db->quote($this->textgap_rating . ""),
$db->quote($complete . ""),
$db->quote($this->original_id . "")
);
$result = $db->query($query);
if ($result == DB_OK)
{
// write answers
// delete old answers
$query = sprintf("DELETE FROM qpl_answers WHERE question_fi = %s",
$db->quote($this->original_id)
);
$result = $db->query($query);
foreach ($this->gaps as $key => $value)
{
foreach ($value as $answer_id => $answer_obj)
{
$query = sprintf("INSERT INTO qpl_answers (answer_id, question_fi, gap_id, answertext, points, aorder, cloze_type, name, shuffle, correctness, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
$db->quote($this->original_id . ""),
$db->quote($key . ""),
$db->quote($answer_obj->get_answertext() . ""),
$db->quote($answer_obj->get_points() . ""),
$db->quote($answer_obj->get_order() . ""),
$db->quote($answer_obj->get_cloze_type() . ""),
$db->quote($answer_obj->get_name() . ""),
$db->quote($answer_obj->get_shuffle() . ""),
$db->quote($answer_obj->getState() . "")
);
$answer_result = $db->query($query);
}
}
}
parent::syncWithOriginal();
}
}
Here is the call graph for this function:| ASS_ClozeTest::to_xml | ( | $ | a_include_header = true, |
|
| $ | a_include_binary = true, |
|||
| $ | a_shuffle = false, |
|||
| $ | test_output = false, |
|||
| $ | force_image_references = false | |||
| ) |
Returns a QTI xml representation of the question.
Returns a QTI xml representation of the question and sets the internal domxml variable with the DOM XML representation of the QTI xml representation
Definition at line 557 of file class.assClozeTest.php.
References $key, $pos, $xml, get_cloze_text(), get_gap(), get_gap_count(), ASS_Question::getAuthor(), getColumnSize(), ASS_Question::getComment(), ASS_Question::getEstimatedWorkingTime(), ASS_Question::getSuggestedSolution(), getTextgapRating(), ASS_Question::getTitle(), and ASS_Question::pcArrayShuffle().
{
include_once("./classes/class.ilXmlWriter.php");
$a_xml_writer = new ilXmlWriter;
// set xml header
$a_xml_writer->xmlHeader();
$a_xml_writer->xmlStartTag("questestinterop");
$attrs = array(
"ident" => "il_".IL_INST_ID."_qst_".$this->getId(),
"title" => $this->getTitle()
);
$a_xml_writer->xmlStartTag("item", $attrs);
// add question description
$a_xml_writer->xmlElement("qticomment", NULL, $this->getComment());
// add estimated working time
$workingtime = $this->getEstimatedWorkingTime();
$duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
$a_xml_writer->xmlElement("duration", NULL, $duration);
// add ILIAS specific metadata
$a_xml_writer->xmlStartTag("itemmetadata");
$a_xml_writer->xmlStartTag("qtimetadata");
$a_xml_writer->xmlStartTag("qtimetadatafield");
$a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
$a_xml_writer->xmlElement("fieldentry", NULL, $this->ilias->getSetting("ilias_version"));
$a_xml_writer->xmlEndTag("qtimetadatafield");
$a_xml_writer->xmlStartTag("qtimetadatafield");
$a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
$a_xml_writer->xmlElement("fieldentry", NULL, CLOZE_TEST_IDENTIFIER);
$a_xml_writer->xmlEndTag("qtimetadatafield");
$a_xml_writer->xmlStartTag("qtimetadatafield");
$a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
$a_xml_writer->xmlElement("fieldentry", NULL, $this->getAuthor());
$a_xml_writer->xmlEndTag("qtimetadatafield");
$a_xml_writer->xmlStartTag("qtimetadatafield");
$a_xml_writer->xmlElement("fieldlabel", NULL, "textgaprating");
$a_xml_writer->xmlElement("fieldentry", NULL, $this->getTextgapRating());
$a_xml_writer->xmlEndTag("qtimetadatafield");
$a_xml_writer->xmlEndTag("qtimetadata");
$a_xml_writer->xmlEndTag("itemmetadata");
// PART I: qti presentation
$attrs = array(
"label" => $this->getTitle()
);
$a_xml_writer->xmlStartTag("presentation", $attrs);
// add flow to presentation
$a_xml_writer->xmlStartTag("flow");
$text_parts = preg_split("/<gap.*?<\/gap>/", $this->get_cloze_text());
// add material with question text to presentation
for ($i = 0; $i <= $this->get_gap_count(); $i++)
{
// n-th text part
$a_xml_writer->xmlStartTag("material");
$a_xml_writer->xmlElement("mattext", NULL, $text_parts[$i]);
$a_xml_writer->xmlEndTag("material");
if ($i < $this->get_gap_count())
{
// add gap
$gap = $this->get_gap($i);
if ($gap[0]->get_cloze_type() == CLOZE_SELECT)
{
// comboboxes
$attrs = array(
"ident" => "gap_$i",
"rcardinality" => "Single"
);
$a_xml_writer->xmlStartTag("response_str", $attrs);
$solution = $this->getSuggestedSolution($i);
if (count($solution))
{
if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
{
$attrs = array(
"label" => "suggested_solution"
);
$a_xml_writer->xmlStartTag("material", $attrs);
$intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
if (strcmp($matches[1], "") != 0)
{
$intlink = $solution["internal_link"];
}
$a_xml_writer->xmlElement("mattext", NULL, $intlink);
$a_xml_writer->xmlEndTag("material");
}
}
$attrs = array();
if ($gap[0]->get_shuffle())
{
$attrs = array("shuffle" => "Yes");
}
else
{
$attrs = array("shuffle" => "No");
}
$a_xml_writer->xmlStartTag("render_choice", $attrs);
// shuffle output
$gkeys = array_keys($gap);
if ($gap[0]->get_shuffle() && $a_shuffle)
{
$gkeys = $this->pcArrayShuffle($gkeys);
}
// add answers
foreach ($gkeys as $key)
{
$value = $gap[$key];
$attrs = array(
"ident" => $key
);
$a_xml_writer->xmlStartTag("response_label", $attrs);
$a_xml_writer->xmlStartTag("material");
$a_xml_writer->xmlElement("mattext", NULL, $value->get_answertext());
$a_xml_writer->xmlEndTag("material");
$a_xml_writer->xmlEndTag("response_label");
}
$a_xml_writer->xmlEndTag("render_choice");
$a_xml_writer->xmlEndTag("response_str");
}
else
{
// text fields
$attrs = array(
"ident" => "gap_$i",
"rcardinality" => "Single"
);
$a_xml_writer->xmlStartTag("response_str", $attrs);
$solution = $this->getSuggestedSolution($i);
if (count($solution))
{
if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
{
$attrs = array(
"label" => "suggested_solution"
);
$a_xml_writer->xmlStartTag("material", $attrs);
$intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
if (strcmp($matches[1], "") != 0)
{
$intlink = $solution["internal_link"];
}
$a_xml_writer->xmlElement("mattext", NULL, $intlink);
$a_xml_writer->xmlEndTag("material");
}
}
$attrs = array(
"fibtype" => "String",
"prompt" => "Box",
"columns" => $this->getColumnSize($gap)
);
$a_xml_writer->xmlStartTag("render_fib", $attrs);
$a_xml_writer->xmlEndTag("render_fib");
$a_xml_writer->xmlEndTag("response_str");
}
}
}
$a_xml_writer->xmlEndTag("flow");
$a_xml_writer->xmlEndTag("presentation");
// PART II: qti resprocessing
$a_xml_writer->xmlStartTag("resprocessing");
$a_xml_writer->xmlStartTag("outcomes");
$a_xml_writer->xmlStartTag("decvar");
$a_xml_writer->xmlEndTag("decvar");
$a_xml_writer->xmlEndTag("outcomes");
// add response conditions
for ($i = 0; $i < $this->get_gap_count(); $i++)
{
$gap = $this->get_gap($i);
if ($gap[0]->get_cloze_type() == CLOZE_SELECT)
{
foreach ($gap as $index => $answer)
{
$attrs = array(
"continue" => "Yes"
);
$a_xml_writer->xmlStartTag("respcondition", $attrs);
// qti conditionvar
$a_xml_writer->xmlStartTag("conditionvar");
if (!$answer->isStateSet())
{
$a_xml_writer->xmlStartTag("not");
}
$attrs = array(
"respident" => "gap_$i"
);
$a_xml_writer->xmlElement("varequal", $attrs, $answer->get_answertext());
if (!$answer->isStateSet())
{
$a_xml_writer->xmlEndTag("not");
}
$a_xml_writer->xmlEndTag("conditionvar");
// qti setvar
$attrs = array(
"action" => "Add"
);
$a_xml_writer->xmlElement("setvar", $attrs, $answer->get_points());
// qti displayfeedback
$linkrefid = "";
if ($answer->get_points() > 0)
{
$linkrefid = "$i" . "_True";
}
else
{
$linkrefid = "$i" . "_False_$index";
}
$attrs = array(
"feedbacktype" => "Response",
"linkrefid" => $linkrefid
);
$a_xml_writer->xmlElement("displayfeedback", $attrs);
$a_xml_writer->xmlEndTag("respcondition");
}
}
else
{
foreach ($gap as $index => $answer)
{
$attrs = array(
"continue" => "Yes"
);
$a_xml_writer->xmlStartTag("respcondition", $attrs);
// qti conditionvar
$a_xml_writer->xmlStartTag("conditionvar");
$attrs = array(
"respident" => "gap_$i"
);
$a_xml_writer->xmlElement("varequal", $attrs, $answer->get_answertext());
$a_xml_writer->xmlEndTag("conditionvar");
// qti setvar
$attrs = array(
"action" => "Add"
);
$a_xml_writer->xmlElement("setvar", $attrs, $answer->get_points());
// qti displayfeedback
$attrs = array(
"feedbacktype" => "Response",
"linkrefid" => "$i" . "_True_$index"
);
$a_xml_writer->xmlElement("displayfeedback", $attrs);
$a_xml_writer->xmlEndTag("respcondition");
}
}
}
$a_xml_writer->xmlEndTag("resprocessing");
// PART III: qti itemfeedback
for ($i = 0; $i < $this->get_gap_count(); $i++)
{
$gap = $this->get_gap($i);
if ($gap[0]->get_cloze_type() == CLOZE_SELECT)
{
foreach ($gap as $index => $answer)
{
$linkrefid = "";
if ($answer->isStateSet())
{
$linkrefid = "$i" . "_True";
}
else
{
$linkrefid = "$i" . "_False_$index";
}
$attrs = array(
"ident" => $linkrefid,
"view" => "All"
);
$a_xml_writer->xmlStartTag("itemfeedback", $attrs);
// qti flow_mat
$a_xml_writer->xmlStartTag("flow_mat");
$a_xml_writer->xmlStartTag("material");
$a_xml_writer->xmlElement("mattext");
$a_xml_writer->xmlEndTag("material");
$a_xml_writer->xmlEndTag("flow_mat");
$a_xml_writer->xmlEndTag("itemfeedback");
}
}
else
{
foreach ($gap as $index => $answer)
{
$linkrefid = "";
if ($answer->isStateSet())
{
$linkrefid = "$i" . "_True_$index";
}
else
{
$linkrefid = "$i" . "_False_$index";
}
$attrs = array(
"ident" => $linkrefid,
"view" => "All"
);
$a_xml_writer->xmlStartTag("itemfeedback", $attrs);
// qti flow_mat
$a_xml_writer->xmlStartTag("flow_mat");
$a_xml_writer->xmlStartTag("material");
$a_xml_writer->xmlElement("mattext");
$a_xml_writer->xmlEndTag("material");
$a_xml_writer->xmlEndTag("flow_mat");
$a_xml_writer->xmlEndTag("itemfeedback");
}
}
}
$a_xml_writer->xmlEndTag("item");
$a_xml_writer->xmlEndTag("questestinterop");
$xml = $a_xml_writer->xmlDumpMem(FALSE);
if (!$a_include_header)
{
$pos = strpos($xml, "?>");
$xml = substr($xml, $pos + 2);
}
return $xml;
}
Here is the call graph for this function:| ASS_ClozeTest::update_all_gap_params | ( | ) |
Updates the cloze text setting the cloze type for every gap.
Updates the cloze text setting the cloze type for every gap
public
Definition at line 1226 of file class.assClozeTest.php.
References ASS_Question::$lng, createCloseTextArray(), createCloseTextFromArray(), get_gap_count(), and get_gap_text_list().
{
global $lng;
$close = $this->createCloseTextArray();
for ($i = 0; $i < $this->get_gap_count(); $i++)
{
$gaptext = $this->get_gap_text_list($i);
if ($this->gaps[$i][0]->get_cloze_type() == CLOZE_TEXT)
{
$close["gaps"][$i]["params"]["type"] = "text";
if (array_key_exists("shuffle", $close["gaps"][$i]["params"]))
{
unset($close["gaps"][$i]["params"]["shuffle"]);
}
}
else
{
$close["gaps"][$i]["params"]["type"] = "select";
if ($this->gaps[$i][0]->get_shuffle() == 0)
{
$close["gaps"][$i]["params"]["shuffle"] = "no";
}
else
{
$close["gaps"][$i]["params"]["shuffle"] = "yes";
}
}
$name = $this->gaps[$i][0]->get_name();
if (!$name)
{
$name = $this->lng->txt("gap") . " " . ($i+1);
}
$close["gaps"][$i]["params"]["name"] = $name;
}
$this->createCloseTextFromArray($close);
}
Here is the call graph for this function:| ASS_ClozeTest::$cloze_text |
Definition at line 47 of file class.assClozeTest.php.
Referenced by ASS_ClozeTest(), and set_cloze_text().
| ASS_ClozeTest::$end_tag |
Definition at line 74 of file class.assClozeTest.php.
Referenced by set_end_tag().
| ASS_ClozeTest::$gaps |
Definition at line 56 of file class.assClozeTest.php.
Referenced by createCloseTextArray().
| ASS_ClozeTest::$start_tag |
Definition at line 65 of file class.assClozeTest.php.
Referenced by set_start_tag().
| ASS_ClozeTest::$textgap_rating |
Definition at line 86 of file class.assClozeTest.php.
1.7.1