Class for ordering questions. More...
Inheritance diagram for ASS_OrderingQuestion:
Collaboration diagram for ASS_OrderingQuestion:Public Member Functions | |
| ASS_OrderingQuestion ($title="", $comment="", $author="", $owner=-1, $question="", $ordering_type=OQ_TERMS) | |
| ASS_OrderingQuestion constructor. | |
| isComplete () | |
| Returns true, if a ordering 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_OrderingQuestion object to a database. | |
| loadFromDb ($question_id) | |
| Loads a ASS_OrderingQuestion object from a database. | |
| addAnswer ($answertext, $points, $answerorder, $solutionorder) | |
| Adds an answer to the question. | |
| duplicate ($for_test=true, $title="", $author="", $owner="") | |
| Duplicates an ASS_OrderingQuestion. | |
| copyObject ($target_questionpool, $title="") | |
| Copies an ASS_OrderingQuestion object. | |
| duplicateImages ($question_id) | |
| copyImages ($question_id, $source_questionpool) | |
| set_question ($question="") | |
| Sets the ordering question text. | |
| set_ordering_type ($ordering_type=OQ_TERMS) | |
| Sets the ordering question type. | |
| get_question () | |
| Returns the question text. | |
| get_ordering_type () | |
| Returns the ordering question type. | |
| add_answer ($answertext="", $points=0.0, $order=0, $solution_order=0) | |
| Adds an answer for an ordering question. | |
| get_answer ($index=0) | |
| Returns an ordering answer. | |
| delete_answer ($index=0) | |
| Deletes an answer. | |
| flush_answers () | |
| Deletes all answers. | |
| get_answer_count () | |
| Returns the number of answers. | |
| get_max_solution_order () | |
| Returns the maximum solution order. | |
| 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. | |
| set_image_file ($image_filename, $image_tempfilename="") | |
| Sets the image file. | |
| checkSaveData () | |
| Checks the data to be saved for consistency. | |
| saveWorkingData ($test_id, $pass=NULL) | |
| Saves the learners input of the question to the database. | |
| syncWithOriginal () | |
| pc_array_shuffle ($array) | |
| createRandomSolution ($test_id, $user_id, $pass=NULL) | |
| getQuestionType () | |
| Returns the question type of the question. | |
Data Fields | |
| $question | |
| $answers | |
| $ordering_type | |
Class for ordering questions.
ASS_OrderingQuestion is a class for ordering questions.
class.assOrderingQuestion.php Assessment
Definition at line 37 of file class.assOrderingQuestion.php.
| ASS_OrderingQuestion::add_answer | ( | $ | answertext = "", |
|
| $ | points = 0.0, |
|||
| $ | order = 0, |
|||
| $ | solution_order = 0 | |||
| ) |
Adds an answer for an ordering question.
Adds an answer for an ordering choice question. The students have to fill in an order for the answer. The answer is an ASS_AnswerOrdering object that 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) | |
| integer | $order A possible display order of the answer | |
| integer | $solution_order An unique integer value representing the correct order of that answer in the solution of a question public |
Definition at line 771 of file class.assOrderingQuestion.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.assAnswerOrdering.php";
if ($found >= 0)
{
// Antwort einfügen
$answer = new ASS_AnswerOrdering($answertext, $points, $found, $solution_order);
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_AnswerOrdering($answertext, $points,
count($this->answers), $solution_order);
array_push($this->answers, $answer);
}
}
| ASS_OrderingQuestion::addAnswer | ( | $ | answertext, | |
| $ | points, | |||
| $ | answerorder, | |||
| $ | solutionorder | |||
| ) |
Adds an answer to the question.
Adds an answer to the question
public
Definition at line 564 of file class.assOrderingQuestion.php.
References ASS_Question::$points.
{
include_once "./assessment/classes/class.assAnswerOrdering.php";
array_push($this->answers, new ASS_AnswerOrdering($answertext, $points, $answerorder, $solutionorder));
}
| ASS_OrderingQuestion::ASS_OrderingQuestion | ( | $ | title = "", |
|
| $ | comment = "", |
|||
| $ | author = "", |
|||
| $ | owner = -1, |
|||
| $ | question = "", |
|||
| $ | ordering_type = OQ_TERMS | |||
| ) |
ASS_OrderingQuestion constructor.
The constructor takes possible arguments an creates an instance of the ASS_OrderingQuestion 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 ordering test public |
Definition at line 79 of file class.assOrderingQuestion.php.
References ASS_Question::$author, ASS_Question::$comment, $ordering_type, ASS_Question::$owner, $question, ASS_Question::$title, and ASS_Question::ASS_Question().
{
$this->ASS_Question($title, $comment, $author, $owner);
$this->answers = array();
$this->question = $question;
$this->ordering_type = $ordering_type;
}
Here is the call graph for this function:| ASS_OrderingQuestion::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 927 of file class.assOrderingQuestion.php.
References $data, $key, ASS_Question::$points, $query, $result, $row, ASS_Question::$test_id, $user_id, ASS_Question::getId(), getMaximumPoints(), and ASS_Question::getSolutionMaxPass().
{
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_order = array();
while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
{
if ((strcmp($data->value1, "") != 0) && (strcmp($data->value2, "") != 0))
{
$user_order[$data->value2] = $data->value1;
}
}
ksort($user_order);
$user_order = array_values($user_order);
$answer_order = array();
foreach ($this->answers as $key => $answer)
{
$answer_order[$answer->get_solution_order()] = $key;
}
ksort($answer_order);
$answer_order = array_values($answer_order);
$points = 0;
foreach ($answer_order as $index => $answer_id)
{
if (strcmp($user_order[$index], "") != 0)
{
if ($answer_id == $user_order[$index])
{
$points += $this->answers[$answer_id]->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_OrderingQuestion::checkSaveData | ( | ) |
Checks the data to be saved for consistency.
Checks the data to be saved for consistency
Definition at line 1104 of file class.assOrderingQuestion.php.
References $_POST, $key, $result, ASS_Question::getOutputType(), and sendInfo().
Referenced by saveWorkingData().
{
$result = true;
if ($this->getOutputType() == OUTPUT_JAVASCRIPT)
{
if (strlen($_POST["orderresult"]))
{
return $result;
}
}
$order_values = array();
foreach ($_POST as $key => $value)
{
if (preg_match("/^order_(\d+)/", $key, $matches))
{
if (strcmp($value, "") != 0)
{
array_push($order_values, $value);
}
}
}
$check_order = array_flip($order_values);
if (count($check_order) != count($order_values))
{
// duplicate order values!!!
$result = false;
sendInfo($this->lng->txt("duplicate_order_values_entered"), TRUE);
}
return $result;
}
Here is the call graph for this function:
Here is the caller graph for this function:| ASS_OrderingQuestion::copyImages | ( | $ | question_id, | |
| $ | source_questionpool | |||
| ) |
Definition at line 677 of file class.assOrderingQuestion.php.
References get_ordering_type(), ASS_Question::getImagePath(), and ilUtil::makeDirParents().
{
if ($this->get_ordering_type() == OQ_PICTURES)
{
$imagepath = $this->getImagePath();
$imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
$imagepath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $imagepath_original);
if (!file_exists($imagepath)) {
ilUtil::makeDirParents($imagepath);
}
foreach ($this->answers as $answer)
{
$filename = $answer->get_answertext();
if (!copy($imagepath_original . $filename, $imagepath . $filename)) {
print "image could not be copied!!!! ";
}
if (!copy($imagepath_original . $filename . ".thumb.jpg", $imagepath . $filename . ".thumb.jpg")) {
print "image thumbnail could not be copied!!!! ";
}
}
}
}
Here is the call graph for this function:| ASS_OrderingQuestion::copyObject | ( | $ | target_questionpool, | |
| $ | title = "" | |||
| ) |
Copies an ASS_OrderingQuestion object.
Copies an ASS_OrderingQuestion object
public
Definition at line 626 of file class.assOrderingQuestion.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);
// duplicate the image
$clone->copyImages($original_id, $source_questionpool);
return $clone->id;
}
Here is the call graph for this function:| ASS_OrderingQuestion::createRandomSolution | ( | $ | test_id, | |
| $ | user_id, | |||
| $ | pass = NULL | |||
| ) |
Definition at line 1307 of file class.assOrderingQuestion.php.
References $ilUser, $key, $query, $result, ASS_Question::$test_id, $user_id, ASS_Question::getId(), ASS_Question::getSolutionMaxPass(), and pc_array_shuffle().
{
global $ilDB;
global $ilUser;
$db =& $ilDB->db;
if (is_null($pass))
{
$pass = $this->getSolutionMaxPass($user_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($user_id . ""),
$db->quote($test_id . ""),
$db->quote($this->getId() . ""),
$db->quote($pass . "")
);
$result = $db->query($query);
$orders = range(1, count($this->answers));
$orders = $this->pc_array_shuffle($orders);
foreach ($this->answers 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, %s, %s, NULL)",
$db->quote($user_id . ""),
$db->quote($test_id . ""),
$db->quote($this->getId() . ""),
$db->quote($key . ""),
$db->quote(array_pop($orders) . ""),
$db->quote($pass . "")
);
$result = $db->query($query);
}
}
Here is the call graph for this function:| ASS_OrderingQuestion::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 836 of file class.assOrderingQuestion.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_OrderingQuestion::duplicate | ( | $ | for_test = true, |
|
| $ | title = "", |
|||
| $ | author = "", |
|||
| $ | owner = "" | |||
| ) |
Duplicates an ASS_OrderingQuestion.
Duplicates an ASS_OrderingQuestion
public
Definition at line 577 of file class.assOrderingQuestion.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);
// duplicate the image
$clone->duplicateImages($this_id);
return $clone->id;
}
Here is the call graph for this function:| ASS_OrderingQuestion::duplicateImages | ( | $ | question_id | ) |
Definition at line 655 of file class.assOrderingQuestion.php.
References get_ordering_type(), ASS_Question::getImagePath(), and ilUtil::makeDirParents().
{
if ($this->get_ordering_type() == OQ_PICTURES)
{
$imagepath = $this->getImagePath();
$imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
if (!file_exists($imagepath)) {
ilUtil::makeDirParents($imagepath);
}
foreach ($this->answers as $answer)
{
$filename = $answer->get_answertext();
if (!copy($imagepath_original . $filename, $imagepath . $filename)) {
print "image could not be duplicated!!!! ";
}
if (!copy($imagepath_original . $filename . ".thumb.jpg", $imagepath . $filename . ".thumb.jpg")) {
print "image thumbnail could not be duplicated!!!! ";
}
}
}
}
Here is the call graph for this function:| ASS_OrderingQuestion::flush_answers | ( | ) |
Deletes all answers.
Deletes all answers
public
Definition at line 869 of file class.assOrderingQuestion.php.
{
$this->answers = array();
}
| ASS_OrderingQuestion::get_answer | ( | $ | index = 0 |
) |
Returns an ordering answer.
Returns an ordering 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 818 of file class.assOrderingQuestion.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_OrderingQuestion::get_answer_count | ( | ) |
Returns the number of answers.
Returns the number of answers
Definition at line 883 of file class.assOrderingQuestion.php.
{
return count($this->answers);
}
| ASS_OrderingQuestion::get_max_solution_order | ( | ) |
Returns the maximum solution order.
Returns the maximum solution order of all ordering answers
Definition at line 896 of file class.assOrderingQuestion.php.
References $key.
{
if (count($this->answers) == 0)
{
$max = 0;
}
else
{
$max = $this->answers[0]->get_solution_order();
}
foreach ($this->answers as $key => $value)
{
if ($value->get_solution_order() > $max)
{
$max = $value->get_solution_order();
}
}
return $max;
}
| ASS_OrderingQuestion::get_ordering_type | ( | ) |
Returns the ordering question type.
Returns the ordering question type
Definition at line 751 of file class.assOrderingQuestion.php.
Referenced by copyImages(), duplicateImages(), and to_xml().
{
return $this->ordering_type;
}
Here is the caller graph for this function:| ASS_OrderingQuestion::get_question | ( | ) |
Returns the question text.
Returns the question text
Definition at line 737 of file class.assOrderingQuestion.php.
Referenced by to_xml().
{
return $this->question;
}
Here is the caller graph for this function:| ASS_OrderingQuestion::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 1040 of file class.assOrderingQuestion.php.
References $key, and ASS_Question::$points.
Referenced by calculateReachedPoints(), isComplete(), saveToDb(), and syncWithOriginal().
{
$points = 0;
foreach ($this->answers as $key => $value)
{
$points += $value->get_points();
}
return $points;
}
Here is the caller graph for this function:| ASS_OrderingQuestion::getQuestionType | ( | ) |
Returns the question type of the question.
Returns the question type of the question
Definition at line 1351 of file class.assOrderingQuestion.php.
Referenced by saveToDb().
{
return 5;
}
Here is the caller graph for this function:| ASS_OrderingQuestion::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 1005 of file class.assOrderingQuestion.php.
References $data, $query, $result, ASS_Question::$test_id, $user_id, ASS_Question::getId(), and ASS_Question::getSolutionMaxPass().
{
$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",
$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);
$user_result = array();
while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
{
$solution = array(
"answer_id" => $data->value1,
"order" => $data->value2
);
$user_result[$data->value1] = $solution;
}
return $user_result;
}
Here is the call graph for this function:| ASS_OrderingQuestion::isComplete | ( | ) |
Returns true, if a ordering question is complete for use.
Returns true, if a ordering question is complete for use
Reimplemented from ASS_Question.
Definition at line 102 of file class.assOrderingQuestion.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_OrderingQuestion::loadFromDb | ( | $ | question_id | ) |
Loads a ASS_OrderingQuestion object from a database.
Loads a ASS_OrderingQuestion 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 513 of file class.assOrderingQuestion.php.
References $data, ASS_Question::$ilias, $query, $result, and ASS_Question::setEstimatedWorkingTime().
{
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->obj_id = $data->obj_fi;
$this->comment = $data->comment;
$this->original_id = $data->original_id;
$this->author = $data->author;
$this->owner = $data->owner;
$this->question = $data->question_text;
$this->solution_hint = $data->solution_hint;
$this->ordering_type = $data->ordering_type;
$this->points = $data->points;
$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.assAnswerOrdering.php";
if (strcmp(strtolower(get_class($result)), db_result) == 0)
{
while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
{
array_push($this->answers, new ASS_AnswerOrdering($data->answertext, $data->points, $data->aorder, $data->solution_order));
}
}
}
parent::loadFromDb($question_id);
}
Here is the call graph for this function:| ASS_OrderingQuestion::pc_array_shuffle | ( | $ | array | ) |
Definition at line 1290 of file class.assOrderingQuestion.php.
Referenced by createRandomSolution().
{
mt_srand((double)microtime()*1000000);
$i = count($array);
while(--$i)
{
$j = mt_rand(0, $i);
if ($i != $j)
{
// swap elements
$tmp = $array[$j];
$array[$j] = $array[$i];
$array[$i] = $tmp;
}
}
return $array;
}
Here is the caller graph for this function:| ASS_OrderingQuestion::saveToDb | ( | $ | original_id = "" |
) |
Saves a ASS_OrderingQuestion object to a database.
Saves a ASS_OrderingQuestion object to a database (experimental)
| object | $db A pear DB object public |
Reimplemented from ASS_Question.
Definition at line 402 of file class.assOrderingQuestion.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;
$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']);
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, working_time, ordering_type, points, complete, created, original_id, TIMESTAMP) VALUES (NULL, %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($estw_time . ""),
$db->quote($this->ordering_type . ""),
$db->quote($this->getMaximumPoints() . ""),
$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, working_time = %s, ordering_type = %s, points = %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($estw_time . ""),
$db->quote($this->ordering_type . ""),
$db->quote($this->getMaximumPoints() . ""),
$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, solution_order, 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->get_solution_order() . "")
);
$answer_result = $db->query($query);
}
}
parent::saveToDb($original_id);
}
Here is the call graph for this function:| ASS_OrderingQuestion::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 1145 of file class.assOrderingQuestion.php.
References $_POST, $ilUser, $key, $query, $result, ASS_Question::$test_id, ilObjAssessmentFolder::_enabledAssessmentLogging(), ilObjAssessmentFolder::_getLogLanguage(), ilObjTest::_getPass(), checkSaveData(), ASS_Question::getId(), ASS_Question::getOutputType(), and ASS_Question::logAction().
{
global $ilDB;
global $ilUser;
$saveWorkingDataResult = $this->checkSaveData();
$entered_values = 0;
if ($saveWorkingDataResult)
{
$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);
if ($this->getOutputType() == OUTPUT_JAVASCRIPT)
{
$orderresult = $_POST["orderresult"];
if (strlen($orderresult))
{
$orderarray = explode(":", $orderresult);
$ordervalue = 1;
foreach ($orderarray as $index)
{
$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($index . ""),
$db->quote($ordervalue . ""),
$db->quote($activepass . "")
);
$result = $db->query($query);
$ordervalue++;
$entered_values++;
}
}
}
else
{
foreach ($_POST as $key => $value)
{
if (preg_match("/^order_(\d+)/", $key, $matches))
{
if (!(preg_match("/initial_value_\d+/", $value)))
{
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, %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 $saveWorkingDataResult;
}
Here is the call graph for this function:| ASS_OrderingQuestion::set_image_file | ( | $ | image_filename, | |
| $ | image_tempfilename = "" | |||
| ) |
Sets the image file.
Sets the image file and uploads the image to the object's image directory.
| string | $image_filename Name of the original image file | |
| string | $image_tempfilename Name of the temporary uploaded image file |
Definition at line 1060 of file class.assOrderingQuestion.php.
References $result, ilUtil::convertImage(), ASS_Question::getImagePath(), ilObjMediaObject::getMimeType(), ilUtil::makeDirParents(), and ilUtil::moveUploadedFile().
{
$result = 0;
if (!empty($image_tempfilename))
{
$image_filename = str_replace(" ", "_", $image_filename);
$imagepath = $this->getImagePath();
if (!file_exists($imagepath))
{
ilUtil::makeDirParents($imagepath);
}
if (!ilUtil::moveUploadedFile($image_tempfilename,$image_filename, $imagepath.$image_filename))
{
$result = 2;
}
else
{
include_once "./content/classes/Media/class.ilObjMediaObject.php";
$mimetype = ilObjMediaObject::getMimeType($imagepath . $image_filename);
if (!preg_match("/^image/", $mimetype))
{
unlink($imagepath . $image_filename);
$result = 1;
}
else
{
// create thumbnail file
$thumbpath = $imagepath . $image_filename . "." . "thumb.jpg";
ilUtil::convertImage($imagepath.$image_filename, $thumbpath, strtoupper($extension), 100);
}
}
}
return $result;
}
Here is the call graph for this function:| ASS_OrderingQuestion::set_ordering_type | ( | $ | ordering_type = OQ_TERMS |
) |
Sets the ordering question type.
Sets the ordering question type
| integer | $ordering_type The question ordering type public |
Definition at line 723 of file class.assOrderingQuestion.php.
References $ordering_type.
{
$this->ordering_type = $ordering_type;
}
| ASS_OrderingQuestion::set_question | ( | $ | question = "" |
) |
Sets the ordering question text.
Sets the ordering question text
| string | $question The question text public |
Definition at line 709 of file class.assOrderingQuestion.php.
References $question.
{
$this->question = $question;
}
| ASS_OrderingQuestion::syncWithOriginal | ( | ) |
Reimplemented from ASS_Question.
Definition at line 1235 of file class.assOrderingQuestion.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, working_time = %s, ordering_type = %s, points = %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($estw_time . ""),
$db->quote($this->ordering_type . ""),
$db->quote($this->getMaximumPoints() . ""),
$db->quote($complete . ""),
$db->quote($this->original_id . "")
);
$result = $db->query($query);
if ($result == DB_OK)
{
// write ansers
// 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, solution_order, 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->get_solution_order() . "")
);
$answer_result = $db->query($query);
}
}
parent::syncWithOriginal();
}
}
Here is the call graph for this function:| ASS_OrderingQuestion::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 123 of file class.assOrderingQuestion.php.
References $ilUser, $pos, $query, $user_id, $xml, ilObjTest::_getHidePreviousResults(), ilObjTest::_getPass(), get_ordering_type(), get_question(), ASS_Question::getAuthor(), ASS_Question::getComment(), ASS_Question::getEstimatedWorkingTime(), ASS_Question::getId(), ASS_Question::getImagePath(), ASS_Question::getImagePathWeb(), ASS_Question::getOutputType(), ASS_Question::getShuffle(), ASS_Question::getSolutionMaxPass(), ASS_Question::getSuggestedSolution(), ASS_Question::getTitle(), and ASS_Question::pcArrayShuffle().
{
global $ilDB;
global $ilUser;
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, ORDERING_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->get_ordering_type() == OQ_PICTURES)
{
$attrs = array(
"ident" => "OQP",
"rcardinality" => "Ordered"
);
}
else
{
$attrs = array(
"ident" => "OQT",
"rcardinality" => "Ordered"
);
}
if ($this->getOutputType() == OUTPUT_JAVASCRIPT)
{
$attrs["output"] = "javascript";
}
$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);
// shuffle
$akeys = array_keys($this->answers);
if ($this->getshuffle() && $a_shuffle)
{
$akeys = $this->pcArrayShuffle($akeys);
}
if ($test_output)
{
include_once "./assessment/classes/class.ilObjTest.php";
if (ilObjTest::_getHidePreviousResults($test_output, true))
{
$pass = ilObjTest::_getPass($ilUser->id, $test_output);
}
else
{
$pass = $this->getSolutionMaxPass($user_id, $test_output);
}
// create array keys from an existing solution
$query = sprintf("SELECT * FROM tst_solutions WHERE test_fi = %s AND user_fi = %s AND question_fi = %s AND pass = %s ORDER BY value2",
$ilDB->quote($test_output . ""),
$ilDB->quote($ilUser->id . ""),
$ilDB->quote($this->getId() . ""),
$ilDB->quote($pass . "")
);
$queryres = $ilDB->query($query);
if ($queryres->numRows() == count($this->answers))
{
//$akeys = array();
//while ($row = $queryres->fetchRow(DB_FETCHMODE_ASSOC))
//{
// array_push($akeys, $row["value1"]);
//}
}
}
// 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");
if ($this->get_ordering_type() == OQ_PICTURES)
{
if ($force_image_references)
{
$attrs = array(
"imagtype" => $imagetype,
"label" => $answer->get_answertext(),
"uri" => $this->getImagePathWeb() . $answer->get_answertext()
);
$a_xml_writer->xmlElement("matimage", $attrs);
}
else
{
$imagepath = $this->getImagePath() . $answer->get_answertext();
$fh = @fopen($imagepath, "rb");
if ($fh != false)
{
$imagefile = fread($fh, filesize($imagepath));
fclose($fh);
$base64 = base64_encode($imagefile);
$imagetype = "image/jpeg";
if (preg_match("/.*\.(png|gif)$/", $answer->get_answertext(), $matches))
{
$imagetype = "image/".$matches[1];
}
$attrs = array(
"imagtype" => $imagetype,
"label" => $answer->get_answertext(),
"embedded" => "base64"
);
$a_xml_writer->xmlElement("matimage", $attrs, $base64, FALSE, FALSE);
}
}
}
else
{
$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");
$attrs = array();
if ($this->get_ordering_type() == OQ_PICTURES)
{
$attrs = array(
"respident" => "OQP"
);
}
else
{
$attrs = array(
"respident" => "OQT"
);
}
$attrs["index"] = $answer->get_solution_order();
$a_xml_writer->xmlElement("varequal", $attrs, $index);
$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" => "link_$index"
);
$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)
{
$attrs = array(
"ident" => "link_$index",
"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_OrderingQuestion::$answers |
Definition at line 55 of file class.assOrderingQuestion.php.
| ASS_OrderingQuestion::$ordering_type |
Definition at line 65 of file class.assOrderingQuestion.php.
Referenced by ASS_OrderingQuestion(), and set_ordering_type().
| ASS_OrderingQuestion::$question |
Definition at line 46 of file class.assOrderingQuestion.php.
Referenced by ASS_OrderingQuestion(), and set_question().
1.7.1