Class for multiple choice tests. More...
Inheritance diagram for ASS_MultipleChoice:
Collaboration diagram for ASS_MultipleChoice:Public Member Functions | |
| ASS_MultipleChoice ($title="", $comment="", $author="", $owner=-1, $question="", $response=RESPONSE_SINGLE, $output_type=OUTPUT_ORDER) | |
| ASS_MultipleChoice constructor. | |
| isComplete () | |
| Returns true, if a multiple choice question is complete for use. | |
| 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. | |
| saveToDb ($original_id="") | |
| Saves a ASS_MultipleChoice object to a database. | |
| loadFromDb ($question_id) | |
| Loads a ASS_MultipleChoice object from a database. | |
| addAnswer ($answertext, $points, $answerorder, $correctness) | |
| Adds an answer to the question. | |
| duplicate ($for_test=true, $title="", $author="", $owner="") | |
| Duplicates an ASS_MultipleChoiceQuestion. | |
| copyObject ($target_questionpool, $title="") | |
| Copies an ASS_MultipleChoice object. | |
| get_question () | |
| Gets the multiple choice question. | |
| set_question ($question="") | |
| Sets the multiple choice question. | |
| get_response () | |
| Gets the multiple choice response type. | |
| set_response ($response="") | |
| Sets the multiple choice response type. | |
| get_output_type () | |
| Gets the multiple choice output type. | |
| set_output_type ($output_type=OUTPUT_ORDER) | |
| Sets the multiple choice output type. | |
| add_answer ($answertext="", $points=0.0, $state=0, $order=0) | |
| Adds a possible answer for a multiple choice question. | |
| get_answer_count () | |
| Returns the number of answers. | |
| get_answer ($index=0) | |
| Returns an answer. | |
| delete_answer ($index=0) | |
| Deletes an answer. | |
| flush_answers () | |
| Deletes all answers. | |
| getMaximumPoints () | |
| Returns the maximum points, a learner can reach answering the question. | |
| calculateReachedPoints ($user_id, $test_id, $pass=NULL) | |
| Returns the points, a learner has reached answering the question. | |
| wasAnsweredByUser ($user_id, $test_id, $pass=NULL) | |
| Returns if the question was answered by a user or not. | |
| getReachedInformation ($user_id, $test_id, $pass=NULL) | |
| Returns the evaluation data, a learner has entered to answer the question. | |
| saveWorkingData ($test_id, $pass=NULL) | |
| Saves the learners input of the question to the database. | |
| syncWithOriginal () | |
| createRandomSolution ($test_id, $user_id, $pass=NULL) | |
| getQuestionType () | |
| Returns the question type of the question. | |
Data Fields | |
| $question | |
| $answers | |
| $response | |
| $output_type | |
Class for multiple choice tests.
ASS_MultipleChoice is a class for multiple choice tests. It supports single and multiple response.
class.assMultipleChoice.php Assessment
Definition at line 37 of file class.assMultipleChoice.php.
| ASS_MultipleChoice::add_answer | ( | $ | answertext = "", |
|
| $ | points = 0.0, |
|||
| $ | state = 0, |
|||
| $ | order = 0 | |||
| ) |
Adds a possible answer for a multiple choice question.
Adds a possible answer for a multiple choice question. A ASS_AnswerBinaryState object will be created and assigned to the array $this->answers.
| string | $answertext The answer text | |
| double | $points The points for selecting the answer (even negative points can be used) | |
| boolean | $state Defines the answer as correct (TRUE) or incorrect (FALSE) | |
| integer | $order A possible display order of the answer public |
Definition at line 740 of file class.assMultipleChoice.php.
References $key, and ASS_Question::$points.
{
$found = -1;
foreach ($this->answers as $key => $value)
{
if ($value->get_order() == $order)
{
$found = $order;
}
}
include_once "./assessment/classes/class.assAnswerBinaryState.php";
if ($found >= 0)
{
// Antwort einfügen
$answer = new ASS_AnswerBinaryState($answertext, $points, $found, $state);
array_push($this->answers, $answer);
for ($i = $found + 1; $i < count($this->answers); $i++)
{
$this->answers[$i] = $this->answers[$i-1];
}
$this->answers[$found] = $answer;
}
else
{
// Anwort anhängen
$answer = new ASS_AnswerBinaryState($answertext, $points, count($this->answers), $state);
array_push($this->answers, $answer);
}
}
| ASS_MultipleChoice::addAnswer | ( | $ | answertext, | |
| $ | points, | |||
| $ | answerorder, | |||
| $ | correctness | |||
| ) |
Adds an answer to the question.
Adds an answer to the question
public
Definition at line 554 of file class.assMultipleChoice.php.
References ASS_Question::$points.
{
include_once "./assessment/classes/class.assAnswerBinaryState.php";
array_push($this->answers, new ASS_AnswerBinaryState($answertext, $points, $answerorder, $correctness));
}
| ASS_MultipleChoice::ASS_MultipleChoice | ( | $ | title = "", |
|
| $ | comment = "", |
|||
| $ | author = "", |
|||
| $ | owner = -1, |
|||
| $ | question = "", |
|||
| $ | response = RESPONSE_SINGLE, |
|||
| $ | output_type = OUTPUT_ORDER | |||
| ) |
ASS_MultipleChoice constructor.
The constructor takes possible arguments an creates an instance of the ASS_MultipleChoice 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 multiple choice question | |
| integer | $response Indicates the response type of the multiple choice question | |
| integer | $output_type The output order of the multiple choice answers public |
Definition at line 92 of file class.assMultipleChoice.php.
References ASS_Question::$author, ASS_Question::$comment, $output_type, ASS_Question::$owner, $question, $response, ASS_Question::$title, and ASS_Question::ASS_Question().
{
$this->ASS_Question($title, $comment, $author, $owner);
$this->question = $question;
$this->response = $response;
$this->output_type = $output_type;
$this->answers = array();
}
Here is the call graph for this function:| ASS_MultipleChoice::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 891 of file class.assMultipleChoice.php.
References $data, $key, ASS_Question::$points, $query, $result, $row, ASS_Question::$test_id, $user_id, get_response(), ASS_Question::getId(), getMaximumPoints(), and ASS_Question::getSolutionMaxPass().
{
global $ilDB;
$found_values = 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);
while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
{
if (strcmp($data->value1, "") != 0)
{
array_push($found_values, $data->value1);
}
}
$points = 0;
foreach ($this->answers as $key => $answer)
{
if ((count($found_values) > 0) || ($this->get_response() == RESPONSE_MULTIPLE))
{
if ($answer->isStateChecked())
{
if (in_array($key, $found_values))
{
$points += $answer->get_points();
}
}
else
{
if (!in_array($key, $found_values))
{
$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["mc_scoring"] == 0)
{
if (count($found_values) == 0)
{
$points = 0;
}
}
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_MultipleChoice::copyObject | ( | $ | target_questionpool, | |
| $ | title = "" | |||
| ) |
Copies an ASS_MultipleChoice object.
Copies an ASS_MultipleChoice object
public
Definition at line 616 of file class.assMultipleChoice.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_MultipleChoice::createRandomSolution | ( | $ | test_id, | |
| $ | user_id, | |||
| $ | pass = NULL | |||
| ) |
Definition at line 1230 of file class.assMultipleChoice.php.
References $ilUser, $key, $query, $result, $row, ASS_Question::$test_id, $user_id, ASS_Question::getId(), and ASS_Question::getSolutionMaxPass().
{
mt_srand((double)microtime()*1000000);
$answer = mt_rand(0, count($this->answers)-1);
global $ilDB;
global $ilUser;
$db =& $ilDB->db;
if (is_null($pass))
{
$pass = $this->getSolutionMaxPass($user_id, $test_id);
}
if ($this->response == RESPONSE_SINGLE)
{
$query = sprintf("SELECT * FROM tst_solutions WHERE user_fi = %s AND test_fi = %s AND question_fi = %s AND pass = %s",
$db->quote($user_id),
$db->quote($test_id),
$db->quote($this->getId()),
$db->quote($pass . "")
);
$result = $db->query($query);
$row = $result->fetchRow(DB_FETCHMODE_OBJECT);
$update = $row->solution_id;
if ($update)
{
$query = sprintf("UPDATE tst_solutions SET value1 = %s WHERE solution_id = %s",
$db->quote($answer),
$db->quote($update));
}
else
{
$query = sprintf("INSERT INTO tst_solutions (solution_id, user_fi, test_fi, question_fi, value1, value2, pass, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL, %s, NULL)",
$db->quote($user_id),
$db->quote($test_id),
$db->quote($this->getId()),
$db->quote($answer),
$db->quote($pass . "")
);
}
$result = $db->query($query);
}
else
{
$query = sprintf("DELETE FROM tst_solutions WHERE user_fi = %s AND test_fi = %s AND question_fi = %s AND pass = %s",
$db->quote($user_id),
$db->quote($test_id),
$db->quote($this->getId()),
$db->quote($pass . "")
);
$result = $db->query($query);
$answerarray = array();
for ($i = 0; $i < $answer; $i++)
{
$manswer = mt_rand(0, count($this->answers)-1);
$answerarray[$manswer]++;
}
foreach ($answerarray as $key => $value)
{
$query = sprintf("INSERT INTO tst_solutions (solution_id, user_fi, test_fi, question_fi, value1, value2, pass, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL, %s, NULL)",
$db->quote($user_id),
$db->quote($test_id),
$db->quote($this->getId()),
$db->quote($key),
$db->quote($pass . "")
);
$result = $db->query($query);
}
}
}
Here is the call graph for this function:| ASS_MultipleChoice::delete_answer | ( | $ | index = 0 |
) |
Deletes an answer.
Deletes an answer with a given index. The index of the first answer is 0, the index of the second answer is 1 and so on.
| integer | $index A nonnegative index of the n-th answer public |
Definition at line 819 of file class.assMultipleChoice.php.
{
if ($index < 0) return;
if (count($this->answers) < 1) return;
if ($index >= count($this->answers)) return;
unset($this->answers[$index]);
$this->answers = array_values($this->answers);
for ($i = 0; $i < count($this->answers); $i++)
{
if ($this->answers[$i]->get_order() > $index)
{
$this->answers[$i]->set_order($i);
}
}
}
| ASS_MultipleChoice::duplicate | ( | $ | for_test = true, |
|
| $ | title = "", |
|||
| $ | author = "", |
|||
| $ | owner = "" | |||
| ) |
Duplicates an ASS_MultipleChoiceQuestion.
Duplicates an ASS_MultipleChoiceQuestion
public
Definition at line 567 of file class.assMultipleChoice.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_MultipleChoice::flush_answers | ( | ) |
Deletes all answers.
Deletes all answers
public
Definition at line 843 of file class.assMultipleChoice.php.
{
$this->answers = array();
}
| ASS_MultipleChoice::get_answer | ( | $ | index = 0 |
) |
Returns an answer.
Returns an answer with a given index. The index of the first answer is 0, the index of the second answer is 1 and so on.
| integer | $index A nonnegative index of the n-th answer |
Definition at line 800 of file class.assMultipleChoice.php.
{
if ($index < 0) return NULL;
if (count($this->answers) < 1) return NULL;
if ($index >= count($this->answers)) return NULL;
return $this->answers[$index];
}
| ASS_MultipleChoice::get_answer_count | ( | ) |
Returns the number of answers.
Returns the number of answers
Definition at line 784 of file class.assMultipleChoice.php.
{
return count($this->answers);
}
| ASS_MultipleChoice::get_output_type | ( | ) |
Gets the multiple choice output type.
Gets the multiple choice output type which is either OUTPUT_ORDER (=0) or OUTPUT_RANDOM (=1).
Definition at line 707 of file class.assMultipleChoice.php.
{
return $this->output_type;
}
| ASS_MultipleChoice::get_question | ( | ) |
Gets the multiple choice question.
Gets the question string of the ASS_MultipleChoice object
Definition at line 651 of file class.assMultipleChoice.php.
Referenced by to_xml().
{
return $this->question;
}
Here is the caller graph for this function:| ASS_MultipleChoice::get_response | ( | ) |
Gets the multiple choice response type.
Gets the multiple choice response type which is either RESPONSE_SINGLE (=0) or RESPONSE_MULTI (=1).
Definition at line 679 of file class.assMultipleChoice.php.
Referenced by calculateReachedPoints(), and getMaximumPoints().
{
return $this->response;
}
Here is the caller graph for this function:| ASS_MultipleChoice::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 856 of file class.assMultipleChoice.php.
References $key, ASS_Question::$points, and get_response().
Referenced by calculateReachedPoints(), isComplete(), saveToDb(), and syncWithOriginal().
{
$points = array("set" => 0, "unset" => 0);
if ($this->get_response() == RESPONSE_SINGLE)
{
foreach ($this->answers as $key => $value)
{
if ($value->get_points() > $points["set"])
{
$points["set"] = $value->get_points();
}
}
return $points["set"];
}
else
{
$allpoints = 0;
foreach ($this->answers as $key => $value) {
$allpoints += $value->get_points();
}
return $allpoints;
}
}
Here is the call graph for this function:
Here is the caller graph for this function:| ASS_MultipleChoice::getQuestionType | ( | ) |
Returns the question type of the question.
Returns the question type of the question
Definition at line 1310 of file class.assMultipleChoice.php.
Referenced by saveToDb().
{
if ($this->response == RESPONSE_SINGLE)
{
$question_type = 1;
}
else
{
$question_type = 2;
}
return $question_type;
}
Here is the caller graph for this function:| ASS_MultipleChoice::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 1017 of file class.assMultipleChoice.php.
References $counter, $data, $key, $query, $result, ASS_Question::$test_id, $user_id, ASS_Question::getId(), and ASS_Question::getSolutionMaxPass().
{
$found_values = 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_values, $data->value1);
}
$counter = 1;
$user_result = array();
foreach ($found_values as $key => $value)
{
$solution = array(
"order" => "$counter",
"points" => 0,
"true" => 0,
"value" => "",
);
if (strlen($value) > 0)
{
$solution["value"] = $value;
$solution["points"] = $this->answers[$value]->get_points();
if ($this->answers[$value]->isStateChecked())
{
$solution["true"] = 1;
}
}
$counter++;
$user_result[$value] = $solution;
}
return $user_result;
}
Here is the call graph for this function:| ASS_MultipleChoice::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 ASS_Question.
Definition at line 117 of file class.assMultipleChoice.php.
References getMaximumPoints().
Referenced by saveToDb(), and syncWithOriginal().
{
if (($this->title) and ($this->author) and ($this->question) and (count($this->answers)) 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_MultipleChoice::loadFromDb | ( | $ | question_id | ) |
Loads a ASS_MultipleChoice object from a database.
Loads a ASS_MultipleChoice object from a database (experimental)
| object | $db A pear DB object | |
| integer | $question_id A unique key which defines the multiple choice test in the database public |
Reimplemented from ASS_Question.
Definition at line 493 of file class.assMultipleChoice.php.
References $data, ASS_Question::$ilias, $query, $result, ASS_Question::setEstimatedWorkingTime(), and ASS_Question::setShuffle().
{
global $ilias;
$db = & $ilias->db;
$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->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;
$this->points = $data->points;
$this->question = $data->question_text;
$this->response = $data->choice_response;
$this->setShuffle($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 aorder ASC",
$db->quote($question_id));
$result = $db->query($query);
include_once "./assessment/classes/class.assAnswerBinaryState.php";
if (strcmp(strtolower(get_class($result)), db_result) == 0)
{
while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
{
if ($this->response == RESPONSE_SINGLE)
{
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->answers, new ASS_AnswerBinaryState($data->answertext, $data->points, $data->aorder, $data->correctness));
}
}
}
parent::loadFromDb($question_id);
}
Here is the call graph for this function:| ASS_MultipleChoice::saveToDb | ( | $ | original_id = "" |
) |
Saves a ASS_MultipleChoice object to a database.
Saves a ASS_MultipleChoice object to a database (experimental)
| object | $db A pear DB object public |
Reimplemented from ASS_Question.
Definition at line 379 of file class.assMultipleChoice.php.
References ASS_Question::$ilias, $key, $query, $result, ASS_Question::createPageObject(), ASS_Question::getEstimatedWorkingTime(), getMaximumPoints(), getQuestionType(), ASS_Question::getTestId(), ASS_Question::insertIntoTest(), and isComplete().
{
global $ilias;
$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']);
if ($original_id)
{
$original_id = $db->quote($original_id);
}
else
{
$original_id = "NULL";
}
if ($this->id == -1)
{
// Neuen Datensatz schreiben
$now = getdate();
$question_type = $this->getQuestionType();
$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, question_text, points, working_time, shuffle, choice_response, complete, created, original_id, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
$db->quote($question_type),
$db->quote($this->obj_id),
$db->quote($this->title),
$db->quote($this->comment),
$db->quote($this->author),
$db->quote($this->owner),
$db->quote($this->question),
$db->quote($this->getMaximumPoints() . ""),
$db->quote($estw_time),
$db->quote("$this->shuffle"),
$db->quote($this->response),
$db->quote("$complete"),
$db->quote($created),
$original_id
);
$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, author = %s, question_text = %s, points = %s, working_time=%s, shuffle = %s, choice_response = %s, complete = %s WHERE question_id = %s",
$db->quote($this->obj_id. ""),
$db->quote($this->title),
$db->quote($this->comment),
$db->quote($this->author),
$db->quote($this->question),
$db->quote($this->getMaximumPoints() . ""),
$db->quote($estw_time),
$db->quote("$this->shuffle"),
$db->quote($this->response),
$db->quote("$complete"),
$db->quote($this->id)
);
$result = $db->query($query);
}
if ($result == DB_OK)
{
// Antworten schreiben
// alte Antworten löschen
$query = sprintf("DELETE FROM qpl_answers WHERE question_fi = %s",
$db->quote($this->id)
);
$result = $db->query($query);
// Anworten wegschreiben
foreach ($this->answers as $key => $value)
{
$answer_obj = $this->answers[$key];
$query = sprintf("INSERT INTO qpl_answers (answer_id, question_fi, answertext, points, aorder, correctness, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, NULL)",
$db->quote($this->id),
$db->quote($answer_obj->get_answertext()),
$db->quote($answer_obj->get_points() . ""),
$db->quote($answer_obj->get_order() . ""),
$db->quote($answer_obj->getState() . "")
);
$answer_result = $db->query($query);
}
}
parent::saveToDb($original_id);
}
Here is the call graph for this function:| ASS_MultipleChoice::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 1070 of file class.assMultipleChoice.php.
References $_POST, $ilUser, $key, $query, $result, $row, ASS_Question::$test_id, ilObjAssessmentFolder::_enabledAssessmentLogging(), ilObjAssessmentFolder::_getLogLanguage(), ilObjTest::_getPass(), ASS_Question::getId(), and ASS_Question::logAction().
{
global $ilDB;
global $ilUser;
$db =& $ilDB->db;
include_once "./assessment/classes/class.ilObjTest.php";
$activepass = ilObjTest::_getPass($ilUser->id, $test_id);
$entered_values = 0;
if ($this->response == RESPONSE_SINGLE)
{
$query = sprintf("SELECT * 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);
$row = $result->fetchRow(DB_FETCHMODE_OBJECT);
$update = $row->solution_id;
if ($update)
{
if (strlen($_POST["multiple_choice_result"]))
{
$query = sprintf("UPDATE tst_solutions SET value1 = %s WHERE solution_id = %s",
$db->quote($_POST["multiple_choice_result"]),
$db->quote($update)
);
$result = $db->query($query);
$entered_values++;
}
else
{
$query = sprintf("DELETE FROM tst_solutions WHERE solution_id = %s",
$db->quote($update)
);
$result = $db->query($query);
}
}
else
{
if (strlen($_POST["multiple_choice_result"]))
{
$query = sprintf("INSERT INTO tst_solutions (solution_id, user_fi, test_fi, question_fi, value1, value2, pass, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL, %s, NULL)",
$db->quote($ilUser->id),
$db->quote($test_id),
$db->quote($this->getId()),
$db->quote($_POST["multiple_choice_result"]),
$db->quote($activepass . "")
);
$result = $db->query($query);
$entered_values++;
}
}
}
else
{
$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);
foreach ($_POST as $key => $value)
{
if (preg_match("/^multiple_choice_result_(\d+)/", $key, $matches))
{
if (strlen($value))
{
$query = sprintf("INSERT INTO tst_solutions (solution_id, user_fi, test_fi, question_fi, value1, value2, pass, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL, %s, NULL)",
$db->quote($ilUser->id),
$db->quote($test_id),
$db->quote($this->getId()),
$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_MultipleChoice::set_output_type | ( | $ | output_type = OUTPUT_ORDER |
) |
Sets the multiple choice output type.
Sets the output type of the ASS_MultipleChoice object
| integer | $output_type A nonnegative integer value specifying the output type. It is OUTPUT_ORDER (=0) or OUTPUT_RANDOM (=1). public |
Definition at line 721 of file class.assMultipleChoice.php.
References $output_type.
{
$this->output_type = $output_type;
}
| ASS_MultipleChoice::set_question | ( | $ | question = "" |
) |
Sets the multiple choice question.
Sets the question string of the ASS_MultipleChoice object
| string | $question A string containing the multiple choice question public |
Definition at line 665 of file class.assMultipleChoice.php.
References $question.
{
$this->question = $question;
}
| ASS_MultipleChoice::set_response | ( | $ | response = "" |
) |
Sets the multiple choice response type.
Sets the response type of the ASS_MultipleChoice object
| integer | $response A nonnegative integer value specifying the response type. It is RESPONSE_SINGLE (=0) or RESPONSE_MULTI (=1). public |
Definition at line 693 of file class.assMultipleChoice.php.
References $response.
{
$this->response = $response;
}
| ASS_MultipleChoice::syncWithOriginal | ( | ) |
Reimplemented from ASS_Question.
Definition at line 1174 of file class.assMultipleChoice.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, author = %s, question_text = %s, points = %s, working_time=%s, shuffle = %s, choice_response = %s, complete = %s WHERE question_id = %s",
$db->quote($this->obj_id. ""),
$db->quote($this->title. ""),
$db->quote($this->comment. ""),
$db->quote($this->author. ""),
$db->quote($this->question. ""),
$db->quote($this->getMaximumPoints() . ""),
$db->quote($estw_time. ""),
$db->quote($this->shuffle. ""),
$db->quote($this->response. ""),
$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->answers as $key => $value)
{
$answer_obj = $this->answers[$key];
$query = sprintf("INSERT INTO qpl_answers (answer_id, question_fi, answertext, points, aorder, correctness, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, NULL)",
$db->quote($this->original_id. ""),
$db->quote($answer_obj->get_answertext(). ""),
$db->quote($answer_obj->get_points() . ""),
$db->quote($answer_obj->get_order() . ""),
$db->quote($answer_obj->getState() . "")
);
$answer_result = $db->query($query);
}
}
parent::syncWithOriginal();
}
}
Here is the call graph for this function:| ASS_MultipleChoice::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 138 of file class.assMultipleChoice.php.
References $pos, $xml, get_question(), ASS_Question::getAuthor(), ASS_Question::getComment(), ASS_Question::getEstimatedWorkingTime(), ASS_Question::getShuffle(), ASS_Question::getSuggestedSolution(), 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, MULTIPLE_CHOICE_QUESTION_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->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");
// add material with question text to presentation
$a_xml_writer->xmlStartTag("material");
$a_xml_writer->xmlElement("mattext", NULL, $this->get_question());
$a_xml_writer->xmlEndTag("material");
// add answers to presentation
$attrs = array();
if ($this->response == RESPONSE_SINGLE)
{
$attrs = array(
"ident" => "MCSR",
"rcardinality" => "Single"
);
}
else
{
$attrs = array(
"ident" => "MCMR",
"rcardinality" => "Multiple"
);
}
$a_xml_writer->xmlStartTag("response_lid", $attrs);
$solution = $this->getSuggestedSolution(0);
if (count($solution))
{
if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
{
$a_xml_writer->xmlStartTag("material");
$intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
if (strcmp($matches[1], "") != 0)
{
$intlink = $solution["internal_link"];
}
$attrs = array(
"label" => "suggested_solution"
);
$a_xml_writer->xmlElement("mattext", $attrs, $intlink);
$a_xml_writer->xmlEndTag("material");
}
}
// shuffle output
$attrs = array();
if ($this->getShuffle())
{
$attrs = array(
"shuffle" => "Yes"
);
}
else
{
$attrs = array(
"shuffle" => "No"
);
}
$a_xml_writer->xmlStartTag("render_choice", $attrs);
$akeys = array_keys($this->answers);
if ($this->getshuffle() && $a_shuffle)
{
$akeys = $this->pcArrayShuffle($akeys);
}
// add answers
foreach ($akeys as $index)
{
$answer = $this->answers[$index];
$attrs = array(
"ident" => $index
);
$a_xml_writer->xmlStartTag("response_label", $attrs);
$a_xml_writer->xmlStartTag("material");
$a_xml_writer->xmlElement("mattext", NULL, $answer->get_answertext());
$a_xml_writer->xmlEndTag("material");
$a_xml_writer->xmlEndTag("response_label");
}
$a_xml_writer->xmlEndTag("render_choice");
$a_xml_writer->xmlEndTag("response_lid");
$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
foreach ($this->answers 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();
if ($this->response == RESPONSE_SINGLE)
{
$attrs = array(
"respident" => "MCSR"
);
}
else
{
$attrs = array(
"respident" => "MCMR"
);
}
$a_xml_writer->xmlElement("varequal", $attrs, $index);
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
if ($answer->isStateChecked())
{
if ($this->response == RESPONSE_SINGLE)
{
$linkrefid = "True";
}
else
{
$linkrefid = "True_$index";
}
}
else
{
$linkrefid = "False_$index";
}
$attrs = array(
"feedbacktype" => "Response",
"linkrefid" => $linkrefid
);
$a_xml_writer->xmlElement("displayfeedback", $attrs);
$a_xml_writer->xmlEndTag("respcondition");
}
$a_xml_writer->xmlEndTag("resprocessing");
// PART III: qti itemfeedback
foreach ($this->answers as $index => $answer)
{
$linkrefid = "";
if ($answer->isStateChecked())
{
if ($this->response == RESPONSE_SINGLE)
{
$linkrefid = "True";
}
else
{
$linkrefid = "True_$index";
}
}
else
{
$linkrefid = "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_MultipleChoice::wasAnsweredByUser | ( | $ | user_id, | |
| $ | test_id, | |||
| $ | pass = NULL | |||
| ) |
Returns if the question was answered by a user or not.
Returns if the question was answered by a user or not
| integer | $user_id The database ID of the learner | |
| integer | $test_id The database Id of the test containing the question |
Definition at line 976 of file class.assMultipleChoice.php.
References $data, $query, $result, ASS_Question::$test_id, $user_id, ASS_Question::getId(), and ASS_Question::getSolutionMaxPass().
{
global $ilDB;
$found_values = 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);
while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
{
if (strcmp($data->value1, "") != 0)
{
array_push($found_values, $data->value1);
}
}
if (count($found_values) == 0)
{
return FALSE;
}
else
{
return TRUE;
}
}
Here is the call graph for this function:| ASS_MultipleChoice::$answers |
Definition at line 55 of file class.assMultipleChoice.php.
| ASS_MultipleChoice::$output_type |
Definition at line 75 of file class.assMultipleChoice.php.
Referenced by ASS_MultipleChoice(), and set_output_type().
| ASS_MultipleChoice::$question |
Definition at line 46 of file class.assMultipleChoice.php.
Referenced by ASS_MultipleChoice(), and set_question().
| ASS_MultipleChoice::$response |
Definition at line 65 of file class.assMultipleChoice.php.
Referenced by ASS_MultipleChoice(), and set_response().
1.7.1