From ecb5d875af883cf2c9070646d8710fd8b1da5495 Mon Sep 17 00:00:00 2001 From: mjollnir_ Date: Wed, 1 Mar 2006 03:00:33 +0000 Subject: [PATCH] Updated the comments around the horrible sql construction in the quiz reports for overview & response --- mod/quiz/report/overview/report.php | 16 +++++++++------- mod/quiz/report/responses/report.php | 16 +++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php index cb8eecc47dd..35933e426fa 100644 --- a/mod/quiz/report/overview/report.php +++ b/mod/quiz/report/overview/report.php @@ -247,27 +247,29 @@ class quiz_report extends quiz_default_report { 'JOIN '.$CFG->prefix.'quiz_attempts qa ON u.id = qa.userid AND qa.quiz = '.$quiz->id; $where = ' WHERE us.course = '.$course->id.' AND gm.groupid = '.$currentgroup; } else if (!empty($currentgroup) && !empty($noattempts)) { - // We want a particular group and we only want to see students WITHOUT attempts. - // So join on groups_members and do a left join on attempts where the right side is null (no records in the attempts table) + // We want a particular group and we want to do something funky with attempts + // So join on groups_members and left join on attempts... $from = 'FROM '.$CFG->prefix.'user u JOIN '.$CFG->prefix.'user_students us ON us.userid = u.id JOIN '.$CFG->prefix.'groups_members gm ON u.id = gm.userid '. 'LEFT JOIN '.$CFG->prefix.'quiz_attempts qa ON u.id = qa.userid AND qa.quiz = '.$quiz->id; $where = ' WHERE us.course = '.$course->id.' AND gm.groupid = '.$currentgroup; if ($noattempts == 1) { + // noattempts = 1 means only no attempts, so make the left join ask for only records where the right is null (no attempts) $where .= ' AND qa.userid IS NULL'; // show ONLY no attempts; - } + } // no else, the left join is not filtered, which means we get both back. } else if (empty($currentgroup) && empty($noattempts)) { // We don't care about group, and we only want to see students WITH attempts. // So just do a striaght inner join on attempts, don't worry about the groups_members table $from = 'FROM '.$CFG->prefix.'user u JOIN '.$CFG->prefix.'quiz_attempts qa ON u.id = qa.userid '; $where = ' WHERE qa.quiz = '.$quiz->id; } else if (empty($currentgroup) && !empty($noattempts)) { - // We don't care about group, and we only want to see students WITHOUT attempts. - // So do a left join on attempts where the right side is null (no records in the attempts table), and don't worry about groups_members. + // We don't care about group, and we to do something funky with attempts + // So do a left join on attempts $from = 'FROM '.$CFG->prefix.'user u JOIN '.$CFG->prefix.'user_students us ON us.userid = u.id LEFT JOIN '.$CFG->prefix.'quiz_attempts qa ON u.id = qa.userid AND qa.quiz = '.$quiz->id; $where = ' WHERE us.course = '.$course->id; if ($noattempts == 1) { - $where .= ' AND qa.userid IS NULL'; - } + // noattempts = 1 means only no attempts, so make the left join ask for only records where the right is null (no attempts) + $where .= ' AND qa.userid IS NULL'; // show ONLY no attempts; + } // no else, the left join is not filtered, which means we get both back. } $countsql = 'SELECT COUNT(DISTINCT('.$db->Concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).')) '.$from.$where; } else { diff --git a/mod/quiz/report/responses/report.php b/mod/quiz/report/responses/report.php index 14da085fae7..84a5323d2dc 100644 --- a/mod/quiz/report/responses/report.php +++ b/mod/quiz/report/responses/report.php @@ -108,27 +108,29 @@ class quiz_report extends quiz_default_report { 'JOIN '.$CFG->prefix.'quiz_attempts qa ON u.id = qa.userid AND qa.quiz = '.$quiz->id; $where = ' WHERE us.course = '.$course->id.' AND gm.groupid = '.$currentgroup; } else if (!empty($currentgroup) && !empty($noattempts)) { - // We want a particular group and we only want to see students WITHOUT attempts. - // So join on groups_members and do a left join on attempts where the right side is null (no records in the attempts table) + // We want a particular group and we want to do something funky with attempts + // So join on groups_members and left join on attempts... $from = 'FROM '.$CFG->prefix.'user u JOIN '.$CFG->prefix.'user_students us ON us.userid = u.id JOIN '.$CFG->prefix.'groups_members gm ON u.id = gm.userid '. 'LEFT JOIN '.$CFG->prefix.'quiz_attempts qa ON u.id = qa.userid AND qa.quiz = '.$quiz->id; $where = ' WHERE us.course = '.$course->id.' AND gm.groupid = '.$currentgroup; if ($noattempts == 1) { + // noattempts = 1 means only no attempts, so make the left join ask for only records where the right is null (no attempts) $where .= ' AND qa.userid IS NULL'; // show ONLY no attempts; - } + } // no else, the left join is not filtered, which means we get both back. } else if (empty($currentgroup) && empty($noattempts)) { // We don't care about group, and we only want to see students WITH attempts. // So just do a striaght inner join on attempts, don't worry about the groups_members table $from = 'FROM '.$CFG->prefix.'user u JOIN '.$CFG->prefix.'quiz_attempts qa ON u.id = qa.userid '; $where = ' WHERE qa.quiz = '.$quiz->id; } else if (empty($currentgroup) && !empty($noattempts)) { - // We don't care about group, and we only want to see students WITHOUT attempts. - // So do a left join on attempts where the right side is null (no records in the attempts table), and don't worry about groups_members. + // We don't care about group, and we to do something funky with attempts + // So do a left join on attempts $from = 'FROM '.$CFG->prefix.'user u JOIN '.$CFG->prefix.'user_students us ON us.userid = u.id LEFT JOIN '.$CFG->prefix.'quiz_attempts qa ON u.id = qa.userid AND qa.quiz = '.$quiz->id; $where = ' WHERE us.course = '.$course->id; if ($noattempts == 1) { - $where .= ' AND qa.userid IS NULL'; - } + // noattempts = 1 means only no attempts, so make the left join ask for only records where the right is null (no attempts) + $where .= ' AND qa.userid IS NULL'; // show ONLY no attempts; + } // no else, the left join is not filtered, which means we get both back. } $countsql = 'SELECT COUNT(DISTINCT('.$db->Concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).')) '.$from.$where; } else {