From 155ac544d56f5ac77e2a292108da60ea83b2a7e7 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 5 Aug 2010 15:37:05 +0000 Subject: [PATCH] quiz reports MDL-21262 do not work for quizzes on the front page. This was already fixed in 2.0. A bit of a hack to make it work in 1.9 too. Hopefully there won't be any side-effects. --- mod/quiz/report/grading/report.php | 29 ++++++++++++++++++++--------- mod/quiz/report/overview/report.php | 2 +- mod/quiz/report/reportlib.php | 7 ++++++- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/mod/quiz/report/grading/report.php b/mod/quiz/report/grading/report.php index d1bacb05cc40a..f75c9a87b27b9 100644 --- a/mod/quiz/report/grading/report.php +++ b/mod/quiz/report/grading/report.php @@ -84,8 +84,11 @@ function display($quiz, $cm, $course) { $currentgroup = groups_get_activity_group($this->cm, true); $this->users = get_users_by_capability($this->context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),'','','','',$currentgroup,'',false); - $this->userids = implode(',', array_keys($this->users)); - + if ($this->users) { + $this->userids = implode(',', array_keys($this->users)); + } else { + $this->userids = 0; + } if (!empty($questionid)) { if (!isset($gradeableqs[$questionid])){ @@ -124,8 +127,7 @@ function display($quiz, $cm, $course) { $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)){ + "quiz = " . $quiz->id)){ error('No such attempt ID exists'); } @@ -162,13 +164,13 @@ function display($quiz, $cm, $course) { echo '
' . quiz_num_attempt_summary($quiz, $cm, true, $currentgroup) . '
'; - if(empty($this->users)) { + if (empty($this->users)) { if ($currentgroup){ notify(get_string('nostudentsingroup')); + return true; } else { notify(get_string('nostudentsyet')); } - return true; } $gradeablequestionids = implode(',',array_keys($gradeableqs)); $qattempts = quiz_get_total_qas_graded_and_ungraded($quiz, $gradeablequestionids, $this->userids); @@ -196,7 +198,7 @@ function display($quiz, $cm, $course) { if (!$questionid){ return true; } - $a= new object(); + $a = new object(); $a->number = $question->number; $a->name = $question->name; $a->gradedattempts =$qattempts[$question->id]->gradedattempts; @@ -448,13 +450,22 @@ function attempts_sql($quizid, $wantstateevent=false, $questionid=0, $userid=0, "ON (qs.id = qns.newgraded AND qs.question = $questionid) "; } if ($gradenextungraded || $gradeungraded) { // get ungraded attempts - $where = 'WHERE u.id IN ('.$this->userids.') AND qs.event NOT IN ('.QUESTION_EVENTS_GRADED.') '; + if ($this->userids) { + $where = 'WHERE u.id IN ('.$this->userids.')'; + } else { + $where = 'WHERE u.id = u.id'; + } + $where .= ' 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 $where = 'WHERE qa.id='.$attemptid.' '; } else { // get all user attempts - $where = 'WHERE u.id IN ('.$this->userids.') '; + if ($this->userids) { + $where = 'WHERE u.id IN ('.$this->userids.')'; + } else { + $where = 'WHERE u.id = u.id'; + } } $where .= ' AND u.id = qa.userid AND qa.quiz = '.$quizid; diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php index 1cdd5acd5ca6c..c0fca7ddf7c66 100644 --- a/mod/quiz/report/overview/report.php +++ b/mod/quiz/report/overview/report.php @@ -105,7 +105,7 @@ function display($quiz, $cm, $course) { if (!$students = get_users_by_capability($context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),'u.id,1','','','','','',false)) { notify(get_string('nostudentsyet')); $nostudents = true; - $studentslist = ''; + $studentslist = 0; } else { $studentslist = join(',',array_keys($students)); } diff --git a/mod/quiz/report/reportlib.php b/mod/quiz/report/reportlib.php index 3a09a1b5ead70..9e960dcc3afb4 100644 --- a/mod/quiz/report/reportlib.php +++ b/mod/quiz/report/reportlib.php @@ -56,6 +56,11 @@ function quiz_get_average_grade_for_questions($quiz, $userids){ function quiz_get_total_qas_graded_and_ungraded($quiz, $questionids, $userids){ global $CFG; + if ($userids) { + $userwhere = "qa.userid IN ({$userids}) AND "; + } else { + $userwhere = ''; + } $sql = "SELECT qs.question, COUNT(1) AS totalattempts, " . "SUM(CASE WHEN (qs.event IN (".QUESTION_EVENTS_GRADED.")) THEN 1 ELSE 0 END) AS gradedattempts " . "FROM " . @@ -64,7 +69,7 @@ function quiz_get_total_qas_graded_and_ungraded($quiz, $questionids, $userids){ "{$CFG->prefix}question_states qs " . "WHERE " . "qa.quiz = {$quiz->id} AND " . - "qa.userid IN ({$userids}) AND " . + $userwhere . "qns.attemptid = qa.uniqueid AND " . "qns.newgraded = qs.id AND " . "qs.question IN ({$questionids}) " .