本文整理汇总了PHP中forum_get_all_discussion_posts函数的典型用法代码示例。如果您正苦于以下问题:PHP forum_get_all_discussion_posts函数的具体用法?PHP forum_get_all_discussion_posts怎么用?PHP forum_get_all_discussion_posts使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了forum_get_all_discussion_posts函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: forum_check_throttling
if ($forum->type == 'qanda' && !has_capability('mod/forum:viewqandawithoutposting', $modcontext) && !empty($discussion->id) && !forum_user_has_posted($forum->id, $discussion->id, $USER->id)) {
echo $OUTPUT->notification(get_string('qandanotify', 'forum'));
}
forum_check_throttling($forum, $cm);
if (!empty($parent)) {
if (!($discussion = $DB->get_record('forum_discussions', array('id' => $parent->discussion)))) {
print_error('notpartofdiscussion', 'forum');
}
// #marginalia begin
$moodlemia = moodle_marginalia::get_instance();
$miaprofile = $moodlemia->get_profile($PAGE->url->out(false));
if ($miaprofile) {
$miaprofile->emit_body();
$miaprofile->emit_margin_controls();
}
// #marginalia end
forum_print_post($parent, $discussion, $forum, $cm, $course, false, false, false);
if (empty($post->edit)) {
if ($forum->type != 'qanda' || forum_user_can_see_discussion($forum, $discussion, $modcontext)) {
$forumtracked = forum_tp_is_tracked($forum);
$posts = forum_get_all_discussion_posts($discussion->id, "created ASC", $forumtracked);
forum_print_posts_threaded($course, $cm, $forum, $discussion, $parent, 0, false, $forumtracked, $posts);
}
}
} else {
if (!empty($forum->intro)) {
echo $OUTPUT->box(format_module_intro('forum', $forum, $cm->id), 'generalbox', 'intro');
}
}
$mform_post->display();
echo $OUTPUT->footer();
开发者ID:njorth,项目名称:marginalia,代码行数:31,代码来源:post.php
示例2: forum_print_discussion
/**
* Prints a forum discussion
*
* @uses CONTEXT_MODULE
* @uses FORUM_MODE_FLATNEWEST
* @uses FORUM_MODE_FLATOLDEST
* @uses FORUM_MODE_THREADED
* @uses FORUM_MODE_NESTED
* @param stdClass $course
* @param stdClass $cm
* @param stdClass $forum
* @param stdClass $discussion
* @param stdClass $post
* @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 :
//.........这里部分代码省略.........
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:101,代码来源:lib.php
示例3: load_data
/**
* @global object
*/
public function load_data()
{
global $DB;
if ($this->postid) {
if (!($this->post = $DB->get_record('forum_posts', array('id' => $this->postid)))) {
throw new portfolio_caller_exception('invalidpostid', 'forum');
}
}
$dparams = array();
if ($this->discussionid) {
$dbparams = array('id' => $this->discussionid);
} else {
if ($this->post) {
$dbparams = array('id' => $this->post->discussion);
} else {
throw new portfolio_caller_exception('mustprovidediscussionorpost', 'forum');
}
}
if (!($this->discussion = $DB->get_record('forum_discussions', $dbparams))) {
throw new portfolio_caller_exception('invaliddiscussionid', 'forum');
}
if (!($this->forum = $DB->get_record('forum', array('id' => $this->discussion->forum)))) {
throw new portfolio_caller_exception('invalidforumid', 'forum');
}
if (!($this->cm = get_coursemodule_from_instance('forum', $this->forum->id))) {
throw new portfolio_caller_exception('invalidcoursemodule');
}
$this->modcontext = get_context_instance(CONTEXT_MODULE, $this->cm->id);
$fs = get_file_storage();
if ($this->post) {
if ($this->attachment) {
$this->set_file_and_format_data($this->attachment);
} else {
$attach = $fs->get_area_files($this->modcontext->id, 'mod_forum', 'attachment', $this->post->id, 'timemodified', false);
$embed = $fs->get_area_files($this->modcontext->id, 'mod_forum', 'post', $this->post->id, 'timemodified', false);
$files = array_merge($attach, $embed);
$this->set_file_and_format_data($files);
}
if (!empty($this->multifiles)) {
$this->keyedfiles[$this->post->id] = $this->multifiles;
} else {
if (!empty($this->singlefile)) {
$this->keyedfiles[$this->post->id] = array($this->singlefile);
}
}
} else {
// whole thread
$fs = get_file_storage();
$this->posts = forum_get_all_discussion_posts($this->discussion->id, 'p.created ASC');
$this->multifiles = array();
foreach ($this->posts as $post) {
$attach = $fs->get_area_files($this->modcontext->id, 'mod_forum', 'attachment', $post->id, 'timemodified', false);
$embed = $fs->get_area_files($this->modcontext->id, 'mod_forum', 'post', $post->id, 'timemodified', false);
$files = array_merge($attach, $embed);
if ($files) {
$this->keyedfiles[$post->id] = $files;
} else {
continue;
}
$this->multifiles = array_merge($this->multifiles, array_values($this->keyedfiles[$post->id]));
}
}
if (empty($this->multifiles) && !empty($this->singlefile)) {
$this->multifiles = array($this->singlefile);
// copy_files workaround
}
// depending on whether there are files or not, we might have to change richhtml/plainhtml
if (empty($this->attachment)) {
if (!empty($this->multifiles)) {
$this->add_format(PORTFOLIO_FORMAT_RICHHTML);
} else {
$this->add_format(PORTFOLIO_FORMAT_PLAINHTML);
}
}
}
开发者ID:nmicha,项目名称:moodle,代码行数:78,代码来源:locallib.php
示例4: get_forum_discussion_posts
/**
* Returns a list of forum posts for a discussion
*
* @param int $discussionid the post ids
* @param string $sortby sort by this element (id, created or modified)
* @param string $sortdirection sort direction: ASC or DESC
*
* @return array the forum post details
* @since Moodle 2.7
*/
public static function get_forum_discussion_posts($discussionid, $sortby = "created", $sortdirection = "DESC")
{
global $CFG, $DB, $USER;
$warnings = array();
// Validate the parameter.
$params = self::validate_parameters(self::get_forum_discussion_posts_parameters(), array('discussionid' => $discussionid, 'sortby' => $sortby, 'sortdirection' => $sortdirection));
// Compact/extract functions are not recommended.
$discussionid = $params['discussionid'];
$sortby = $params['sortby'];
$sortdirection = $params['sortdirection'];
$sortallowedvalues = array('id', 'created', 'modified');
if (!in_array($sortby, $sortallowedvalues)) {
throw new invalid_parameter_exception('Invalid value for sortby parameter (value: ' . $sortby . '),' . 'allowed values are: ' . implode(',', $sortallowedvalues));
}
$sortdirection = strtoupper($sortdirection);
$directionallowedvalues = array('ASC', 'DESC');
if (!in_array($sortdirection, $directionallowedvalues)) {
throw new invalid_parameter_exception('Invalid value for sortdirection parameter (value: ' . $sortdirection . '),' . 'allowed values are: ' . implode(',', $directionallowedvalues));
}
$discussion = $DB->get_record('forum_discussions', array('id' => $discussionid), '*', MUST_EXIST);
$forum = $DB->get_record('forum', array('id' => $discussion->forum), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $forum->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id, false, MUST_EXIST);
// Validate the module context. It checks everything that affects the module visibility (including groupings, etc..).
$modcontext = context_module::instance($cm->id);
self::validate_context($modcontext);
// This require must be here, see mod/forum/discuss.php.
require_once $CFG->dirroot . "/mod/forum/lib.php";
// Check they have the view forum capability.
require_capability('mod/forum:viewdiscussion', $modcontext, null, true, 'noviewdiscussionspermission', 'forum');
if (!($post = forum_get_post_full($discussion->firstpost))) {
throw new moodle_exception('notexists', 'forum');
}
// This function check groups, qanda, timed discussions, etc.
if (!forum_user_can_see_post($forum, $discussion, $post, null, $cm)) {
throw new moodle_exception('noviewdiscussionspermission', 'forum');
}
$canviewfullname = has_capability('moodle/site:viewfullnames', $modcontext);
// We will add this field in the response.
$canreply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext);
$forumtracked = forum_tp_is_tracked($forum);
$sort = 'p.' . $sortby . ' ' . $sortdirection;
$posts = forum_get_all_discussion_posts($discussion->id, $sort, $forumtracked);
foreach ($posts as $pid => $post) {
if (!forum_user_can_see_post($forum, $discussion, $post, null, $cm)) {
$warning = array();
$warning['item'] = 'post';
$warning['itemid'] = $post->id;
$warning['warningcode'] = '1';
$warning['message'] = 'You can\'t see this post';
$warnings[] = $warning;
continue;
}
// Function forum_get_all_discussion_posts adds postread field.
// Note that the value returned can be a boolean or an integer. The WS expects a boolean.
if (empty($post->postread)) {
$posts[$pid]->postread = false;
} else {
$posts[$pid]->postread = true;
}
$posts[$pid]->canreply = $canreply;
if (!empty($posts[$pid]->children)) {
$posts[$pid]->children = array_keys($posts[$pid]->children);
} else {
$posts[$pid]->children = array();
}
$user = new stdclass();
$user = username_load_fields_from_object($user, $post);
$posts[$pid]->userfullname = fullname($user, $canviewfullname);
$posts[$pid] = (array) $post;
}
$result = array();
$result['posts'] = $posts;
$result['warnings'] = $warnings;
return $result;
}
开发者ID:educacionbe,项目名称:cursos,代码行数:86,代码来源:externallib.php
示例5: get_news_item
function get_news_item($id)
{
global $CFG, $DB;
$posts = forum_get_all_discussion_posts($id, 'created');
$item_posts = array();
foreach ($posts as $post) {
$p['subject'] = $post->subject;
$p['message'] = $post->message;
$item_posts[] = $p;
}
return $item_posts;
}
开发者ID:anawu2006,项目名称:PeerLearning,代码行数:12,代码来源:auth.php
示例6: 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;
}
//.........这里部分代码省略.........
开发者ID:r007,项目名称:PMoodle,代码行数:101,代码来源:lib.php
示例7: load_data
public function load_data()
{
global $DB;
if ($this->postid) {
if (!($this->post = $DB->get_record('forum_posts', array('id' => $this->postid)))) {
throw new portfolio_caller_exception('invalidpostid', 'forum');
}
}
$dparams = array();
if ($this->discussionid) {
$dbparams = array('id' => $this->discussionid);
} else {
if ($this->post) {
$dbparams = array('id' => $this->post->discussion);
} else {
throw new portfolio_caller_exception('mustprovidediscussionorpost', 'forum');
}
}
if (!($this->discussion = $DB->get_record('forum_discussions', $dbparams))) {
throw new portfolio_caller_exception('invaliddiscussionid', 'forum');
}
if (!($this->forum = $DB->get_record('forum', array('id' => $this->discussion->forum)))) {
throw new portfolio_caller_exception('invalidforumid', 'forum');
}
if (!($this->cm = get_coursemodule_from_instance('forum', $this->forum->id))) {
throw new portfolio_caller_exception('invalidcoursemodule');
}
$modcontext = get_context_instance(CONTEXT_MODULE, $this->cm->id);
if ($this->post) {
$this->set_file_and_format_data($this->attachment, $modcontext->id, 'forum_attachment', $this->post->id);
if (!empty($this->multifiles)) {
$this->keyedfiles[$this->post->id] = $this->multifiles;
} else {
if (!empty($this->singlefile)) {
$this->keyedfiles[$this->post->id] = $this->singlefile;
}
}
} else {
// whole thread
$fs = get_file_storage();
$this->posts = forum_get_all_discussion_posts($this->discussion->id, 'p.created ASC');
$this->multifiles = array();
foreach ($this->posts as $post) {
if (!($this->keyedfiles[$post->id] = $fs->get_area_files($modcontext->id, 'forum_attachment', $post->id, "timemodified", false))) {
continue;
}
$this->multifiles = array_merge($this->multifiles, array_values($this->keyedfiles[$post->id]));
}
}
if ($this->attachment) {
// do nothing
} else {
if (!empty($this->multifiles) || !empty($this->singlefile)) {
$this->supportedformats = array(PORTFOLIO_FORMAT_FILE, PORTFOLIO_FORMAT_RICHHTML);
} else {
$this->supportedformats = array(PORTFOLIO_FORMAT_PLAINHTML);
}
}
}
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:59,代码来源:lib.php
示例8: leaf_get_newsitem
function leaf_get_newsitem($d)
{
global $DB, $USER, $CFG, $OUTPUT;
static $str;
require_once $CFG->libdir . '/filelib.php';
$discussion = $DB->get_record('forum_discussions', array('id' => $d, 'course' => 1), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $discussion->course), '*', MUST_EXIST);
$forum = $DB->get_record('forum', array('id' => $discussion->forum), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id, false, MUST_EXIST);
$parent = $discussion->firstpost;
$post = forum_get_post_full($parent);
$displaymode = -1;
$canreply = false;
$canrate = false;
$sort = "p.created ASC";
$posts = forum_get_all_discussion_posts($discussion->id, $sort, false);
foreach ($posts as $post) {
$post->course = $course->id;
$post->forum = $forum->id;
$postuser = new stdClass();
$postuser->id = $post->userid;
$postuser->firstname = $post->firstname;
$postuser->lastname = $post->lastname;
$postuser->imagealt = $post->imagealt;
$postuser->picture = $post->picture;
$postuser->email = $post->email;
$postuser->fullname = fullname($postuser);
$output = '';
$output .= html_writer::tag('a', '', array('id' => 'p' . $post->id));
$output .= html_writer::start_tag('div', array('class' => 'forumpost clearfix firstpost starter'));
$output .= html_writer::start_tag('div', array('class' => 'row header clearfix'));
$output .= html_writer::start_tag('div', array('class' => 'left picture'));
$output .= $OUTPUT->user_picture($postuser, array('courseid' => $course->id));
$output .= html_writer::end_tag('div');
$output .= html_writer::start_tag('div', array('class' => 'topic firstpost starter'));
$postsubject = $post->subject;
if (empty($post->subjectnoformat)) {
$postsubject = format_string($postsubject);
}
$output .= html_writer::tag('div', $postsubject, array('class' => 'subject'));
$output .= html_writer::tag('div', $postuser->fullname, array('class' => 'author'));
$output .= html_writer::end_tag('div');
//topic
$output .= html_writer::end_tag('div');
//row
$output .= html_writer::start_tag('div', array('class' => 'row maincontent clearfix'));
$output .= html_writer::start_tag('div', array('class' => 'left'));
$output .= html_writer::tag('div', ' ', array('class' => 'grouppictures'));
$output .= html_writer::end_tag('div');
//left side
$output .= html_writer::start_tag('div', array('class' => 'no-overflow'));
$output .= html_writer::start_tag('div', array('class' => 'content'));
$options = new stdClass();
$options->para = false;
$options->trusted = $post->messagetrust;
// Prepare whole post
$postclass = 'fullpost';
$postcontent = format_text($post->message, $post->messageformat, $options, $course->id);
// Output the post content
$output .= html_writer::tag('div', $postcontent, array('class' => 'posting ' . $postclass));
$output .= html_writer::end_tag('div');
// Content
$output .= html_writer::end_tag('div');
// Content mask
$output .= html_writer::end_tag('div');
// Row
$output .= html_writer::start_tag('div', array('class' => 'row side'));
$output .= html_writer::tag('div', ' ', array('class' => 'left'));
$output .= html_writer::start_tag('div', array('class' => 'options clearfix'));
// Close remaining open divs
$output .= html_writer::end_tag('div');
// content
$output .= html_writer::end_tag('div');
// row
$output .= html_writer::end_tag('div');
// forumpost
echo $output;
}
}
开发者ID:bmbrands,项目名称:moodle-theme_leaf,代码行数:79,代码来源:lib.php
示例9: get_forum_discussion_posts
/**
* Returns a list of forum posts for a discussion
*
* @param int $discussionid the post ids
* @param string $sortby sort by this element (id, created or modified)
* @param string $sortdirection sort direction: ASC or DESC
*
* @return array the forum post details
* @since Moodle 2.7
*/
public static function get_forum_discussion_posts($discussionid, $sortby = "created", $sortdirection = "DESC") {
global $CFG, $DB, $USER;
$posts = array();
$warnings = array();
// Validate the parameter.
$params = self::validate_parameters(self::get_forum_discussion_posts_parameters(),
array(
'discussionid' => $discussionid,
'sortby' => $sortby,
'sortdirection' => $sortdirection));
// Compact/extract functions are not recommended.
$discussionid = $params['discussionid'];
$sortby = $params['sortby'];
$sortdirection = $params['sortdirection'];
$sortallowedvalues = array('id', 'created', 'modified');
if (!in_array($sortby, $sortallowedvalues)) {
throw new invalid_parameter_exception('Invalid value for sortby parameter (value: ' . $sortby . '),' .
'allowed values are: ' . implode(',', $sortallowedvalues));
}
$sortdirection = strtoupper($sortdirection);
$directionallowedvalues = array('ASC', 'DESC');
if (!in_array($sortdirection, $directionallowedvalues)) {
throw new invalid_parameter_exception('Invalid value for sortdirection parameter (value: ' . $sortdirection . '),' .
'allowed values are: ' . implode(',', $directionallowedvalues));
}
$discussion = $DB->get_record('forum_discussions', array('id' => $discussionid), '*', MUST_EXIST);
$forum = $DB->get_record('forum', array('id' => $discussion->forum), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $forum->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id, false, MUST_EXIST);
// Validate the module context. It checks everything that affects the module visibility (including groupings, etc..).
$modcontext = context_module::instance($cm->id);
self::validate_context($modcontext);
// This require must be here, see mod/forum/discuss.php.
require_once($CFG->dirroot . "/mod/forum/lib.php");
// Check they have the view forum capability.
require_capability('mod/forum:viewdiscussion', $modcontext, null, true, 'noviewdiscussionspermission', 'forum');
if (! $post = forum_get_post_full($discussion->firstpost)) {
throw new moodle_exception('notexists', 'forum');
}
// This function check groups, qanda, timed discussions, etc.
if (!forum_user_can_see_post($forum, $discussion, $post, null, $cm)) {
throw new moodle_exception('noviewdiscussionspermission', 'forum');
}
$canviewfullname = has_capability('moodle/site:viewfullnames', $modcontext);
// We will add this field in the response.
$canreply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext);
$forumtracked = forum_tp_is_tracked($forum);
$sort = 'p.' . $sortby . ' ' . $sortdirection;
$allposts = forum_get_all_discussion_posts($discussion->id, $sort, $forumtracked);
foreach ($allposts as $post) {
if (!forum_user_can_see_post($forum, $discussion, $post, null, $cm)) {
$warning = array();
$warning['item'] = 'post';
$warning['itemid'] = $post->id;
$warning['warningcode'] = '1';
$warning['message'] = 'You can\'t see this post';
$warnings[] = $warning;
continue;
}
// Function forum_get_all_discussion_posts adds postread field.
// Note that the value returned can be a boolean or an integer. The WS expects a boolean.
if (empty($post->postread)) {
$post->postread = false;
} else {
$post->postread = true;
}
$post->canreply = $canreply;
if (!empty($post->children)) {
$post->children = array_keys($post->children);
} else {
$post->children = array();
//.........这里部分代码省略.........
开发者ID:papillon326,项目名称:moodle-51419,代码行数:101,代码来源:externallib.php
注:本文中的forum_get_all_discussion_posts函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论