$digestoptions = forum_get_user_digest_options(); $digestoptions_selector = new single_select(new moodle_url('/mod/forum/maildigest.php', array('backtoindex' => 1)), 'maildigest', $digestoptions, null, ''); $digestoptions_selector->method = 'post'; // Start of the table for General Forums $generaltable = new html_table(); $generaltable->head = array($strforum, $strdescription, $strdiscussions); $generaltable->align = array('left', 'left', 'center'); if ($usetracking = forum_tp_can_track_forums()) { $untracked = forum_tp_get_untracked_forums($USER->id, $course->id); $generaltable->head[] = $strunreadposts; $generaltable->align[] = 'center'; $generaltable->head[] = $strtracking; $generaltable->align[] = 'center'; } // Fill the subscription cache for this course and user combination. \mod_forum\subscriptions::fill_subscription_cache_for_course($course->id, $USER->id); $can_subscribe = is_enrolled($coursecontext); if ($can_subscribe) { $generaltable->head[] = $strsubscribed; $generaltable->align[] = 'center'; $generaltable->head[] = $stremaildigest . ' ' . $OUTPUT->help_icon('emaildigesttype', 'mod_forum'); $generaltable->align[] = 'center'; } if ($show_rss = ($can_subscribe || $course->id == SITEID) && isset($CFG->enablerssfeeds) && isset($CFG->forum_enablerssfeeds) && $CFG->enablerssfeeds && $CFG->forum_enablerssfeeds) { $generaltable->head[] = $strrss; $generaltable->align[] = 'center'; } $usesections = course_format_uses_sections($course->format); $table = new html_table(); // Parse and organise all the forums. Most forums are course modules but // some special ones are not. These get placed in the general forums
/** * Test that the discussion subscription cache can filled course-at-a-time. */ public function test_discussion_subscription_cache_fill_for_course() { global $DB; $this->resetAfterTest(true); // Create a course, with a forum. $course = $this->getDataGenerator()->create_course(); // Create the forums. $options = array('course' => $course->id, 'forcesubscribe' => FORUM_DISALLOWSUBSCRIBE); $disallowforum = $this->getDataGenerator()->create_module('forum', $options); $options = array('course' => $course->id, 'forcesubscribe' => FORUM_CHOOSESUBSCRIBE); $chooseforum = $this->getDataGenerator()->create_module('forum', $options); $options = array('course' => $course->id, 'forcesubscribe' => FORUM_INITIALSUBSCRIBE); $initialforum = $this->getDataGenerator()->create_module('forum', $options); // Create some users and keep a reference to the first user. $users = $this->helper_create_users($course, 20); $user = reset($users); // Reset the subscription caches. \mod_forum\subscriptions::reset_forum_cache(); $startcount = $DB->perf_get_reads(); $result = \mod_forum\subscriptions::fill_subscription_cache_for_course($course->id, $user->id); $this->assertNull($result); $postfillcount = $DB->perf_get_reads(); $this->assertEquals(1, $postfillcount - $startcount); $this->assertFalse(\mod_forum\subscriptions::fetch_subscription_cache($disallowforum->id, $user->id)); $this->assertFalse(\mod_forum\subscriptions::fetch_subscription_cache($chooseforum->id, $user->id)); $this->assertTrue(\mod_forum\subscriptions::fetch_subscription_cache($initialforum->id, $user->id)); $finalcount = $DB->perf_get_reads(); $this->assertEquals(0, $finalcount - $postfillcount); // Test for all users. foreach ($users as $user) { $result = \mod_forum\subscriptions::fill_subscription_cache_for_course($course->id, $user->id); $this->assertFalse(\mod_forum\subscriptions::fetch_subscription_cache($disallowforum->id, $user->id)); $this->assertFalse(\mod_forum\subscriptions::fetch_subscription_cache($chooseforum->id, $user->id)); $this->assertTrue(\mod_forum\subscriptions::fetch_subscription_cache($initialforum->id, $user->id)); } $finalcount = $DB->perf_get_reads(); $this->assertEquals(count($users), $finalcount - $postfillcount); }