Skip to content

Commit

Permalink
The teacher now can choose whether to see the advanced quiz
Browse files Browse the repository at this point in the history
options or not. This is handled as in the resource module. The
"Show advanced options" button is only shown if the admin has
chosen to declare some of the options as advanced.

There are now 4 review options as suggested by Martin in
http://moodle.org/mod/forum/discuss.php?d=16709

Provides separate buttons "Update this quiz" and "Edit questions",
see http://moodle.org/mod/forum/discuss.php?d=16708. To make this
possible edit.php can now be called with a quiz id and it saves
its data itself rather than relying on mod.php.

mod.html now has a "Save changes" and a "Save changes and edit questions" button.

"Attempt quiz now" button gets a different language string for
re-attempts. This is currently set to "Re-attempt quiz".

After viewing the feedback for an attempt the "Continue" button
leads back to the course homepage, as requested in bugs 1224 and
1976. If there is no feedback the user is brought straight to quiz/view.php.
  • Loading branch information
gustav_delius committed Jan 2, 2005
1 parent 405f01e commit 34283aa
Show file tree
Hide file tree
Showing 16 changed files with 431 additions and 129 deletions.
12 changes: 10 additions & 2 deletions course/mod.php
Expand Up @@ -76,7 +76,11 @@
error($return, "view.php?id=$course->id");
}

$SESSION->returnpage = "$CFG->wwwroot/mod/$mod->modulename/view.php?id=$mod->coursemodule";
if (isset($mod->redirect)) {
$SESSION->returnpage = $mod->redirecturl;
} else {
$SESSION->returnpage = "$CFG->wwwroot/mod/$mod->modulename/view.php?id=$mod->coursemodule";
}

add_to_log($course->id, "course", "update mod",
"../mod/$mod->modulename/view.php?id=$mod->coursemodule",
Expand Down Expand Up @@ -128,7 +132,11 @@
error("Could not update the course module with the correct section");
}

$SESSION->returnpage = "$CFG->wwwroot/mod/$mod->modulename/view.php?id=$mod->coursemodule";
if (isset($mod->redirect)) {
$SESSION->returnpage = $mod->redirecturl;
} else {
$SESSION->returnpage = "$CFG->wwwroot/mod/$mod->modulename/view.php?id=$mod->coursemodule";
}

