From: vyshane Date: Fri, 15 Sep 2006 06:04:23 +0000 (+0000) Subject: Fixed bug in forum_search_posts(). More testing needed still. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=67875aa108a68a57da146edd1fde0e43bb1b4731;p=moodle.git Fixed bug in forum_search_posts(). More testing needed still. --- diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 30fc460c21..1d400ea8ea 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -1195,6 +1195,9 @@ function forum_get_readable_forums($userid, $courseid=0) { } } // End foreach $courses + //print_object($courses); + //print_object($readableforums); + return $readableforums; } @@ -1208,13 +1211,16 @@ function forum_get_readable_forums($userid, $courseid=0) { * @param $extrasql * @return array of posts found */ -function forum_search_posts($searchterms, $courseid=0, $page=0, $recordsperpage=50, +function forum_search_posts($searchterms, $courseid=0, $limitfrom=0, $limitnum=50, &$totalcount, $extrasql='') { global $CFG, $USER; require_once($CFG->libdir.'/searchlib.php'); $forums = forum_get_readable_forums($USER->id, $courseid); - + + if (count($forums) == 0) { + return false; + } for ($i=0; $i'; - // Get the posts regardless of group first. - if ($posts = forum_search_posts($searchterms, $course->id, $page*$perpage, $perpage, + + + if ($course->id == SITEID) { + // Search throughout the whole site. + $searchcourse = 0; + } else { + // Search only for posts the user made in this course. + $searchcourse = $course->id; + } + + // Get the posts. + if ($posts = forum_search_posts($searchterms, $searchcourse, $page*$perpage, $perpage, $totalcount, $extrasql)) { print_paging_bar($totalcount, $page, $perpage, "user.php?id=$user->id&course=$course->id&mode=$mode&perpage=$perpage&"); + foreach ($posts as $post) { if (! $discussion = get_record('forum_discussions', 'id', $post->discussion)) { @@ -101,7 +112,6 @@ get_string("postincontext", "forum").""; forum_print_post($post, $course->id, false, false, false, false, $fulllink); - echo "
"; } @@ -113,5 +123,4 @@ echo ''; print_footer($course); -?> - +?> \ No newline at end of file