Skip to content

Commit

Permalink
Forum search now no longer shows posts from other groups from forums …
Browse files Browse the repository at this point in the history
…that are in separate groups mode, see bug 2308
  • Loading branch information
gustav_delius committed Feb 13, 2005
1 parent aa26fa2 commit c7a5b3b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
13 changes: 9 additions & 4 deletions mod/forum/lib.php
Expand Up @@ -976,7 +976,7 @@ function forum_get_child_posts($parent) {
}


function forum_search_posts($searchterms, $courseid, $page=0, $recordsperpage=50, &$totalcount) {
function forum_search_posts($searchterms, $courseid, $page=0, $recordsperpage=50, &$totalcount, $groupid=0) {
/// Returns a list of posts found using an array of search terms
/// eg word +word -word
///
Expand All @@ -986,13 +986,18 @@ function forum_search_posts($searchterms, $courseid, $page=0, $recordsperpage=50

if (!isteacher($courseid)) {
$notteacherforum = "AND f.type <> 'teacher'";

$forummodule = get_record("modules", "name", "forum");
$onlyvisible = " AND f.id = cm.instance AND cm.visible = 1 AND cm.module = $forummodule->id";
$onlyvisibletable = ", {$CFG->prefix}course_modules cm";
if ($groupid) {
$separategroups = SEPARATEGROUPS;
$selectgroup = " AND (cm.groupmode <> '$separategroups' OR d.groupid = '$groupid')";
} else {
$selectgroup = '';
}
} else {
$notteacherforum = "";

$selectgroup = '';
$onlyvisible = "";
$onlyvisibletable = "";
}
Expand Down Expand Up @@ -1049,7 +1054,7 @@ function forum_search_posts($searchterms, $courseid, $page=0, $recordsperpage=50
AND p.userid = u.id
AND p.discussion = d.id
AND d.course = '$courseid'
AND d.forum = f.id $notteacherforum $onlyvisible";
AND d.forum = f.id $notteacherforum $onlyvisible $selectgroup";

$totalcount = count_records_sql("SELECT COUNT(*) FROM $selectsql");

Expand Down
8 changes: 6 additions & 2 deletions mod/forum/search.php
Expand Up @@ -58,8 +58,12 @@
$strippedsearch = str_replace("user:","",$search);
$strippedsearch = str_replace("subject:","",$strippedsearch);
$strippedsearch = str_replace("&quot;","",$strippedsearch);

if (!$posts = forum_search_posts($searchterms, $course->id, $page*$perpage, $perpage, $totalcount)) {
if ($group = user_group($id, $USER->id)) {
$groupid = $group->id;
} else {
$groupid = 0;
}
if (!$posts = forum_search_posts($searchterms, $course->id, $page*$perpage, $perpage, $totalcount, $groupid)) {

print_header_simple("$strsearchresults", "",
"<a href=\"index.php?id=$course->id\">$strforums</a> ->
Expand Down

0 comments on commit c7a5b3b

Please sign in to comment.