Skip to content

Commit

Permalink
MDL-20636 Fix lots of minor quiz editing glitches.
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed Feb 11, 2011
1 parent fd214b5 commit a13d4fb
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 22 deletions.
4 changes: 4 additions & 0 deletions mod/quiz/addrandom.php
Expand Up @@ -21,6 +21,7 @@
$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))) {
Expand All @@ -36,6 +37,9 @@
} 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;
Expand Down
6 changes: 3 additions & 3 deletions mod/quiz/locallib.php
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/mod_form.php
Expand Up @@ -57,7 +57,6 @@ public function __construct($current, $section, $cm, $course) {
}

function definition() {

global $COURSE, $CFG, $DB, $PAGE;
$quizconfig = get_config('quiz');
$mform = $this->_form;
Expand Down Expand Up @@ -133,6 +132,7 @@ function definition() {
$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);
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/summary.php
Expand Up @@ -123,7 +123,7 @@
$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) {
Expand Down
6 changes: 3 additions & 3 deletions question/editlib.php
Expand Up @@ -1693,15 +1693,15 @@ 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;
}
}
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";
Expand All @@ -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'));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion question/engine/bank.php
Expand Up @@ -168,7 +168,7 @@ public static function get_creatable_qtypes() {
foreach ($otherqtypes as $name => $notused) {
$creatableqtypes[$name] = $allqtypes[$name];
}
return $qtypes;
return $creatableqtypes;
}

/**
Expand Down
18 changes: 10 additions & 8 deletions question/qbank.js
Expand Up @@ -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);
Expand All @@ -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() {
Expand All @@ -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;
Expand Down
13 changes: 11 additions & 2 deletions question/question.php
Expand Up @@ -25,6 +25,7 @@
$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) {
Expand Down Expand Up @@ -57,6 +58,9 @@
if ($inpopup !== 0) {
$url->param('inpopup', $inpopup);
}
if ($scrollpos) {
$url->param('scrollpos', $scrollpos);
}
$PAGE->set_url($url);

if ($originalreturnurl) {
Expand All @@ -69,6 +73,9 @@
} 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);
Expand Down Expand Up @@ -175,6 +182,7 @@
}
$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;
}
Expand All @@ -197,7 +205,7 @@
if ($inpopup) {
close_window();
} else {
redirect($returnurl->out(false));
redirect($returnurl);
}

} else if ($fromform = $mform->get_data()) {
Expand Down Expand Up @@ -263,7 +271,8 @@
} 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;
Expand Down
4 changes: 4 additions & 0 deletions question/type/edit_question_form.php
Expand Up @@ -204,6 +204,10 @@ public function definition() {
$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);
Expand Down
2 changes: 1 addition & 1 deletion question/type/random/edit_random_form.php
Expand Up @@ -43,7 +43,7 @@ public function definition() {
$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'));
Expand Down
1 change: 1 addition & 0 deletions question/type/random/lang/en/qtype_random.php
Expand Up @@ -30,4 +30,5 @@
$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';
6 changes: 4 additions & 2 deletions question/type/random/questiontype.php
Expand Up @@ -143,14 +143,16 @@ protected function set_selected_question_name($question, $randomname) {
$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.
Expand Down

0 comments on commit a13d4fb

Please sign in to comment.