예제 #1
0
$strdiscussions = get_string('discussions', 'forum');
$strsubscribed = get_string('subscribed', 'forum');
$strunreadposts = get_string('unreadposts', 'forum');
$strtracking = get_string('tracking', 'forum');
$strmarkallread = get_string('markallread', 'forum');
$strtrackforum = get_string('trackforum', 'forum');
$strnotrackforum = get_string('notrackforum', 'forum');
$strsubscribe = get_string('subscribe', 'forum');
$strunsubscribe = get_string('unsubscribe', 'forum');
$stryes = get_string('yes');
$strno = get_string('no');
$strrss = get_string('rss');
$stremaildigest = get_string('emaildigest');
$searchform = forum_search_form($course);
// Retrieve the list of forum digest options for later.
$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';
}
$subscribed_forums = forum_get_subscribed_forums($course);
$can_subscribe = is_enrolled($coursecontext);
예제 #2
0
파일: lib.php 프로젝트: abhilash1994/moodle
/**
 * 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 forum_set_user_maildigest($forum, $maildigest, $user = null)
{
    global $DB, $USER;
    if (is_number($forum)) {
        $forum = $DB->get_record('forum', array('id' => $forum));
    }
    if ($user === null) {
        $user = $USER;
    }
    $course = $DB->get_record('course', array('id' => $forum->course), '*', MUST_EXIST);
    $cm = get_coursemodule_from_instance('forum', $forum->id, $course->id, false, MUST_EXIST);
    $context = context_module::instance($cm->id);
    // User must be allowed to see this forum.
    require_capability('mod/forum:viewdiscussion', $context, $user->id);
    // Validate the maildigest setting.
    $digestoptions = forum_get_user_digest_options($user);
    if (!isset($digestoptions[$maildigest])) {
        throw new moodle_exception('invaliddigestsetting', 'mod_forum');
    }
    // Attempt to retrieve any existing forum digest record.
    $subscription = $DB->get_record('forum_digests', array('userid' => $user->id, 'forum' => $forum->id));
    // Create or Update the existing maildigest setting.
    if ($subscription) {
        if ($maildigest == -1) {
            $DB->delete_records('forum_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('forum_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('forum_digests', $subscription);
        }
    }
}
예제 #3
0
파일: renderer.php 프로젝트: evltuma/moodle
 /**
  * Create the inplace_editable used to select forum digest options.
  *
  * @param   stdClass    $forum  The forum to create the editable for.
  * @param   int         $value  The current value for this user
  * @return  inplace_editable
  */
 public function render_digest_options($forum, $value)
 {
     $options = forum_get_user_digest_options();
     $editable = new \core\output\inplace_editable('mod_forum', 'digestoptions', $forum->id, true, $options[$value], $value);
     $editable->set_type_select($options);
     return $editable;
 }
예제 #4
0
 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 = forum_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;
     }
 }
 public function test_mod_forum_get_user_digest_options_sorting()
 {
     global $USER, $DB;
     $this->resetAfterTest(true);
     // Create a user.
     $user = self::getDataGenerator()->create_user();
     // Set to the user.
     self::setUser($user);
     // Retrieve the list of applicable options.
     $options = forum_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;
     }
 }