本文整理汇总了PHP中forum_get_discussions函数的典型用法代码示例。如果您正苦于以下问题:PHP forum_get_discussions函数的具体用法?PHP forum_get_discussions怎么用?PHP forum_get_discussions使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了forum_get_discussions函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: forum_check_updates_since
/**
* Check if the module has any update that affects the current user since a given time.
*
* @param cm_info $cm course module data
* @param int $from the time to check updates from
* @param array $filter if we need to check only specific updates
* @return stdClass an object with the different type of areas indicating if they were updated or not
* @since Moodle 3.2
*/
function forum_check_updates_since(cm_info $cm, $from, $filter = array())
{
$context = $cm->context;
$updates = new stdClass();
if (!has_capability('mod/forum:viewdiscussion', $context)) {
return $updates;
}
$updates = course_check_module_updates_since($cm, $from, array(), $filter);
// Check if there are new discussions in the forum.
$updates->discussions = (object) array('updated' => false);
$discussions = forum_get_discussions($cm, '', false, -1, -1, true, -1, 0, FORUM_POSTS_ALL_USER_GROUPS, $from);
if (!empty($discussions)) {
$updates->discussions->updated = true;
$updates->discussions->itemids = array_keys($discussions);
}
return $updates;
}
开发者ID:rezaies,项目名称:moodle,代码行数:26,代码来源:lib.php
示例2: forum_print_latest_discussions
//.........这里部分代码省略.........
switch ($forum->type) {
case 'news':
case 'blog':
$buttonadd = get_string('addanewtopic', 'forum');
break;
case 'qanda':
$buttonadd = get_string('addanewquestion', 'forum');
break;
default:
$buttonadd = get_string('addanewdiscussion', 'forum');
break;
}
echo '<input type="submit" value="'.$buttonadd.'" />';
echo '</div>';
echo '</form>';
echo "</div>\n";
} else if (isguestuser() or !isloggedin() or $forum->type == 'news') {
// no button and no info
} else if ($groupmode and has_capability('mod/forum:startdiscussion', $context)) {
// inform users why they can not post new discussion
if ($currentgroup) {
echo $OUTPUT->notification(get_string('cannotadddiscussion', 'forum'));
} else {
echo $OUTPUT->notification(get_string('cannotadddiscussionall', 'forum'));
}
}
// Get all the recent discussions we're allowed to see
$getuserlastmodified = ($displayformat == 'header');
if (! $discussions = forum_get_discussions($cm, $sort, $fullpost, null, $maxdiscussions, $getuserlastmodified, $page, $perpage) ) {
echo '<div class="forumnodiscuss">';
if ($forum->type == 'news') {
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;
}
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:67,代码来源:lib.php
示例3: test_forum_get_discussions_with_groups
/**
* Test forum_get_discussions
*/
public function test_forum_get_discussions_with_groups()
{
global $DB;
$this->resetAfterTest(true);
// Create course to add the module.
$course = self::getDataGenerator()->create_course(array('groupmode' => VISIBLEGROUPS, 'groupmodeforce' => 0));
$user1 = self::getDataGenerator()->create_user();
$user2 = self::getDataGenerator()->create_user();
$user3 = self::getDataGenerator()->create_user();
$role = $DB->get_record('role', array('shortname' => 'student'), '*', MUST_EXIST);
self::getDataGenerator()->enrol_user($user1->id, $course->id, $role->id);
self::getDataGenerator()->enrol_user($user2->id, $course->id, $role->id);
self::getDataGenerator()->enrol_user($user3->id, $course->id, $role->id);
// Forum forcing separate gropus.
$record = new stdClass();
$record->course = $course->id;
$forum = self::getDataGenerator()->create_module('forum', $record, array('groupmode' => SEPARATEGROUPS));
$cm = get_coursemodule_from_instance('forum', $forum->id);
// Create groups.
$group1 = self::getDataGenerator()->create_group(array('courseid' => $course->id));
$group2 = self::getDataGenerator()->create_group(array('courseid' => $course->id));
$group3 = self::getDataGenerator()->create_group(array('courseid' => $course->id));
// Add the user1 to g1 and g2 groups.
groups_add_member($group1->id, $user1->id);
groups_add_member($group2->id, $user1->id);
// Add the user 2 and 3 to only one group.
groups_add_member($group1->id, $user2->id);
groups_add_member($group3->id, $user3->id);
// Add a few discussions.
$record = array();
$record['course'] = $course->id;
$record['forum'] = $forum->id;
$record['userid'] = $user1->id;
$record['groupid'] = $group1->id;
$discussiong1u1 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
$record['groupid'] = $group2->id;
$discussiong2u1 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
$record['userid'] = $user2->id;
$record['groupid'] = $group1->id;
$discussiong1u2 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
$record['userid'] = $user3->id;
$record['groupid'] = $group3->id;
$discussiong3u3 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
self::setUser($user1);
// Test retrieve discussions not passing the groupid parameter. We will receive only first group discussions.
$discussions = forum_get_discussions($cm);
self::assertCount(2, $discussions);
foreach ($discussions as $discussion) {
self::assertEquals($group1->id, $discussion->groupid);
}
// Get all my discussions.
$discussions = forum_get_discussions($cm, '', true, -1, -1, false, -1, 0, 0);
self::assertCount(3, $discussions);
// Get all my g1 discussions.
$discussions = forum_get_discussions($cm, '', true, -1, -1, false, -1, 0, $group1->id);
self::assertCount(2, $discussions);
foreach ($discussions as $discussion) {
self::assertEquals($group1->id, $discussion->groupid);
}
// Get all my g2 discussions.
$discussions = forum_get_discussions($cm, '', true, -1, -1, false, -1, 0, $group2->id);
self::assertCount(1, $discussions);
$discussion = array_shift($discussions);
self::assertEquals($group2->id, $discussion->groupid);
self::assertEquals($user1->id, $discussion->userid);
self::assertEquals($discussiong2u1->id, $discussion->discussion);
// Get all my g3 discussions (I'm not enrolled in that group).
$discussions = forum_get_discussions($cm, '', true, -1, -1, false, -1, 0, $group3->id);
self::assertCount(0, $discussions);
// This group does not exist.
$discussions = forum_get_discussions($cm, '', true, -1, -1, false, -1, 0, $group3->id + 1000);
self::assertCount(0, $discussions);
self::setUser($user2);
// Test retrieve discussions not passing the groupid parameter. We will receive only first group discussions.
$discussions = forum_get_discussions($cm);
self::assertCount(2, $discussions);
foreach ($discussions as $discussion) {
self::assertEquals($group1->id, $discussion->groupid);
}
// Get all my viewable discussions.
$discussions = forum_get_discussions($cm, '', true, -1, -1, false, -1, 0, 0);
self::assertCount(2, $discussions);
foreach ($discussions as $discussion) {
self::assertEquals($group1->id, $discussion->groupid);
}
// Get all my g2 discussions (I'm not enrolled in that group).
$discussions = forum_get_discussions($cm, '', true, -1, -1, false, -1, 0, $group2->id);
self::assertCount(0, $discussions);
// Get all my g3 discussions (I'm not enrolled in that group).
$discussions = forum_get_discussions($cm, '', true, -1, -1, false, -1, 0, $group3->id);
self::assertCount(0, $discussions);
}
开发者ID:rushi963,项目名称:moodle,代码行数:95,代码来源:lib_test.php
示例4: get_content
function get_content()
{
global $CFG, $USER;
if ($this->content !== NULL) {
return $this->content;
}
$this->content = new stdClass();
$this->content->text = '';
$this->content->footer = '';
if (empty($this->instance)) {
return $this->content;
}
if ($this->page->course->newsitems) {
// Create a nice listing of recent postings
require_once $CFG->dirroot . '/mod/forum/lib.php';
// We'll need this
$text = '';
if (!($forum = forum_get_course_forum($this->page->course->id, 'news'))) {
return '';
}
$modinfo = get_fast_modinfo($this->page->course);
if (empty($modinfo->instances['forum'][$forum->id])) {
return '';
}
$cm = $modinfo->instances['forum'][$forum->id];
if (!$cm->uservisible) {
return '';
}
$context = context_module::instance($cm->id);
/// User must have perms to view discussions in that forum
if (!has_capability('mod/forum:viewdiscussion', $context)) {
return '';
}
/// First work out whether we can post to this group and if so, include a link
$groupmode = groups_get_activity_groupmode($cm);
$currentgroup = groups_get_activity_group($cm, true);
if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context)) {
$text .= '<div class="newlink"><a href="' . $CFG->wwwroot . '/mod/forum/post.php?forum=' . $forum->id . '">' . get_string('addanewtopic', 'forum') . '</a>...</div>';
}
/// Get all the recent discussions we're allowed to see
if (!($discussions = forum_get_discussions($cm, 'p.modified DESC', false, $currentgroup, $this->page->course->newsitems))) {
$text .= '(' . get_string('nonews', 'forum') . ')';
$this->content->text = $text;
return $this->content;
}
/// Actually create the listing now
$strftimerecent = get_string('strftimerecent');
$strmore = get_string('more', 'forum');
/// Accessibility: markup as a list.
$text .= "\n<ul class='unlist'>\n";
foreach ($discussions as $discussion) {
$discussion->subject = $discussion->name;
$discussion->subject = format_string($discussion->subject, true, $forum->course);
$text .= '<li class="post">' . '<div class="head clearfix">' . '<div class="date">' . userdate($discussion->modified, $strftimerecent) . '</div>' . '<div class="name">' . fullname($discussion) . '</div></div>' . '<div class="info"><a href="' . $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $discussion->discussion . '">' . $discussion->subject . '</a></div>' . "</li>\n";
}
$text .= "</ul>\n";
$this->content->text = $text;
$this->content->footer = '<a href="' . $CFG->wwwroot . '/mod/forum/view.php?f=' . $forum->id . '">' . get_string('oldertopics', 'forum') . '</a> ...';
/// If RSS is 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 && $forum->rssarticles) {
require_once $CFG->dirroot . '/lib/rsslib.php';
// We'll need this
if ($forum->rsstype == 1) {
$tooltiptext = get_string('rsssubscriberssdiscussions', 'forum');
} else {
$tooltiptext = get_string('rsssubscriberssposts', 'forum');
}
if (!isloggedin()) {
$userid = $CFG->siteguest;
} else {
$userid = $USER->id;
}
$this->content->footer .= '<br />' . rss_get_link($context->id, $userid, 'mod_forum', $forum->id, $tooltiptext);
}
}
return $this->content;
}
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:77,代码来源:block_news_items.php
示例5: test_fixed_data_set
/**
* Creates an small test course with fixed data set and checks the used sections and users.
*/
public function test_fixed_data_set()
{
$this->resetAfterTest();
$this->setAdminUser();
// Create the S course (more sections and activities than XS).
$backend = new tool_generator_course_backend('TOOL_S_COURSE_1', 1, true, false, false);
$courseid = $backend->make();
// Get course details.
$course = get_course($courseid);
$modinfo = get_fast_modinfo($course);
// Check module instances belongs to section 1.
$instances = $modinfo->get_instances_of('page');
foreach ($instances as $instance) {
$this->assertEquals(1, $instance->sectionnum);
}
// Users that started discussions are the same.
$forums = $modinfo->get_instances_of('forum');
$discussions = forum_get_discussions(reset($forums), 'd.timemodified ASC');
$lastusernumber = 0;
$discussionstarters = array();
foreach ($discussions as $discussion) {
$usernumber = intval($discussion->lastname);
// Checks that the users are odd numbers.
$this->assertEquals(1, $usernumber % 2);
// Checks that the users follows an increasing order.
$this->assertGreaterThan($lastusernumber, $usernumber);
$lastusernumber = $usernumber;
$discussionstarters[$discussion->userid] = $discussion->subject;
}
}
开发者ID:verbazend,项目名称:AWFA,代码行数:33,代码来源:maketestcourse_test.php
示例6: 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
示例7: get_news_items
/**
* Returns last news for a course
*
* @param int $id Course identifier
*/
function get_news_items($id)
{
global $CFG, $DB;
$conditions = array('id' => $id);
$COURSE = $DB->get_record('course', $conditions);
if (!($forum = forum_get_course_forum($COURSE->id, 'news'))) {
return array();
}
$modinfo = get_fast_modinfo($COURSE);
if (empty($modinfo->instances['forum'][$forum->id])) {
return array();
}
$cm = $modinfo->instances['forum'][$forum->id];
/// Get all the recent discussions we're allowed to see
if (!($discussions = forum_get_discussions($cm, 'p.modified DESC', false, -1, $COURSE->newsitems))) {
return array();
}
$data = array();
foreach ($discussions as $r) {
$e['discussion'] = $r->discussion;
$e['subject'] = $r->subject;
$e['timemodified'] = $r->timemodified;
$data[] = $e;
}
return $data;
}
开发者ID:anawu2006,项目名称:PeerLearning,代码行数:31,代码来源:auth.php
示例8: site_frontpage_news
/**
* Alternative rendering of front page news, called from layout/faux_site_index.php which
* replaces the standard news output with this.
*
* @return string
*/
public function site_frontpage_news()
{
global $CFG, $SITE;
require_once $CFG->dirroot . '/mod/forum/lib.php';
if (!($forum = forum_get_course_forum($SITE->id, 'news'))) {
print_error('cannotfindorcreateforum', 'forum');
}
$cm = get_coursemodule_from_instance('forum', $forum->id, $SITE->id, false, MUST_EXIST);
$context = \context_module::instance($cm->id, MUST_EXIST);
$output = html_writer::start_tag('div', array('id' => 'site-news-forum', 'class' => 'clearfix'));
$output .= $this->heading(format_string($forum->name, true, array('context' => $context)));
$groupmode = groups_get_activity_groupmode($cm, $SITE);
$currentgroup = groups_get_activity_group($cm);
if (!($discussions = forum_get_discussions($cm, 'p.modified DESC', true, null, $SITE->newsitems, false, -1, $SITE->newsitems))) {
$output .= html_writer::tag('div', '(' . get_string('nonews', 'forum') . ')', array('class' => 'forumnodiscuss'));
if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context)) {
$output .= html_writer::link(new moodle_url('/mod/forum/post.php', array('forum' => $forum->id)), get_string('addanewtopic', 'forum'), array('class' => 'btn btn-primary'));
} else {
// No news and user cannot edit, so return nothing.
return '';
}
return $output . '</div>';
}
$output .= html_writer::start_div('', array('id' => 'news-articles'));
foreach ($discussions as $discussion) {
if (!forum_user_can_see_discussion($forum, $discussion, $context)) {
continue;
}
$message = file_rewrite_pluginfile_urls($discussion->message, 'pluginfile.php', $context->id, 'mod_forum', 'post', $discussion->id);
$imagestyle = '';
$imgarr = \theme_snap\local::extract_first_image($message);
if ($imgarr) {
$imageurl = s($imgarr['src']);
$imagestyle = " style=\"background-image:url('{$imageurl}')\"";
}
$name = format_string($discussion->name, true, array('context' => $context));
$date = userdate($discussion->timemodified, get_string('strftimedatetime', 'langconfig'));
$readmorebtn = "<a class='btn btn-default toggle' href='" . $CFG->wwwroot . "/mod/forum/discuss.php?d=" . $discussion->discussion . "'>" . get_string('readmore', 'theme_snap') . "</a>";
$preview = '';
$newsimage = '';
if (!$imagestyle) {
$preview = html_to_text($message, 0, false);
$preview = "<div class='news-article-preview'><p>" . shorten_text($preview, 200) . "</p>\n <p class='text-right'>" . $readmorebtn . "</p></div>";
} else {
$newsimage = '<div class="news-article-image toggle"' . $imagestyle . ' title="' . get_string('readmore', 'theme_snap') . '"></div>';
}
$close = get_string('close', 'theme_snap');
$output .= <<<HTML
<div class="news-article clearfix">
{$newsimage}
<div class="news-article-inner">
<div class="news-article-content">
<h3 class='toggle'><a href="{$CFG->wwwroot}/mod/forum/discuss.php?d={$discussion->discussion}">{$name}</a></h3>
<em class="news-article-date">{$date}</em>
</div>
</div>
{$preview}
<div class="news-article-message" tabindex="-1">
{$message}
<div><hr><a class="snap-action-icon toggle" href="#">
<i class="icon icon-close"></i><small>{$close}</small></a></div>
</div>
</div>
HTML;
}
$actionlinks = html_writer::link(new moodle_url('/mod/forum/view.php', array('id' => $cm->id)), get_string('morenews', 'theme_snap'), array('class' => 'btn btn-default'));
if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context)) {
$actionlinks .= html_writer::link(new moodle_url('/mod/forum/post.php', array('forum' => $forum->id)), get_string('addanewtopic', 'forum'), array('class' => 'btn btn-primary'));
}
$output .= html_writer::end_div();
$output .= "<br><div class='text-center'>{$actionlinks}</div>";
$output .= html_writer::end_tag('div');
return $output;
}
开发者ID:pramithkm,项目名称:moodle-theme_snap,代码行数:80,代码来源:core_renderer.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, $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
示例10: get_course_test_data
/**
* Gets the data required to fill the test plan template with the database contents.
*
* @param int $targetcourseid The target course id
* @return stdClass The ids required by the test plan
*/
protected static function get_course_test_data($targetcourseid)
{
global $DB, $USER;
$data = new stdClass();
// Getting course contents info as the current user (will be an admin).
$course = new stdClass();
$course->id = $targetcourseid;
$courseinfo = new course_modinfo($course, $USER->id);
// Getting the first page module instance.
if (!($pages = $courseinfo->get_instances_of('page'))) {
print_error('error_nopageinstances', 'tool_generator');
}
$data->pageid = reset($pages)->id;
// Getting the first forum module instance and it's first discussion and reply as well.
if (!($forums = $courseinfo->get_instances_of('forum'))) {
print_error('error_noforuminstances', 'tool_generator');
}
$forum = reset($forums);
// Getting the first discussion (and reply).
if (!($discussions = forum_get_discussions($forum, 'd.timemodified ASC', false, -1, 1))) {
print_error('error_noforumdiscussions', 'tool_generator');
}
$discussion = reset($discussions);
$data->forumid = $forum->id;
$data->forumdiscussionid = $discussion->discussion;
$data->forumreplyid = $discussion->id;
// According to the current test plan.
return $data;
}
开发者ID:evltuma,项目名称:moodle,代码行数:35,代码来源:testplan_backend.php
示例11: get_content
function get_content() {
global $CFG, $USER,$DB;
if ($this->content !== NULL) {
return $this->content;
}
$this->content = new stdClass;
$this->content->text = '';
$this->content->footer = '';
if (empty($this->instance)) {
return $this->content;
}
if ($this->page->course->newsitems) { // Create a nice listing of recent postings
require_once($CFG->dirroot.'/mod/forum/lib.php'); // We'll need this
$text = '';
if (!$forum = forum_get_course_forum($this->page->course->id, 'news')) {
return '';
}
$modinfo = get_fast_modinfo($this->page->course);
if (empty($modinfo->instances['forum'][$forum->id])) {
return '';
}
$cm = $modinfo->instances['forum'][$forum->id];
if (!$cm->uservisible) {
return '';
}
$context = context_module::instance($cm->id);
/// User must have perms to view discussions in that forum
if (!has_capability('mod/forum:viewdiscussion', $context)) {
return '';
}
/// First work out whether we can post to this group and if so, include a link
$groupmode = groups_get_activity_groupmode($cm);
$currentgroup = groups_get_activity_group($cm, true);
if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context)) {
$text .= '<div class="newlink"><a href="'.$CFG->wwwroot.'/mod/forum/post.php?forum='.$forum->id.'">'.
get_string('addanewtopic', 'forum').'</a></div>';
}
/// Get all the recent discussions we're allowed to see
if (! $discussions = forum_get_discussions($cm, 'p.modified DESC', false,
$currentgroup, $this->page->course->newsitems) ) {
$text .= '('.get_string('nonews', 'forum').')';
$this->content->text = $text;
return $this->content;
}
/// Actually create the listing now
$strftimerecent = get_string('strftimerecent');
$strmore = get_string('more', 'forum');
/// Accessibility: markup as a list.
$text .= "\n<ul class='unlist'>\n";
foreach ($discussions as $discussion) {
$discussion->subject = $discussion->name;
$discussion->subject = format_string($discussion->subject, true, $forum->course);
/******************code by sreekanth*****************/
$subject1 = html_writer::tag('b',get_string('subject', 'block_site_blog'),array());
$message = $DB->get_record_sql("SELECT * FROM {forum_posts} WHERE id = $discussion->id");
//print_object($message);
$text .= '<li class="post">'.
'<div class="head clearfix">'.
'<div class="date">'.userdate($discussion->modified, $strftimerecent).'</div>'.
'<div class="name">'.fullname($discussion).'</div></div>'.
'<div class="info">'.$subject1. ': <a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$discussion->discussion.'">'.$discussion->subject.'</a></div>'.
"</li>\n";
$string1= $message->message;
//$text .= $message->message;
$string = strip_tags($string1);
if (strlen($string) > 480) {
// truncate string
$stringCut = substr($string, 0, 480);
//print_object($stringCut);
// make sure it ends in a word so assassinate doesn't become ass...
$view = html_writer::tag('a',get_string('view', 'block_my_blog'),array('href'=>$CFG->wwwroot.'/mod/forum/discuss.php?d='.$discussion->discussion));
$text .= "<div class='bulletin_message'>".substr($stringCut, 0, strrpos($stringCut, ' '))."...".$view."</div>";
} else{
$text .= "<div class='bulletin_message'>". $message->message ."</div>";
}
//.........这里部分代码省略.........
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:101,代码来源:block_news_items.php
示例12: get_content
function get_content()
{
global $CFG, $USER, $COURSE;
if ($this->content !== NULL) {
return $this->content;
}
$this->content = new stdClass();
$this->content->text = '';
$this->content->footer = '';
if (empty($this->instance)) {
return $this->content;
}
if ($COURSE->newsitems) {
// Create a nice listing of recent postings
require_once $CFG->dirroot . '/mod/forum/lib.php';
// We'll need this
if (!($forum = forum_get_course_forum($COURSE->id, 'news'))) {
return '';
}
$modinfo = get_fast_modinfo($COURSE);
if (empty($modinfo->instances['forum'][$forum->id])) {
return '';
}
$cm = $modinfo->instances['forum'][$forum->id];
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
/// First work out whether we can post to this group and if so, include a link
$groupmode = groups_get_activity_groupmode($cm);
$currentgroup = groups_get_activity_group($cm, true);
/// Get all the recent discussions we're allowed to see
if (!($discussions = forum_get_discussions($cm, 'p.modified DESC', false, $currentgroup, $COURSE->newsitems))) {
$this->content->text = '(' . get_string('nonews', 'forum') . ')';
// add a link to add "a new news item" (nadavkav)
if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context)) {
$this->content->footer = '<div class="newlink"><a href="' . $CFG->wwwroot . '/mod/forum/post.php?forum=' . $forum->id . '">' . get_string('addanewitem', 'block_news_items_scrolling') . '</a>...</div>';
}
return $this->content;
}
// add scrolling effect <marquee> (nadavkav)
$text = '<marquee width="100%" height="120" align="right" direction="up" scrolldelay="50" scrollamount="1" onmouseout="this.start();" style="padding-top: 2px;" onmouseover="this.stop();" dir="rtl">';
/// Actually create the listing now
$strftimerecent = get_string('strftimerecent');
$strmore = get_string('more', 'block_news_items_scrolling');
/// Accessibility: markup as a list.
$text .= "\n<ul class='unlist'>\n";
foreach ($discussions as $discussion) {
$discussion->subject = $discussion->name;
$discussion->subject = format_string($discussion->subject, true, $forum->course);
//if (! $post = forum_get_post_full($discussion->discussion)) {
//error("Could not find the first post in this forum");
//}
$post = get_record("forum_posts", "discussion", $discussion->discussion);
$text .= '<li class="post">' . '<div class="head">' . '<div class="info">' . format_text($post->message) . ' ' . '<a href="' . $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $discussion->discussion . '">' . $strmore . '...</a></div>' . "</li>\n";
}
$text .= "</ul>\n";
$text .= '</marquee>';
$this->content->text = $text;
$this->content->footer = '<a href="' . $CFG->wwwroot . '/mod/forum/view.php?f=' . $forum->id . '">' . get_string('olditems', 'block_news_items_scrolling') . '</a> ...';
if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context)) {
$this->content->footer = '<div class="newlink"><a href="' . $CFG->wwwroot . '/mod/forum/post.php?forum=' . $forum->id . '">' . get_string('addanewitem', 'block_news_items_scrolling') . '</a>...</div>';
}
/// If RSS is 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 && $forum->rssarticles) {
require_once $CFG->dirroot . '/lib/rsslib.php';
// We'll need this
if ($forum->rsstype == 1) {
$tooltiptext = get_string('rsssubscriberssdiscussions', 'forum', format_string($forum->name));
} else {
$tooltiptext = get_string('rsssubscriberssposts', 'forum', format_string($forum->name));
}
if (empty($USER->id)) {
$userid = 0;
} else {
$userid = $USER->id;
}
$this->content->footer .= '<br />' . rss_get_link($COURSE->id, $userid, 'forum', $forum->id, $tooltiptext);
}
}
return $this->content;
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:79,代码来源:block_news_items_scrolling.php
示例13: offline_get_dynamic_files
/**
* Retrieve all dynamic files
*
* @return string[] The array of dynamic files
*/
function offline_get_dynamic_files()
{
global $CFG, $COURSE, $USER, $DB;
require_once $CFG->dirroot . '/course/lib.php';
// Include homepage and accessible course pages
$files = array('.', $CFG->wwwroot . '/', $CFG->wwwroot . '/index.php', $CFG->wwwroot . '/lib/offline/go_offline.js', $CFG->wwwroot . '/user/editadvanced.
|
请发表评论