From 25a03faacacd1f1b1ca9890101ddfc077dc408df Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 12 May 2011 00:30:25 +0100 Subject: [PATCH] MDL-20636 fix many code-checker issues in mod/quiz. --- mod/quiz/accessrules.php | 83 ++++--- mod/quiz/addrandom.php | 1 - mod/quiz/addrandomform.php | 1 - mod/quiz/attempt.php | 1 - mod/quiz/attemptlib.php | 78 ++++--- .../backup_quiz_activity_task.class.php | 1 - .../backup/moodle2/backup_quiz_stepslib.php | 1 - .../restore_quiz_activity_task.class.php | 114 ++++++---- .../backup/moodle2/restore_quiz_stepslib.php | 1 - mod/quiz/comment.php | 1 - mod/quiz/db/access.php | 1 - mod/quiz/db/install.php | 1 - mod/quiz/db/log.php | 1 - mod/quiz/db/messages.php | 1 - mod/quiz/db/subplugins.php | 1 - mod/quiz/db/upgrade.php | 210 ++++++++++-------- mod/quiz/edit.php | 59 ++--- mod/quiz/editlib.php | 6 +- mod/quiz/grade.php | 1 - mod/quiz/index.php | 1 - mod/quiz/lang/en/quiz.php | 1 - mod/quiz/lib.php | 187 +++++++++------- mod/quiz/locallib.php | 91 +++++--- mod/quiz/mod_form.php | 3 +- mod/quiz/module.js | 2 +- mod/quiz/override_form.php | 62 +++--- mod/quiz/overridedelete.php | 6 +- mod/quiz/overrideedit.php | 1 - mod/quiz/overrides.php | 68 +++--- mod/quiz/processattempt.php | 1 - mod/quiz/report.php | 1 - mod/quiz/report/attemptsreport.php | 32 +-- mod/quiz/report/default.php | 1 - mod/quiz/report/grading/db/access.php | 1 - .../report/grading/gradingsettings_form.php | 1 - .../report/grading/lang/en/quiz_grading.php | 1 - mod/quiz/report/grading/report.php | 1 - mod/quiz/report/grading/version.php | 1 - mod/quiz/report/overview/db/upgrade.php | 52 +++-- .../report/overview/lang/en/quiz_overview.php | 1 - mod/quiz/report/overview/overview_table.php | 56 +++-- mod/quiz/report/overview/overviewgraph.php | 1 - .../report/overview/overviewsettings_form.php | 45 ++-- mod/quiz/report/overview/report.php | 80 ++++--- mod/quiz/report/overview/version.php | 1 - mod/quiz/report/reportlib.php | 69 +++--- .../responses/lang/en/quiz_responses.php | 1 - mod/quiz/report/responses/report.php | 1 - mod/quiz/report/responses/responses_table.php | 5 +- .../responses/responsessettings_form.php | 46 ++-- mod/quiz/report/simpletest/testreportlib.php | 1 - mod/quiz/report/statistics/cron.php | 1 - mod/quiz/report/statistics/db/access.php | 1 - mod/quiz/report/statistics/db/install.php | 1 - mod/quiz/report/statistics/db/upgrade.php | 162 ++++++++------ .../statistics/lang/en/quiz_statistics.php | 1 - mod/quiz/report/statistics/qstats.php | 26 ++- mod/quiz/report/statistics/report.php | 110 +++++---- .../report/statistics/responseanalysis.php | 1 - .../statistics/simpletest/test_qstats.php | 48 ++-- .../report/statistics/statistics_form.php | 1 - .../report/statistics/statistics_graph.php | 1 - .../statistics/statistics_question_table.php | 1 - .../report/statistics/statistics_table.php | 1 - mod/quiz/report/statistics/version.php | 1 - mod/quiz/reviewquestion.php | 1 - mod/quiz/settings.php | 1 - mod/quiz/settingslib.php | 1 - mod/quiz/simpletest/testaccessrules.php | 154 ++++++++----- mod/quiz/simpletest/testeditlib.php | 1 - mod/quiz/simpletest/testlib.php | 1 - mod/quiz/simpletest/testlocallib.php | 1 - .../simpletest/testquizdisplayoptions.php | 1 - mod/quiz/startattempt.php | 1 - mod/quiz/summary.php | 1 - mod/quiz/version.php | 1 - mod/quiz/view.php | 1 - 77 files changed, 1125 insertions(+), 780 deletions(-) diff --git a/mod/quiz/accessrules.php b/mod/quiz/accessrules.php index 13806a00493b7..fc79ddbe539af 100644 --- a/mod/quiz/accessrules.php +++ b/mod/quiz/accessrules.php @@ -1,5 +1,4 @@ popup)) { if ($quiz->popup == 1) { - $this->_securewindowrule = new securewindow_access_rule($this->_quizobj, $this->_timenow); + $this->_securewindowrule = new securewindow_access_rule( + $this->_quizobj, $this->_timenow); $this->_rules[] = $this->_securewindowrule; - } elseif ($quiz->popup == 2) { - $this->_safebrowserrule = new safebrowser_access_rule($this->_quizobj, $this->_timenow); + } else if ($quiz->popup == 2) { + $this->_safebrowserrule = new safebrowser_access_rule( + $this->_quizobj, $this->_timenow); $this->_rules[] = $this->_safebrowserrule; } } @@ -154,7 +155,8 @@ public function prevent_access() { * * @param int $numattempts the number of previous attempts this user has made. * @param object $lastattempt information about the user's last completed attempt. - * @return bool true if there is no way the user will ever be allowed to attempt this quiz again. + * @return bool true if there is no way the user will ever be allowed to attempt + * this quiz again. */ public function is_finished($numprevattempts, $lastattempt) { foreach ($this->_rules as $rule) { @@ -185,8 +187,8 @@ public function show_attempt_timer_if_needed($attempt, $timenow) { } } if ($timeleft !== false) { - /// Make sure the timer starts just above zero. If $timeleft was <= 0, then - /// this will just have the effect of causing the quiz to be submitted immediately. + // Make sure the timer starts just above zero. If $timeleft was <= 0, then + // this will just have the effect of causing the quiz to be submitted immediately. $timerstartvalue = max($timeleft, 1); $PAGE->requires->js_init_call('M.mod_quiz.timer.init', array($timerstartvalue), false, quiz_get_js_module()); @@ -202,7 +204,7 @@ public function securewindow_required($canpreview) { /** * @return bolean if this quiz should only be shown to students with safe browser. - */ + */ public function safebrowser_required($canpreview) { return !$canpreview && !is_null($this->_safebrowserrule); } @@ -268,7 +270,8 @@ public function back_to_view_page($canpreview, $message = '') { echo '

' . get_string('pleaseclose', 'quiz') . '

'; $delay = 0; } - $PAGE->requires->js_function_call('M.mod_quiz.secure_window.close', array($url, $delay)); + $PAGE->requires->js_function_call('M.mod_quiz.secure_window.close', + array($url, $delay)); echo $OUTPUT->box_end(); echo $OUTPUT->footer(); die(); @@ -338,11 +341,11 @@ public function do_password_check($canpreview) { public function confirm_start_attempt_message() { $quiz = $this->_quizobj->get_quiz(); if ($quiz->timelimit && $quiz->attempts) { - return get_string('confirmstartattempttimelimit','quiz', $quiz->attempts); + return get_string('confirmstartattempttimelimit', 'quiz', $quiz->attempts); } else if ($quiz->timelimit) { - return get_string('confirmstarttimelimit','quiz'); + return get_string('confirmstarttimelimit', 'quiz'); } else if ($quiz->attempts) { - return get_string('confirmstartattemptlimit','quiz', $quiz->attempts); + return get_string('confirmstartattemptlimit', 'quiz', $quiz->attempts); } return ''; } @@ -352,18 +355,20 @@ public function confirm_start_attempt_message() { * * @param string $linktext some text. * @param object $attempt the attempt object - * @return string some HTML, the $linktext either unmodified or wrapped in a link to the review page. + * @return string some HTML, the $linktext either unmodified or wrapped in a + * link to the review page. */ public function make_review_link($attempt, $canpreview, $reviewoptions) { global $CFG; - /// If review of responses is not allowed, or the attempt is still open, don't link. + // If review of responses is not allowed, or the attempt is still open, don't link. if (!$attempt->timefinish) { return ''; } $when = quiz_attempt_state($this->_quizobj->get_quiz(), $attempt); - $reviewoptions = mod_quiz_display_options::make_from_quiz($this->_quizobj->get_quiz(), $when); + $reviewoptions = mod_quiz_display_options::make_from_quiz( + $this->_quizobj->get_quiz(), $when); if (!$reviewoptions->attempt) { $message = $this->cannot_review_message($when, true); @@ -376,7 +381,7 @@ public function make_review_link($attempt, $canpreview, $reviewoptions) { $linktext = get_string('review', 'quiz'); - /// It is OK to link, does it need to be in a secure window? + // It is OK to link, does it need to be in a secure window? if ($this->securewindow_required($canpreview)) { return $this->_securewindowrule->make_review_link($linktext, $attempt->id); } else { @@ -403,11 +408,13 @@ public function cannot_review_message($when, $short = false) { $langstrsuffix = ''; $dateformat = ''; } - if ($when == mod_quiz_display_options::DURING || $when == mod_quiz_display_options::IMMEDIATELY_AFTER) { + if ($when == mod_quiz_display_options::DURING || + $when == mod_quiz_display_options::IMMEDIATELY_AFTER) { return ''; - } else if ($when == mod_quiz_display_options::LATER_WHILE_OPEN && - $quiz->timeclose && $quiz->reviewattempt & mod_quiz_display_options::AFTER_CLOSE) { - return get_string('noreviewuntil' . $langstrsuffix, 'quiz', userdate($quiz->timeclose, $dateformat)); + } else if ($when == mod_quiz_display_options::LATER_WHILE_OPEN && $quiz->timeclose && + $quiz->reviewattempt & mod_quiz_display_options::AFTER_CLOSE) { + return get_string('noreviewuntil' . $langstrsuffix, 'quiz', + userdate($quiz->timeclose, $dateformat)); } else { return get_string('noreview' . $langstrsuffix, 'quiz'); } @@ -444,14 +451,16 @@ public function __construct($quizobj, $timenow) { * Whether or not a user should be allowed to start a new attempt at this quiz now. * @param int $numattempts the number of previous attempts this user has made. * @param object $lastattempt information about the user's last completed attempt. - * @return string false if access should be allowed, a message explaining the reason if access should be prevented. + * @return string false if access should be allowed, a message explaining the + * reason if access should be prevented. */ public function prevent_new_attempt($numprevattempts, $lastattempt) { return false; } /** * Whether or not a user should be allowed to start a new attempt at this quiz now. - * @return string false if access should be allowed, a message explaining the reason if access should be prevented. + * @return string false if access should be allowed, a message explaining the + * reason if access should be prevented. */ public function prevent_access() { return false; @@ -575,11 +584,11 @@ public function time_left($attempt, $timenow) { class inter_attempt_delay_access_rule extends quiz_access_rule_base { public function prevent_new_attempt($numprevattempts, $lastattempt) { if ($this->_quiz->attempts > 0 && $numprevattempts >= $this->_quiz->attempts) { - /// No more attempts allowed anyway. + // No more attempts allowed anyway. return false; } if ($this->_quiz->timeclose != 0 && $this->_timenow > $this->_quiz->timeclose) { - /// No more attempts allowed anyway. + // No more attempts allowed anyway. return false; } $nextstarttime = $this->compute_next_start_time($numprevattempts, $lastattempt); @@ -606,7 +615,7 @@ protected function compute_next_start_time($numprevattempts, $lastattempt) { } $lastattemptfinish = $lastattempt->timefinish; - if ($this->_quiz->timelimit > 0){ + if ($this->_quiz->timelimit > 0) { $lastattemptfinish = min($lastattemptfinish, $lastattempt->timestart + $this->_quiz->timelimit); } @@ -673,17 +682,17 @@ public function clear_access_allowed() { public function do_password_check($canpreview, $accessmanager) { global $CFG, $SESSION, $OUTPUT, $PAGE; - /// We have already checked the password for this quiz this session, so don't ask again. + // We have already checked the password for this quiz this session, so don't ask again. if (!empty($SESSION->passwordcheckedquizzes[$this->_quiz->id])) { return; } - /// If the user cancelled the password form, send them back to the view page. + // If the user cancelled the password form, send them back to the view page. if (optional_param('cancelpassword', false, PARAM_BOOL)) { $accessmanager->back_to_view_page($canpreview); } - /// If they entered the right password, let them in. + // If they entered the right password, let them in. $enteredpassword = optional_param('quizpassword', '', PARAM_RAW); $validpassword = false; if (strcmp($this->_quiz->password, $enteredpassword) === 0) { @@ -702,15 +711,16 @@ public function do_password_check($canpreview, $accessmanager) { return; } - /// User entered the wrong password, or has not entered one yet, so display the form. + // User entered the wrong password, or has not entered one yet, so display the form. $output = ''; - /// Start the page and print the quiz intro, if any. + // Start the page and print the quiz intro, if any. if ($accessmanager->securewindow_required($canpreview)) { $accessmanager->setup_secure_page($this->_quizobj->get_course()->shortname . ': ' . format_string($this->_quizobj->get_quiz_name())); } else if ($accessmanager->safebrowser_required($canpreview)) { - $PAGE->set_title($this->_quizobj->get_course()->shortname . ': '.format_string($this->_quizobj->get_quiz_name())); + $PAGE->set_title($this->_quizobj->get_course()->shortname . ': ' . + format_string($this->_quizobj->get_quiz_name())); $PAGE->set_cacheable(false); echo $OUTPUT->header(); } else { @@ -719,16 +729,17 @@ public function do_password_check($canpreview, $accessmanager) { } if (trim(strip_tags($this->_quiz->intro))) { - $output .= $OUTPUT->box(format_module_intro('quiz', $this->_quiz, $this->_quizobj->get_cmid()), 'generalbox', 'intro'); + $output .= $OUTPUT->box(format_module_intro('quiz', $this->_quiz, + $this->_quizobj->get_cmid()), 'generalbox', 'intro'); } $output .= $OUTPUT->box_start('generalbox', 'passwordbox'); - /// If they have previously tried and failed to enter a password, tell them it was wrong. + // If they have previously tried and failed to enter a password, tell them it was wrong. if (!empty($enteredpassword)) { $output .= '

' . get_string('passworderror', 'quiz') . '

'; } - /// Print the password entry form. + // Print the password entry form. $output .= '

' . get_string('requirepasswordmessage', 'quiz') . "

\n"; $output .= '
' . "\n"; @@ -744,10 +755,10 @@ public function do_password_check($canpreview, $accessmanager) { $output .= "\n"; $output .= "
\n"; - /// Finish page. + // Finish page. $output .= $OUTPUT->box_end(); - /// return or display form. + // return or display form. echo $output; echo $OUTPUT->footer(); exit; diff --git a/mod/quiz/addrandom.php b/mod/quiz/addrandom.php index 9ff0afe86f929..9950735746d5e 100644 --- a/mod/quiz/addrandom.php +++ b/mod/quiz/addrandom.php @@ -1,5 +1,4 @@ view_url(); } @@ -128,8 +128,9 @@ public function preload_questions() { array('quizid' => $this->quiz->id)); } - /** - * Fully load some or all of the questions for this quiz. You must call {@link preload_questions()} first. + /** + * Fully load some or all of the questions for this quiz. You must call + * {@link preload_questions()} first. * * @param array $questionids question ids of the questions to load. null for all. */ @@ -238,12 +239,13 @@ public function get_questions($questionids = null) { /** * @param int $timenow the current time as a unix timestamp. - * @return quiz_access_manager and instance of the quiz_access_manager class for this quiz at this time. + * @return quiz_access_manager and instance of the quiz_access_manager class + * for this quiz at this time. */ public function get_access_manager($timenow) { if (is_null($this->accessmanager)) { $this->accessmanager = new quiz_access_manager($this, $timenow, - has_capability('mod/quiz:ignoretimelimits', $this->context, NULL, false)); + has_capability('mod/quiz:ignoretimelimits', $this->context, null, false)); } return $this->accessmanager; } @@ -251,14 +253,14 @@ public function get_access_manager($timenow) { /** * Wrapper round the has_capability funciton that automatically passes in the quiz context. */ - public function has_capability($capability, $userid = NULL, $doanything = true) { + public function has_capability($capability, $userid = null, $doanything = true) { return has_capability($capability, $this->context, $userid, $doanything); } /** * Wrapper round the require_capability funciton that automatically passes in the quiz context. */ - public function require_capability($capability, $userid = NULL, $doanything = true) { + public function require_capability($capability, $userid = null, $doanything = true) { return require_capability($capability, $this->context, $userid, $doanything); } @@ -319,8 +321,8 @@ public function navigation($title) { // Private methods ===================================================================== /** - * Check that the definition of a particular question is loaded, and if not throw an exception. - * @param $id a questionid. + * Check that the definition of a particular question is loaded, and if not throw an exception. + * @param $id a questionid. */ protected function ensure_question_loaded($id) { if (isset($this->questions[$id]->_partiallyloaded)) { @@ -372,11 +374,11 @@ public function __construct($attempt, $quiz, $cm, $course) { protected static function create_helper($conditions) { global $DB; -// TODO deal with the issue that makes this necessary. -// if (!$DB->record_exists('question_sessions', array('attemptid' => $attempt->uniqueid))) { -// // this attempt has not yet been upgraded to the new model -// quiz_upgrade_states($attempt); -// } + // TODO deal with the issue that makes this necessary. + // if (!$DB->record_exists('question_sessions', array('attemptid' => $attempt->uniqueid))) { + // // this attempt has not yet been upgraded to the new model + // quiz_upgrade_states($attempt); + // } $attempt = $DB->get_record('quiz_attempts', $conditions, '*', MUST_EXIST); $quiz = $DB->get_record('quiz', array('id' => $attempt->quiz), '*', MUST_EXIST); @@ -507,7 +509,8 @@ public function get_num_pages() { /** * @param int $timenow the current time as a unix timestamp. - * @return quiz_access_manager and instance of the quiz_access_manager class for this quiz at this time. + * @return quiz_access_manager and instance of the quiz_access_manager class + * for this quiz at this time. */ public function get_access_manager($timenow) { return $this->quizobj->get_access_manager($timenow); @@ -538,7 +541,10 @@ public function get_userid() { return $this->attempt->userid; } - /** @return bool whether this attempt has been finished (true) or is still in progress (false). */ + /** + * @return bool whether this attempt has been finished (true) or is still + * in progress (false). + */ public function is_finished() { return $this->attempt->timefinish != 0; } @@ -588,7 +594,8 @@ public function is_review_allowed() { // Check the users have at least one group in common. $teachersgroups = groups_get_activity_allowed_groups($cm); - $studentsgroups = groups_get_all_groups($cm->course, $this->attempt->userid, $cm->groupingid); + $studentsgroups = groups_get_all_groups( + $cm->course, $this->attempt->userid, $cm->groupingid); return $teachersgroups && $studentsgroups && array_intersect(array_keys($teachersgroups), array_keys($studentsgroups)); } @@ -605,14 +612,14 @@ public function get_overall_feedback($grade) { /** * Wrapper round the has_capability funciton that automatically passes in the quiz context. */ - public function has_capability($capability, $userid = NULL, $doanything = true) { + public function has_capability($capability, $userid = null, $doanything = true) { return $this->quizobj->has_capability($capability, $userid, $doanything); } /** * Wrapper round the require_capability funciton that automatically passes in the quiz context. */ - public function require_capability($capability, $userid = NULL, $doanything = true) { + public function require_capability($capability, $userid = null, $doanything = true) { return $this->quizobj->require_capability($capability, $userid, $doanything); } @@ -715,35 +722,41 @@ public function is_question_flagged($slot) { } /** - * Return the grade obtained on a particular question, if the user is permitted to see it. - * You must previously have called load_question_states to load the state data about this question. + * Return the grade obtained on a particular question, if the user is permitted + * to see it. You must previously have called load_question_states to load the + * state data about this question. * * @param int $slot the number used to identify this question within this attempt. - * @return string the formatted grade, to the number of decimal places specified by the quiz. + * @return string the formatted grade, to the number of decimal places specified + * by the quiz. */ public function get_question_number($slot) { return $this->quba->get_question($slot)->_number; } /** - * Return the grade obtained on a particular question, if the user is permitted to see it. - * You must previously have called load_question_states to load the state data about this question. + * Return the grade obtained on a particular question, if the user is permitted + * to see it. You must previously have called load_question_states to load the + * state data about this question. * * @param int $slot the number used to identify this question within this attempt. - * @return string the formatted grade, to the number of decimal places specified by the quiz. + * @return string the formatted grade, to the number of decimal places specified + * by the quiz. */ public function get_question_name($slot) { return $this->quba->get_question($slot)->name; } /** - * Return the grade obtained on a particular question, if the user is permitted to see it. - * You must previously have called load_question_states to load the state data about this question. + * Return the grade obtained on a particular question, if the user is permitted + * to see it. You must previously have called load_question_states to load the + * state data about this question. * * @param int $slot the number used to identify this question within this attempt. * @param bool $showcorrectness Whether right/partial/wrong states should * be distinguised. - * @return string the formatted grade, to the number of decimal places specified by the quiz. + * @return string the formatted grade, to the number of decimal places specified + * by the quiz. */ public function get_question_status($slot, $showcorrectness) { return $this->quba->get_question_state_string($slot, $showcorrectness); @@ -911,7 +924,8 @@ public function render_question_for_commenting($slot) { $options = $this->get_display_options(true); $options->hide_all_feedback(); $options->manualcomment = question_display_options::EDITABLE; - return $this->quba->render_question($slot, $options, $this->quba->get_question($slot)->_number); + return $this->quba->render_question($slot, $options, + $this->quba->get_question($slot)->_number); } /** @@ -1054,8 +1068,10 @@ public function question_print_comment_fields($slot, $prefix) { * Used by {@link attempt_url()} and {@link review_url()}. * * @param string $script. Used in the URL like /mod/quiz/$script.php - * @param int $slot identifies the specific question on the page to jump to. 0 to just use the $page parameter. - * @param int $page -1 to look up the page number from the slot, otherwise the page number to go to. + * @param int $slot identifies the specific question on the page to jump to. + * 0 to just use the $page parameter. + * @param int $page -1 to look up the page number from the slot, otherwise + * the page number to go to. * @param bool $showall if true, return a URL with showall=1, and not page number * @param int $thispage the page we are currently on. Links to questions on this * page will just be a fragment #q123. -1 to disable this. diff --git a/mod/quiz/backup/moodle2/backup_quiz_activity_task.class.php b/mod/quiz/backup/moodle2/backup_quiz_activity_task.class.php index dedde469d02f9..e5092f4b42fdf 100644 --- a/mod/quiz/backup/moodle2/backup_quiz_activity_task.class.php +++ b/mod/quiz/backup/moodle2/backup_quiz_activity_task.class.php @@ -1,5 +1,4 @@ dirroot . '/mod/quiz/backup/moodle2/restore_quiz_stepslib.php'); // Because it exists (must) +require_once($CFG->dirroot . '/mod/quiz/backup/moodle2/restore_quiz_stepslib.php'); +// Because it exists (must) /** @@ -60,7 +60,8 @@ public static function define_decode_contents() { $contents = array(); $contents[] = new restore_decode_content('quiz', array('intro'), 'quiz'); - $contents[] = new restore_decode_content('quiz_feedback', array('feedbacktext'), 'quiz_feedback'); + $contents[] = new restore_decode_content('quiz_feedback', + array('feedbacktext'), 'quiz_feedback'); return $contents; } @@ -72,9 +73,12 @@ public static function define_decode_contents() { public static function define_decode_rules() { $rules = array(); - $rules[] = new restore_decode_rule('QUIZVIEWBYID', '/mod/quiz/view.php?id=$1', 'course_module'); - $rules[] = new restore_decode_rule('QUIZVIEWBYQ', '/mod/quiz/view.php?q=$1', 'quiz'); - $rules[] = new restore_decode_rule('QUIZINDEX', '/mod/quiz/index.php?id=$1', 'course'); + $rules[] = new restore_decode_rule('QUIZVIEWBYID', + '/mod/quiz/view.php?id=$1', 'course_module'); + $rules[] = new restore_decode_rule('QUIZVIEWBYQ', + '/mod/quiz/view.php?q=$1', 'quiz'); + $rules[] = new restore_decode_rule('QUIZINDEX', + '/mod/quiz/index.php?id=$1', 'course'); return $rules; @@ -89,51 +93,77 @@ public static function define_decode_rules() { public static function define_restore_log_rules() { $rules = array(); - $rules[] = new restore_log_rule('quiz', 'add', 'view.php?id={course_module}', '{quiz}'); - $rules[] = new restore_log_rule('quiz', 'update', 'view.php?id={course_module}', '{quiz}'); - $rules[] = new restore_log_rule('quiz', 'view', 'view.php?id={course_module}', '{quiz}'); - $rules[] = new restore_log_rule('quiz', 'preview', 'view.php?id={course_module}', '{quiz}'); - $rules[] = new restore_log_rule('quiz', 'report', 'report.php?id={course_module}', '{quiz}'); - $rules[] = new restore_log_rule('quiz', 'editquestions', 'view.php?id={course_module}', '{quiz}'); - $rules[] = new restore_log_rule('quiz', 'delete attempt', 'report.php?id={course_module}', '[oldattempt]'); - $rules[] = new restore_log_rule('quiz', 'edit override', 'overrideedit.php?id={quiz_override}', '{quiz}'); - $rules[] = new restore_log_rule('quiz', 'delete override', 'overrides.php.php?cmid={course_module}', '{quiz}'); - $rules[] = new restore_log_rule('quiz', 'addcategory', 'view.php?id={course_module}', '{question_category}'); - $rules[] = new restore_log_rule('quiz', 'view summary', 'summary.php?attempt={quiz_attempt_id}', '{quiz}'); - $rules[] = new restore_log_rule('quiz', 'manualgrade', 'comment.php?attempt={quiz_attempt_id}&question={question}', '{quiz}'); - $rules[] = new restore_log_rule('quiz', 'manualgrading', 'report.php?mode=grading&q={quiz}', '{quiz}'); + $rules[] = new restore_log_rule('quiz', 'add', + 'view.php?id={course_module}', '{quiz}'); + $rules[] = new restore_log_rule('quiz', 'update', + 'view.php?id={course_module}', '{quiz}'); + $rules[] = new restore_log_rule('quiz', 'view', + 'view.php?id={course_module}', '{quiz}'); + $rules[] = new restore_log_rule('quiz', 'preview', + 'view.php?id={course_module}', '{quiz}'); + $rules[] = new restore_log_rule('quiz', 'report', + 'report.php?id={course_module}', '{quiz}'); + $rules[] = new restore_log_rule('quiz', 'editquestions', + 'view.php?id={course_module}', '{quiz}'); + $rules[] = new restore_log_rule('quiz', 'delete attempt', + 'report.php?id={course_module}', '[oldattempt]'); + $rules[] = new restore_log_rule('quiz', 'edit override', + 'overrideedit.php?id={quiz_override}', '{quiz}'); + $rules[] = new restore_log_rule('quiz', 'delete override', + 'overrides.php.php?cmid={course_module}', '{quiz}'); + $rules[] = new restore_log_rule('quiz', 'addcategory', + 'view.php?id={course_module}', '{question_category}'); + $rules[] = new restore_log_rule('quiz', 'view summary', + 'summary.php?attempt={quiz_attempt_id}', '{quiz}'); + $rules[] = new restore_log_rule('quiz', 'manualgrade', + 'comment.php?attempt={quiz_attempt_id}&question={question}', '{quiz}'); + $rules[] = new restore_log_rule('quiz', 'manualgrading', + 'report.php?mode=grading&q={quiz}', '{quiz}'); // All the ones calling to review.php have two rules to handle both old and new urls // in any case they are always converted to new urls on restore // TODO: In Moodle 2.x (x >= 5) kill the old rules - // Note we are using the 'quiz_attempt_id' mapping becuase that is the one containing the quiz_attempt->ids - // old an new for quiz-attempt - $rules[] = new restore_log_rule('quiz', 'attempt', 'review.php?id={course_module}&attempt={quiz_attempt}', '{quiz}', - null, null, 'review.php?attempt={quiz_attempt}'); + // Note we are using the 'quiz_attempt_id' mapping becuase that is the + // one containing the quiz_attempt->ids old an new for quiz-attempt + $rules[] = new restore_log_rule('quiz', 'attempt', + 'review.php?id={course_module}&attempt={quiz_attempt}', '{quiz}', + null, null, 'review.php?attempt={quiz_attempt}'); // old an new for quiz-submit - $rules[] = new restore_log_rule('quiz', 'submit', 'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}', - null, null, 'review.php?attempt={quiz_attempt_id}'); - $rules[] = new restore_log_rule('quiz', 'submit', 'review.php?attempt={quiz_attempt_id}', '{quiz}'); + $rules[] = new restore_log_rule('quiz', 'submit', + 'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}', + null, null, 'review.php?attempt={quiz_attempt_id}'); + $rules[] = new restore_log_rule('quiz', 'submit', + 'review.php?attempt={quiz_attempt_id}', '{quiz}'); // old an new for quiz-review - $rules[] = new restore_log_rule('quiz', 'review', 'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}', - null, null, 'review.php?attempt={quiz_attempt_id}'); - $rules[] = new restore_log_rule('quiz', 'review', 'review.php?attempt={quiz_attempt_id}', '{quiz}'); + $rules[] = new restore_log_rule('quiz', 'review', + 'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}', + null, null, 'review.php?attempt={quiz_attempt_id}'); + $rules[] = new restore_log_rule('quiz', 'review', + 'review.php?attempt={quiz_attempt_id}', '{quiz}'); // old an new for quiz-start attemp - $rules[] = new restore_log_rule('quiz', 'start attempt', 'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}', - null, null, 'review.php?attempt={quiz_attempt_id}'); - $rules[] = new restore_log_rule('quiz', 'start attempt', 'review.php?attempt={quiz_attempt_id}', '{quiz}'); + $rules[] = new restore_log_rule('quiz', 'start attempt', + 'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}', + null, null, 'review.php?attempt={quiz_attempt_id}'); + $rules[] = new restore_log_rule('quiz', 'start attempt', + 'review.php?attempt={quiz_attempt_id}', '{quiz}'); // old an new for quiz-close attemp - $rules[] = new restore_log_rule('quiz', 'close attempt', 'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}', - null, null, 'review.php?attempt={quiz_attempt_id}'); - $rules[] = new restore_log_rule('quiz', 'close attempt', 'review.php?attempt={quiz_attempt_id}', '{quiz}'); + $rules[] = new restore_log_rule('quiz', 'close attempt', + 'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}', + null, null, 'review.php?attempt={quiz_attempt_id}'); + $rules[] = new restore_log_rule('quiz', 'close attempt', + 'review.php?attempt={quiz_attempt_id}', '{quiz}'); // old an new for quiz-continue attempt - $rules[] = new restore_log_rule('quiz', 'continue attempt', 'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}', - null, null, 'review.php?attempt={quiz_attempt_id}'); - $rules[] = new restore_log_rule('quiz', 'continue attempt', 'review.php?attempt={quiz_attempt_id}', '{quiz}'); + $rules[] = new restore_log_rule('quiz', 'continue attempt', + 'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}', + null, null, 'review.php?attempt={quiz_attempt_id}'); + $rules[] = new restore_log_rule('quiz', 'continue attempt', + 'review.php?attempt={quiz_attempt_id}', '{quiz}'); // old an new for quiz-continue attemp - $rules[] = new restore_log_rule('quiz', 'continue attemp', 'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}', - null, 'continue attempt', 'review.php?attempt={quiz_attempt_id}'); - $rules[] = new restore_log_rule('quiz', 'continue attemp', 'review.php?attempt={quiz_attempt_id}', '{quiz}', - null, 'continue attempt'); + $rules[] = new restore_log_rule('quiz', 'continue attemp', + 'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}', + null, 'continue attempt', 'review.php?attempt={quiz_attempt_id}'); + $rules[] = new restore_log_rule('quiz', 'continue attemp', + 'review.php?attempt={quiz_attempt_id}', '{quiz}', + null, 'continue attempt'); return $rules; } diff --git a/mod/quiz/backup/moodle2/restore_quiz_stepslib.php b/mod/quiz/backup/moodle2/restore_quiz_stepslib.php index fd8a19151d3bf..68da356999f58 100644 --- a/mod/quiz/backup/moodle2/restore_quiz_stepslib.php +++ b/mod/quiz/backup/moodle2/restore_quiz_stepslib.php @@ -1,5 +1,4 @@ get_manager(); -//===== 1.9.0 upgrade line ======// + //===== 1.9.0 upgrade line ======// if ($oldversion < 2008062000) { - /// Define table quiz_report to be created + // Define table quiz_report to be created $table = new xmldb_table('quiz_report'); - /// Adding fields to table quiz_report - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null); - $table->add_field('displayorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); + // Adding fields to table quiz_report + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, + null, null, null); + $table->add_field('displayorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, null); - /// Adding keys to table quiz_report + // Adding keys to table quiz_report $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - /// Conditionally launch create table for quiz_report + // Conditionally launch create table for quiz_report if (!$dbman->table_exists($table)) { $dbman->create_table($table); } @@ -86,60 +88,64 @@ function xmldb_quiz_upgrade($oldversion) { if ($oldversion < 2008072402) { - /// Define field lastcron to be added to quiz_report + // Define field lastcron to be added to quiz_report $table = new xmldb_table('quiz_report'); - $field = new xmldb_field('lastcron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'displayorder'); + $field = new xmldb_field('lastcron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, '0', 'displayorder'); - /// Conditionally launch add field lastcron + // Conditionally launch add field lastcron if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } - /// Define field cron to be added to quiz_report - $field = new xmldb_field('cron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'lastcron'); + // Define field cron to be added to quiz_report + $field = new xmldb_field('cron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, '0', 'lastcron'); - /// Conditionally launch add field cron + // Conditionally launch add field cron if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } - /// quiz savepoint reached + // quiz savepoint reached upgrade_mod_savepoint(true, 2008072402, 'quiz'); } if ($oldversion < 2008072900) { - /// Delete the regrade report - it is now part of the overview report. + // Delete the regrade report - it is now part of the overview report. $DB->delete_records('quiz_report', array('name' => 'regrade')); - /// quiz savepoint reached + // quiz savepoint reached upgrade_mod_savepoint(true, 2008072900, 'quiz'); } if ($oldversion < 2008081500) { - /// Define table quiz_question_versions to be dropped + // Define table quiz_question_versions to be dropped $table = new xmldb_table('quiz_question_versions'); - /// Launch drop table for quiz_question_versions + // Launch drop table for quiz_question_versions $dbman->drop_table($table); - /// quiz savepoint reached + // quiz savepoint reached upgrade_mod_savepoint(true, 2008081500, 'quiz'); } - /// Changing the type of all the columns that store grades to be NUMBER(10, 5) or similar. + // Changing the type of all the columns that store grades to be NUMBER(10, 5) or similar. if ($oldversion < 2008081501) { // First set all quiz.sumgrades to 0 if they are null. This should never // happen however some users have encountered a null value there. $DB->execute('UPDATE {quiz} SET sumgrades=0 WHERE sumgrades IS NULL'); $table = new xmldb_table('quiz'); - $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'questions'); + $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, + XMLDB_NOTNULL, null, '0', 'questions'); $dbman->change_field_type($table, $field); upgrade_mod_savepoint(true, 2008081501, 'quiz'); } if ($oldversion < 2008081502) { $table = new xmldb_table('quiz'); - $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'sumgrades'); + $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, + XMLDB_NOTNULL, null, '0', 'sumgrades'); $dbman->change_field_type($table, $field); upgrade_mod_savepoint(true, 2008081502, 'quiz'); } @@ -149,40 +155,45 @@ function xmldb_quiz_upgrade($oldversion) { // happen however some users have encountered a null value there. $DB->execute('UPDATE {quiz_attempts} SET sumgrades=0 WHERE sumgrades IS NULL'); $table = new xmldb_table('quiz_attempts'); - $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'attempt'); + $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, + XMLDB_NOTNULL, null, '0', 'attempt'); $dbman->change_field_type($table, $field); upgrade_mod_savepoint(true, 2008081503, 'quiz'); } if ($oldversion < 2008081504) { $table = new xmldb_table('quiz_feedback'); - $field = new xmldb_field('mingrade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'feedbacktext'); + $field = new xmldb_field('mingrade', XMLDB_TYPE_NUMBER, '10, 5', null, + XMLDB_NOTNULL, null, '0', 'feedbacktext'); $dbman->change_field_type($table, $field); upgrade_mod_savepoint(true, 2008081504, 'quiz'); } if ($oldversion < 2008081505) { $table = new xmldb_table('quiz_feedback'); - $field = new xmldb_field('maxgrade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'mingrade'); + $field = new xmldb_field('maxgrade', XMLDB_TYPE_NUMBER, '10, 5', null, + XMLDB_NOTNULL, null, '0', 'mingrade'); $dbman->change_field_type($table, $field); upgrade_mod_savepoint(true, 2008081505, 'quiz'); } if ($oldversion < 2008081506) { $table = new xmldb_table('quiz_grades'); - $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'userid'); + $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, + XMLDB_NOTNULL, null, '0', 'userid'); $dbman->change_field_type($table, $field); upgrade_mod_savepoint(true, 2008081506, 'quiz'); } if ($oldversion < 2008081507) { $table = new xmldb_table('quiz_question_instances'); - $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0', 'question'); + $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, + XMLDB_NOTNULL, null, '0', 'question'); $dbman->change_field_type($table, $field); upgrade_mod_savepoint(true, 2008081507, 'quiz'); } - /// Move all of the quiz config settings from $CFG to the config_plugins table. + // Move all of the quiz config settings from $CFG to the config_plugins table. if ($oldversion < 2008082200) { foreach (get_object_vars($CFG) as $name => $value) { if (strpos($name, 'quiz_') === 0) { @@ -198,11 +209,11 @@ function xmldb_quiz_upgrade($oldversion) { upgrade_mod_savepoint(true, 2008082200, 'quiz'); } - /// Now that the quiz is no longer responsible for creating all the question - /// bank tables, and some of the tables are now the responsibility of the - /// datasetdependent question type, which did not have a version.php file before, - /// we need to say that these tables are already installed, otherwise XMLDB - /// will try to create them again and give an error. + // Now that the quiz is no longer responsible for creating all the question + // bank tables, and some of the tables are now the responsibility of the + // datasetdependent question type, which did not have a version.php file before, + // we need to say that these tables are already installed, otherwise XMLDB + // will try to create them again and give an error. if ($oldversion < 2008082600) { // Since MDL-16505 was fixed, and we eliminated the datasetdependent // question type, this is now a no-op. @@ -211,37 +222,39 @@ function xmldb_quiz_upgrade($oldversion) { if ($oldversion < 2008112101) { - /// Define field lastcron to be added to quiz_report + // Define field lastcron to be added to quiz_report $table = new xmldb_table('quiz_report'); - $field = new xmldb_field('capability', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'cron'); + $field = new xmldb_field('capability', XMLDB_TYPE_CHAR, '255', null, + null, null, null, 'cron'); - /// Conditionally launch add field lastcron + // Conditionally launch add field lastcron if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } - /// quiz savepoint reached + // quiz savepoint reached upgrade_mod_savepoint(true, 2008112101, 'quiz'); } if ($oldversion < 2009010700) { - /// Define field showuserpicture to be added to quiz + // Define field showuserpicture to be added to quiz $table = new xmldb_table('quiz'); - $field = new xmldb_field('showuserpicture', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'delay2'); + $field = new xmldb_field('showuserpicture', XMLDB_TYPE_INTEGER, '4', null, + XMLDB_NOTNULL, null, '0', 'delay2'); - /// Conditionally launch add field showuserpicture + // Conditionally launch add field showuserpicture if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } - /// quiz savepoint reached + // quiz savepoint reached upgrade_mod_savepoint(true, 2009010700, 'quiz'); } if ($oldversion < 2009030900) { - /// If there are no quiz settings set to advanced yet, the set up the default - /// advanced fields from Moodle 2.0. + // If there are no quiz settings set to advanced yet, the set up the default + // advanced fields from Moodle 2.0. $quizconfig = get_config('quiz'); $arealreadyadvanced = false; foreach (array($quizconfig) as $name => $value) { @@ -262,37 +275,39 @@ function xmldb_quiz_upgrade($oldversion) { set_config('fix_popup', 1, 'quiz'); } - /// quiz savepoint reached + // quiz savepoint reached upgrade_mod_savepoint(true, 2009030900, 'quiz'); } if ($oldversion < 2009031000) { - /// Add new questiondecimaldigits setting, separate form the overall decimaldigits one. + // Add new questiondecimaldigits setting, separate form the overall decimaldigits one. $table = new xmldb_table('quiz'); - $field = new xmldb_field('questiondecimalpoints', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '-2', 'decimalpoints'); + $field = new xmldb_field('questiondecimalpoints', XMLDB_TYPE_INTEGER, '4', null, + XMLDB_NOTNULL, null, '-2', 'decimalpoints'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } - /// quiz savepoint reached + // quiz savepoint reached upgrade_mod_savepoint(true, 2009031000, 'quiz'); } if ($oldversion < 2009031001) { - /// Convert quiz.timelimit from minutes to seconds. + // Convert quiz.timelimit from minutes to seconds. $DB->execute('UPDATE {quiz} SET timelimit = timelimit * 60'); $default = get_config('quiz', 'timelimit'); set_config('timelimit', 60 * $default, 'quiz'); - /// quiz savepoint reached + // quiz savepoint reached upgrade_mod_savepoint(true, 2009031001, 'quiz'); } if ($oldversion < 2009042000) { - /// Define field introformat to be added to quiz + // Define field introformat to be added to quiz $table = new xmldb_table('quiz'); - $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro'); + $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, '0', 'intro'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); @@ -300,7 +315,8 @@ function xmldb_quiz_upgrade($oldversion) { // conditionally migrate to html format in intro if ($CFG->texteditors !== 'textarea') { - $rs = $DB->get_recordset('quiz', array('introformat' => FORMAT_MOODLE), '', 'id,intro,introformat'); + $rs = $DB->get_recordset('quiz', array('introformat' => FORMAT_MOODLE), + '', 'id, intro, introformat'); foreach ($rs as $q) { $q->intro = text_to_html($q->intro, false, false, true); $q->introformat = FORMAT_HTML; @@ -310,37 +326,45 @@ function xmldb_quiz_upgrade($oldversion) { $rs->close(); } - /// quiz savepoint reached + // quiz savepoint reached upgrade_mod_savepoint(true, 2009042000, 'quiz'); } if ($oldversion < 2010030501) { - /// Define table quiz_overrides to be created + // Define table quiz_overrides to be created $table = new xmldb_table('quiz_overrides'); - /// Adding fields to table quiz_overrides - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('quiz', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); - $table->add_field('groupid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); - $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); - $table->add_field('timeopen', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); - $table->add_field('timeclose', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); - $table->add_field('timelimit', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); - $table->add_field('attempts', XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, null, null, null); + // Adding fields to table quiz_overrides + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('quiz', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, '0'); + $table->add_field('groupid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + null, null, null); + $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + null, null, null); + $table->add_field('timeopen', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + null, null, null); + $table->add_field('timeclose', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + null, null, null); + $table->add_field('timelimit', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + null, null, null); + $table->add_field('attempts', XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, + null, null, null); $table->add_field('password', XMLDB_TYPE_CHAR, '255', null, null, null, null); - /// Adding keys to table quiz_overrides + // Adding keys to table quiz_overrides $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('quiz', XMLDB_KEY_FOREIGN, array('quiz'), 'quiz', array('id')); $table->add_key('groupid', XMLDB_KEY_FOREIGN, array('groupid'), 'groups', array('id')); $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); - /// Conditionally launch create table for quiz_overrides + // Conditionally launch create table for quiz_overrides if (!$dbman->table_exists($table)) { $dbman->create_table($table); } - /// quiz savepoint reached + // quiz savepoint reached upgrade_mod_savepoint(true, 2010030501, 'quiz'); } @@ -348,7 +372,8 @@ function xmldb_quiz_upgrade($oldversion) { // Define field showblocks to be added to quiz $table = new xmldb_table('quiz'); - $field = new xmldb_field('showblocks', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'showuserpicture'); + $field = new xmldb_field('showblocks', XMLDB_TYPE_INTEGER, '4', null, + XMLDB_NOTNULL, null, '0', 'showuserpicture'); // Conditionally launch add field showblocks if (!$dbman->field_exists($table, $field)) { @@ -363,7 +388,8 @@ function xmldb_quiz_upgrade($oldversion) { // Define field feedbacktextformat to be added to quiz_feedback $table = new xmldb_table('quiz_feedback'); - $field = new xmldb_field('feedbacktextformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'feedbacktext'); + $field = new xmldb_field('feedbacktextformat', XMLDB_TYPE_INTEGER, '2', null, + XMLDB_NOTNULL, null, '0', 'feedbacktext'); // Conditionally launch add field feedbacktextformat if (!$dbman->field_exists($table, $field)) { @@ -381,7 +407,8 @@ function xmldb_quiz_upgrade($oldversion) { // Define field showblocks to be added to quiz // Repeat this step, because the column was missing from install.xml for a time. $table = new xmldb_table('quiz'); - $field = new xmldb_field('showblocks', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'showuserpicture'); + $field = new xmldb_field('showblocks', XMLDB_TYPE_INTEGER, '4', null, + XMLDB_NOTNULL, null, '0', 'showuserpicture'); // Conditionally launch add field showblocks if (!$dbman->field_exists($table, $field)) { @@ -398,28 +425,32 @@ function xmldb_quiz_upgrade($oldversion) { $columns = $DB->get_columns('quiz'); // quiz.questiondecimalpoints should be int (4) not null default -2 - if (array_key_exists('questiondecimalpoints', $columns) && $columns['questiondecimalpoints']->default_value != '-2') { - $field = new xmldb_field('questiondecimalpoints', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, -2, 'decimalpoints'); + if (array_key_exists('questiondecimalpoints', $columns) && + $columns['questiondecimalpoints']->default_value != '-2') { + $field = new xmldb_field('questiondecimalpoints', XMLDB_TYPE_INTEGER, '4', null, + XMLDB_NOTNULL, null, -2, 'decimalpoints'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } } - // quiz.sumgrades should be decimal(10,5) not null default 0 + // quiz.sumgrades should be decimal(10, 5) not null default 0 if (array_key_exists('sumgrades', $columns) && empty($columns['sumgrades']->not_null)) { // First set all quiz.sumgrades to 0 if they are null. This should never // happen however some users have encountered a null value there. $DB->execute('UPDATE {quiz} SET sumgrades=0 WHERE sumgrades IS NULL'); - $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'questions'); + $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, + XMLDB_NOTNULL, null, '0', 'questions'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } } - // quiz.grade should be decimal(10,5) not null default 0 + // quiz.grade should be decimal(10, 5) not null default 0 if (array_key_exists('grade', $columns) && empty($columns['grade']->not_null)) { - $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'sumgrades'); + $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, + XMLDB_NOTNULL, null, '0', 'sumgrades'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } @@ -433,13 +464,14 @@ function xmldb_quiz_upgrade($oldversion) { $table = new xmldb_table('quiz_attempts'); $columns = $DB->get_columns('quiz_attempts'); - // quiz_attempts.sumgrades should be decimal(10,5) not null default 0 + // quiz_attempts.sumgrades should be decimal(10, 5) not null default 0 if (array_key_exists('sumgrades', $columns) && empty($columns['sumgrades']->not_null)) { // First set all quiz.sumgrades to 0 if they are null. This should never // happen however some users have encountered a null value there. $DB->execute('UPDATE {quiz_attempts} SET sumgrades=0 WHERE sumgrades IS NULL'); - $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'attempt'); + $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, + XMLDB_NOTNULL, null, '0', 'attempt'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } @@ -453,18 +485,20 @@ function xmldb_quiz_upgrade($oldversion) { $table = new xmldb_table('quiz_feedback'); $columns = $DB->get_columns('quiz_feedback'); - // quiz_feedback.mingrade should be decimal(10,5) not null default 0 + // quiz_feedback.mingrade should be decimal(10, 5) not null default 0 if (array_key_exists('mingrade', $columns) && empty($columns['mingrade']->not_null)) { - $field = new xmldb_field('mingrade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'feedbacktextformat'); + $field = new xmldb_field('mingrade', XMLDB_TYPE_NUMBER, '10, 5', null, + XMLDB_NOTNULL, null, '0', 'feedbacktextformat'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } } - // quiz_feedback.maxgrade should be decimal(10,5) not null default 0 + // quiz_feedback.maxgrade should be decimal(10, 5) not null default 0 if (array_key_exists('maxgrade', $columns) && empty($columns['maxgrade']->not_null)) { // Fixed in earlier upgrade code - $field = new xmldb_field('maxgrade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'mingrade'); + $field = new xmldb_field('maxgrade', XMLDB_TYPE_NUMBER, '10, 5', null, + XMLDB_NOTNULL, null, '0', 'mingrade'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } @@ -478,9 +512,10 @@ function xmldb_quiz_upgrade($oldversion) { $table = new xmldb_table('quiz_grades'); $columns = $DB->get_columns('quiz_grades'); - // quiz_grades.grade should be decimal(10,5) not null default 0 + // quiz_grades.grade should be decimal(10, 5) not null default 0 if (array_key_exists('grade', $columns) && empty($columns['grade']->not_null)) { - $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'userid'); + $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, + XMLDB_NOTNULL, null, '0', 'userid'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } @@ -494,9 +529,10 @@ function xmldb_quiz_upgrade($oldversion) { $table = new xmldb_table('quiz_question_instances'); $columns = $DB->get_columns('quiz_question_instances'); - // quiz_question_instances.grade should be decimal(12,7) not null default 0 + // quiz_question_instances.grade should be decimal(12, 7) not null default 0 if (array_key_exists('grade', $columns) && empty($columns['grade']->not_null)) { - $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0', 'question'); + $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, + XMLDB_NOTNULL, null, '0', 'question'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } diff --git a/mod/quiz/edit.php b/mod/quiz/edit.php index e65105354681d..1241f8a8cdd0b 100644 --- a/mod/quiz/edit.php +++ b/mod/quiz/edit.php @@ -1,5 +1,4 @@ larrow() . ' ' . get_string('addtoquiz', 'quiz') . - '" ' . $disabled . "/>\n"; + $out = '\n"; return $out; } @@ -212,7 +211,7 @@ function module_specific_controls($totalnumber, $recurse, $category, $cmid, $cmo } if (($addquestion = optional_param('addquestion', 0, PARAM_INT)) && confirm_sesskey()) { -/// Add a single question to the current quiz + // Add a single question to the current quiz $addonpage = optional_param('addonpage', 0, PARAM_INT); quiz_add_quiz_question($addquestion, $quiz, $addonpage); quiz_delete_previews($quiz); @@ -222,7 +221,7 @@ function module_specific_controls($totalnumber, $recurse, $category, $cmid, $cmo } if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) { -/// Add selected questions to the current quiz + // Add selected questions to the current quiz $rawdata = (array) data_submitted(); foreach ($rawdata as $key => $value) { // Parse input for question ids if (preg_match('!^q([0-9]+)$!', $key, $matches)) { @@ -248,7 +247,8 @@ function module_specific_controls($totalnumber, $recurse, $category, $cmid, $cmo redirect($afteractionurl); } -if (optional_param('addnewpagesafterselected', null, PARAM_CLEAN) && !empty($selectedquestionids) && confirm_sesskey()) { +if (optional_param('addnewpagesafterselected', null, PARAM_CLEAN) && + !empty($selectedquestionids) && confirm_sesskey()) { foreach ($selectedquestionids as $questionid) { $quiz->questions = quiz_add_page_break_after($quiz->questions, $questionid); } @@ -281,7 +281,8 @@ function module_specific_controls($totalnumber, $recurse, $category, $cmid, $cmo redirect($afteractionurl); } -if (optional_param('quizdeleteselected', false, PARAM_BOOL) && !empty($selectedquestionids) && confirm_sesskey()) { +if (optional_param('quizdeleteselected', false, PARAM_BOOL) && + !empty($selectedquestionids) && confirm_sesskey()) { foreach ($selectedquestionids as $questionid) { quiz_remove_question($quiz, $questionid); } @@ -305,7 +306,7 @@ function module_specific_controls($totalnumber, $recurse, $category, $cmid, $cmo foreach ($rawdata as $key => $value) { if (preg_match('!^g([0-9]+)$!', $key, $matches)) { - /// Parse input for question -> grades + // Parse input for question -> grades $questionid = $matches[1]; $quiz->grades[$questionid] = clean_param($value, PARAM_FLOAT); quiz_update_question_instance($quiz->grades[$questionid], $questionid, $quiz); @@ -313,7 +314,7 @@ function module_specific_controls($totalnumber, $recurse, $category, $cmid, $cmo $recomputesummarks = true; } else if (preg_match('!^o(pg)?([0-9]+)$!', $key, $matches)) { - /// Parse input for ordering info + // Parse input for ordering info $questionid = $matches[2]; // Make sure two questions don't overwrite each other. If we get a second // question with the same position, shift the second one along to the next gap. @@ -389,8 +390,10 @@ function module_specific_controls($totalnumber, $recurse, $category, $cmid, $cmo $PAGE->requires->yui2_lib('container'); $PAGE->requires->yui2_lib('dragdrop'); -$PAGE->requires->skip_link_to('questionbank', get_string('skipto', 'access', get_string('questionbank', 'question'))); -$PAGE->requires->skip_link_to('quizcontentsblock', get_string('skipto', 'access', get_string('questionsinthisquiz', 'quiz'))); +$PAGE->requires->skip_link_to('questionbank', + get_string('skipto', 'access', get_string('questionbank', 'question'))); +$PAGE->requires->skip_link_to('quizcontentsblock', + get_string('skipto', 'access', get_string('questionsinthisquiz', 'quiz'))); $PAGE->set_title($pagetitle); $PAGE->set_heading($course->fullname); $node = $PAGE->settingsnav->find('mod_quiz_edit', navigation_node::TYPE_SETTING); @@ -419,8 +422,10 @@ function module_specific_controls($totalnumber, $recurse, $category, $cmid, $cmo $currenttab = 'edit'; } $tabs = array(array( - new tabobject('edit', new moodle_url($thispageurl, array('reordertool' => 0)), get_string('editingquiz', 'quiz')), - new tabobject('reorder', new moodle_url($thispageurl, array('reordertool' => 1)), get_string('orderingquiz', 'quiz')), + new tabobject('edit', new moodle_url($thispageurl, + array('reordertool' => 0)), get_string('editingquiz', 'quiz')), + new tabobject('reorder', new moodle_url($thispageurl, + array('reordertool' => 1)), get_string('orderingquiz', 'quiz')), )); print_tabs($tabs, $currenttab); @@ -469,7 +474,8 @@ function module_specific_controls($totalnumber, $recurse, $category, $cmid, $cmo $repaginatingdisabled = false; } if ($quiz_reordertool) { - echo '
'; echo '
'; } @@ -523,10 +529,12 @@ function module_specific_controls($totalnumber, $recurse, $category, $cmid, $cmo echo ''; $attributes = array(); $attributes['disabled'] = $repaginatingdisabledhtml ? 'disabled' : null; - $select = html_writer::select($perpage, 'questionsperpage', $quiz->questionsperpage, null, $attributes); + $select = html_writer::select( + $perpage, 'questionsperpage', $quiz->questionsperpage, null, $attributes); print_string('repaginate', 'quiz', $select); echo '
'; - echo ' '; + echo ' '; echo '
'; } @@ -551,16 +559,15 @@ function module_specific_controls($totalnumber, $recurse, $category, $cmid, $cmo 'cmid' => $cm->id, )); ?> -
-
name); ?> - - -
-
display(); -?>
-
+
+
name); ?> + + +
+
display(); + ?>
+
footer(); -?> diff --git a/mod/quiz/editlib.php b/mod/quiz/editlib.php index abe20982609e6..78c01fc8c6157 100644 --- a/mod/quiz/editlib.php +++ b/mod/quiz/editlib.php @@ -1,5 +1,4 @@ get_records_sql( - "SELECT q.id,q.qtype FROM {question} q + "SELECT q.id, q.qtype FROM {question} q WHERE qtype = 'random' AND category = ? AND " . $DB->sql_compare_text('questiontext') . " = ? @@ -815,7 +814,7 @@ function quiz_print_randomquestion(&$question, &$pageurl, &$quiz, $quiz_qbanktoo // Get a sample from the database, $questionidstoshow = array_slice($questionids, 0, NUM_QS_TO_SHOW_IN_RANDOM); $questionstoshow = $DB->get_records_list('question', 'id', $questionidstoshow, - '', 'id,qtype,name,questiontext,questiontextformat'); + '', 'id, qtype, name, questiontext, questiontextformat'); // list them, echo '