groups_print_activity_menu($cm, $url);
    $groupid = mod_forumng::get_activity_group($cm, true);
    $forum->require_view($groupid, 0, true);
    print '<br/><br/>';
}
$editform->display();
if ($data) {
    // Searching for free text with or without filtering author and date range.
    if ($query) {
        $result = new local_ousearch_search($query);
        if ($allforums) {
            // Search all forums.
            // NOTE: I think this code branch is no longer used as we removed
            // the 'all forums' facility to the resources_search block, but
            // perhaps it may be used in standard Moodle installs somehow.
            $result->set_plugin('mod/forumng');
            $result->set_course_id($courseid);
            $result->set_visible_modules_in_course($COURSE);
            // Restrict them to the groups they belong to.
            if (!isset($USER->groupmember[$courseid])) {
                $result->set_group_ids(array());
            } else {
                $result->set_group_ids($USER->groupmember[$courseid]);
            }
            // Add exceptions where they can see other groups.
            $result->set_group_exceptions(local_ousearch_search::get_group_exceptions($courseid));
            $result->set_user_id($USER->id);
        } else {
            // Search this forum.
            $result->set_coursemodule($forum->get_course_module(true));
            if ($groupid && $groupid != mod_forumng::NO_GROUPS) {
 /**
  * Do a coursewide search as the current user on the given course, through
  * all forums.
  *
  * @param stdClass $course Moodle course object
  * @param string $search Search query
  * @return array Array of titles of results (empty array if none)
  */
 protected function coursewide_search($course, $search)
 {
     global $USER;
     // Based on the code in blocks/resources_search/search.class.php.
     $query = new local_ousearch_search($search);
     $query->set_course_id($course->id);
     $query->set_plugin('mod_forumng');
     $query->set_visible_modules_in_course($course, 'forumng');
     $groups = groups_get_all_groups($course->id, $USER->id);
     $groupids = array();
     foreach ($groups as $group) {
         $groupids[] = $group->id;
     }
     $query->set_group_ids($groupids);
     $query->set_group_exceptions($query->get_group_exceptions($course->id));
     $query->set_user_id($USER->id);
     $results = $query->query(0, 10);
     $out = array();
     if ($results->success) {
         foreach ($results->results as $result) {
             $out[] = strip_tags($result->title);
         }
     }
     sort($out);
     return $out;
 }
 /**
  * Test the search function with a list of CMs. This was broken at one point.
  */
 public function test_search_with_cm_list()
 {
     global $DB;
     $this->resetAfterTest();
     // Turn on the system.
     set_config(year_tables::CONFIG_ENABLED, year_tables::ENABLED_ON, 'local_ousearch');
     // Create a test courses.
     $course1 = $this->getDataGenerator()->create_course(array('startdate' => strtotime('2013-01-04 10:00')));
     // Create imaginary CMs.
     $cm1 = (object) array('id' => 19, 'course' => $course1->id);
     $cm2 = (object) array('id' => 77, 'course' => $course1->id);
     $cm3 = (object) array('id' => 138, 'course' => $course1->id);
     // Add four documents, two to one CM and one to two others..
     self::add_test_document(1, $course1, 'Doc One', $cm1->id);
     self::add_test_document(2, $course1, 'Doc Two', $cm2->id);
     self::add_test_document(3, $course1, 'Doc Three', $cm2->id);
     self::add_test_document(4, $course1, 'Doc Four', $cm3->id);
     // Check search on whole course.
     $this->check_search($course1, 'Doc', array(1, 2, 3, 4));
     // Check search on cm1 and cm2.
     $search = new local_ousearch_search('Doc');
     $search->set_plugin('test_yeartablestest');
     $search->set_coursemodule_array(array($cm1, $cm2));
     $this->check_search_inner($search, array(1, 2, 3));
     // Check on cm1 and cm3.
     $search = new local_ousearch_search('Doc');
     $search->set_plugin('test_yeartablestest');
     $search->set_coursemodule_array(array($cm1, $cm3));
     $this->check_search_inner($search, array(1, 4));
 }
 /**
  * Reused code to run a query on the zombie documents.
  *
  * @param string $query Query text
  * @param int $dbstart DB start
  * @param int $desired Desired number
  * @return stdClass Search result object
  */
 private function do_zombie_query($query, $dbstart = 0, $desired = 10)
 {
     $search = new local_ousearch_search($query);
     $search->set_plugin('test_zombie');
     return $search->query($dbstart, $desired);
 }