本文整理汇总了PHP中forum_print_posts_flat函数的典型用法代码示例。如果您正苦于以下问题:PHP forum_print_posts_flat函数的具体用法?PHP forum_print_posts_flat怎么用?PHP forum_print_posts_flat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了forum_print_posts_flat函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: forum_print_discussion
/**
*
*/
function forum_print_discussion($course, $cm, $forum, $discussion, $post, $mode, $canreply = NULL, $canrate = false)
{
global $USER, $CFG;
if (!empty($USER->id)) {
$ownpost = $USER->id == $post->userid;
} else {
$ownpost = false;
}
if ($canreply === NULL) {
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
$reply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext);
} else {
$reply = $canreply;
}
// $cm holds general cache for forum functions
$cm->cache = new object();
$cm->cache->groups = groups_get_all_groups($course->id, 0, $cm->groupingid);
$cm->cache->usersgroups = array();
$posters = array();
// preload all posts - TODO: improve...
if ($mode == FORUM_MODE_FLATNEWEST) {
$sort = "p.created DESC";
} else {
$sort = "p.created ASC";
}
$forumtracked = forum_tp_is_tracked($forum);
$posts = forum_get_all_discussion_posts($discussion->id, $sort, $forumtracked);
$post = $posts[$post->id];
foreach ($posts as $pid => $p) {
$posters[$p->userid] = $p->userid;
}
// preload all groups of ppl that posted in this discussion
if ($postersgroups = groups_get_all_groups($course->id, $posters, $cm->groupingid, 'gm.id, gm.groupid, gm.userid')) {
foreach ($postersgroups as $pg) {
if (!isset($cm->cache->usersgroups[$pg->userid])) {
$cm->cache->usersgroups[$pg->userid] = array();
}
$cm->cache->usersgroups[$pg->userid][$pg->groupid] = $pg->groupid;
}
unset($postersgroups);
}
$ratings = NULL;
$ratingsmenuused = false;
$ratingsformused = false;
if ($forum->assessed and isloggedin()) {
if ($ratings->scale = make_grades_menu($forum->scale)) {
$ratings->assesstimestart = $forum->assesstimestart;
$ratings->assesstimefinish = $forum->assesstimefinish;
$ratings->allow = $canrate;
if ($ratings->allow) {
echo '<form id="form" method="post" action="rate.php">';
echo '<div class="ratingform">';
echo '<input type="hidden" name="forumid" value="' . $forum->id . '" />';
$ratingsformused = true;
}
// preload all ratings - one query only and minimal memory
$cm->cache->ratings = array();
$cm->cache->myratings = array();
if ($postratings = forum_get_all_discussion_ratings($discussion)) {
foreach ($postratings as $pr) {
if (!isset($cm->cache->ratings[$pr->postid])) {
$cm->cache->ratings[$pr->postid] = array();
}
$cm->cache->ratings[$pr->postid][$pr->id] = $pr->rating;
if ($pr->userid == $USER->id) {
$cm->cache->myratings[$pr->postid] = $pr->rating;
}
}
unset($postratings);
}
}
}
$post->forum = $forum->id;
// Add the forum id to the post object, later used by forum_print_post
$post->forumtype = $forum->type;
$post->subject = format_string($post->subject);
$postread = !empty($post->postread);
if (forum_print_post($post, $discussion, $forum, $cm, $course, $ownpost, $reply, false, $ratings, '', '', $postread, true, $forumtracked)) {
$ratingsmenuused = true;
}
switch ($mode) {
case FORUM_MODE_FLATOLDEST:
case FORUM_MODE_FLATNEWEST:
default:
if (forum_print_posts_flat($course, $cm, $forum, $discussion, $post, $mode, $ratings, $reply, $forumtracked, $posts)) {
$ratingsmenuused = true;
}
break;
case FORUM_MODE_THREADED:
if (forum_print_posts_threaded($course, $cm, $forum, $discussion, $post, 0, $ratings, $reply, $forumtracked, $posts)) {
$ratingsmenuused = true;
}
break;
case FORUM_MODE_NESTED:
if (forum_print_posts_nested($course, $cm, $forum, $discussion, $post, $ratings, $reply, $forumtracked, $posts)) {
$ratingsmenuused = true;
}
//.........这里部分代码省略.........
示例2: forum_print_discussion
//.........这里部分代码省略.........
* @param int $mode
* @param mixed $canreply
* @param bool $canrate
*/
function forum_print_discussion($course, $cm, $forum, $discussion, $post, $mode, $canreply=NULL, $canrate=false) {
global $USER, $CFG;
require_once($CFG->dirroot.'/rating/lib.php');
$ownpost = (isloggedin() && $USER->id == $post->userid);
$modcontext = context_module::instance($cm->id);
if ($canreply === NULL) {
$reply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext);
} else {
$reply = $canreply;
}
// $cm holds general cache for forum functions
$cm->cache = new stdClass;
$cm->cache->groups = groups_get_all_groups($course->id, 0, $cm->groupingid);
$cm->cache->usersgroups = array();
$posters = array();
// preload all posts - TODO: improve...
if ($mode == FORUM_MODE_FLATNEWEST) {
$sort = "p.created DESC";
} else {
$sort = "p.created ASC";
}
$forumtracked = forum_tp_is_tracked($forum);
$posts = forum_get_all_discussion_posts($discussion->id, $sort, $forumtracked);
$post = $posts[$post->id];
foreach ($posts as $pid=>$p) {
$posters[$p->userid] = $p->userid;
}
// preload all groups of ppl that posted in this discussion
if ($postersgroups = groups_get_all_groups($course->id, $posters, $cm->groupingid, 'gm.id, gm.groupid, gm.userid')) {
foreach($postersgroups as $pg) {
if (!isset($cm->cache->usersgroups[$pg->userid])) {
$cm->cache->usersgroups[$pg->userid] = array();
}
$cm->cache->usersgroups[$pg->userid][$pg->groupid] = $pg->groupid;
}
unset($postersgroups);
}
//load ratings
if ($forum->assessed != RATING_AGGREGATE_NONE) {
$ratingoptions = new stdClass;
$ratingoptions->context = $modcontext;
$ratingoptions->component = 'mod_forum';
$ratingoptions->ratingarea = 'post';
$ratingoptions->items = $posts;
$ratingoptions->aggregate = $forum->assessed;//the aggregation method
$ratingoptions->scaleid = $forum->scale;
$ratingoptions->userid = $USER->id;
if ($forum->type == 'single' or !$discussion->id) {
$ratingoptions->returnurl = "$CFG->wwwroot/mod/forum/view.php?id=$cm->id";
} else {
$ratingoptions->returnurl = "$CFG->wwwroot/mod/forum/discuss.php?d=$discussion->id";
}
$ratingoptions->assesstimestart = $forum->assesstimestart;
$ratingoptions->assesstimefinish = $forum->assesstimefinish;
$rm = new rating_manager();
$posts = $rm->get_ratings($ratingoptions);
}
$post->forum = $forum->id; // Add the forum id to the post object, later used by forum_print_post
$post->forumtype = $forum->type;
$post->subject = format_string($post->subject);
$postread = !empty($post->postread);
forum_print_post($post, $discussion, $forum, $cm, $course, $ownpost, $reply, false,
'', '', $postread, true, $forumtracked);
switch ($mode) {
case FORUM_MODE_FLATOLDEST :
case FORUM_MODE_FLATNEWEST :
default:
forum_print_posts_flat($course, $cm, $forum, $discussion, $post, $mode, $reply, $forumtracked, $posts);
break;
case FORUM_MODE_THREADED :
forum_print_posts_threaded($course, $cm, $forum, $discussion, $post, 0, $reply, $forumtracked, $posts);
break;
case FORUM_MODE_NESTED :
forum_print_posts_nested($course, $cm, $forum, $discussion, $post, $reply, $forumtracked, $posts);
break;
}
}