Commit fd892c6f authored by Sam Hemelryk's avatar Sam Hemelryk
Browse files

Merge branch 'MDL-32931_master' of git://github.com/dmonllao/moodle

parents ac881779 ba4ee840
......@@ -1310,23 +1310,33 @@ function forum_print_overview($courses,&$htmlarray) {
return;
}
// get all forum logs in ONE query (much better!)
// Courses to search for new posts
$coursessqls = array();
$params = array();
$sql = "SELECT instance,cmid,l.course,COUNT(l.id) as count FROM {log} l "
." JOIN {course_modules} cm ON cm.id = cmid "
." WHERE (";
foreach ($courses as $course) {
$sql .= '(l.course = ? AND l.time > ?) OR ';
$params[] = $course->id;
$params[] = $course->lastaccess;
}
$sql = substr($sql,0,-3); // take off the last OR
$sql .= ") AND l.module = 'forum' AND action = 'add post' "
." AND userid != ? GROUP BY cmid,l.course,instance";
// If the user has never entered into the course all posts are pending
if ($course->lastaccess == 0) {
$coursessqls[] = '(f.course = ?)';
$params[] = $course->id;
// Only posts created after the course last access
} else {
$coursessqls[] = '(f.course = ? AND p.created > ?)';
$params[] = $course->id;
$params[] = $course->lastaccess;
}
}
$params[] = $USER->id;
$coursessql = implode(' OR ', $coursessqls);
$sql = "SELECT f.id, COUNT(*) as count "
.'FROM {forum} f '
.'JOIN {forum_discussions} d ON d.forum = f.id '
.'JOIN {forum_posts} p ON p.discussion = d.id '
."WHERE ($coursessql) "
.'AND p.userid != ? '
.'GROUP BY f.id';
if (!$new = $DB->get_records_sql($sql, $params)) {
$new = array(); // avoid warnings
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment