当前位置: 首页>>代码示例>>PHP>>正文


PHP forum_user_has_posted函数代码示例

本文整理汇总了PHP中forum_user_has_posted函数的典型用法代码示例。如果您正苦于以下问题:PHP forum_user_has_posted函数的具体用法?PHP forum_user_has_posted怎么用?PHP forum_user_has_posted使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了forum_user_has_posted函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sesskey

            if ($forumidcompare and $forumtypecheck) {
                $url = "/mod/forum/discuss.php?d={$discussion->id}&move={$forumcm->instance}&sesskey=" . sesskey();
                $forummenu[$section][$sectionname][$url] = format_string($forumcm->name);
            }
        }
        if (!empty($forummenu)) {
            echo '<div class="movediscussionoption">';
            $select = new url_select($forummenu, '', array('' => get_string("movethisdiscussionto", "forum")), 'forummenu', get_string('move'));
            echo $OUTPUT->render($select);
            echo "</div>";
        }
    }
    echo "</div>";
}
echo '<div class="clearfloat">&nbsp;</div>';
echo "</div>";
if (!empty($forum->blockafter) && !empty($forum->blockperiod)) {
    $a = new stdClass();
    $a->blockafter = $forum->blockafter;
    $a->blockperiod = get_string('secondstotime' . $forum->blockperiod);
    echo $OUTPUT->notification(get_string('thisforumisthrottled', 'forum', $a));
}
if ($forum->type == 'qanda' && !has_capability('mod/forum:viewqandawithoutposting', $modcontext) && !forum_user_has_posted($forum->id, $discussion->id, $USER->id)) {
    echo $OUTPUT->notification(get_string('qandanotify', 'forum'));
}
if ($move == -1 and confirm_sesskey()) {
    echo $OUTPUT->notification(get_string('discussionmoved', 'forum', format_string($forum->name, true)));
}
$canrate = has_capability('mod/forum:rate', $modcontext);
forum_print_discussion($course, $cm, $forum, $discussion, $post, $displaymode, $canreply, $canrate);
echo $OUTPUT->footer();
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:31,代码来源:discuss.php

示例2: forum_user_can_see_discussion

/**
 * @global object
 * @global object
 * @uses DEBUG_DEVELOPER
 * @param object $forum
 * @param object $discussion
 * @param object $context
 * @param object $user
 * @return bool
 */
function forum_user_can_see_discussion($forum, $discussion, $context, $user=NULL) {
    global $USER, $DB;

    if (empty($user) || empty($user->id)) {
        $user = $USER;
    }

    // retrieve objects (yuk)
    if (is_numeric($forum)) {
        debugging('missing full forum', DEBUG_DEVELOPER);
        if (!$forum = $DB->get_record('forum',array('id'=>$forum))) {
            return false;
        }
    }
    if (is_numeric($discussion)) {
        debugging('missing full discussion', DEBUG_DEVELOPER);
        if (!$discussion = $DB->get_record('forum_discussions',array('id'=>$discussion))) {
            return false;
        }
    }
    if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course)) {
        print_error('invalidcoursemodule');
    }

    if (!has_capability('mod/forum:viewdiscussion', $context)) {
        return false;
    }

    if (!forum_user_can_see_timed_discussion($discussion, $user, $context)) {
        return false;
    }

    if (!forum_user_can_see_group_discussion($discussion, $cm, $context)) {
        return false;
    }

    if ($forum->type == 'qanda' &&
            !forum_user_has_posted($forum->id, $discussion->id, $user->id) &&
            !has_capability('mod/forum:viewqandawithoutposting', $context)) {
        return false;
    }
    return true;
}
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:53,代码来源:lib.php

