Updated the comments around the horrible sql construction in the quiz reports for overview & response

This commit is contained in:
mjollnir_
2006-03-01 03:00:33 +00:00
parent eeaf5ebce1
commit ecb5d875af
2 changed files with 18 additions and 14 deletions
+9 -7
View File
@@ -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 {
+9 -7
View File
@@ -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 {