$strforums = get_string('forums', 'hsuforum'); $strforum = get_string('forum', 'hsuforum'); $strdescription = get_string('description'); $strdiscussions = get_string('discussions', 'hsuforum'); $strsubscribed = get_string('subscribed', 'hsuforum'); $strunreadposts = get_string('unreadposts', 'hsuforum'); $strmarkallread = get_string('markallread', 'hsuforum'); $strsubscribe = get_string('subscribe', 'hsuforum'); $strunsubscribe = get_string('unsubscribe', 'hsuforum'); $stryes = get_string('yes'); $strno = get_string('no'); $strrss = get_string('rss'); $stremaildigest = get_string('emaildigest'); $searchform = hsuforum_search_form($course); // Retrieve the list of forum digest options for later. $digestoptions = hsuforum_get_user_digest_options(); $digestoptions_selector = new single_select(new moodle_url('/mod/hsuforum/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'); $generaltable->head[] = $strunreadposts; $generaltable->align[] = 'center'; $subscribed_forums = hsuforum_get_subscribed_forums($course); $can_subscribe = is_enrolled($coursecontext); if ($can_subscribe) { $generaltable->head[] = $strsubscribed; $generaltable->align[] = 'center'; $generaltable->head[] = $stremaildigest . ' ' . $OUTPUT->help_icon('emaildigesttype', 'mod_hsuforum'); $generaltable->align[] = 'center';
public function test_get_user_digest_options_sorting() { global $USER, $DB; $this->resetAfterTest(true); // Set up a basic user enrolled in a course. $helper = $this->helper_setup_user_in_course(); $user = $helper->user; $course1 = $helper->courses->course1; $forum1 = $helper->forums->forum1; // Set to the user. self::setUser($helper->user); // Retrieve the list of applicable options. $options = hsuforum_get_user_digest_options(); // The default option must always be at the top of the list. $lastoption = -2; foreach ($options as $value => $description) { $this->assertGreaterThan($lastoption, $value); $lastoption = $value; } }
/** * Set the per-forum maildigest option for the specified user. * * @param stdClass $forum The forum to set the option for. * @param int $maildigest The maildigest option. * @param stdClass $user The user object. This defaults to the global $USER object. * @throws invalid_digest_setting thrown if an invalid maildigest option is provided. */ function hsuforum_set_user_maildigest($forum, $maildigest, $user = null) { global $DB, $USER; if (is_number($forum)) { $forum = $DB->get_record('hsuforum', array('id' => $forum)); } if ($user === null) { $user = $USER; } $course = $DB->get_record('course', array('id' => $forum->course), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('hsuforum', $forum->id, $course->id, false, MUST_EXIST); $context = context_module::instance($cm->id); // User must be allowed to see this forum. require_capability('mod/hsuforum:viewdiscussion', $context, $user->id); // Validate the maildigest setting. $digestoptions = hsuforum_get_user_digest_options($user); if (!isset($digestoptions[$maildigest])) { throw new moodle_exception('invaliddigestsetting', 'mod_hsuforum'); } // Attempt to retrieve any existing forum digest record. $subscription = $DB->get_record('hsuforum_digests', array('userid' => $user->id, 'forum' => $forum->id)); // Create or Update the existing maildigest setting. if ($subscription) { if ($maildigest == -1) { $DB->delete_records('hsuforum_digests', array('forum' => $forum->id, 'userid' => $user->id)); } else { if ($maildigest !== $subscription->maildigest) { // Only update the maildigest setting if it's changed. $subscription->maildigest = $maildigest; $DB->update_record('hsuforum_digests', $subscription); } } } else { if ($maildigest != -1) { // Only insert the maildigest setting if it's non-default. $subscription = new stdClass(); $subscription->forum = $forum->id; $subscription->userid = $user->id; $subscription->maildigest = $maildigest; $subscription->id = $DB->insert_record('hsuforum_digests', $subscription); } } }