示例3: get_forum_discussions

    /**
     * Returns a list of forum discussions as well as a summary of the discussion
     * in a provided list of forums.
     *
     * @param array $forumids the forum ids
     * @return array the forum discussion details
     * @since Moodle 2.5
     */
    public static function get_forum_discussions($forumids) {
        global $CFG, $DB, $USER;

        require_once($CFG->dirroot . "/mod/forum/lib.php");

        // Validate the parameter.
        $params = self::validate_parameters(self::get_forum_discussions_parameters(), array('forumids' => $forumids));
        $forumids = $params['forumids'];

        // Array to store the forum discussions to return.
        $arrdiscussions = array();
        // Keep track of the course ids we have performed a require_course_login check on to avoid repeating.
        $arrcourseschecked = array();
        // Store the modinfo for the forums in an individual courses.
        $arrcoursesforuminfo = array();
        // Keep track of the users we have looked up in the DB.
        $arrusers = array();

        // Loop through them.
        foreach ($forumids as $id) {
            // Get the forum object.
            $forum = $DB->get_record('forum', array('id' => $id), '*', MUST_EXIST);
            // Check that that user can view this course if check not performed yet.
            if (!in_array($forum->course, $arrcourseschecked)) {
                // Check the user can function in this context.
                self::validate_context(context_course::instance($forum->course));
                // Add to the array.
                $arrcourseschecked[] = $forum->course;
            }
            // Get the modinfo for the course if we haven't already.
            if (!isset($arrcoursesforuminfo[$forum->course])) {
                $modinfo = get_fast_modinfo($forum->course);
                $arrcoursesforuminfo[$forum->course] = $modinfo->get_instances_of('forum');
            }
            // Check if this forum does not exist in the modinfo array, should always be false unless DB is borked.
            if (empty($arrcoursesforuminfo[$forum->course][$forum->id])) {
                throw new moodle_exception('invalidmodule', 'error');
            }
            // We now have the course module.
            $cm = $arrcoursesforuminfo[$forum->course][$forum->id];
            // If the forum is not visible throw an exception.
            if (!$cm->uservisible) {
                throw new moodle_exception('nopermissiontoshow', 'error');
            }
            // Get the module context.
            $modcontext = context_module::instance($cm->id);
            // Check they have the view forum capability.
            require_capability('mod/forum:viewdiscussion', $modcontext);
            // Check if they can view full names.
            $canviewfullname = has_capability('moodle/site:viewfullnames', $modcontext);
            // Get the unreads array, this takes a forum id and returns data for all discussions.
            $unreads = array();
            if ($cantrack = forum_tp_can_track_forums($forum)) {
                if ($forumtracked = forum_tp_is_tracked($forum)) {
                    $unreads = forum_get_discussions_unread($cm);
                }
            }
            // The forum function returns the replies for all the discussions in a given forum.
            $replies = forum_count_discussion_replies($id);
            // Get the discussions for this forum.
            if ($discussions = $DB->get_records('forum_discussions', array('forum' => $id))) {
                foreach ($discussions as $discussion) {
                    // If the forum is of type qanda and the user has not posted in the discussion
                    // we need to ensure that they have the required capability.
                    if ($forum->type == 'qanda' && !forum_user_has_posted($discussion->forum, $discussion->id, $USER->id)) {
                        require_capability('mod/forum:viewqandawithoutposting', $modcontext);
                    }
                    // If we don't have the users details then perform DB call.
                    if (empty($arrusers[$discussion->userid])) {
                        $arrusers[$discussion->userid] = $DB->get_record('user', array('id' => $discussion->userid),
                            'firstname, lastname, email, picture, imagealt', MUST_EXIST);
                    }
                    // Get the subject.
                    $subject = $DB->get_field('forum_posts', 'subject', array('id' => $discussion->firstpost), MUST_EXIST);
                    // Create object to return.
                    $return = new stdClass();
                    $return->id = (int) $discussion->id;
                    $return->course = $discussion->course;
                    $return->forum = $discussion->forum;
                    $return->name = $discussion->name;
                    $return->userid = $discussion->userid;
                    $return->groupid = $discussion->groupid;
                    $return->assessed = $discussion->assessed;
                    $return->timemodified = (int) $discussion->timemodified;
                    $return->usermodified = $discussion->usermodified;
                    $return->timestart = $discussion->timestart;
                    $return->timeend = $discussion->timeend;
                    $return->firstpost = (int) $discussion->firstpost;
                    $return->firstuserfullname = fullname($arrusers[$discussion->userid], $canviewfullname);
                    $return->firstuserimagealt = $arrusers[$discussion->userid]->imagealt;
                    $return->firstuserpicture = $arrusers[$discussion->userid]->picture;
                    $return->firstuseremail = $arrusers[$discussion->userid]->email;
//.........这里部分代码省略.........
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:101,代码来源:externallib.php

示例4: forum_print_latest_discussions


//.........这里部分代码省略.........
        $unreads = array();
    }
    if ($displayformat == 'header') {
        echo '<table cellspacing="0" class="forumheaderlist">';
        echo '<thead>';
        echo '<tr>';
        echo '<th class="header topic" scope="col">' . get_string('discussion', 'forum') . '</th>';
        echo '<th class="header author" colspan="2" scope="col">' . get_string('startedby', 'forum') . '</th>';
        if ($groupmode > 0) {
            echo '<th class="header group" scope="col">' . get_string('group') . '</th>';
        }
        if (has_capability('mod/forum:viewdiscussion', $context)) {
            echo '<th class="header replies" scope="col">' . get_string('replies', 'forum') . '</th>';
            // If the forum can be tracked, display the unread column.
            if ($cantrack) {
                echo '<th class="header replies" scope="col">' . get_string('unread', 'forum');
                if ($forumtracked) {
                    echo '<a title="' . get_string('markallread', 'forum') . '" href="' . $CFG->wwwroot . '/mod/forum/markposts.php?f=' . $forum->id . '&amp;mark=read&amp;returnpage=view.php">' . '<img src="' . $OUTPUT->pix_url('t/markasread') . '" class="iconsmall" alt="' . get_string('markallread', 'forum') . '" /></a>';
                }
                echo '</th>';
            }
        }
        echo '<th class="header lastpost" scope="col">' . get_string('lastpost', 'forum') . '</th>';
        if (has_capability('mod/forum:viewdiscussion', $context)) {
            if (\mod_forum\subscriptions::is_subscribable($forum)) {
                echo '<th class="header discussionsubscription" scope="col">&nbsp;</th>';
            }
        }
        echo '</tr>';
        echo '</thead>';
        echo '<tbody>';
    }
    foreach ($discussions as $discussion) {
        if ($forum->type == 'qanda' && !has_capability('mod/forum:viewqandawithoutposting', $context) && !forum_user_has_posted($forum->id, $discussion->discussion, $USER->id)) {
            $canviewparticipants = false;
        }
        if (!empty($replies[$discussion->discussion])) {
            $discussion->replies = $replies[$discussion->discussion]->replies;
            $discussion->lastpostid = $replies[$discussion->discussion]->lastpostid;
        } else {
            $discussion->replies = 0;
        }
        // SPECIAL CASE: The front page can display a news item post to non-logged in users.
        // All posts are read in this case.
        if (!$forumtracked) {
            $discussion->unread = '-';
        } else {
            if (empty($USER)) {
                $discussion->unread = 0;
            } else {
                if (empty($unreads[$discussion->discussion])) {
                    $discussion->unread = 0;
                } else {
                    $discussion->unread = $unreads[$discussion->discussion];
                }
            }
        }
        if (isloggedin()) {
            $ownpost = $discussion->userid == $USER->id;
        } else {
            $ownpost = false;
        }
        // Use discussion name instead of subject of first post
        $discussion->subject = $discussion->name;
        switch ($displayformat) {
            case 'header':
开发者ID:abhilash1994,项目名称:moodle,代码行数:67,代码来源:lib.php

示例5: forum_user_can_see_post

/**
 *
 */
function forum_user_can_see_post($forum, $discussion, $post, $user = NULL, $cm = NULL)
{
    global $USER;
    // retrieve objects (yuk)
    if (is_numeric($forum)) {
        debugging('missinf full forum', DEBUG_DEVELOPER);
        if (!($forum = get_record('forum', 'id', $forum))) {
            return false;
        }
    }
    if (is_numeric($discussion)) {
        debugging('missinf full discussion', DEBUG_DEVELOPER);
        if (!($discussion = get_record('forum_discussions', 'id', $discussion))) {
            return false;
        }
    }
    if (is_numeric($post)) {
        debugging('missinf full post', DEBUG_DEVELOPER);
        if (!($post = get_record('forum_posts', 'id', $post))) {
            return false;
        }
    }
    if (!isset($post->id) && isset($post->parent)) {
        $post->id = $post->parent;
    }
    if (!$cm) {
        debugging('missing cm', DEBUG_DEVELOPER);
        if (!($cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course))) {
            error('Course Module ID was incorrect');
        }
    }
    if (empty($user) || empty($user->id)) {
        $user = $USER;
    }
    if (isset($cm->cache->caps['mod/forum:viewdiscussion'])) {
        if (!$cm->cache->caps['mod/forum:viewdiscussion']) {
            return false;
        }
    } else {
        $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
        if (!has_capability('mod/forum:viewdiscussion', $modcontext, $user->id)) {
            return false;
        }
    }
    if (isset($cm->uservisible)) {
        if (!$cm->uservisible) {
            return false;
        }
    } else {
        if (!coursemodule_visible_for_user($cm, $user->id)) {
            return false;
        }
    }
    if ($forum->type == 'qanda') {
        $firstpost = forum_get_firstpost_from_discussion($discussion->id);
        $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
        return forum_user_has_posted($forum->id, $discussion->id, $user->id) || $firstpost->id == $post->id || has_capability('mod/forum:viewqandawithoutposting', $modcontext, $user->id, false);
    }
    return true;
}
开发者ID:r007,项目名称:PMoodle,代码行数:63,代码来源:lib.php

示例6: print_error

echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($forum->name), 2);

// checkup
if (!empty($parent) && !forum_user_can_see_post($forum, $discussion, $post, null, $cm)) {
    print_error('cannotreply', 'forum');
}
if (empty($parent) && empty($edit) && !forum_user_can_post_discussion($forum, $groupid, -1, $cm, $modcontext)) {
    print_error('cannotcreatediscussion', 'forum');
}

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'));
}

// If there is a warning message and we are not editing a post we need to handle the warning.
if (!empty($thresholdwarning) && !$edit) {
    // Here we want to throw an exception if they are no longer allowed to post.
    forum_check_blocking_threshold($thresholdwarning);
}

if (!empty($parent)) {
    if (!$discussion = $DB->get_record('forum_discussions', array('id' => $parent->discussion))) {
        print_error('notpartofdiscussion', 'forum');
    }

    forum_print_post($parent, $discussion, $forum, $cm, $course, false, false, false);
开发者ID:nickbert77,项目名称:moodle,代码行数:30,代码来源:post.php

示例7: forum_user_can_see_post

/**
 * TODO document
 */
function forum_user_can_see_post($forum, $discussion, $post, $user = NULL)
{
    global $USER;
    // retrieve objects (yuk)
    if (is_numeric($forum)) {
        if (!($forum = get_record('forum', 'id', $forum))) {
            return false;
        }
    }
    if (is_numeric($discussion)) {
        if (!($discussion = get_record('forum_discussions', 'id', $discussion))) {
            return false;
        }
    }
    if (is_numeric($post)) {
        if (!($post = get_record('forum_posts', 'id', $post))) {
            return false;
        }
    }
    if (!isset($post->id) && isset($post->parent)) {
        $post->id = $post->parent;
    }
    if (!($cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course))) {
        error('Course Module ID was incorrect');
    }
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    if (empty($user) || empty($user->id)) {
        $user = $USER;
    }
    if (!has_capability('mod/forum:viewdiscussion', $context, $user->id)) {
        return false;
    }
    if ($forum->type == 'qanda') {
        $firstpost = forum_get_firstpost_from_discussion($discussion->id);
        return forum_user_has_posted($forum->id, $discussion->id, $user->id) || $firstpost->id == $post->id || has_capability('mod/forum:viewqandawithoutposting', $context, false, $user->id);
    }
    return true;
}
开发者ID:njorth,项目名称:marginalia,代码行数:41,代码来源:lib.php

示例8: get_string

        $heading = get_string('yournewquestion', 'forum');
    } else {
        $heading = get_string('yournewtopic', 'forum');
    }
}
if ($USER->id != $post->userid) {
    // Not the original author, so add a message to the end
    $data->date = userdate($post->modified);
    if ($post->format == FORMAT_HTML) {
        $data->name = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $USER->id . '&course=' . $post->course . '">' . fullname($USER) . '</a>';
        $post->message .= '<p>(<span class="edited">' . get_string('editedby', 'forum', $data) . '</span>)</p>';
    } else {
        $data->name = fullname($USER);
        $post->message .= "\n\n(" . get_string('editedby', 'forum', $data) . ')';
    }
}
//load data into form
if (forum_is_subscribed($USER->id, $forum->id)) {
    $subscribe = true;
} else {
    if (forum_user_has_posted($forum->id, 0, $USER->id)) {
        $subscribe = false;
    } else {
        // user not posted yet - use subscription default specified in profile
        $subscribe = !empty($USER->autosubscribe);
    }
}
// HACK ALERT: this is very wrong, the defaults should be always initialized before calling $mform->get_data() !!!
$mform_post->set_data(array('general' => $heading, 'subject' => $post->subject, 'message' => $post->message, 'subscribe' => $subscribe ? 1 : 0, 'mailnow' => !empty($post->mailnow), 'userid' => $post->userid, 'parent' => $post->parent, 'discussion' => $post->discussion, 'course' => $course->id) + $page_params + (isset($post->format) ? array('format' => $post->format) : array()) + (isset($discussion->timestart) ? array('timestart' => $discussion->timestart) : array()) + (isset($discussion->timeend) ? array('timeend' => $discussion->timeend) : array()) + (isset($post->groupid) ? array('groupid' => $post->groupid) : array()) + (isset($discussion->id) ? array('discussion' => $discussion->id) : array()));
$mform_post->display();
print_footer($course);
开发者ID:laiello,项目名称:poodll,代码行数:31,代码来源:post.php