add_to_log($course->id, "course", "add mod",
"../mod/$mod->modulename/view.php?id=$mod->coursemodule",
Expand Down
7 changes: 7 additions & 0 deletions lang/en/help/hideoptions.html
@@ -0,0 +1,7 @@
<p align="center"><b>Hide options</b></p>

<p>If you tick these boxes then the corresponding options will be
hidden from the teacher by default. However the teacher can access
these options by choosing "<?php
print_string('showadvancedsettings'); ?>" on the quiz setup
page.</p>
5 changes: 5 additions & 0 deletions lang/en/help/quiz/review2.html
@@ -0,0 +1,5 @@
<p align="center"><b>Allow review</b></p>

<p>This option controls whether and when students will be able to
review their past attempts at this quiz.</p>

4 changes: 3 additions & 1 deletion lang/en/moodle.php
Expand Up @@ -62,6 +62,7 @@
$string['administratorsall'] = 'All administrators';
$string['administratorsandteachers'] = 'Administrators and teachers';
$string['advancedfilter'] = 'Advanced search';
$string['advancedsettings'] = 'Advanced settings';
$string['again'] = 'again';
$string['all'] = 'All';
$string['allactivities'] = 'All activities';
Expand Down Expand Up @@ -474,7 +475,6 @@
$string['firstdayofweek'] = '0';
$string['firstname'] = 'First name';
$string['firsttime'] = 'Is this your first time here?';
$string['fix'] = 'Fix';
$string['followingoptional'] = 'The following items are optional';
$string['followingrequired'] = 'The following items are required';
$string['force'] = 'Force';
Expand Down Expand Up @@ -570,6 +570,7 @@
$string['hiddensectionscollapsed'] = 'Hidden sections are shown in collapsed form';
$string['hiddensectionsinvisible'] = 'Hidden sections are completely invisible';
$string['hide'] = 'Hide';
$string['hideadvancedsettings'] = 'Hide advanced settings';
$string['hidepicture'] = 'Hide picture';
$string['hidesettings'] = 'Hide settings';
$string['hits'] = 'Hits';
Expand Down Expand Up @@ -928,6 +929,7 @@
$string['shortnametaken'] = 'Short name is already used for another course ($a)';
$string['shortsitename'] = 'Short name for site (eg single word)';
$string['show'] = 'Show';
$string['showadvancedsettings'] = 'Show advanced settings';
$string['showall'] = 'Show all $a';
$string['showallcourses'] = 'Show all courses';
$string['showalltopics'] = 'Show all topics';
Expand Down
6 changes: 6 additions & 0 deletions lang/en/quiz.php
Expand Up @@ -211,11 +211,16 @@
$string['randomsamatchintro'] = 'For each of the following questions, select the matching answer from the menu.';
$string['randomsamatchnumber'] = 'Number of questions to select';
$string['readytosend'] = 'You are about to send your whole quiz to be graded. Are you sure you want to continue?';
$string['reattemptquiz'] = 'Re-attempt quiz';
$string['recentlyaddedquestion'] = 'Recently added question!';
$string['regrade'] = 'Regrade all attempts';
$string['regradecomplete'] = 'All attempts have been regraded';
$string['regradecount'] = '$a->changed out of $a->attempt grades were changed';
$string['relative'] = 'Relative';
$string['reviewnever'] = 'Never allow review';
$string['reviewafter'] = 'Allow review after quiz is closed';
$string['reviewbefore'] = 'Allow review while quiz is open';
$string['reviewalways'] = 'Allow review at any time';
$string['remove'] = 'Remove';
$string['rename'] = 'Rename';
$string['report'] = 'Reports';
Expand All @@ -232,6 +237,7 @@
$string['reuseifpossible'] = 'reuse previously removed';
$string['review'] = 'Review';
$string['save'] = 'Save';
$string['saveandedit'] = 'Save changes and edit questions';
$string['savegrades'] = 'Save grades';
$string['savemyanswers'] = 'Save my answers';
$string['savequiz'] = 'Save this whole quiz';
Expand Down
9 changes: 7 additions & 2 deletions mod/quiz/attempt.php
Expand Up @@ -117,7 +117,7 @@
}


/// BEGIN EDIT Get time limit if any.
/// Get time limit if any.

$timelimit = $quiz->timelimit * 60;

Expand All @@ -135,7 +135,7 @@
if($timelimit and $timerstartvalue <= 0) {
$timerstartvalue = 1;
}
/// END EDIT

$timenow = time();
$available = ($quiz->timeopen < $timenow and $timenow < $quiz->timeclose) || isteacher($course->id);

Expand Down Expand Up @@ -202,6 +202,11 @@
if (! quiz_save_best_grade($quiz, $USER->id)) {
error("Sorry! Could not calculate your best grade!");
}

if (empty($quiz->popup) and !$quiz->feedback) {
// No need to stop on this page, go directly to view.php
redirect('view.php?q='.$quiz->id);
}

$strgrade = get_string("grade");
$strscore = get_string("score", "quiz");
Expand Down
4 changes: 2 additions & 2 deletions mod/quiz/attempt_close_js.php
Expand Up @@ -9,7 +9,7 @@
<!--

document.write('<input type="button" value="<?php print_string('continue') ?>" '+
'onclick="javascript: window.opener.location.href=\'view.php?id=<?php echo $cm->id ?>\'; '+
'onclick="javascript: window.opener.location.href=\'../../course/view.php?id=<?php echo $course->id ?>\'; '+
'window.close();" />');
// -->
</script>
Expand All @@ -19,7 +19,7 @@

