本文整理匯總了PHP中mod_forum\subscriptions::fetch_discussion_subscription方法的典型用法代碼示例。如果您正苦於以下問題:PHP subscriptions::fetch_discussion_subscription方法的具體用法?PHP subscriptions::fetch_discussion_subscription怎麽用?PHP subscriptions::fetch_discussion_subscription使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mod_forum\subscriptions
的用法示例。
在下文中一共展示了subscriptions::fetch_discussion_subscription方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: forum_cron
//.........這裏部分代碼省略.........
if (isset($userto->username)) {
$userto = clone $userto;
} else {
$userto = $DB->get_record('user', array('id' => $userto->id));
forum_cron_minimise_user_record($userto);
}
$userto->viewfullnames = array();
$userto->canpost = array();
$userto->markposts = array();
// Setup this user so that the capabilities are cached, and environment matches receiving user.
cron_setup_user($userto);
// Reset the caches.
foreach ($coursemodules as $forumid => $unused) {
$coursemodules[$forumid]->cache = new stdClass();
$coursemodules[$forumid]->cache->caps = array();
unset($coursemodules[$forumid]->uservisible);
}
foreach ($posts as $pid => $post) {
$discussion = $discussions[$post->discussion];
$forum = $forums[$discussion->forum];
$course = $courses[$forum->course];
$cm =& $coursemodules[$forum->id];
// Do some checks to see if we can bail out now.
// Only active enrolled users are in the list of subscribers.
// This does not necessarily mean that the user is subscribed to the forum or to the discussion though.
if (!isset($subscribedusers[$forum->id][$userto->id])) {
// The user does not subscribe to this forum.
continue;
}
if (!\mod_forum\subscriptions::is_subscribed($userto->id, $forum, $post->discussion, $coursemodules[$forum->id])) {
// The user does not subscribe to this forum, or to this specific discussion.
continue;
}
if ($subscriptiontime = \mod_forum\subscriptions::fetch_discussion_subscription($forum->id, $userto->id)) {
// Skip posts if the user subscribed to the discussion after it was created.
if (isset($subscriptiontime[$post->discussion]) && $subscriptiontime[$post->discussion] > $post->created) {
continue;
}
}
// Don't send email if the forum is Q&A and the user has not posted.
// Initial topics are still mailed.
if ($forum->type == 'qanda' && !forum_get_user_posted_time($discussion->id, $userto->id) && $pid != $discussion->firstpost) {
mtrace('Did not email ' . $userto->id . ' because user has not posted in discussion');
continue;
}
// Get info about the sending user.
if (array_key_exists($post->userid, $users)) {
// We might know the user already.
$userfrom = $users[$post->userid];
if (!isset($userfrom->idnumber)) {
// Minimalised user info, fetch full record.
$userfrom = $DB->get_record('user', array('id' => $userfrom->id));
forum_cron_minimise_user_record($userfrom);
}
} else {
if ($userfrom = $DB->get_record('user', array('id' => $post->userid))) {
forum_cron_minimise_user_record($userfrom);
// Fetch only once if possible, we can add it to user list, it will be skipped anyway.
if ($userscount <= FORUM_CRON_USER_CACHE) {
$userscount++;
$users[$userfrom->id] = $userfrom;
}
} else {
mtrace('Could not find user ' . $post->userid . ', author of post ' . $post->id . '. Unable to send message.');
continue;
}
示例2: test_discussion_subscription_cache_fill
/**
* Test that the discussion subscription cache can filled user-at-a-time.
*/
public function test_discussion_subscription_cache_fill()
{
global $DB;
$this->resetAfterTest(true);
// Create a course, with a forum.
$course = $this->getDataGenerator()->create_course();
$options = array('course' => $course->id, 'forcesubscribe' => FORUM_INITIALSUBSCRIBE);
$forum = $this->getDataGenerator()->create_module('forum', $options);
// Create some users.
$users = $this->helper_create_users($course, 20);
// Post some discussions to the forum.
$discussions = array();
$author = $users[0];
for ($i = 0; $i < 20; $i++) {
list($discussion, $post) = $this->helper_post_to_forum($forum, $author);
$discussions[] = $discussion;
}
// Unsubscribe half the users from the half the discussions.
$forumcount = 0;
$usercount = 0;
foreach ($discussions as $data) {
if ($forumcount % 2) {
continue;
}
foreach ($users as $user) {
if ($usercount % 2) {
continue;
}
\mod_forum\subscriptions::unsubscribe_user_from_discussion($user->id, $discussion);
$usercount++;
}
$forumcount++;
}
// Reset the subscription caches.
\mod_forum\subscriptions::reset_forum_cache();
\mod_forum\subscriptions::reset_discussion_cache();
$startcount = $DB->perf_get_reads();
// Now fetch some subscriptions from that forum - these should use
// the cache and not perform additional queries.
foreach ($users as $user) {
$result = \mod_forum\subscriptions::fetch_discussion_subscription($forum->id, $user->id);
$this->assertInternalType('array', $result);
}
$finalcount = $DB->perf_get_reads();
$this->assertEquals(20, $finalcount - $startcount);
}