Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple Quiz feature #42

Open
wants to merge 1 commit into
base: MOODLE_38_STABLE
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions classes/quiz_observers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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)) {
Expand Down
3 changes: 3 additions & 0 deletions lang/en/block_grade_me.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
7 changes: 7 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
34 changes: 24 additions & 10 deletions plugins/quiz/quiz_plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
5 changes: 5 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down