<?php
} else {
print_single_button("view.php", array( 'id' => $cm->id ), get_string('continue'));
print_single_button("../../course/view.php", array( 'id' => $course->id ), get_string('continue'));
}
?>
</div>
14 changes: 8 additions & 6 deletions mod/quiz/config.html
Expand Up @@ -9,7 +9,7 @@
<?php print_string('sitedefault'); ?>
</th>
<th align="center">
<?php print_string('fix'); helpbutton("fixdefaults"); ?>
<?php print_string('hide'); helpbutton("hideoptions"); ?>
</th>
</tr>

Expand Down Expand Up @@ -150,11 +150,13 @@
<td align="right"><b><?php print_string("allowreview", "quiz") ?>:</b></td>
<td>
<?php
unset($options);
$options[0] = get_string("no");
$options[1] = get_string("yes");
choose_from_menu ($options, "quiz_allowreview", $CFG->quiz_allowreview, "", "", "");
helpbutton("review", get_string("allowreview","quiz"), "quiz");
$reviewoptions = array();
$reviewoptions[0] = get_string('reviewnever', 'quiz');
$reviewoptions[1] = get_string('reviewafter', 'quiz');
$reviewoptions[2] = get_string('reviewbefore', 'quiz');
$reviewoptions[3] = get_string('reviewalways', 'quiz');
choose_from_menu ($reviewoptions, "quiz_allowreview", $CFG->quiz_allowreview, "", "", "");
helpbutton("review2", get_string("allowreview","quiz"), "quiz");
?>
</td>
<td align="center">
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/defaults.php
Expand Up @@ -4,7 +4,7 @@
// It defines default values for any important configuration variables

$defaults = array (
'quiz_allowreview' => 0,
'quiz_allowreview' => 1,
'quiz_attemptonlast' => 0,
'quiz_attempts' => 0,
'quiz_grademethod' => '',
Expand Down
48 changes: 42 additions & 6 deletions mod/quiz/edit.php
Expand Up @@ -6,14 +6,15 @@
require_login();

optional_variable($courseid);
optional_variable($quizid);

if (empty($destination)) {
$destination = "";
}

$modform = data_submitted($destination);

if ($modform and !empty($modform->course)) { // form submitted from mod.html
if ($modform and !empty($modform->course)) { // data submitted

$modform->name = trim($modform->name);

Expand All @@ -27,6 +28,15 @@

$SESSION->modform = $modform; // Save the form in the current session

} else if ($quizid) {
if (! $modform = get_record('quiz', 'id', $quizid)) {
error("The required quiz doesn't exist");
}

$modform->instance = $modform->id;

$SESSION->modform = $modform; // Save the form in the current session

} else if ($courseid) { // Page retrieve through "Edit Questions" link - no quiz selected
$modform->course = $courseid;
unset($modform->instance);
Expand All @@ -35,7 +45,9 @@

} else {
if (!isset($SESSION->modform)) {
error("You have used this page incorrectly!");
// We currently also get here after editing a question by
// following the edit link on the review page. Perhaps that should be fixed.
error('');
}

$modform = $SESSION->modform;
Expand All @@ -60,6 +72,10 @@


// Now, check for commands on this page and modify variables as necessary

if (isset($cancel)) {
redirect('view.php?q='.$modform->instance);
}

if (!empty($up)) { /// Move the given question up a slot
$questions = explode(",", $modform->questions);
Expand Down Expand Up @@ -147,6 +163,25 @@
}
}
}

if (!empty($save)) { // Save the list of questions and grades in the database and return

//If caller is correct, $SESSION->sesskey must exist and coincide
if (empty($SESSION->sesskey) or !confirm_sesskey($SESSION->sesskey)) {
error(get_string('confirmsesskeybad', 'error'));
}
//Unset this, check done
unset($SESSION->sesskey);

quiz_update_instance($modform);
$coursemodule = get_coursemodule_from_instance('quiz', $modform->instance);
add_to_log($course->id, 'quiz', 'editquestions',
"view.php?id=$coursemodule",
"$modform->instance", $coursemodule);
redirect('view.php?q='.$modform->instance);
die;
}


if (!empty($cat)) { //-----------------------------------------------------------
$modform->category = $cat;
Expand Down Expand Up @@ -204,11 +239,12 @@
}
notify("$strattemptsexist<br /><a href=\"report.php?id=$cm->id\">$strviewallanswers ($usercount $strusers)</a>");
}


$SESSION->sesskey = !empty($USER->id) ? $USER->sesskey : '';
?>
<form name="theform" method="post" action=<?php echo $modform->destination ?>>
<input type="hidden" name="course" value="<?php p($modform->course) ?>" />
<input type="submit" value="<?php print_string("savequiz", "quiz") ?>" />
<form method="post" action="edit.php">
<input type="hidden" name="sesskey" value="save" />
<input type="submit" name="save" value="<?php print_string("savequiz", "quiz") ?>" />
<input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
</form>
</center>
Expand Down
31 changes: 22 additions & 9 deletions mod/quiz/lib.php
Expand Up @@ -43,6 +43,9 @@

define("QUIZ_MAX_EVENT_LENGTH", "432000"); // 5 days maximum

define('QUIZ_REVIEW_AFTER', 1);
define('QUIZ_REVIEW_BEFORE', 2);

$QUIZ_QTYPES= array();

/// QUIZ_QTYPES INITIATION //////////////////
Expand Down Expand Up @@ -337,9 +340,15 @@ function quiz_add_instance($quiz) {
if (!$quiz->id = insert_record("quiz", $quiz)) {
return false; // some error occurred
}

if (isset($quiz->optionsettingspref)) {
set_user_preference('quiz_optionsettingspref', $quiz->optionsettingspref);
}

// The grades for every question in this quiz are stored in an array
if ($quiz->grades) {
// (because this is currently only called from mod.html there are not
// going to be any grades, but we will leave this code here just in case)
if (isset($quiz->grades)) {
foreach ($quiz->grades as $question => $grade) {
if ($question) {
unset($questiongrade);
Expand Down Expand Up @@ -390,31 +399,36 @@ function quiz_add_instance($quiz) {

function quiz_update_instance($quiz) {
/// Given an object containing all the necessary data,
/// (defined by the form in mod.html) this function
/// (defined by the form in mod.html or edit.php) this function
/// will update an existing instance with new data.

global $SESSION;

unset($SESSION->modform);

$quiz->timemodified = time();
$quiz->timeopen = make_timestamp($quiz->openyear, $quiz->openmonth, $quiz->openday,
$quiz->openhour, $quiz->openminute, 0);
$quiz->timeclose = make_timestamp($quiz->closeyear, $quiz->closemonth, $quiz->closeday,
$quiz->closehour, $quiz->closeminute, 0);
if (isset($quiz->openyear)) { // this would not be set if we come from edit.php
$quiz->timeopen = make_timestamp($quiz->openyear, $quiz->openmonth, $quiz->openday,
$quiz->openhour, $quiz->openminute, 0);
$quiz->timeclose = make_timestamp($quiz->closeyear, $quiz->closemonth, $quiz->closeday,
$quiz->closehour, $quiz->closeminute, 0);
}
$quiz->id = $quiz->instance;

if (!update_record("quiz", $quiz)) {
return false; // some error occurred
}

if (isset($quiz->optionsettingspref)) {
set_user_preference('quiz_optionsettingspref', $quiz->optionsettingspref);
}

// The grades for every question in this quiz are stored in an array
// Insert or update records as appropriate

$existing = get_records("quiz_question_grades", "quiz", $quiz->id, "", "question,grade,id");

if ($quiz->grades) {
if (isset($quiz->grades)) { // this will not be set if we come from mod.html
foreach ($quiz->grades as $question => $grade) {
if ($question) {
unset($questiongrade);
Expand Down Expand Up @@ -473,8 +487,6 @@ function quiz_update_instance($quiz) {
add_event($event);
}



return true;
}

Expand Down Expand Up @@ -1234,6 +1246,7 @@ function quiz_gradesmenu_options($defaultgrade) {

function quiz_print_question_list($questionlist, $grades) {
// Prints a list of quiz questions in a small layout form with knobs
// returns sum of maximum grades
// $questionlist is comma-separated list
// $grades is an array of corresponding grades

Expand Down

0 comments on commit 34283aa

Please sign in to comment.