本文整理汇总了PHP中forum::enabled_read_tracking方法的典型用法代码示例。如果您正苦于以下问题:PHP forum::enabled_read_tracking方法的具体用法?PHP forum::enabled_read_tracking怎么用?PHP forum::enabled_read_tracking使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forum
的用法示例。
在下文中一共展示了forum::enabled_read_tracking方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: query_forums
/**
* Internal method. Queries for a number of forums, including additional
* data about unread posts etc. Returns the database result.
* @param array $cmids If specified, array of course-module IDs of desired
* forums
* @param object $course If specified, course object
* @param int $userid User ID, 0 = current user
* @param int $unread Type of unread data to obtain (UNREAD_xx constant).
* @param array $groups Array of group IDs to which the given user belongs
* (may be null if unread data not required)
* @param array $aagforums Array of forums in which the user has
* 'access all groups' (may be null if unread data not required)
* @param array $viewhiddenforums Array of forums in which the user has
* 'view hidden discussions' (may be null if unread data not required)
* @return array Array of row objects
*/
private static function query_forums($cmids = array(), $course = null, $userid, $unread, $groups, $aagforums, $viewhiddenforums)
{
global $CFG, $USER;
if (!count($cmids) && !$course) {
throw new forum_exception("forum::query_forums requires course id or cmids");
}
if (count($cmids)) {
$conditions = "cm.id " . forum_utils::in_or_equals($cmids);
} else {
$conditions = "f.course = {$course->id}";
}
$singleforum = count($cmids) == 1 ? reset($cmids) : false;
$inviewhiddenforums = forum_utils::in_or_equals($viewhiddenforums);
// This array of additional results is used later if combining
// standard results with single-forum calls.
$plusresult = array();
// For read tracking, we get a count of total number of posts in
// forum, and total number of read posts in the forum (this
// is so we can display the number of UNread posts, but the query
// works that way around because it will return 0 if no read
// information is stored).
if ($unread != self::UNREAD_NONE && forum::enabled_read_tracking()) {
// Work out when unread status ends
$endtime = time() - $CFG->forumng_readafterdays * 24 * 3600;
if (!$userid) {
$userid = $USER->id;
}
$ingroups = forum_utils::in_or_equals($groups);
$inaagforums = forum_utils::in_or_equals($aagforums);
$restrictionsql = '';
if ($singleforum) {
// If it is for a single forum, get the restriction from the
// forum type
$forum = forum::get_from_cmid($singleforum, forum::CLONE_DIRECT);
$type = $forum->get_type();
if ($type->has_unread_restriction()) {
$value = $type->get_unread_restriction_sql($forum);
if ($value) {
$restrictionsql = 'AND ' . $value;
}
}
} else {
// When it is not for a single forum, we can only group together
// results for types that do not place restrictions on the
// unread count.
$modinfo = self::get_modinfo_special($course, $cmids);
$okayids = array();
if (array_key_exists('forumng', $modinfo->instances)) {
foreach ($modinfo->instances['forumng'] as $info) {
if (count($cmids) && !in_array($info->id, $cmids)) {
continue;
}
$type = self::get_type_from_modinfo_info($info);
if (forum_type::get_new($type)->has_unread_restriction()) {
// This one's a problem! Do it individually
$problemresults = self::query_forums(array($info->id), null, $userid, $unread, $groups, $aagforums, $viewhiddenforums);
foreach ($problemresults as $problemresult) {
$plusresult[$problemresult->f_id] = $problemresult;
}
} else {
$okayids[] = $info->id;
}
}
}
if (count($okayids) == 0) {
// There are no 'normal' forums, so return result so far
// after sorting it
uasort($plusresult, 'forum::sort_forum_result');
return $plusresult;
} else {
// Fall through to normal calculation, but change conditions
// to include only the 'normal' forums
$conditions .= " AND cm.id " . forum_utils::in_or_equals($okayids);
}
}
// NOTE fpfirst is used only by forum types, not here
$now = time();
$sharedquerypart = "\nFROM\n {$CFG->prefix}forumng_discussions fd\n INNER JOIN {$CFG->prefix}forumng_posts fplast ON fd.lastpostid = fplast.id\n INNER JOIN {$CFG->prefix}forumng_posts fpfirst ON fd.postid = fpfirst.id\n LEFT JOIN {$CFG->prefix}forumng_read fr ON fd.id = fr.discussionid AND fr.userid={$userid}\nWHERE\n fd.forumid=f.id AND fplast.modified>{$endtime}\n AND (\n (fd.groupid IS NULL)\n OR (fd.groupid {$ingroups})\n OR cm.groupmode=" . VISIBLEGROUPS . "\n OR (fd.forumid {$inaagforums})\n )\n AND fd.deleted=0\n AND (\n ((fd.timestart=0 OR fd.timestart <= {$now})\n AND (fd.timeend=0 OR fd.timeend > {$now}))\n OR (fd.forumid {$inviewhiddenforums})\n )\n AND ((fplast.edituserid IS NOT NULL AND fplast.edituserid<>{$userid})\n OR fplast.userid<>{$userid})\n AND (fr.time IS NULL OR fplast.modified>fr.time)\n {$restrictionsql}";
// Note: There is an unusual case in which this number can
// be inaccurate. It is to do with ignoring messages the user
// posted. We consider a discussion as 'not unread' if the last
// message is by current user. In actual fact, a discussion could
// contain unread messages if messages were posted by other users
// after this user viewed the forum last, but before they posted
//.........这里部分代码省略.........
示例2: is_read_tracked
/**
* @return bool True if read tracking is enabled for this discussion
* (it is not too old, and read tracking is turned on globally)
*/
public function is_read_tracked()
{
$this->check_full();
return forum::enabled_read_tracking() && $this->discussionfields->timemodified >= forum::get_read_tracking_deadline();
}
示例3: split
/**
* Splits this post to become a new discussion
* @param $newsubject
* @param bool $log True to log action
* @return int ID of new discussion
*/
function split($newsubject, $log = true)
{
global $CFG;
$this->require_children();
// Begin a transaction
forum_utils::start_transaction();
$olddiscussion = $this->get_discussion();
// Create new discussion
$newest = null;
$this->find_newest_child($newest);
$newdiscussionid = $olddiscussion->clone_for_split($this->get_id(), $newest->get_id());
// Update all child posts
$list = array();
$this->list_child_ids($list);
unset($list[0]);
// Don't include this post itself
if (count($list) > 0) {
$inorequals = forum_utils::in_or_equals($list);
forum_utils::execute_sql("\nUPDATE\n {$CFG->prefix}forumng_posts\nSET\n discussionid = {$newdiscussionid}\nWHERE\n id {$inorequals}");
}
// Update this post
$changes = new stdClass();
$changes->id = $this->get_id();
$changes->subject = addslashes($newsubject);
$changes->parentpostid = null;
//When split the post, reset the important to 0 so that it is not highlighted.
$changes->important = 0;
// Note don't update modified time, or it makes this post unread,
// which isn't very helpful
$changes->discussionid = $newdiscussionid;
forum_utils::update_record('forumng_posts', $changes);
// Update read data if relevant
if (forum::enabled_read_tracking() && $newest->get_modified() >= forum::get_read_tracking_deadline()) {
$rs = forum_utils::get_recordset_sql("\nSELECT\n userid, time\nFROM\n {$CFG->prefix}forumng_read\nWHERE\n discussionid = " . $olddiscussion->get_id() . "\n AND time >= " . $this->get_created());
while ($rec = rs_fetch_next_record($rs)) {
$rec->discussionid = $newdiscussionid;
forum_utils::insert_record('forumng_read', $rec);
}
rs_close($rs);
}
$olddiscussion->possible_lastpost_change();
// Move attachments
$olddiscussionfolder = $olddiscussion->get_attachment_folder();
$newdiscussionfolder = $olddiscussion->get_attachment_folder(0, 0, $newdiscussionid);
if (is_dir($olddiscussionfolder)) {
// Put this post back on the list
$list[0] = $this->get_id();
// Loop through all posts; move attachments if present
$madenewfolder = false;
foreach ($list as $id) {
$oldfolder = $olddiscussionfolder . '/' . $id;
$newfolder = $newdiscussionfolder . '/' . $id;
if (is_dir($oldfolder)) {
if (!$madenewfolder) {
check_dir_exists($newfolder, true, true);
$madenewfolder = true;
}
forum_utils::rename($oldfolder, $newfolder);
}
}
}
if ($log) {
$this->log('split post');
}
forum_utils::finish_transaction();
$this->get_discussion()->uncache();
// If discussion-based completion is turned on, this may enable someone
// to complete
if ($this->get_forum()->get_completion_discussions()) {
$this->update_completion(true);
}
return $newdiscussionid;
}