MDL-16263 Flagging questions during a quiz attempt. Save flag state on the review page when JS is off too.
This commit is contained in:
@@ -146,6 +146,7 @@ $string['questionsmovedto'] = 'Questions still in use moved to "$a" in the paren
|
||||
$string['questionsrescuedfrom'] = 'Questions saved from context $a.';
|
||||
$string['questionsrescuedfrominfo'] = 'These questions (some of which may be hidden) where saved when context $a was deleted because they are still used by some quizzes or other activities.';
|
||||
$string['questionuse'] = 'Use question in this activity';
|
||||
$string['saveflags'] = 'Save the state of the flags';
|
||||
$string['shareincontext'] = 'Share in context for $a';
|
||||
$string['tofilecategory'] = 'Write category to file';
|
||||
$string['tofilecontext'] = 'Write context to file';
|
||||
|
||||
+50
-7
@@ -1780,18 +1780,33 @@ function question_make_name_prefix($id) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract question id from the prefix of form element names
|
||||
*
|
||||
* @return integer The question id
|
||||
* @param string $name The name that contains a prefix that was
|
||||
* constructed with {@link question_make_name_prefix()}
|
||||
*/
|
||||
* Extract question id from the prefix of form element names
|
||||
*
|
||||
* @return integer The question id
|
||||
* @param string $name The name that contains a prefix that was
|
||||
* constructed with {@link question_make_name_prefix()}
|
||||
*/
|
||||
function question_get_id_from_name_prefix($name) {
|
||||
if (!preg_match('/^resp([0-9]+)_/', $name, $matches))
|
||||
if (!preg_match('/^resp([0-9]+)_/', $name, $matches)) {
|
||||
return false;
|
||||
}
|
||||
return (integer) $matches[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract question id from the prefix of form element names
|
||||
*
|
||||
* @return integer The question id
|
||||
* @param string $name The name that contains a prefix that was
|
||||
* constructed with {@link question_make_name_prefix()}
|
||||
*/
|
||||
function question_id_and_key_from_post_name($name) {
|
||||
if (!preg_match('/^resp([0-9]+)_(.*)$/', $name, $matches)) {
|
||||
return array(false, false);
|
||||
}
|
||||
return array((integer) $matches[1], $matches[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unique id for a new attempt
|
||||
*
|
||||
@@ -2577,6 +2592,34 @@ function question_update_flag($sessionid, $newstate) {
|
||||
return $DB->set_field('question_sessions', 'flagged', $newstate, array('id' => $sessionid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the flagged state of all the questions in an attempt, where a new .
|
||||
*
|
||||
* @param integer $sessionid question_session id.
|
||||
* @param boolean $newstate the new state for the flag.
|
||||
* @return boolean success or failure.
|
||||
*/
|
||||
function question_save_flags($formdata, $attemptid, $questionids) {
|
||||
global $DB;
|
||||
$donequestionids = array();
|
||||
foreach ($formdata as $postvariable => $value) {
|
||||
list($qid, $key) = question_id_and_key_from_post_name($postvariable);
|
||||
if ($qid !== false && in_array($qid, $questionids)) {
|
||||
if ($key == '_flagged') {
|
||||
$DB->set_field('question_sessions', 'flagged', !empty($value),
|
||||
array('attemptid' => $attemptid, 'questionid' => $qid));
|
||||
$donequestionids[$qid] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($questionids as $qid) {
|
||||
if (!isset($donequestionids[$qid])) {
|
||||
$DB->set_field('question_sessions', 'flagged', 0,
|
||||
array('attemptid' => $attemptid, 'questionid' => $qid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $attemptid the question_attempt id.
|
||||
* @param integer $questionid the question id.
|
||||
|
||||
+30
-2
@@ -40,7 +40,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
/// load the questions and states needed by this page.
|
||||
/// Load the questions and states needed by this page.
|
||||
if ($showall) {
|
||||
$questionids = $attemptobj->get_question_ids();
|
||||
} else {
|
||||
@@ -49,6 +49,15 @@
|
||||
$attemptobj->load_questions($questionids);
|
||||
$attemptobj->load_question_states($questionids);
|
||||
|
||||
/// Save the flag states, if they are being changed.
|
||||
if ($options->flags == QUESTION_FLAGSEDITABLE && optional_param('savingflags', false, PARAM_BOOL)) {
|
||||
confirm_sesskey();
|
||||
$formdata = data_submitted();
|
||||
|
||||
question_save_flags($formdata, $attemptid, $questionids);
|
||||
redirect($attemptobj->review_url(0, $page, $showall));
|
||||
}
|
||||
|
||||
/// Log this review.
|
||||
add_to_log($attemptobj->get_courseid(), 'quiz', 'review', 'review.php?attempt=' .
|
||||
$attemptobj->get_attemptid(), $attemptobj->get_quizid(), $attemptobj->get_cmid());
|
||||
@@ -199,7 +208,14 @@
|
||||
|
||||
/// Summary table end ==============================================================================
|
||||
|
||||
/// Print all the questions
|
||||
/// Form for saving flags if necessary.
|
||||
if ($options->flags == QUESTION_FLAGSEDITABLE) {
|
||||
echo '<form action="' . $attemptobj->review_url(0, $page, $showall) .
|
||||
'" method="post"><div>';
|
||||
echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
|
||||
}
|
||||
|
||||
/// Print all the questions.
|
||||
if ($showall) {
|
||||
$thispage = 'all';
|
||||
$lastpage = true;
|
||||
@@ -211,6 +227,18 @@
|
||||
$attemptobj->print_question($id);
|
||||
}
|
||||
|
||||
/// Close form if we opened it.
|
||||
if ($options->flags == QUESTION_FLAGSEDITABLE) {
|
||||
echo '<div class="submitbtns">' . "\n" .
|
||||
'<input type="submit" id="savingflagssubmit" name="savingflags" value="' .
|
||||
get_string('saveflags', 'question') . '" />' .
|
||||
"</div>\n" .
|
||||
"\n</div></form>\n" .
|
||||
'<script type="text/javascript">' .
|
||||
"\nquestion_flag_changer.init_flag_save_form('savingflagssubmit');\n" .
|
||||
"</script>\n";
|
||||
}
|
||||
|
||||
/// Print a link to the next page.
|
||||
echo '<div class="submitbtns">';
|
||||
if ($lastpage) {
|
||||
|
||||
@@ -27,6 +27,12 @@ question_flag_changer = {
|
||||
YAHOO.util.Event.addListener(image, 'click', this.flag_state_change);
|
||||
},
|
||||
|
||||
init_flag_save_form: function(submitbuttonid) {
|
||||
// With JS on, we just want to remove all visible traces of the form.
|
||||
var button = document.getElementById(submitbuttonid);
|
||||
button.parentNode.removeChild(button);
|
||||
},
|
||||
|
||||
flag_state_change: function(e) {
|
||||
var image = e.target ? e.target : e.srcElement;
|
||||
var input = image.statestore;
|
||||
|
||||
@@ -3915,6 +3915,7 @@ body#mod-forum-search .introcontent {
|
||||
#mod-quiz-attempt .submitbtns,
|
||||
#mod-quiz-review .submitbtns {
|
||||
text-align: left;
|
||||
margin-top: 1.5em;
|
||||
}
|
||||
#mod-quiz-summary .submitbtns {
|
||||
margin-top: 1.5em;
|
||||
|
||||
Reference in New Issue
Block a user