Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'MDL-32931_22' of git://github.com/dmonllao/moodle into …

…MOODLE_22_STABLE
  • Loading branch information...
commit dd204f3a8f660d2f0229d64bb291962d35dc2f8f 2 parents ab474e3 + b729292
@samhemelryk samhemelryk authored
Showing with 22 additions and 12 deletions.
  1. +22 −12 mod/forum/lib.php
View
34 mod/forum/lib.php
@@ -1221,23 +1221,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
Please sign in to comment.
Something went wrong with that request. Please try again.