MDL-31183 fix non-functional glossary_count_unrated_entries()

This commit is contained in:
Petr Skoda 2012-01-21 16:47:03 +01:00
parent f6b4ec2b4a
commit 2e099772d9

View File

@ -2231,24 +2231,24 @@ function glossary_count_unrated_entries($glossaryid, $userid) {
// Now we need to count the ratings that this user has made // Now we need to count the ratings that this user has made
$sql = "SELECT COUNT('x') AS num $sql = "SELECT COUNT('x') AS num
FROM {glossary_entries} e FROM {glossary_entries} e
JOIN {ratings} r ON r.itemid = e.id JOIN {rating} r ON r.itemid = e.id
WHERE e.glossaryid = :glossaryid AND WHERE e.glossaryid = :glossaryid AND
r.userid = :userid AND r.userid = :userid AND
r.component = 'mod_glossary' AND r.component = 'mod_glossary' AND
r.ratingarea = 'entry' AND r.ratingarea = 'entry' AND
r.contextid = :contextid"; r.contextid = :contextid";
$params = array('glossaryid' => $glossaryid, 'userid' => $userid, 'contextid' => $context->id); $params = array('glossaryid' => $glossaryid, 'userid' => $userid, 'contextid' => $contextid);
$rated = $DB->count_records_sql($sql, $params); $rated = $DB->count_records_sql($sql, $params);
if ($rated) { if ($rated) {
// The number or enties minus the number or rated entries equals the number of unrated // The number or enties minus the number or rated entries equals the number of unrated
// entries // entries
if ($entries->num > $rated->num) { if ($entries > $rated) {
return $entries->num - $rated->num; return $entries - $rated;
} else { } else {
return 0; // Just in case there was a counting error return 0; // Just in case there was a counting error
} }
} else { } else {
return $entries->num; return (int)$entries;
} }
} else { } else {
return 0; return 0;