diff --git a/classes/quiz_observers.php b/classes/quiz_observers.php index 2393196..fe2b69b 100644 --- a/classes/quiz_observers.php +++ b/classes/quiz_observers.php @@ -92,6 +92,12 @@ public static function attempt_deleted(\mod_quiz\event\attempt_deleted $event) { * @return void */ public static function attempt_submitted($event) { + $simplequiz = get_config('block_grade_me','simplequiz'); + //if we are doing simple quiz checkign, skip this + if($simplequiz){ + return; + } + \block_grade_me\quiz_util::update_quiz_ngrade($event->objectid); } @@ -103,6 +109,13 @@ public static function attempt_submitted($event) { */ public static function question_manually_graded(\mod_quiz\event\question_manually_graded $event) { global $DB; + + //if we are doing simple quiz checkign, skip this + $simplequiz = get_config('block_grade_me','simplequiz'); + if($simplequiz){ + return; + } + // Lookup uniqueid from quiz_attempts table. $record = $DB->get_record('quiz_attempts', ['id' => $event->other['attemptid']]); if (empty($record)) { diff --git a/lang/en/block_grade_me.php b/lang/en/block_grade_me.php index cbda12c..1b49f90 100644 --- a/lang/en/block_grade_me.php +++ b/lang/en/block_grade_me.php @@ -49,3 +49,6 @@ $string['quiz_update_ngrade_complete'] = 'Update complete'; $string['quiz_update_ngrade_success'] = 'Quiz attempt list successfully updated, currently there is {$a} questions needing grading.'; + +$string['simplequiz'] = 'Simpler Quiz Check'; +$string['simplequiz_desc'] = 'The standard method of checking quiz completion requires queries against the question attempts table. For courses with lots of users, this can be a very slow and memory intensive process. Normally the plugin checks to make sure every manually graded question attempt has been reviewed, enabling this setting makes the plugin just check to see if the whole quiz has been assigned a grade. If you disable this setting, you will need to run the \'Refresh quiz attempts needing grading\' tool'; diff --git a/lib.php b/lib.php index 0cb7edd..7d6ba7e 100644 --- a/lib.php +++ b/lib.php @@ -334,6 +334,13 @@ function block_grade_me_cache_grade_data() { $DB->update_record('block_grade_me', $params); } } + + + //If using simple quiz grade checking, we don't need to cache data about manually graded questions + $simplequiz = get_config('block_grade_me','simplequiz'); + if($simplquiz){ + continue; + } /** * Build the quiz table per course. Cannot do this in bulk * because temp tables can cause large disk usage. diff --git a/plugins/quiz/quiz_plugin.php b/plugins/quiz/quiz_plugin.php index d53d986..fdd85e2 100644 --- a/plugins/quiz/quiz_plugin.php +++ b/plugins/quiz/quiz_plugin.php @@ -41,15 +41,29 @@ function block_grade_me_query_quiz($gradebookusers) { return false; } list($insql, $inparams) = $DB->get_in_or_equal($gradebookusers); - $query = ", qas.id step_id, qza.userid, qza.timemodified timesubmitted, qza.id submissionid, qas.sequencenumber - FROM {question_attempt_steps} qas - JOIN {block_grade_me_quiz_ngrade} bneeds ON bneeds.questionattemptstepid = qas.id - AND bneeds.userid $insql - JOIN {quiz_attempts} qza ON qas.id = bneeds.questionattemptstepid - JOIN {question_attempts} qna ON qna.questionusageid = qza.uniqueid - AND qas.questionattemptid = qna.id - JOIN {block_grade_me} bgm ON bgm.iteminstance = qza.quiz - AND bgm.itemmodule = 'quiz' - WHERE qas.state = '".question_state::$needsgrading."'"; + + //Simple quiz checking means we only want to check if quiz attempts sumofgrades is null + //this saves querying against the questions_attempts table -- which can be quite bukly + $simplequiz = get_config('block_grade_me','simplequiz'); + if($simplequiz){ + $query = ", qza.userid, qza.timemodified timesubmitted, qza.id submissionid, qza.id attemptid + FROM {quiz} q + JOIN {block_grade_me} bgm ON bgm.courseid = q.course AND bgm.iteminstance = q.id + JOIN {quiz_attempts} qza ON qza.quiz = q.id and qza.userid $insql + WHERE qza.state = 'finished' + AND qza.sumgrades is NULL + "; + }else{ + $query = ", qas.id step_id, qza.userid, qza.timemodified timesubmitted, qza.id submissionid, qas.sequencenumber + FROM {question_attempt_steps} qas + JOIN {block_grade_me_quiz_ngrade} bneeds ON bneeds.questionattemptstepid = qas.id + AND bneeds.userid $insql + JOIN {quiz_attempts} qza ON qas.id = bneeds.questionattemptstepid + JOIN {question_attempts} qna ON qna.questionusageid = qza.uniqueid + AND qas.questionattemptid = qna.id + JOIN {block_grade_me} bgm ON bgm.iteminstance = qza.quiz + AND bgm.itemmodule = 'quiz' + WHERE qas.state = '".question_state::$needsgrading."'"; + } return array($query, $inparams); } diff --git a/settings.php b/settings.php index cc6507d..4aa0057 100644 --- a/settings.php +++ b/settings.php @@ -39,6 +39,11 @@ } } + + $settings->add(new admin_setting_configcheckbox('block_grade_me/simplequiz', get_string('simplequiz', 'block_grade_me'), + get_string('simplequiz_desc', 'block_grade_me'), 0)); + + $label = get_string('grade_me_tools', 'block_grade_me'); $desc = get_string('grade_me_tools_desc', 'block_grade_me', $CFG->wwwroot); $settings->add(new admin_setting_heading('grade_me_tools', $label, $desc)); diff --git a/version.php b/version.php index 9827a1a..e643936 100644 --- a/version.php +++ b/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2019111800; +$plugin->version = 2019111802; $plugin->requires = 2019111800; $plugin->cron = 3600; $plugin->component = 'block_grade_me';