diff --git a/mod/quiz/addrandom.php b/mod/quiz/addrandom.php index 36d603f8ea18d..7c4d12d8c422c 100644 --- a/mod/quiz/addrandom.php +++ b/mod/quiz/addrandom.php @@ -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))) { @@ -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; diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index 33ef60b3067fa..9d41ec441edcc 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -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(); diff --git a/mod/quiz/mod_form.php b/mod/quiz/mod_form.php index 61323a1edc967..dbe1094fd1499 100644 --- a/mod/quiz/mod_form.php +++ b/mod/quiz/mod_form.php @@ -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; @@ -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); diff --git a/mod/quiz/summary.php b/mod/quiz/summary.php index fe6ac1848791f..b4f7e9cbf816c 100644 --- a/mod/quiz/summary.php +++ b/mod/quiz/summary.php @@ -123,7 +123,7 @@ $flag = ' ' .
                 get_string('flagged', 'question') . ''; } - $row = array('' . + $row = array('' . $attemptobj->get_question_number($slot) . $flag . '', $attemptobj->get_question_status($slot, $displayoptions->correctness)); if ($markscolumn) { diff --git a/question/editlib.php b/question/editlib.php index 30ab7692543d1..fdfb4bf959b74 100644 --- a/question/editlib.php +++ b/question/editlib.php @@ -1693,7 +1693,7 @@ function print_choose_qtype_to_add_form($hiddenparams) { echo '
' . "\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 "
\n"; echo '
' . "\n"; - foreach ($fakeqtypes as $qtype => $localizedname) { + foreach ($fakeqtypes as $qtype) { print_qtype_to_add_option($qtype); } echo "
\n"; @@ -1711,7 +1711,7 @@ function print_choose_qtype_to_add_form($hiddenparams) { echo '' . "\n"; echo "\n"; echo "\n"; - $PAGE->requires->js_function_call('qtype_chooser.init', array('chooseqtype')); + $PAGE->requires->js_init_call('qtype_chooser.init', array('chooseqtype')); } /** diff --git a/question/engine/bank.php b/question/engine/bank.php index 012ad3f7834c6..a4bff1f50e9db 100644 --- a/question/engine/bank.php +++ b/question/engine/bank.php @@ -168,7 +168,7 @@ public static function get_creatable_qtypes() { foreach ($otherqtypes as $name => $notused) { $creatableqtypes[$name] = $allqtypes[$name]; } - return $qtypes; + return $creatableqtypes; } /** diff --git a/question/qbank.js b/question/qbank.js index 5cb2757dd8f0d..62f357ce91853 100644 --- a/question/qbank.js +++ b/question/qbank.js @@ -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; diff --git a/question/question.php b/question/question.php index 2ab21d2c8f879..9397febca9ae8 100644 --- a/question/question.php +++ b/question/question.php @@ -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) { @@ -57,6 +58,9 @@ if ($inpopup !== 0) { $url->param('inpopup', $inpopup); } +if ($scrollpos) { + $url->param('scrollpos', $scrollpos); +} $PAGE->set_url($url); if ($originalreturnurl) { @@ -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); @@ -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; } @@ -197,7 +205,7 @@ if ($inpopup) { close_window(); } else { - redirect($returnurl->out(false)); + redirect($returnurl); } } else if ($fromform = $mform->get_data()) { @@ -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; diff --git a/question/type/edit_question_form.php b/question/type/edit_question_form.php index c029d19bbd264..395ac7b3eb945 100644 --- a/question/type/edit_question_form.php +++ b/question/type/edit_question_form.php @@ -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); diff --git a/question/type/random/edit_random_form.php b/question/type/random/edit_random_form.php index 4807b42cc43c8..22c3bbc9dfeab 100644 --- a/question/type/random/edit_random_form.php +++ b/question/type/random/edit_random_form.php @@ -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')); diff --git a/question/type/random/lang/en/qtype_random.php b/question/type/random/lang/en/qtype_random.php index ee00545e063cf..03504d5628fbc 100644 --- a/question/type/random/lang/en/qtype_random.php +++ b/question/type/random/lang/en/qtype_random.php @@ -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'; diff --git a/question/type/random/questiontype.php b/question/type/random/questiontype.php index ae6da187e1704..3cc3ce4e5e18a 100644 --- a/question/type/random/questiontype.php +++ b/question/type/random/questiontype.php @@ -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.