本文整理汇总了PHP中forum_tp_get_course_unread_posts函数的典型用法代码示例。如果您正苦于以下问题:PHP forum_tp_get_course_unread_posts函数的具体用法?PHP forum_tp_get_course_unread_posts怎么用?PHP forum_tp_get_course_unread_posts使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了forum_tp_get_course_unread_posts函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_forum_tp_get_course_unread_posts
/**
* Test the logic in the forum_tp_get_course_unread_posts() function.
*/
public function test_forum_tp_get_course_unread_posts()
{
global $CFG;
$this->resetAfterTest();
$useron = $this->getDataGenerator()->create_user(array('trackforums' => 1));
$useroff = $this->getDataGenerator()->create_user(array('trackforums' => 0));
$course = $this->getDataGenerator()->create_course();
$options = array('course' => $course->id, 'trackingtype' => FORUM_TRACKING_OFF);
// Off.
$forumoff = $this->getDataGenerator()->create_module('forum', $options);
$options = array('course' => $course->id, 'trackingtype' => FORUM_TRACKING_FORCED);
// On.
$forumforce = $this->getDataGenerator()->create_module('forum', $options);
$options = array('course' => $course->id, 'trackingtype' => FORUM_TRACKING_OPTIONAL);
// Optional.
$forumoptional = $this->getDataGenerator()->create_module('forum', $options);
// Add discussions to the tracking off forum.
$record = new stdClass();
$record->course = $course->id;
$record->userid = $useron->id;
$record->forum = $forumoff->id;
$discussionoff = $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
// Add discussions to the tracking forced forum.
$record = new stdClass();
$record->course = $course->id;
$record->userid = $useron->id;
$record->forum = $forumforce->id;
$discussionforce = $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
// Add post to the tracking forced discussion.
$record = new stdClass();
$record->course = $course->id;
$record->userid = $useroff->id;
$record->forum = $forumforce->id;
$record->discussion = $discussionforce->id;
$this->getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
// Add discussions to the tracking optional forum.
$record = new stdClass();
$record->course = $course->id;
$record->userid = $useron->id;
$record->forum = $forumoptional->id;
$discussionoptional = $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
// Allow force.
$CFG->forum_allowforcedreadtracking = 1;
$result = forum_tp_get_course_unread_posts($useron->id, $course->id);
$this->assertEquals(2, count($result));
$this->assertEquals(false, isset($result[$forumoff->id]));
$this->assertEquals(true, isset($result[$forumforce->id]));
$this->assertEquals(2, $result[$forumforce->id]->unread);
$this->assertEquals(true, isset($result[$forumoptional->id]));
$this->assertEquals(1, $result[$forumoptional->id]->unread);
$result = forum_tp_get_course_unread_posts($useroff->id, $course->id);
$this->assertEquals(1, count($result));
$this->assertEquals(false, isset($result[$forumoff->id]));
$this->assertEquals(true, isset($result[$forumforce->id]));
$this->assertEquals(2, $result[$forumforce->id]->unread);
$this->assertEquals(false, isset($result[$forumoptional->id]));
// Don't allow force.
$CFG->forum_allowforcedreadtracking = 0;
$result = forum_tp_get_course_unread_posts($useron->id, $course->id);
$this->assertEquals(2, count($result));
$this->assertEquals(false, isset($result[$forumoff->id]));
$this->assertEquals(true, isset($result[$forumforce->id]));
$this->assertEquals(2, $result[$forumforce->id]->unread);
$this->assertEquals(true, isset($result[$forumoptional->id]));
$this->assertEquals(1, $result[$forumoptional->id]->unread);
$result = forum_tp_get_course_unread_posts($useroff->id, $course->id);
$this->assertEquals(0, count($result));
$this->assertEquals(false, isset($result[$forumoff->id]));
$this->assertEquals(false, isset($result[$forumforce->id]));
$this->assertEquals(false, isset($result[$forumoptional->id]));
// Stop tracking so we can test again.
forum_tp_stop_tracking($forumforce->id, $useron->id);
forum_tp_stop_tracking($forumoptional->id, $useron->id);
forum_tp_stop_tracking($forumforce->id, $useroff->id);
forum_tp_stop_tracking($forumoptional->id, $useroff->id);
// Allow force.
$CFG->forum_allowforcedreadtracking = 1;
$result = forum_tp_get_course_unread_posts($useron->id, $course->id);
$this->assertEquals(1, count($result));
$this->assertEquals(false, isset($result[$forumoff->id]));
$this->assertEquals(true, isset($result[$forumforce->id]));
$this->assertEquals(2, $result[$forumforce->id]->unread);
$this->assertEquals(false, isset($result[$forumoptional->id]));
$result = forum_tp_get_course_unread_posts($useroff->id, $course->id);
$this->assertEquals(1, count($result));
$this->assertEquals(false, isset($result[$forumoff->id]));
$this->assertEquals(true, isset($result[$forumforce->id]));
$this->assertEquals(2, $result[$forumforce->id]->unread);
$this->assertEquals(false, isset($result[$forumoptional->id]));
// Don't allow force.
$CFG->forum_allowforcedreadtracking = 0;
$result = forum_tp_get_course_unread_posts($useron->id, $course->id);
$this->assertEquals(0, count($result));
$this->assertEquals(false, isset($result[$forumoff->id]));
$this->assertEquals(false, isset($result[$forumforce->id]));
$this->assertEquals(false, isset($result[$forumoptional->id]));
$result = forum_tp_get_course_unread_posts($useroff->id, $course->id);
//.........这里部分代码省略.........
示例2: forum_tp_count_forum_unread_posts
/**
* Returns the count of records for the provided user and forum and [optionally] group.
*
* @global object
* @global object
* @global object
* @param object $cm
* @param object $course
* @return int
*/
function forum_tp_count_forum_unread_posts($cm, $course) {
global $CFG, $USER, $DB;
static $readcache = array();
$forumid = $cm->instance;
if (!isset($readcache[$course->id])) {
$readcache[$course->id] = array();
if ($counts = forum_tp_get_course_unread_posts($USER->id, $course->id)) {
foreach ($counts as $count) {
$readcache[$course->id][$count->id] = $count->unread;
}
}
}
if (empty($readcache[$course->id][$forumid])) {
// no need to check group mode ;-)
return 0;
}
$groupmode = groups_get_activity_groupmode($cm, $course);
if ($groupmode != SEPARATEGROUPS) {
return $readcache[$course->id][$forumid];
}
if (has_capability('moodle/site:accessallgroups', context_module::instance($cm->id))) {
return $readcache[$course->id][$forumid];
}
require_once($CFG->dirroot.'/course/lib.php');
$modinfo = get_fast_modinfo($course);
if (is_null($modinfo->groups)) {
$modinfo->groups = groups_get_user_groups($course->id, $USER->id);
}
$mygroups = $modinfo->groups[$cm->groupingid];
// add all groups posts
if (empty($mygroups)) {
$mygroups = array(-1=>-1);
} else {
$mygroups[-1] = -1;
}
list ($groups_sql, $groups_params) = $DB->get_in_or_equal($mygroups);
$now = round(time(), -2); // db cache friendliness
$cutoffdate = $now - ($CFG->forum_oldpostdays*24*60*60);
$params = array($USER->id, $forumid, $cutoffdate);
if (!empty($CFG->forum_enabletimedposts)) {
$timedsql = "AND d.timestart < ? AND (d.timeend = 0 OR d.timeend > ?)";
$params[] = $now;
$params[] = $now;
} else {
$timedsql = "";
}
$params = array_merge($params, $groups_params);
$sql = "SELECT COUNT(p.id)
FROM {forum_posts} p
JOIN {forum_discussions} d ON p.discussion = d.id
LEFT JOIN {forum_read} r ON (r.postid = p.id AND r.userid = ?)
WHERE d.forum = ?
AND p.modified >= ? AND r.id is NULL
$timedsql
AND d.groupid $groups_sql";
return $DB->get_field_sql($sql, $params);
}
示例3: forum_tp_count_forum_unread_posts
/**
* Returns the count of records for the provided user and forum and [optionally] group.
*/
function forum_tp_count_forum_unread_posts($cm, $course)
{
global $CFG, $USER;
static $readcache = array();
$forumid = $cm->instance;
if (!isset($readcache[$course->id])) {
$readcache[$course->id] = array();
if ($counts = forum_tp_get_course_unread_posts($USER->id, $course->id)) {
foreach ($counts as $count) {
$readcache[$course->id][$count->id] = $count->unread;
}
}
}
if (empty($readcache[$course->id][$forumid])) {
// no need to check group mode ;-)
return 0;
}
$groupmode = groups_get_activity_groupmode($cm, $course);
if ($groupmode != SEPARATEGROUPS) {
return $readcache[$course->id][$forumid];
}
if (has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id))) {
return $readcache[$course->id][$forumid];
}
require_once $CFG->dirroot . '/course/lib.php';
$modinfo =& get_fast_modinfo($course);
if (is_null($modinfo->groups)) {
$modinfo->groups = groups_get_user_groups($course->id, $USER->id);
}
if (empty($CFG->enablegroupings)) {
$mygroups = $modinfo->groups[0];
} else {
$mygroups = $modinfo->groups[$cm->groupingid];
}
// add all groups posts
if (empty($mygroups)) {
$mygroups = array(-1 => -1);
} else {
$mygroups[-1] = -1;
}
$mygroups = implode(',', $mygroups);
$now = round(time(), -2);
// db cache friendliness
$cutoffdate = $now - $CFG->forum_oldpostdays * 24 * 60 * 60;
if (!empty($CFG->forum_enabletimedposts)) {
$timedsql = "AND d.timestart < {$now} AND (d.timeend = 0 OR d.timeend > {$now})";
} else {
$timedsql = "";
}
$sql = "SELECT COUNT(p.id)\n FROM {$CFG->prefix}forum_posts p\n JOIN {$CFG->prefix}forum_discussions d ON p.discussion = d.id\n LEFT JOIN {$CFG->prefix}forum_read r ON (r.postid = p.id AND r.userid = {$USER->id})\n WHERE d.forum = {$forumid}\n AND p.modified >= {$cutoffdate} AND r.id is NULL\n {$timedsql}\n AND d.groupid IN ({$mygroups})";
return get_field_sql($sql);
}