當前位置: 首頁>>代碼示例>>PHP>>正文


PHP subscriptions::fetch_subscribed_users方法代碼示例

本文整理匯總了PHP中mod_forum\subscriptions::fetch_subscribed_users方法的典型用法代碼示例。如果您正苦於以下問題:PHP subscriptions::fetch_subscribed_users方法的具體用法?PHP subscriptions::fetch_subscribed_users怎麽用?PHP subscriptions::fetch_subscribed_users使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mod_forum\subscriptions的用法示例。


在下文中一共展示了subscriptions::fetch_subscribed_users方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: forum_cron


//.........這裏部分代碼省略.........
            }
            $forumid = $discussions[$discussionid]->forum;
            if (!isset($forums[$forumid])) {
                if ($forum = $DB->get_record('forum', array('id' => $forumid))) {
                    $forums[$forumid] = $forum;
                } else {
                    mtrace('Could not find forum ' . $forumid);
                    unset($posts[$pid]);
                    continue;
                }
            }
            $courseid = $forums[$forumid]->course;
            if (!isset($courses[$courseid])) {
                if ($course = $DB->get_record('course', array('id' => $courseid))) {
                    $courses[$courseid] = $course;
                } else {
                    mtrace('Could not find course ' . $courseid);
                    unset($posts[$pid]);
                    continue;
                }
            }
            if (!isset($coursemodules[$forumid])) {
                if ($cm = get_coursemodule_from_instance('forum', $forumid, $courseid)) {
                    $coursemodules[$forumid] = $cm;
                } else {
                    mtrace('Could not find course module for forum ' . $forumid);
                    unset($posts[$pid]);
                    continue;
                }
            }
            // Caching subscribed users of each forum.
            if (!isset($subscribedusers[$forumid])) {
                $modcontext = context_module::instance($coursemodules[$forumid]->id);
                if ($subusers = \mod_forum\subscriptions::fetch_subscribed_users($forums[$forumid], 0, $modcontext, 'u.*', true)) {
                    foreach ($subusers as $postuser) {
                        // this user is subscribed to this forum
                        $subscribedusers[$forumid][$postuser->id] = $postuser->id;
                        $userscount++;
                        if ($userscount > FORUM_CRON_USER_CACHE) {
                            // Store minimal user info.
                            $minuser = new stdClass();
                            $minuser->id = $postuser->id;
                            $users[$postuser->id] = $minuser;
                        } else {
                            // Cache full user record.
                            forum_cron_minimise_user_record($postuser);
                            $users[$postuser->id] = $postuser;
                        }
                    }
                    // Release memory.
                    unset($subusers);
                    unset($postuser);
                }
            }
            $mailcount[$pid] = 0;
            $errorcount[$pid] = 0;
        }
    }
    if ($users && $posts) {
        $urlinfo = parse_url($CFG->wwwroot);
        $hostname = $urlinfo['host'];
        foreach ($users as $userto) {
            // Terminate if processing of any account takes longer than 2 minutes.
            core_php_time_limit::raise(120);
            mtrace('Processing user ' . $userto->id);
            // Init user caches - we keep the cache for one cycle only, otherwise it could consume too much memory.
開發者ID:abhilash1994,項目名稱:moodle,代碼行數:67,代碼來源:lib.php

示例2: test_forum_disallow_subscribe_on_create

 /**
  * Test subscription using disallow subscription on create.
  */
 public function test_forum_disallow_subscribe_on_create()
 {
     global $CFG;
     $this->resetAfterTest();
     $usercount = 5;
     $course = $this->getDataGenerator()->create_course();
     $users = array();
     for ($i = 0; $i < $usercount; $i++) {
         $user = $this->getDataGenerator()->create_user();
         $users[] = $user;
         $this->getDataGenerator()->enrol_user($user->id, $course->id);
     }
     $options = array('course' => $course->id, 'forcesubscribe' => FORUM_DISALLOWSUBSCRIBE);
     // Subscription prevented.
     $forum = $this->getDataGenerator()->create_module('forum', $options);
     $result = \mod_forum\subscriptions::fetch_subscribed_users($forum);
     // No subscriptions by default.
     $this->assertEquals(0, count($result));
     foreach ($users as $user) {
         $this->assertFalse(\mod_forum\subscriptions::is_subscribed($user->id, $forum));
     }
 }
開發者ID:rushi963,項目名稱:moodle,代碼行數:25,代碼來源:lib_test.php

示例3: test_fetch_subscribed_users_discussion_subscriptions

 /**
  * Test that unusual combinations of discussion subscriptions do not affect the subscribed user list.
  */
 public function test_fetch_subscribed_users_discussion_subscriptions()
 {
     global $DB;
     $this->resetAfterTest(true);
     // Create a course, with a forum. where users are initially subscribed.
     $course = $this->getDataGenerator()->create_course();
     $options = array('course' => $course->id, 'forcesubscribe' => FORUM_INITIALSUBSCRIBE);
     $forum = $this->getDataGenerator()->create_module('forum', $options);
     // Create some user enrolled in the course as a student.
     $usercount = 5;
     $users = $this->helper_create_users($course, $usercount);
     list($discussion, $post) = $this->helper_post_to_forum($forum, $users[0]);
     // All users should be subscribed.
     $subscribers = \mod_forum\subscriptions::fetch_subscribed_users($forum);
     $this->assertEquals($usercount, count($subscribers));
     $subscribers = \mod_forum\subscriptions::fetch_subscribed_users($forum, 0, null, null, true);
     $this->assertEquals($usercount, count($subscribers));
     \mod_forum\subscriptions::unsubscribe_user_from_discussion($users[0]->id, $discussion);
     // All users should be subscribed.
     $subscribers = \mod_forum\subscriptions::fetch_subscribed_users($forum);
     $this->assertEquals($usercount, count($subscribers));
     // All users should be subscribed.
     $subscribers = \mod_forum\subscriptions::fetch_subscribed_users($forum, 0, null, null, true);
     $this->assertEquals($usercount, count($subscribers));
     // Manually insert an extra subscription for one of the users.
     $record = new stdClass();
     $record->userid = $users[2]->id;
     $record->forum = $forum->id;
     $record->discussion = $discussion->id;
     $record->preference = \mod_forum\subscriptions::FORUM_DISCUSSION_SUBSCRIBED;
     $DB->insert_record('forum_discussion_subs', $record);
     // The discussion count should not have changed.
     $subscribers = \mod_forum\subscriptions::fetch_subscribed_users($forum);
     $this->assertEquals($usercount, count($subscribers));
     $subscribers = \mod_forum\subscriptions::fetch_subscribed_users($forum, 0, null, null, true);
     $this->assertEquals($usercount, count($subscribers));
     // Unsubscribe 2 users.
     $unsubscribedcount = 2;
     for ($i = 0; $i < $unsubscribedcount; $i++) {
         \mod_forum\subscriptions::unsubscribe_user($users[$i]->id, $forum);
     }
     // The subscription count should now take into account those users who have been unsubscribed.
     $subscribers = \mod_forum\subscriptions::fetch_subscribed_users($forum);
     $this->assertEquals($usercount - $unsubscribedcount, count($subscribers));
     $subscribers = \mod_forum\subscriptions::fetch_subscribed_users($forum, 0, null, null, true);
     $this->assertEquals($usercount - $unsubscribedcount, count($subscribers));
     // Now subscribe one of those users back to the discussion.
     $subscribeddiscussionusers = 1;
     for ($i = 0; $i < $subscribeddiscussionusers; $i++) {
         \mod_forum\subscriptions::subscribe_user_to_discussion($users[$i]->id, $discussion);
     }
     $subscribers = \mod_forum\subscriptions::fetch_subscribed_users($forum);
     $this->assertEquals($usercount - $unsubscribedcount, count($subscribers));
     $subscribers = \mod_forum\subscriptions::fetch_subscribed_users($forum, 0, null, null, true);
     $this->assertEquals($usercount - $unsubscribedcount + $subscribeddiscussionusers, count($subscribers));
 }
開發者ID:Jinelle,項目名稱:moodle,代碼行數:59,代碼來源:subscriptions_test.php

示例4: print_error

 $forums = $modinfo->get_instances_of('forum');
 if (!array_key_exists($forumto->id, $forums)) {
     print_error('cannotmovetonotfound', 'forum', $return);
 }
 $cmto = $forums[$forumto->id];
 if (!$cmto->uservisible) {
     print_error('cannotmovenotvisible', 'forum', $return);
 }
 $destinationctx = context_module::instance($cmto->id);
 require_capability('mod/forum:startdiscussion', $destinationctx);
 if (!forum_move_attachments($discussion, $forum->id, $forumto->id)) {
     echo $OUTPUT->notification("Errors occurred while moving attachment directories - check your file permissions");
 }
 // For each subscribed user in this forum and discussion, copy over per-discussion subscriptions if required.
 $discussiongroup = $discussion->groupid == -1 ? 0 : $discussion->groupid;
 $potentialsubscribers = \mod_forum\subscriptions::fetch_subscribed_users($forum, $discussiongroup, $modcontext, 'u.id', true);
 // Pre-seed the subscribed_discussion caches.
 // Firstly for the forum being moved to.
 \mod_forum\subscriptions::fill_subscription_cache($forumto->id);
 // And also for the discussion being moved.
 \mod_forum\subscriptions::fill_subscription_cache($forum->id);
 $subscriptionchanges = array();
 $subscriptiontime = time();
 foreach ($potentialsubscribers as $subuser) {
     $userid = $subuser->id;
     $targetsubscription = \mod_forum\subscriptions::is_subscribed($userid, $forumto, null, $cmto);
     $discussionsubscribed = \mod_forum\subscriptions::is_subscribed($userid, $forum, $discussion->id);
     $forumsubscribed = \mod_forum\subscriptions::is_subscribed($userid, $forum);
     if ($forumsubscribed && !$discussionsubscribed && $targetsubscription) {
         // The user has opted out of this discussion and the move would cause them to receive notifications again.
         // Ensure they are unsubscribed from the discussion still.
開發者ID:mongo0se,項目名稱:moodle,代碼行數:31,代碼來源:discuss.php

示例5: get_string

    }
    $subscriberselector->invalidate_selected_users();
    $existingselector->invalidate_selected_users();
    $subscriberselector->set_existing_subscribers($existingselector->find_users(''));
}
$strsubscribers = get_string("subscribers", "forum");
$PAGE->navbar->add($strsubscribers);
$PAGE->set_title($strsubscribers);
$PAGE->set_heading($COURSE->fullname);
if (has_capability('mod/forum:managesubscriptions', $context)) {
    $PAGE->set_button(forum_update_subscriptions_button($course->id, $id));
    if ($edit != -1) {
        $USER->subscriptionsediting = $edit;
    }
} else {
    unset($USER->subscriptionsediting);
}
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('forum', 'forum') . ' ' . $strsubscribers);
if (empty($USER->subscriptionsediting)) {
    $subscribers = \mod_forum\subscriptions::fetch_subscribed_users($forum, $currentgroup, $context);
    echo $forumoutput->subscriber_overview($subscribers, $forum, $course);
} else {
    if (\mod_forum\subscriptions::is_forcesubscribed($forum)) {
        $subscriberselector->set_force_subscribed(true);
        echo $forumoutput->subscribed_users($subscriberselector);
    } else {
        echo $forumoutput->subscriber_selection_form($existingselector, $subscriberselector);
    }
}
echo $OUTPUT->footer();
開發者ID:abhilash1994,項目名稱:moodle,代碼行數:31,代碼來源:subscribers.php

示例6: forum_subscribed_users

/**
 * Returns list of user objects that are subscribed to this forum.
 *
 * @param stdClass $course the course
 * @param stdClass $forum the forum
 * @param int $groupid group id, or 0 for all.
 * @param context_module $context the forum context, to save re-fetching it where possible.
 * @param string $fields requested user fields (with "u." table prefix)
 * @param boolean $considerdiscussions Whether to take discussion subscriptions and unsubscriptions into consideration.
 * @return array list of users.
 * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::fetch_subscribed_users() instead
 */
function forum_subscribed_users($course, $forum, $groupid = 0, $context = null, $fields = null)
{
    debugging("forum_subscribed_users() has been deprecated, please use \\mod_forum\\subscriptions::fetch_subscribed_users() instead.", DEBUG_DEVELOPER);
    \mod_forum\subscriptions::fetch_subscribed_users($forum, $groupid, $context, $fields);
}
開發者ID:pzhu2004,項目名稱:moodle,代碼行數:17,代碼來源:deprecatedlib.php


注:本文中的mod_forum\subscriptions::fetch_subscribed_users方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。