Skip to content

Commit

Permalink
quiz reports MDL-21262 do not work for quizzes on the front page.
Browse files Browse the repository at this point in the history
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 155ac54
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
29 changes: 20 additions & 9 deletions mod/quiz/report/grading/report.php
Expand Up @@ -84,8 +84,11 @@ function display($quiz, $cm, $course) {


$currentgroup = groups_get_activity_group($this->cm, true); $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->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 (!empty($questionid)) {
if (!isset($gradeableqs[$questionid])){ if (!isset($gradeableqs[$questionid])){
Expand Down Expand Up @@ -124,8 +127,7 @@ function display($quiz, $cm, $course) {
$uniqueid = clean_param($uniqueid, PARAM_INT); $uniqueid = clean_param($uniqueid, PARAM_INT);
if (!$attempt = get_record_sql("SELECT * FROM {$CFG->prefix}quiz_attempts " . if (!$attempt = get_record_sql("SELECT * FROM {$CFG->prefix}quiz_attempts " .
"WHERE uniqueid = $uniqueid AND " . "WHERE uniqueid = $uniqueid AND " .
"userid IN ($this->userids) AND " . "quiz = " . $quiz->id)){
"quiz=".$quiz->id)){
error('No such attempt ID exists'); error('No such attempt ID exists');
} }


Expand Down Expand Up @@ -162,13 +164,13 @@ function display($quiz, $cm, $course) {


echo '<div class="quizattemptcounts">' . quiz_num_attempt_summary($quiz, $cm, true, $currentgroup) . '</div>'; echo '<div class="quizattemptcounts">' . quiz_num_attempt_summary($quiz, $cm, true, $currentgroup) . '</div>';


if(empty($this->users)) { if (empty($this->users)) {
if ($currentgroup){ if ($currentgroup){
notify(get_string('nostudentsingroup')); notify(get_string('nostudentsingroup'));
return true;
} else { } else {
notify(get_string('nostudentsyet')); notify(get_string('nostudentsyet'));
} }
return true;
} }
$gradeablequestionids = implode(',',array_keys($gradeableqs)); $gradeablequestionids = implode(',',array_keys($gradeableqs));
$qattempts = quiz_get_total_qas_graded_and_ungraded($quiz, $gradeablequestionids, $this->userids); $qattempts = quiz_get_total_qas_graded_and_ungraded($quiz, $gradeablequestionids, $this->userids);
Expand Down Expand Up @@ -196,7 +198,7 @@ function display($quiz, $cm, $course) {
if (!$questionid){ if (!$questionid){
return true; return true;
} }
$a= new object(); $a = new object();
$a->number = $question->number; $a->number = $question->number;
$a->name = $question->name; $a->name = $question->name;
$a->gradedattempts =$qattempts[$question->id]->gradedattempts; $a->gradedattempts =$qattempts[$question->id]->gradedattempts;
Expand Down Expand Up @@ -448,13 +450,22 @@ function attempts_sql($quizid, $wantstateevent=false, $questionid=0, $userid=0,
"ON (qs.id = qns.newgraded AND qs.question = $questionid) "; "ON (qs.id = qns.newgraded AND qs.question = $questionid) ";
} }
if ($gradenextungraded || $gradeungraded) { // get ungraded attempts 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 } else if ($userid) { // get all the attempts for a specific user
$where = 'WHERE u.id='.$userid.' '; $where = 'WHERE u.id='.$userid.' ';
} else if ($attemptid) { // get a specific attempt } else if ($attemptid) { // get a specific attempt
$where = 'WHERE qa.id='.$attemptid.' '; $where = 'WHERE qa.id='.$attemptid.' ';
} else { // get all user attempts } 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; $where .= ' AND u.id = qa.userid AND qa.quiz = '.$quizid;
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/report/overview/report.php
Expand Up @@ -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)) { if (!$students = get_users_by_capability($context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),'u.id,1','','','','','',false)) {
notify(get_string('nostudentsyet')); notify(get_string('nostudentsyet'));
$nostudents = true; $nostudents = true;
$studentslist = ''; $studentslist = 0;
} else { } else {
$studentslist = join(',',array_keys($students)); $studentslist = join(',',array_keys($students));
} }
Expand Down
7 changes: 6 additions & 1 deletion mod/quiz/report/reportlib.php
Expand Up @@ -56,6 +56,11 @@ function quiz_get_average_grade_for_questions($quiz, $userids){


function quiz_get_total_qas_graded_and_ungraded($quiz, $questionids, $userids){ function quiz_get_total_qas_graded_and_ungraded($quiz, $questionids, $userids){
global $CFG; global $CFG;
if ($userids) {
$userwhere = "qa.userid IN ({$userids}) AND ";
} else {
$userwhere = '';
}
$sql = "SELECT qs.question, COUNT(1) AS totalattempts, " . $sql = "SELECT qs.question, COUNT(1) AS totalattempts, " .
"SUM(CASE WHEN (qs.event IN (".QUESTION_EVENTS_GRADED.")) THEN 1 ELSE 0 END) AS gradedattempts " . "SUM(CASE WHEN (qs.event IN (".QUESTION_EVENTS_GRADED.")) THEN 1 ELSE 0 END) AS gradedattempts " .
"FROM " . "FROM " .
Expand All @@ -64,7 +69,7 @@ function quiz_get_total_qas_graded_and_ungraded($quiz, $questionids, $userids){
"{$CFG->prefix}question_states qs " . "{$CFG->prefix}question_states qs " .
"WHERE " . "WHERE " .
"qa.quiz = {$quiz->id} AND " . "qa.quiz = {$quiz->id} AND " .
"qa.userid IN ({$userids}) AND " . $userwhere .
"qns.attemptid = qa.uniqueid AND " . "qns.attemptid = qa.uniqueid AND " .
"qns.newgraded = qs.id AND " . "qns.newgraded = qs.id AND " .
"qs.question IN ({$questionids}) " . "qs.question IN ({$questionids}) " .
Expand Down

0 comments on commit 155ac54

Please sign in to comment.