示例9: grading_popup

 /**
  * Makes the pop up contents for the grading interface
  *
  * @param array $params
  * @param $coursemodule
  * @global moodle_database $DB
  * @global $PAGE
  * @global stdClass $CFG
  * @global $SESSION
  * @global $USER
  * @global $OUTPUT
  * @params object $coursemodule
  * @return string HTML
  */
 public function grading_popup($params, $coursemodule)
 {
     global $DB, $PAGE, $CFG, $SESSION, $USER, $OUTPUT;
     $output = '';
     // Lifted from /mod/forum/discuss.php...
     /*
      $parent = $params['parent'];       // If set, then display this post and all children.
      $mode   = $params['mode'];         // If set, changes the layout of the thread
      $move   = $params['move'];         // If set, moves this discussion to another forum
      $mark   = $params['mark'];       // Used for tracking read posts if user initiated.
      $postid = $params['postid'];       // Used for tracking read posts if user initiated.
     */
     $discussion = $DB->get_record('forum_discussions', array('id' => $params['discussionid']), '*', 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);
     $modcontext = context_module::instance($cm->id);
     // Security - cmid is used to check context permissions earlier on, so it must match when
     // derived from the discussion.
     if (!($cm->id == $params['coursemoduleid'])) {
         print_error('Bad params!');
         return false;
     }
     // Add ajax-related libs.
     $PAGE->requires->yui2_lib('event');
     $PAGE->requires->yui2_lib('connection');
     $PAGE->requires->yui2_lib('json');
     // Move this down fix for MDL-6926.
     require_once $CFG->dirroot . '/mod/forum/lib.php';
     // Restrict news forums - should not be graded.
     if ($forum->type == 'news') {
         print_error('invaliddiscussionid', 'forum', "{$CFG->wwwroot}/mod/forum/view.php?f={$forum->id}");
     }
     unset($SESSION->fromdiscussion);
     // In case the user has used the drop-down to change from threaded to flat or something.
     if (isset($params['mode'])) {
         set_user_preference('forum_displaymode', $params['mode']);
     }
     $displaymode = get_user_preferences('forum_displaymode', $CFG->forum_displaymode);
     $parent = $discussion->firstpost;
     $post = forum_get_post_full($parent);
     if (!$post) {
         print_error("notexists", 'forum', "{$CFG->wwwroot}/mod/forum/view.php?f={$forum->id}");
     }
     if (!forum_user_can_view_post($post, $course, $cm, $forum, $discussion)) {
         print_error('nopermissiontoview', 'forum', "{$CFG->wwwroot}/mod/forum/view.php?id={$forum->id}");
     }
     // For now, restrict to rating only.
     $canreply = false;
     // Without this, the nesting doesn't work properly as the css isn't picked up.
     $output .= html_writer::start_tag('div', array('class' => 'path-mod-forum'));
     $output .= html_writer::start_tag('div', array('class' => 'discussioncontrols clearfix'));
     $output .= html_writer::start_tag('div', array('class' => 'discussioncontrol displaymode'));
     // We don't want to have the current mode returned in the url as well as the new one.
     unset($params['mode']);
     $newurl = new moodle_url('/blocks/ajax_marking/actions/grading_popup.php', $params);
     $select = new single_select($newurl, 'mode', forum_get_layout_modes(), $displaymode, null, "mode");
     $output .= $OUTPUT->render($select);
     $output .= html_writer::end_tag('div');
     // If user has not already posted and it's a Q & A forum...
     $forumisqanda = $forum->type == 'qanda';
     $noviewwithoutposting = !has_capability('mod/forum:viewqandawithoutposting', $modcontext);
     $hasnotposted = !forum_user_has_posted($forum->id, $discussion->id, $USER->id);
     if ($forumisqanda && $noviewwithoutposting && $hasnotposted) {
         $output .= $OUTPUT->notification(get_string('qandanotify', 'forum'));
     }
     $canrate = has_capability('mod/forum:rate', $modcontext);
     ob_start();
     forum_print_discussion($course, $cm, $forum, $discussion, $post, $displaymode, $canreply, $canrate);
     $output .= ob_get_contents();
     ob_end_clean();
     $output .= html_writer::end_tag('div');
     $output .= html_writer::end_tag('div');
     return $output;
 }
