if (! $cm = get_record("course_modules", "id", $id)) {
error("Course Module ID was incorrect");
}
-
+
if (! $course = get_record("course", "id", $cm->course)) {
error("Course is misconfigured");
}
-
+
if (! $quiz = get_record("quiz", "id", $cm->instance)) {
error("Course module is incorrect");
}
$strquiz = get_string("modulename", "quiz");
print_header("$course->shortname: $quiz->name", "$course->fullname",
- "$navigation <A HREF=index.php?id=$course->id>$strquizzes</A> ->
- <A HREF=\"view.php?id=$cm->id\">$quiz->name</A> -> $strattemptnum",
+ "$navigation <A HREF=index.php?id=$course->id>$strquizzes</A> ->
+ <A HREF=\"view.php?id=$cm->id\">$quiz->name</A> -> $strattemptnum",
"", "", true);
echo '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'; // for overlib
print_heading(get_string("noanswers", "quiz"));
print_continue("attempt.php?q=$quiz->id");
exit;
- }
+ }
if (!$questions = get_records_list("quiz_questions", "id", $quiz->questions)) {
error("No questions found!");
} else if (ereg('^q([0-9]+)r([0-9]+)$', $key, $keyregs)) { // Random-style answers
$questions[$keyregs[1]]->answer[] = "$keyregs[2]-$value";
-
+
} else if (ereg('^q([0-9]+)ma([0-9]+)$', $key, $keyregs)) { // Multi-answer questions
$questions[$keyregs[1]]->answer[] = "$keyregs[2]-$value";
} else if ('shuffleorder' == $key) {
$shuffleorder = explode(",", $value); // Actual order questions were given in
-
+
} else { // Useful for debugging new question types. Must be last.
error("Answer received for non-existent question ($key -> $value)");
}
}
- if (!$result = quiz_grade_attempt_results($quiz, $questions)) {
- error("Could not grade your quiz attempt!");
- }
-
if($timelimit > 0) {
if(($timelimit + 60) <= $timesincestart) {
- $result->sumgrades = 0;
+ $quiz->timesincestart = $timesincestart;
}
}
+ if (!$result = quiz_grade_attempt_results($quiz, $questions)) {
+ error("Could not grade your quiz attempt!");
+ }
+
if ($attempt = quiz_save_attempt($quiz, $questions, $result, $attemptnumber)) {
- add_to_log($course->id, "quiz", "submit",
+ add_to_log($course->id, "quiz", "submit",
"review.php?id=$cm->id&attempt=$attempt->id", "$quiz->id", $cm->id);
} else {
notice(get_string("alreadysubmitted", "quiz"), "view.php?id=$cm->id");
}
/// Actually seeing the questions marks the start of an attempt
-
+
if (!$unfinished = quiz_get_user_attempt_unfinished($quiz->id, $USER->id)) {
if ($newattemptid = quiz_start_attempt($quiz->id, $USER->id, $attemptnumber)) {
- add_to_log($course->id, "quiz", "attempt",
+ add_to_log($course->id, "quiz", "attempt",
"review.php?id=$cm->id&attempt=$newattemptid", "$quiz->id", $cm->id);
} else {
error("Sorry! Could not start the quiz (could not save starting time)");
$result->feedback = array(); // Not to be printed
$result->attemptbuildsonthelast = true;
}
-
+
} else {
// No latest attempt, or latest attempt was empty - Reset to defaults
$questions = NULL;
function quiz_get_category_coursename($category) {
/// if the category is published, adds on the course
-/// name
+/// name
$cname=$category->name;
if ($category->publish) {
if ($catcourse=get_record("course","id",$category->id)) {
echo '<td width="10" valign="top" align="right">';
helpbutton("questiontypes", $strcreatenewquestion, "quiz");
echo '</td></tr>';
-
+
echo '<tr><td colspan="3" align="right">';
echo '<form method="get" action="import.php">';
echo "<input type=\"hidden\" name=\"category\" value=\"$category->id\" />";
$questionresult = quiz_grade_attempt_question_result($question,
$answers);
+ // if time limit is enabled and exceeded, return zero grades
+ if($quiz->timelimit > 0) {
+ if(($quiz->timelimit + 60) <= $quiz->timesincestart) {
+ $questionresult->grade = 0;
+ }
+ }
$result->grades[$question->id] = round($questionresult->grade, 2);
$result->sumgrades += $questionresult->grade;
// get the list of questions for the category
$questions = get_records("quiz_questions","category",$category->id);
- // iterate through questions, getting stuff we need
+ // iterate through questions, getting stuff we need
foreach($questions as $question) {
$new_question = get_question_data( $question );
$qresults[] = $new_question;
}
// function to read single question, parameter is object view of
-// quiz_categories record, results is a combined object
+// quiz_categories record, results is a combined object
// defined as follows...
-// ->id quiz_questions id
-// ->category category
-// ->name q name
+// ->id quiz_questions id
+// ->category category
+// ->name q name
// ->questiontext
// ->image
-// ->qtype see defines at the top of this file
-// ->stamp not too sure
-// ->version not sure
+// ->qtype see defines at the top of this file
+// ->stamp not too sure
+// ->version not sure
// ----SHORTANSWER
// ->usecase
-// ->answers array of answers
+// ->answers array of answers
// ----TRUEFALSE
-// ->trueanswer truefalse answer
+// ->trueanswer truefalse answer
// ->falseanswer truefalse answer
// ----MULTICHOICE
// ->layout
-// ->single many or just one correct answer
-// ->answers array of answer objects
+// ->single many or just one correct answer
+// ->answers array of answer objects
function get_question_data( $question ) {
// what to do next depends of question type (qtype)
switch ($question->qtype) {
- case SHORTANSWER:
+ case SHORTANSWER:
$shortanswer = get_record("quiz_shortanswer","question",$question->id);
$question->usecase = $shortanswer->usecase;
$question->answers = array();
break;
case MULTICHOICE:
if (!$multichoice = get_record("quiz_multichoice","question",$question->id)) {
- error( "quiz_multichoice $question->id not found" );
+ error( "quiz_multichoice $question->id not found" );
}
$question->layout = $multichoice->layout;
$question->single = $multichoice->single;
}
// function to return single answer
-// ->id answer id
-// ->question question number
+// ->id answer id
+// ->question question number
// ->answer
// ->fraction
// ->feedback