MDL-20636 Fix lots of minor quiz editing glitches.
This commit is contained in:
@@ -21,6 +21,7 @@ list($thispageurl, $contexts, $cmid, $cm, $quiz, $pagevars) =
|
||||
$returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
|
||||
$addonpage = optional_param('addonpage', 0, PARAM_INT);
|
||||
$category = optional_param('category', 0, PARAM_INT);
|
||||
$scrollpos = optional_param('scrollpos', 0, PARAM_INT);
|
||||
|
||||
// Get the course object and related bits.
|
||||
if (!$course = $DB->get_record('course', array('id' => $quiz->course))) {
|
||||
@@ -36,6 +37,9 @@ if ($returnurl) {
|
||||
} else {
|
||||
$returnurl = new moodle_url('/mod/quiz/edit.php', array('cmid' => $cmid));
|
||||
}
|
||||
if ($scrollpos) {
|
||||
$returnurl->param('scrollpos', $scrollpos);
|
||||
}
|
||||
|
||||
$defaultcategoryobj = question_make_default_categories($contexts->all());
|
||||
$defaultcategory = $defaultcategoryobj->id . ',' . $defaultcategoryobj->contextid;
|
||||
|
||||
@@ -462,8 +462,8 @@ function quiz_update_sumgrades($quiz) {
|
||||
WHERE quiz = {quiz}.id
|
||||
), 0)
|
||||
WHERE id = ?';
|
||||
$DB->execute_sql($sql, array($quiz->id));
|
||||
$quiz->sumgrades = get_field('quiz', 'sumgrades', 'id', $quiz->id);
|
||||
$DB->execute($sql, array($quiz->id));
|
||||
$quiz->sumgrades = $DB->get_field('quiz', 'sumgrades', array('id' => $quiz->id));
|
||||
if ($quiz->sumgrades < 0.000005) {
|
||||
quiz_set_grade(0, $quiz);
|
||||
}
|
||||
@@ -749,7 +749,7 @@ function quiz_update_all_final_grades($quiz) {
|
||||
WHERE
|
||||
ABS(newgrades.newgrade - qg.grade) > 0.000005 OR
|
||||
(newgrades.newgrade IS NULL) <> (qg.grade IS NULL)",
|
||||
$params);
|
||||
$param);
|
||||
|
||||
$timenow = time();
|
||||
$todelete = array();
|
||||
|
||||
@@ -57,7 +57,6 @@ class mod_quiz_mod_form extends moodleform_mod {
|
||||
}
|
||||
|
||||
function definition() {
|
||||
|
||||
global $COURSE, $CFG, $DB, $PAGE;
|
||||
$quizconfig = get_config('quiz');
|
||||
$mform = $this->_form;
|
||||
@@ -133,6 +132,7 @@ class mod_quiz_mod_form extends moodleform_mod {
|
||||
$mform->disabledIf('repaginatenow', 'shufflequestions', 'eq', 1);
|
||||
$PAGE->requires->yui2_lib('event');
|
||||
$PAGE->requires->js('/mod/quiz/edit.js');
|
||||
$PAGE->requires->js_init_call('quiz_settings_init');
|
||||
}
|
||||
|
||||
$mform->addGroup($pagegroup, 'questionsperpagegrp', get_string('newpage', 'quiz'), null, false);
|
||||
|
||||
@@ -123,7 +123,7 @@ foreach ($slots as $slot) {
|
||||
$flag = ' <img src="' . $OUTPUT->pix_url('i/flagged') . '" alt="' .
|
||||
get_string('flagged', 'question') . '" class="questionflag" />';
|
||||
}
|
||||
$row = array('<a href="' . s($attemptobj->attempt_url($slot)) . '">' .
|
||||
$row = array('<a href="' . $attemptobj->attempt_url($slot) . '">' .
|
||||
$attemptobj->get_question_number($slot) . $flag . '</a>',
|
||||
$attemptobj->get_question_status($slot, $displayoptions->correctness));
|
||||
if ($markscolumn) {
|
||||
|
||||
@@ -1693,7 +1693,7 @@ function print_choose_qtype_to_add_form($hiddenparams) {
|
||||
echo '<div class="realqtypes">' . "\n";
|
||||
$fakeqtypes = array();
|
||||
foreach (question_bank::get_creatable_qtypes() as $qtype) {
|
||||
if (question_bank::get_qtype($qtype)->is_real_question_type()) {
|
||||
if ($qtype->is_real_question_type()) {
|
||||
print_qtype_to_add_option($qtype);
|
||||
} else {
|
||||
$fakeqtypes[] = $qtype;
|
||||
@@ -1701,7 +1701,7 @@ function print_choose_qtype_to_add_form($hiddenparams) {
|
||||
}
|
||||
echo "</div>\n";
|
||||
echo '<div class="fakeqtypes">' . "\n";
|
||||
foreach ($fakeqtypes as $qtype => $localizedname) {
|
||||
foreach ($fakeqtypes as $qtype) {
|
||||
print_qtype_to_add_option($qtype);
|
||||
}
|
||||
echo "</div>\n";
|
||||
@@ -1711,7 +1711,7 @@ function print_choose_qtype_to_add_form($hiddenparams) {
|
||||
echo '<input type="submit" id="chooseqtypecancel" name="addcancel" value="' . get_string('cancel') . '" />' . "\n";
|
||||
echo "</div></form>\n";
|
||||
echo "</div>\n";
|
||||
$PAGE->requires->js_function_call('qtype_chooser.init', array('chooseqtype'));
|
||||
$PAGE->requires->js_init_call('qtype_chooser.init', array('chooseqtype'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -168,7 +168,7 @@ abstract class question_bank {
|
||||
foreach ($otherqtypes as $name => $notused) {
|
||||
$creatableqtypes[$name] = $allqtypes[$name];
|
||||
}
|
||||
return $qtypes;
|
||||
return $creatableqtypes;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+10
-8
@@ -43,7 +43,7 @@ qtype_chooser = {
|
||||
container: null,
|
||||
submitbutton: null,
|
||||
|
||||
init: function(boxid) {
|
||||
init: function(Y, boxid) {
|
||||
// Find the radio buttons.
|
||||
qtype_chooser.radiobuttons = YAHOO.util.Dom.getElementsBy(
|
||||
function(el) { return el.type == 'radio'; }, 'input' , boxid);
|
||||
@@ -57,9 +57,17 @@ qtype_chooser = {
|
||||
YAHOO.util.Event.addListener(boxid, 'click', qtype_chooser.enable_disable_submit);
|
||||
YAHOO.util.Event.addListener(boxid, 'key_down', qtype_chooser.enable_disable_submit);
|
||||
YAHOO.util.Event.addListener(boxid, 'key_up', qtype_chooser.enable_disable_submit);
|
||||
YAHOO.util.Event.addListener(boxid, 'dblclick', qtype_chooser.double_click);
|
||||
YAHOO.util.Event.addListener(boxid, 'dblclick', function(e) {
|
||||
if (!qtype_chooser.submitbutton.disabled) {
|
||||
M.core_scroll_manager.save_scroll_pos(Y, Y.one(qtype_chooser.submitbutton));
|
||||
qtype_chooser.submitbutton.form.submit();
|
||||
}
|
||||
});
|
||||
|
||||
YAHOO.util.Event.onDOMReady(qtype_chooser.init_container);
|
||||
Y.on('submit', function(e) {
|
||||
M.core_scroll_manager.save_scroll_pos(Y, Y.one(qtype_chooser.submitbutton));
|
||||
}, qtype_chooser.submitbutton.form);
|
||||
},
|
||||
|
||||
enable_disable_submit: function() {
|
||||
@@ -75,12 +83,6 @@ qtype_chooser = {
|
||||
qtype_chooser.submitbutton.disabled = !ok;
|
||||
},
|
||||
|
||||
double_click: function() {
|
||||
if (!qtype_chooser.submitbutton.disabled) {
|
||||
qtype_chooser.submitbutton.form.submit();
|
||||
}
|
||||
},
|
||||
|
||||
init_container: function() {
|
||||
if (!document.getElementById('qtypechoicecontainer')) {
|
||||
return;
|
||||
|
||||
+11
-2
@@ -25,6 +25,7 @@ $movecontext = optional_param('movecontext', 0, PARAM_BOOL); // Switch to make
|
||||
$originalreturnurl = optional_param('returnurl', 0, PARAM_LOCALURL);
|
||||
$appendqnumstring = optional_param('appendqnumstring', '', PARAM_ALPHA);
|
||||
$inpopup = optional_param('inpopup', 0, PARAM_BOOL);
|
||||
$scrollpos = optional_param('scrollpos', 0, PARAM_INT);
|
||||
|
||||
$url = new moodle_url('/question/question.php');
|
||||
if ($id !== 0) {
|
||||
@@ -57,6 +58,9 @@ if ($appendqnumstring !== '') {
|
||||
if ($inpopup !== 0) {
|
||||
$url->param('inpopup', $inpopup);
|
||||
}
|
||||
if ($scrollpos) {
|
||||
$url->param('scrollpos', $scrollpos);
|
||||
}
|
||||
$PAGE->set_url($url);
|
||||
|
||||
if ($originalreturnurl) {
|
||||
@@ -69,6 +73,9 @@ if ($originalreturnurl) {
|
||||
} else {
|
||||
$returnurl = new moodle_url('/question/edit.php', array('courseid' => $courseid));
|
||||
}
|
||||
if ($scrollpos) {
|
||||
$returnurl->param('scrollpos', $scrollpos);
|
||||
}
|
||||
|
||||
if ($movecontext && !$id){
|
||||
print_error('questiondoesnotexist', 'question', $returnurl);
|
||||
@@ -175,6 +182,7 @@ if ($wizardnow!=='' && !$movecontext){
|
||||
}
|
||||
$toform = fullclone($question); // send the question object and a few more parameters to the form
|
||||
$toform->category = "$category->id,$category->contextid";
|
||||
$toform->scrollpos = $scrollpos;
|
||||
if ($formeditable && $id){
|
||||
$toform->categorymoveto = $toform->category;
|
||||
}
|
||||
@@ -197,7 +205,7 @@ if ($mform->is_cancelled()) {
|
||||
if ($inpopup) {
|
||||
close_window();
|
||||
} else {
|
||||
redirect($returnurl->out(false));
|
||||
redirect($returnurl);
|
||||
}
|
||||
|
||||
} else if ($fromform = $mform->get_data()) {
|
||||
@@ -263,7 +271,8 @@ if ($mform->is_cancelled()) {
|
||||
} else {
|
||||
$nexturlparams = array(
|
||||
'returnurl' => $originalreturnurl,
|
||||
'appendqnumstring' => $appendqnumstring);
|
||||
'appendqnumstring' => $appendqnumstring,
|
||||
'scrollpos' => $scrollpos);
|
||||
if (isset($fromform->nextpageparam) && is_array($fromform->nextpageparam)){
|
||||
//useful for passing data to the next page which is not saved in the database.
|
||||
$nexturlparams += $fromform->nextpageparam;
|
||||
|
||||
@@ -204,6 +204,10 @@ abstract class question_edit_form extends moodleform {
|
||||
$mform->setType('returnurl', PARAM_LOCALURL);
|
||||
$mform->setDefault('returnurl', 0);
|
||||
|
||||
$mform->addElement('hidden', 'scrollpos');
|
||||
$mform->setType('scrollpos', PARAM_INT);
|
||||
$mform->setDefault('scrollpos', 0);
|
||||
|
||||
$mform->addElement('hidden', 'appendqnumstring');
|
||||
$mform->setType('appendqnumstring', PARAM_ALPHA);
|
||||
$mform->setDefault('appendqnumstring', 0);
|
||||
|
||||
@@ -43,7 +43,7 @@ class question_edit_random_form extends question_edit_form {
|
||||
$qtype = $this->qtype();
|
||||
$langfile = "qtype_$qtype";
|
||||
|
||||
$mform =& $this->_form;
|
||||
$mform = $this->_form;
|
||||
|
||||
// Standard fields at the start of the form.
|
||||
$mform->addElement('header', 'generalheader', get_string("general", 'form'));
|
||||
|
||||
@@ -30,4 +30,5 @@ $string['random'] = 'Random';
|
||||
$string['random_help'] = 'A random question is not a question type as such, but is a way of inserting a randomly-chosen question from a specified category into a quiz.';
|
||||
$string['randomqname'] = 'Random ({$a})';
|
||||
$string['randomqplusname'] = 'Random ({$a} and sub-categories)';
|
||||
$string['selectedby'] = '{$a->questionname} selected by {$a->randomname}';
|
||||
$string['selectmanualquestions'] = 'Random questions can use manually graded questions';
|
||||
|
||||
@@ -143,14 +143,16 @@ class qtype_random extends question_type {
|
||||
$question->name = get_string('selectedby', 'qtype_random', $a);
|
||||
}
|
||||
|
||||
public function save_question($question, $form, $course) {
|
||||
public function save_question($question, $form) {
|
||||
$form->name = '';
|
||||
// Name is not a required field for random questions, but
|
||||
// parent::save_question Assumes that it is.
|
||||
return parent::save_question($question, $form, $course);
|
||||
return parent::save_question($question, $form);
|
||||
}
|
||||
|
||||
public function save_question_options($question) {
|
||||
global $DB;
|
||||
|
||||
// No options, as such, but we set the parent field to the question's
|
||||
// own id. Setting the parent field has the effect of hiding this
|
||||
// question in various places.
|
||||
|
||||
Reference in New Issue
Block a user