Permalink
Browse files

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.
  • Loading branch information...
timhunt committed Aug 5, 2010
1 parent d35f34c commit 155ac544d56f5ac77e2a292108da60ea83b2a7e7
Showing with 27 additions and 11 deletions.
  1. +20 −9 mod/quiz/report/grading/report.php
  2. +1 −1 mod/quiz/report/overview/report.php
  3. +6 −1 mod/quiz/report/reportlib.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 '<div class="quizattemptcounts">' . quiz_num_attempt_summary($quiz, $cm, true, $currentgroup) . '</div>';
- 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;
@@ -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));
}
@@ -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}) " .

0 comments on commit 155ac54

Please sign in to comment.