From f17a34b5efeda8e7eaf5122640b67187e4f56c15 Mon Sep 17 00:00:00 2001 From: jamiesensei Date: Thu, 29 May 2008 14:14:27 +0000 Subject: [PATCH] MDL-15011 "grading report : allow user to select to grade next 10 ungraded attempts" added a new link and options to the grading report page to display only the next 10 ungraded attempts to grade. Also some fixes for faulty sql for ungraded option which was not respecting the users groups selection. --- lang/en_utf8/quiz_grading.php | 2 ++ mod/quiz/report/grading/report.php | 50 +++++++++++++++++++++--------- mod/quiz/report/reportlib.php | 1 + 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/lang/en_utf8/quiz_grading.php b/lang/en_utf8/quiz_grading.php index 35ec4c62fc..907f81a819 100644 --- a/lang/en_utf8/quiz_grading.php +++ b/lang/en_utf8/quiz_grading.php @@ -7,9 +7,11 @@ $string['grading'] = 'Manual grading'; $string['gradeall'] = 'Grade all $a attempts'; $string['graded'] = '(graded)'; $string['gradeungraded'] = 'Grade all $a ungraded attempts'; +$string['gradenextungraded'] = 'Grade next $a ungraded attempts'; $string['gradinguser'] = 'Attempts for $a'; $string['gradingall'] = 'All $a attempts on this question.'; $string['gradingattempt'] = 'Attempt number $a->attempt for $a->fullname.'; +$string['gradingnextungraded'] = 'Next $a ungraded attempts'; $string['gradingnotallowed'] = 'You do not have permission to manually grade responses in this quiz'; $string['gradingungraded'] = '$a ungraded attempts'; $string['questiontitle'] = 'Question $a->number : \"$a->name\" ({$a->openspan}$a->gradedattempts{$a->closespan} / $a->totalattempts attempts {$a->openspan}graded{$a->closespan}).'; diff --git a/mod/quiz/report/grading/report.php b/mod/quiz/report/grading/report.php index c7ac2bede6..d68b54802f 100644 --- a/mod/quiz/report/grading/report.php +++ b/mod/quiz/report/grading/report.php @@ -51,6 +51,9 @@ class quiz_report extends quiz_default_report { if ($gradeungraded = optional_param('gradeungraded', 0, PARAM_INT)){ $viewoptions += array('gradeungraded'=> $gradeungraded); } + if ($gradenextungraded = optional_param('gradenextungraded', 0, PARAM_INT)){ + $viewoptions += array('gradenextungraded'=> $gradenextungraded); + } $this->cm = $cm; @@ -78,6 +81,11 @@ class quiz_report extends quiz_default_report { $questionid = array_shift(array_keys($gradeableqs)); } + $currentgroup = groups_get_activity_group($this->cm, true); + $this->users = get_users_by_capability($this->context, 'mod/quiz:attempt','','','','',$currentgroup,'',false); + $this->userids = implode(',', array_keys($this->users)); + + if (!empty($questionid)) { if (!isset($gradeableqs[$questionid])){ error("Gradeable question with id $questionid not found"); @@ -112,7 +120,11 @@ class quiz_report extends quiz_default_report { $allok = true; foreach($data->manualgrades as $uniqueid => $response) { // get our attempt - if (! $attempt = get_record('quiz_attempts', 'uniqueid', $uniqueid)) { + $uniqueid = clean_param($uniqueid, PARAM_INT); + if (!$attempt = get_record_sql("SELECT * FROM {$CFG->prefix}quiz_attempts " . + "WHERE uniqueid = $uniqueid AND " . + "userid IN ($this->userids) AND " . + "quiz=".$quiz->id)){ error('No such attempt ID exists'); } @@ -142,7 +154,6 @@ class quiz_report extends quiz_default_report { } $this->viewurl = new moodle_url($CFG->wwwroot.'/mod/quiz/report.php', $viewoptions); /// find out current groups mode - $currentgroup = groups_get_activity_group($this->cm, true); if ($groupmode = groups_get_activity_groupmode($this->cm)) { // Groups are being used groups_print_activity_menu($this->cm, $this->viewurl->out(false, array('userid'=>0, 'attemptid'=>0))); @@ -150,8 +161,6 @@ class quiz_report extends quiz_default_report { echo '
' . quiz_num_attempt_summary($quiz, $cm, true, $currentgroup) . '
'; - $this->users = get_users_by_capability($this->context, 'mod/quiz:attempt','','','','',$currentgroup,'',false); - $this->userids = implode(',', array_keys($this->users)); if(empty($this->users)) { if ($currentgroup){ notify(get_string('nostudentsingroup')); @@ -179,7 +188,7 @@ class quiz_report extends quiz_default_report { } if (count($gradeableqs)!=1){ $qurl = fullclone($this->viewurl); - $qurl->remove_params('questionid', 'attemptid', 'gradeall', 'gradeungraded'); + $qurl->remove_params('questionid', 'attemptid', 'gradeall', 'gradeungraded', 'gradenextungraded'); $menu = popup_form(($qurl->out()).'&questionid=',$qmenu, 'questionid', $questionid, 'choose', '', '', true); echo '
'.$menu.'
'; } @@ -206,8 +215,8 @@ class quiz_report extends quiz_default_report { // and grade form underneath it $ungraded = $qattempts[$questionid]->totalattempts- $qattempts[$questionid]->gradedattempts; - if ($gradeungraded || $gradeall || $userid || $attemptid){ - $this->print_questions_and_form($quiz, $question, $userid, $attemptid, $gradeungraded, $ungraded); + if ($gradenextungraded ||$gradeungraded || $gradeall || $userid || $attemptid){ + $this->print_questions_and_form($quiz, $question, $userid, $attemptid, $gradeungraded, $gradenextungraded, $ungraded); } else { $this->view_question($quiz, $question, $qattempts[$questionid]->totalattempts, $ungraded); } @@ -279,8 +288,11 @@ class quiz_report extends quiz_default_report { if ($attempts = get_records_sql($select.$from.$where.$sort,$table->get_page_start(), $table->get_page_size())) { // grade all link $links = "id&questionid=$question->id\">".get_string('gradeall', 'quiz_grading', $totalattempts).''; - if (($ungraded)>0){ + if ($ungraded>0){ $links .="
id&questionid=$question->id\">".get_string('gradeungraded', 'quiz_grading', $ungraded).''; + if ($ungraded>QUIZ_REPORT_DEFAULT_GRADING_PAGE_SIZE){ + $links .="
id&questionid=$question->id\">".get_string('gradenextungraded', 'quiz_grading', QUIZ_REPORT_DEFAULT_GRADING_PAGE_SIZE).''; + } } $table->add_data_keyed(array('grade'=> $links)); $table->add_separator(); @@ -324,7 +336,7 @@ class quiz_report extends quiz_default_report { * @return void * @todo Finish documenting this function **/ - function print_questions_and_form($quiz, $question, $userid, $attemptid, $gradeungraded, $ungraded) { + function print_questions_and_form($quiz, $question, $userid, $attemptid, $gradeungraded, $gradenextungraded, $ungraded) { global $CFG; // TODO get the context, and put in proper roles an permissions checks. @@ -333,15 +345,23 @@ class quiz_report extends quiz_default_report { $questions[$question->id] = &$question; $usehtmleditor = can_use_html_editor(); - list($select, $from, $where) = $this->attempts_sql($quiz->id, false, $question->id, $userid, $attemptid, $gradeungraded); + list($select, $from, $where) = $this->attempts_sql($quiz->id, false, $question->id, $userid, $attemptid, $gradeungraded, $gradenextungraded); $sort = 'ORDER BY u.firstname, u.lastname, qa.attempt ASC'; - $attempts = get_records_sql($select.$from.$where.$sort); + + if ($gradenextungraded){ + $limit = ' LIMIT '.QUIZ_REPORT_DEFAULT_GRADING_PAGE_SIZE; + } else { + $limit = ''; + } + $attempts = get_records_sql($select.$from.$where.$sort.$limit); if ($attempts){ $firstattempt = current($attempts); $fullname = fullname($firstattempt); if ($gradeungraded) { // getting all ungraded attempts print_heading(get_string('gradingungraded','quiz_grading', $ungraded), '', 3); + } else if ($gradenextungraded) { // getting next ungraded attempts + print_heading(get_string('gradingnextungraded','quiz_grading', QUIZ_REPORT_DEFAULT_GRADING_PAGE_SIZE), '', 3); } else if ($userid){ print_heading(get_string('gradinguser','quiz_grading', $fullname), '', 3); } else if ($attemptid){ @@ -408,7 +428,7 @@ class quiz_report extends quiz_default_report { } } - function attempts_sql($quizid, $wantstateevent=false, $questionid=0, $userid=0, $attemptid=0, $gradeungraded=0){ + function attempts_sql($quizid, $wantstateevent=false, $questionid=0, $userid=0, $attemptid=0, $gradeungraded=0, $gradenextungraded=0){ global $CFG; // this sql joins the attempts table and the user table $select = 'SELECT qa.id AS attemptid, qa.uniqueid, qa.attempt, qa.timefinish, qa.preview, @@ -418,14 +438,14 @@ class quiz_report extends quiz_default_report { } $from = 'FROM '.$CFG->prefix.'user u, ' . $CFG->prefix.'quiz_attempts qa '; - if (($wantstateevent|| $gradeungraded) && $questionid){ + if (($wantstateevent|| $gradenextungraded || $gradeungraded) && $questionid){ $from .= "LEFT JOIN {$CFG->prefix}question_sessions qns " . "ON (qns.attemptid = qa.uniqueid AND qns.questionid = $questionid) "; $from .= "LEFT JOIN {$CFG->prefix}question_states qs " . "ON (qs.id = qns.newgraded AND qs.question = $questionid) "; } - if ($gradeungraded) { // get all ungraded attempts - $where = 'WHERE qs.event NOT IN ('.QUESTION_EVENTS_GRADED.') '; + if ($gradenextungraded || $gradeungraded) { // get ungraded attempts + $where = 'WHERE u.id IN ('.$this->userids.') AND qs.event NOT IN ('.QUESTION_EVENTS_GRADED.') '; } else if ($userid) { // get all the attempts for a specific user $where = 'WHERE u.id='.$userid.' '; } else if ($attemptid) { // get a specific attempt diff --git a/mod/quiz/report/reportlib.php b/mod/quiz/report/reportlib.php index 1ecf955cb0..62205f7ee3 100644 --- a/mod/quiz/report/reportlib.php +++ b/mod/quiz/report/reportlib.php @@ -1,5 +1,6 @@