开发者ID:nadavkav,项目名称:moodle-block_ajax_marking,代码行数:89,代码来源:block_ajax_marking_forum.class.php

示例10: forum_user_can_see_discussion

/**
 *
 */
function forum_user_can_see_discussion($forum, $discussion, $context, $user = NULL)
{
    global $USER;
    if (empty($user) || empty($user->id)) {
        $user = $USER;
    }
    // retrieve objects (yuk)
    if (is_numeric($forum)) {
        debugging('missing full forum', DEBUG_DEVELOPER);
        if (!($forum = get_record('forum', 'id', $forum))) {
            return false;
        }
    }
    if (is_numeric($discussion)) {
        debugging('missing full discussion', DEBUG_DEVELOPER);
        if (!($discussion = get_record('forum_discussions', 'id', $discussion))) {
            return false;
        }
    }
    if (!has_capability('mod/forum:viewdiscussion', $context)) {
        return false;
    }
    if ($forum->type == 'qanda' && !forum_user_has_posted($forum->id, $discussion->id, $user->id) && !has_capability('mod/forum:viewqandawithoutposting', $context)) {
        return false;
    }
    return true;
}
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:30,代码来源:lib.php

示例11: get_forum_posts

 /**
  * Returns a list of forum posts for a discussion
  *
  * @param int $discussionid the post ids
  * @return array the forum post details
  * @since Moodle 2.5
  */
 public static function get_forum_posts($discussionid)
 {
     global $CFG, $DB, $USER;
     require_once $CFG->dirroot . "/mod/forum/lib.php";
     // Validate the parameter.
     $params = self::validate_parameters(self::get_forum_posts_parameters(), array('discussionid' => $discussionid));
     $discussionid = $params['discussionid'];
     if (!($forumid = $DB->get_field('forum_discussions', 'forum', array('id' => $discussionid)))) {
         throw new moodle_exception("Invalid discussion id");
     }
     // Get the forum object.
     $forum = $DB->get_record('forum', array('id' => $forumid), '*', MUST_EXIST);
     // Check that that user can view this course if check not performed yet.
     self::validate_context(context_course::instance($forum->course));
     // Get the modinfo for the course if we haven't already.
     $modinfo = get_fast_modinfo($forum->course);
     $forums = $modinfo->get_instances_of('forum');
     // Check if this forum does not exist in the modinfo array, should always be false unless DB is borked.
     if (empty($forums[$forum->id])) {
         throw new moodle_exception('invalidmodule', 'error');
     }
     // We now have the course module.
     $cm = $forums[$forum->id];
     // If the forum is not visible throw an exception.
     if (!$cm->uservisible) {
         throw new moodle_exception('nopermissiontoshow', 'error');
     }
     // Get the module context.
     $modcontext = context_module::instance($cm->id);
     // Check they have the view forum capability.
     require_capability('mod/forum:viewdiscussion', $modcontext);
     // Check if they can view full names.
     $canviewfullname = has_capability('moodle/site:viewfullnames', $modcontext);
     // If the forum is of type qanda and the user has not posted in the post
     // we need to ensure that they have the required capability.
     if ($forum->type == 'qanda' && !forum_user_has_posted($forumid, $discussionid, $USER->id)) {
         require_capability('mod/forum:viewqandawithoutposting', $modcontext);
     }
     $arrposts = array();
     $arrusers = array();
     // Get the posts for this discussion.
     if ($posts = $DB->get_records('forum_posts', array('discussion' => $discussionid))) {
         foreach ($posts as $post) {
             // If we don't have the users details then perform DB call.
             if (empty($arrusers[$post->userid])) {
                 $arrusers[$post->userid] = $DB->get_record('user', array('id' => $post->userid), 'firstname, lastname, email, picture, imagealt', MUST_EXIST);
             }
             $post->userfullname = fullname($arrusers[$post->userid], $canviewfullname);
             $post->message = file_rewrite_pluginfile_urls($post->message, 'pluginfile.php', $modcontext->id, 'mod_forum', 'post', $post->id);
             $arrposts[] = (array) $post;
         }
     }
     return $arrposts;
 }
开发者ID:prabodatest,项目名称:moodle-local_custommm,代码行数:61,代码来源:externallib.php


注:本文中的forum_user_has_posted函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。