本文整理汇总了PHP中forum_tp_is_tracked函数的典型用法代码示例。如果您正苦于以下问题:PHP forum_tp_is_tracked函数的具体用法?PHP forum_tp_is_tracked怎么用?PHP forum_tp_is_tracked使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了forum_tp_is_tracked函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: print_error
print_error('invalidcoursemodule');
}
if (!($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id))) {
print_error('invalidcoursemodule');
}
require_login($course, false, $cm);
$returnpageurl = new moodle_url('/mod/forum/' . $returnpage, array('id' => $course->id, 'f' => $forum->id));
$returnto = forum_go_back_to($returnpageurl);
if (!forum_tp_can_track_forums($forum)) {
redirect($returnto);
}
$info = new stdClass();
$info->name = fullname($USER);
$info->forum = format_string($forum->name);
$eventparams = array('context' => context_module::instance($cm->id), 'relateduserid' => $USER->id, 'other' => array('forumid' => $forum->id));
if (forum_tp_is_tracked($forum)) {
if (forum_tp_stop_tracking($forum->id)) {
$event = \mod_forum\event\readtracking_disabled::create($eventparams);
$event->trigger();
redirect($returnto, get_string("nownottracking", "forum", $info), 1);
} else {
print_error('cannottrack', '', get_local_referer(false));
}
} else {
// subscribe
if (forum_tp_start_tracking($forum->id)) {
$event = \mod_forum\event\readtracking_enabled::create($eventparams);
$event->trigger();
redirect($returnto, get_string("nowtracking", "forum", $info), 1);
} else {
print_error('cannottrack', '', get_local_referer(false));
开发者ID:evltuma,项目名称:moodle,代码行数:31,代码来源:settracking.php
示例3: forum_extend_settings_navigation
//.........这里部分代码省略.........
// 0
$allowchoice->action = null;
$allowchoice->add_class('activesetting');
$allowchoice->icon = new pix_icon('t/selected', '', 'mod_forum');
break;
case FORUM_FORCESUBSCRIBE:
// 1
$forceforever->action = null;
$forceforever->add_class('activesetting');
$forceforever->icon = new pix_icon('t/selected', '', 'mod_forum');
break;
case FORUM_INITIALSUBSCRIBE:
// 2
$forceinitially->action = null;
$forceinitially->add_class('activesetting');
$forceinitially->icon = new pix_icon('t/selected', '', 'mod_forum');
break;
case FORUM_DISALLOWSUBSCRIBE:
// 3
$disallowchoice->action = null;
$disallowchoice->add_class('activesetting');
$disallowchoice->icon = new pix_icon('t/selected', '', 'mod_forum');
break;
}
} else {
if ($activeenrolled) {
switch ($subscriptionmode) {
case FORUM_CHOOSESUBSCRIBE:
// 0
$notenode = $forumnode->add(get_string('subscriptionoptional', 'forum'));
break;
case FORUM_FORCESUBSCRIBE:
// 1
$notenode = $forumnode->add(get_string('subscriptionforced', 'forum'));
break;
case FORUM_INITIALSUBSCRIBE:
// 2
$notenode = $forumnode->add(get_string('subscriptionauto', 'forum'));
break;
case FORUM_DISALLOWSUBSCRIBE:
// 3
$notenode = $forumnode->add(get_string('subscriptiondisabled', 'forum'));
break;
}
}
}
if ($cansubscribe) {
if (\mod_forum\subscriptions::is_subscribed($USER->id, $forumobject, null, $PAGE->cm)) {
$linktext = get_string('unsubscribe', 'forum');
} else {
$linktext = get_string('subscribe', 'forum');
}
$url = new moodle_url('/mod/forum/subscribe.php', array('id' => $forumobject->id, 'sesskey' => sesskey()));
$forumnode->add($linktext, $url, navigation_node::TYPE_SETTING);
if (isset($discussionid)) {
if (\mod_forum\subscriptions::is_subscribed($USER->id, $forumobject, $discussionid, $PAGE->cm)) {
$linktext = get_string('unsubscribediscussion', 'forum');
} else {
$linktext = get_string('subscribediscussion', 'forum');
}
$url = new moodle_url('/mod/forum/subscribe.php', array('id' => $forumobject->id, 'sesskey' => sesskey(), 'd' => $discussionid, 'returnurl' => $PAGE->url->out()));
$forumnode->add($linktext, $url, navigation_node::TYPE_SETTING);
}
}
if (has_capability('mod/forum:viewsubscribers', $PAGE->cm->context)) {
$url = new moodle_url('/mod/forum/subscribers.php', array('id' => $forumobject->id));
$forumnode->add(get_string('showsubscribers', 'forum'), $url, navigation_node::TYPE_SETTING);
}
if ($enrolled && forum_tp_can_track_forums($forumobject)) {
// keep tracking info for users with suspended enrolments
if ($forumobject->trackingtype == FORUM_TRACKING_OPTIONAL || !$CFG->forum_allowforcedreadtracking && $forumobject->trackingtype == FORUM_TRACKING_FORCED) {
if (forum_tp_is_tracked($forumobject)) {
$linktext = get_string('notrackforum', 'forum');
} else {
$linktext = get_string('trackforum', 'forum');
}
$url = new moodle_url('/mod/forum/settracking.php', array('id' => $forumobject->id, 'sesskey' => sesskey()));
$forumnode->add($linktext, $url, navigation_node::TYPE_SETTING);
}
}
if (!isloggedin() && $PAGE->course->id == SITEID) {
$userid = guest_user()->id;
} else {
$userid = $USER->id;
}
$hascourseaccess = $PAGE->course->id == SITEID || can_access_course($PAGE->course, $userid);
$enablerssfeeds = !empty($CFG->enablerssfeeds) && !empty($CFG->forum_enablerssfeeds);
if ($enablerssfeeds && $forumobject->rsstype && $forumobject->rssarticles && $hascourseaccess) {
if (!function_exists('rss_get_url')) {
require_once "{$CFG->libdir}/rsslib.php";
}
if ($forumobject->rsstype == 1) {
$string = get_string('rsssubscriberssdiscussions', 'forum');
} else {
$string = get_string('rsssubscriberssposts', 'forum');
}
$url = new moodle_url(rss_get_url($PAGE->cm->context->id, $userid, "mod_forum", $forumobject->id));
$forumnode->add($string, $url, settings_navigation::TYPE_SETTING, null, null, new pix_icon('i/rss', ''));
}
}
开发者ID:rezaies,项目名称:moodle,代码行数:101,代码来源:lib.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: error
}
// checkup
if (!empty($parent) && !forum_user_can_see_post($forum, $discussion, $post)) {
error("You cannot reply to this post");
}
if (empty($parent) && empty($edit) && !forum_user_can_post_discussion($forum)) {
error("You cannot start a new discussion in this forum");
}
if ($forum->type == 'qanda' && !has_capability('mod/forum:viewqandawithoutposting', $modcontext) && !empty($discussion->id) && !forum_user_has_posted($forum->id, $discussion->id, $USER->id)) {
notify(get_string('qandanotify', 'forum'));
}
forum_check_throttling($forum);
if (!empty($parent)) {
forum_print_post($parent, $course->id, $ownpost = false, $reply = false, $link = false);
if (empty($post->edit)) {
if (forum_tp_can_track_forums($forum) && forum_tp_is_tracked($forum)) {
$user_read_array = forum_tp_get_discussion_read_records($USER->id, $discussion->id);
} else {
$user_read_array = array();
}
if ($forum->type != 'qanda' || forum_user_can_see_discussion($forum, $discussion, $modcontext)) {
forum_print_posts_threaded($parent->id, $course->id, 0, false, false, $user_read_array, $discussion->forum, $modcontext);
}
}
$heading = get_string("yourreply", "forum");
} else {
$forum->intro = trim($forum->intro);
if (!empty($forum->intro)) {
print_box(format_text($forum->intro), 'generalbox', 'intro');
}
if ($forum->type == 'qanda') {
开发者ID:veritech,项目名称:pare-project,代码行数:31,代码来源:post.php
示例6: oc_forum_print_latest_discussions
//.........这里部分代码省略.........
echo '(' . get_string('nonews', 'forum') . ')';
} else {
if ($forum->type == 'qanda') {
echo '(' . get_string('noquestions', 'forum') . ')';
} else {
echo '(' . get_string('nodiscussions', 'forum') . ')';
}
}
echo "</div>\n";
return;
}
// If we want paging
if ($page != -1) {
///Get the number of discussions found
$numdiscussions = forum_get_discussions_count($cm);
///Show the paging bar
echo $OUTPUT->paging_bar($numdiscussions, $page, $perpage, "view.php?f={$forum->id}");
if ($numdiscussions > 1000) {
// saves some memory on sites with very large forums
$replies = forum_count_discussion_replies($forum->id, $sort, $maxdiscussions, $page, $perpage);
} else {
$replies = forum_count_discussion_replies($forum->id);
}
} else {
$replies = forum_count_discussion_replies($forum->id);
if ($maxdiscussions > 0 and $maxdiscussions <= count($discussions)) {
$olddiscussionlink = true;
}
}
$canviewparticipants = has_capability('moodle/course:viewparticipants', $context);
$strdatestring = get_string('strftimerecentfull');
// Check if the forum is tracked.
if ($cantrack = forum_tp_can_track_forums($forum)) {
$forumtracked = forum_tp_is_tracked($forum);
} else {
$forumtracked = false;
}
if ($forumtracked) {
$unreads = forum_get_discussions_unread($cm);
} else {
$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 . '&mark=read&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 (!is_guest($context, $USER) && isloggedin() && has_capability('mod/forum:viewdiscussion', $context)) {
if (\mod_forum\subscriptions::is_subscribable($forum)) {
echo '<th class="header discussionsubscription" scope="col">';
开发者ID:oncampus,项目名称:mooin_block_oc_mooc_nav,代码行数:67,代码来源:forum_lib.php
示例7: test_forum_tp_is_tracked
/**
* Test the logic in the test_forum_tp_is_tracked() function.
*/
public function test_forum_tp_is_tracked()
{
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);
// Allow force.
$CFG->forum_allowforcedreadtracking = 1;
// User on, forum off, should be off.
$result = forum_tp_is_tracked($forumoff, $useron);
$this->assertEquals(false, $result);
// User on, forum force, should be on.
$result = forum_tp_is_tracked($forumforce, $useron);
$this->assertEquals(true, $result);
// User on, forum optional, should be on.
$result = forum_tp_is_tracked($forumoptional, $useron);
$this->assertEquals(true, $result);
// User off, forum off, should be off.
$result = forum_tp_is_tracked($forumoff, $useroff);
$this->assertEquals(false, $result);
// User off, forum force, should be on.
$result = forum_tp_is_tracked($forumforce, $useroff);
$this->assertEquals(true, $result);
// User off, forum optional, should be off.
$result = forum_tp_is_tracked($forumoptional, $useroff);
$this->assertEquals(false, $result);
// Don't allow force.
$CFG->forum_allowforcedreadtracking = 0;
// User on, forum off, should be off.
$result = forum_tp_is_tracked($forumoff, $useron);
$this->assertEquals(false, $result);
// User on, forum force, should be on.
$result = forum_tp_is_tracked($forumforce, $useron);
$this->assertEquals(true, $result);
// User on, forum optional, should be on.
$result = forum_tp_is_tracked($forumoptional, $useron);
$this->assertEquals(true, $result);
// User off, forum off, should be off.
$result = forum_tp_is_tracked($forumoff, $useroff);
$this->assertEquals(false, $result);
// User off, forum force, should be off.
$result = forum_tp_is_tracked($forumforce, $useroff);
$this->assertEquals(false, $result);
// User off, forum optional, should be off.
$result = forum_tp_is_tracked($forumoptional, $useroff);
$this->assertEquals(false, $result);
// 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;
// User on, preference off, forum force, should be on.
$result = forum_tp_is_tracked($forumforce, $useron);
$this->assertEquals(true, $result);
// User on, preference off, forum optional, should be on.
$result = forum_tp_is_tracked($forumoptional, $useron);
$this->assertEquals(false, $result);
// User off, preference off, forum force, should be on.
$result = forum_tp_is_tracked($forumforce, $useroff);
$this->assertEquals(true, $result);
// User off, preference off, forum optional, should be off.
$result = forum_tp_is_tracked($forumoptional, $useroff);
$this->assertEquals(false, $result);
// Don't allow force.
$CFG->forum_allowforcedreadtracking = 0;
// User on, preference off, forum force, should be on.
$result = forum_tp_is_tracked($forumforce, $useron);
$this->assertEquals(false, $result);
// User on, preference off, forum optional, should be on.
$result = forum_tp_is_tracked($forumoptional, $useron);
$this->assertEquals(false, $result);
// User off, preference off, forum force, should be off.
$result = forum_tp_is_tracked($forumforce, $useroff);
$this->assertEquals(false, $result);
// User off, preference off, forum optional, should be off.
$result = forum_tp_is_tracked($forumoptional, $useroff);
$this->assertEquals(false, $result);
}
开发者ID:rushi963,项目名称:moodle,代码行数:93,代码来源:lib_test.php
示例8: 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
示例9: get_forum_discussions_paginated
/**
* Returns a list of forum discussions optionally sorted and paginated.
*
* @param int $forumid the forum instance id
* @param string $sortby sort by this element (id, timemodified, timestart or timeend)
* @param string $sortdirection sort direction: ASC or DESC
* @param int $page page number
* @param int $perpage items per page
*
* @return array the forum discussion details including warnings
* @since Moodle 2.8
*/
public static function get_forum_discussions_paginated($forumid, $sortby = 'timemodified', $sortdirection = 'DESC', $page = -1, $perpage = 0)
{
global $CFG, $DB, $USER;
require_once $CFG->dirroot . "/mod/forum/lib.php";
$warnings = array();
$discussions = array();
$params = self::validate_parameters(self::get_forum_discussions_paginated_parameters(), array('forumid' => $forumid, 'sortby' => $sortby, 'sortdirection' => $sortdirection, 'page' => $page, 'perpage' => $perpage));
// Compact/extract functions are not recommended.
$forumid = $params['forumid'];
$sortby = $params['sortby'];
$sortdirection = $params['sortdirection'];
$page = $params['page'];
$perpage = $params['perpage'];
$sortallowedvalues = array('id', 'timemodified', 'timestart', 'timeend');
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));
}
$forum = $DB->get_record('forum', array('id' => $forumid), '*', 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);
// Check they have the view forum capability.
require_capability('mod/forum:viewdiscussion', $modcontext, null, true, 'noviewdiscussionspermission', 'forum');
$sort = 'd.' . $sortby . ' ' . $sortdirection;
$alldiscussions = forum_get_discussions($cm, $sort, true, -1, -1, true, $page, $perpage);
if ($alldiscussions) {
$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($forumid, $sort, -1, $page, $perpage);
foreach ($alldiscussions as $discussion) {
// This function checks for qanda forums.
// Note that the forum_get_discussions returns as id the post id, not the discussion id so we need to do this.
$discussionrec = clone $discussion;
$discussionrec->id = $discussion->discussion;
if (!forum_user_can_see_discussion($forum, $discussionrec, $modcontext)) {
$warning = array();
// Function forum_get_discussions returns forum_posts ids not forum_discussions ones.
$warning['item'] = 'post';
$warning['itemid'] = $discussion->id;
$warning['warningcode'] = '1';
$warning['message'] = 'You can\'t see this discussion';
$warnings[] = $warning;
continue;
}
$discussion->numunread = 0;
if ($cantrack && $forumtracked) {
if (isset($unreads[$discussion->discussion])) {
$discussion->numunread = (int) $unreads[$discussion->discussion];
}
}
$discussion->numreplies = 0;
if (!empty($replies[$discussion->discussion])) {
$discussion->numreplies = (int) $replies[$discussion->discussion]->replies;
}
// Load user objects from the results of the query.
$user = new stdclass();
$user->id = $discussion->userid;
$user = username_load_fields_from_object($user, $discussion);
$discussion->userfullname = fullname($user, $canviewfullname);
// We can have post written by users that are deleted. In this case, those users don't have a valid context.
$usercontext = context_user::instance($user->id, IGNORE_MISSING);
if ($usercontext) {
$discussion->userpictureurl = moodle_url::make_webservice_pluginfile_url($usercontext->id, 'user', 'icon', null, '/', 'f1')->out(false);
} else {
$discussion->userpictureurl = '';
}
$usermodified = new stdclass();
$usermodified->id = $discussion->usermodified;
$usermodified = username_load_fields_from_object($usermodified, $discussion, 'um');
$discussion->usermodifiedfullname = fullname($usermodified, $canviewfullname);
// We can have post written by users that are deleted. In this case, those users don't have a valid context.
$usercontext = context_user::instance($usermodified->id, IGNORE_MISSING);
if ($usercontext) {
$discussion->usermodifiedpictureurl = moodle_url::make_webservice_pluginfile_url($usercontext->id, 'user', 'icon', null, '/', 'f1')->out(false);
//.........这里部分代码省略.........
开发者ID:educakanchay,项目名称:campus,代码行数:101,代码来源:externallib.php
示例10: get_string
} else {
echo '<span class="helplink">' . $streveryonecannowchoose . '</span>';
}
if (forum_is_subscribed($USER->id, $forum->id)) {
$subtexttitle = get_string('subscribestop', 'forum');
$subtext = get_string('unsubscribe', 'forum');
} else {
$subtexttitle = get_string('subscribestart', 'forum');
$subtext = get_string('subscribe', 'forum');
}
echo "<br />";
echo "<span class=\"helplink\"><a title=\"{$subtexttitle}\" href=\"subscribe.php?id={$forum->id}\">{$subtext}</a></span>";
}
}
if (forum_tp_can_track_forums($forum) && $forum->trackingtype == FORUM_TRACKING_OPTIONAL) {
if (forum_tp_is_tracked($forum, $USER->id)) {
$trtitle = get_string('notrackforum', 'forum');
$trackedlink = '<a title="' . get_string('notrackforum', 'forum') . '" href="settracking.php?id=' . $forum->id . '&returnpage=view.php">' . get_string('forumtracked', 'forum') . '</a>';
} else {
$trtitle = get_string('trackforum', 'forum');
$trackedlink = '<a title="' . get_string('trackforum', 'forum') . '" href="settracking.php?id=' . $forum->id . '&returnpage=view.php">' . get_string('forumtrackednot', 'forum') . '</a>';
}
echo '<br />';
echo "<span class=\"helplink\">{$trackedlink}</span>";
}
}
/// If rss are activated at site and forum level and this forum has rss defined, show link
if (isset($CFG->enablerssfeeds) && isset($CFG->forum_enablerssfeeds) && $CFG->enablerssfeeds && $CFG->forum_enablerssfeeds && $forum->rsstype and $forum->rssarticles) {
if ($forum->rsstype == 1) {
$tooltiptext = get_string('rsssubscriberssdiscussions', 'forum', format_string($forum->name));
} else {
开发者ID:veritech,项目名称:pare-project,代码行数:31,代码来源:view.php
示例11: get_forum_discussions_paginated
/**
* Returns a list of forum discussions optionally sorted and paginated.
*
* @param int $forumid the forum instance id
* @param string $sortby sort by this element (id, timemodified, timestart or timeend)
* @param string $sortdirection sort direction: ASC or DESC
* @param int $page page number
* @param int $perpage items per page
*
* @return array the forum discussion details including warnings
* @since Moodle 2.8
*/
public static function get_forum_discussions_paginated($forumid, $sortby = 'timemodified', $sortdirection = 'DESC', $page = -1, $perpage = 0)
{
global $CFG, $DB, $USER, $PAGE;
require_once $CFG->dirroot . "/mod/forum/lib.php";
$warnings = array();
$discussions = array();
$params = self::validate_parameters(self::get_forum_discussions_paginated_parameters(), array('forumid' => $forumid, 'sortby' => $sortby, 'sortdirection' => $sortdirection, 'page' => $page, 'perpage' => $perpage));
// Compact/extract functions are not recommended.
$forumid = $params['forumid'];
$sortby = $params['sortby'];
$sortdirection = $params['sortdirection'];
$page = $params['page'];
$perpage = $params['perpage'];
$sortallowedvalues = array('id', 'timemodified', 'timestart', 'timeend');
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));
}
$forum = $DB->get_record('forum', array('id' => $forumid), '*', 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);
// Check they have the view forum capability.
require_capability('mod/forum:viewdiscussion', $modcontext, null, true, 'noviewdiscussionspermission', 'forum');
$sort = 'd.pinned DESC, d.' . $sortby . ' ' . $sortdirection;
$alldiscussions = forum_get_discussions($cm, $sort, true, -1, -1, true, $page, $perpage, FORUM_POSTS_ALL_USER_GROUPS);
if ($alldiscussions) {
$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($forumid, $sort, -1, $page, $perpage);
foreach ($alldiscussions as $discussion) {
// This function checks for qanda forums.
// Note that the forum_get_discussions returns as id the post id, not the discussion id so we need to do this.
$discussionrec = clone $discussion;
$discussionrec->id = $discussion->discussion;
if (!forum_user_can_see_discussion($forum, $discussionrec, $modcontext)) {
$warning = array();
// Function forum_get_discussions returns forum_posts ids not forum_discussions ones.
$warning['item'] = 'post';
$warning['itemid'] = $discussion->id;
$warning['warningcode'] = '1';
$warning['message'] = 'You can\'t see this discussion';
$warnings[] = $warning;
continue;
}
$discussion->numunread = 0;
if ($cantrack && $forumtracked) {
if (isset($unreads[$discussion->discussion])) {
$discussion->numunread = (int) $unreads[$discussion->discussion];
}
}
$discussion->numreplies = 0;
if (!empty($replies[$discussion->discussion])) {
$discussion->numreplies = (int) $replies[$discussion->discussion]->replies;
}
$discussion->name = external_format_string($discussion->name, $modcontext->id);
$discussion->subject = external_format_string($discussion->subject, $modcontext->id);
// Rewrite embedded images URLs.
list($discussion->message, $discussion->messageformat) = external_format_text($discussion->message, $discussion->messageformat, $modcontext->id, 'mod_forum', 'post', $discussion->id);
// List attachments.
if (!empty($discussion->attachment)) {
$discussion->attachments = external_util::get_area_files($modcontext->id, 'mod_forum', 'attachment', $discussion->id);
}
$messageinlinefiles = external_util::get_area_files($modcontext->id, 'mod_forum', 'post', $discussion->id);
if (!empty($messageinlinefiles)) {
$discussion->messageinlinefiles = $messageinlinefiles;
}
$discussion->locked = forum_discussion_is_locked($forum, $discussion);
$discussion->canreply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext);
if (forum_is_author_hidden($discussion, $forum)) {
$discussion->userid = null;
$discussion->userfullname = null;
$discussion->userpictureurl = null;
$discussion->usermodified = null;
$discussion->usermodifiedfullname = null;
//.........这里部分代码省略.........
开发者ID:lucaboesch,项目名称:moodle,代码行数:101,代码来源:externallib.php
示例12: 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 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);
$course = get_course($forum->course);
$modinfo = get_fast_modinfo($course);
$forums = $modinfo->get_instances_of('forum');
$cm = $forums[$forum->id];
// Get the module context.
$modcontext = context_module::instance($cm->id);
// Validate the context.
self::validate_context($modcontext);
require_capability('mod/forum:viewdiscussion', $modcontext);
// Get the discussions for this forum.
$params = array();
$groupselect = "";
$groupmode = groups_get_activity_groupmode($cm, $course);
if ($groupmode and $groupmode != VISIBLEGROUPS and !has_capability('moodle/site:accessallgroups', $modcontext)) {
// Get all the discussions from all the groups this user belongs to.
$usergroups = groups_get_user_groups($course->id);
if (!empty($usergroups['0'])) {
list($sql, $params) = $DB->get_in_or_equal($usergroups['0']);
$groupselect = "AND (groupid {$sql} OR groupid = -1)";
}
}
array_unshift($params, $id);
$select = "forum = ? {$groupselect}";
if ($discussions = $DB->get_records_select('forum_discussions', $select, $params, 'timemodified DESC')) {
// 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);
foreach ($discussions as $discussion) {
// This function checks capabilities, timed discussions, groups and qanda forums posting.
if (!forum_user_can_see_discussion($forum, $discussion, $modcontext)) {
continue;
}
$usernamefields = user_picture::fields();
// 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), $usernamefields, 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[$dis
|
请发表评论