本文整理汇总了PHP中forum_user_can_post_discussion函数的典型用法代码示例。如果您正苦于以下问题:PHP forum_user_can_post_discussion函数的具体用法?PHP forum_user_can_post_discussion怎么用?PHP forum_user_can_post_discussion使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了forum_user_can_post_discussion函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: format_string
}
$PAGE->set_title("{$course->shortname}: {$strdiscussionname} " . format_string($toppost->subject));
$PAGE->set_heading($course->fullname);
// #marginalia begin
$moodlemia = moodle_marginalia::get_instance();
$miaprofile = $moodlemia->get_profile($PAGE->url->out(false));
if ($miaprofile) {
$miaprofile->emit_requires($moodlemia);
}
// #marginalia end
echo $OUTPUT->header();
// 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'));
}
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();
示例2: forum_user_can_post
}
$canreply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $context);
$canrate = has_capability('mod/forum:rate', $context);
$displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode);
echo ' '; // this should fix the floating in FF
forum_print_discussion($course, $cm, $forum, $discussion, $post, $displaymode, $canreply, $canrate);
break;
case 'eachuser':
if (!empty($forum->intro)) {
echo $OUTPUT->box(format_module_intro('forum', $forum, $cm->id), 'generalbox', 'intro');
}
echo '<p class="mdl-align">';
if (forum_user_can_post_discussion($forum, null, -1, $cm)) {
print_string("allowsdiscussions", "forum");
} else {
echo ' ';
}
echo '</p>';
if (!empty($showall)) {
forum_print_latest_discussions($course, $forum, 0, 'header', '', -1, -1, -1, 0, $cm);
} else {
forum_print_latest_discussions($course, $forum, -1, 'header', '', -1, -1, $page, $CFG->forum_manydiscussions, $cm);
}
break;
case 'teacher':
if (!empty($showall)) {
forum_print_latest_discussions($course, $forum, 0, 'header', '', -1, -1, -1, 0, $cm);
示例3: format_string
$navtail = '';
} else {
// Show the discussion name in the breadcrumbs.
$strdiscussionname = format_string($discussion->name) . ':';
}
$forcefocus = empty($reply) ? NULL : 'message';
if ($course->id != SITEID) {
print_header("{$course->shortname}: {$strdiscussionname} " . format_string($toppost->subject), $course->fullname, "<a href=\"../../course/view.php?id={$course->id}\">{$course->shortname}</a> ->\n {$navmiddle} {$navtail}", $mform_post->focus($forcefocus), "", true, "", navmenu($course, $cm));
} else {
print_header("{$course->shortname}: {$strdiscussionname} " . format_string($toppost->subject), $course->fullname, "{$navmiddle} {$navtail}", $mform_post->focus($forcefocus), "", true, "", navmenu($course, $cm));
}
// 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)) {
示例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;
}
示例5: 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;
}
示例6: test_forum_user_can_post_discussion
/**
* Test forum_user_can_post_discussion
*/
public function test_forum_user_can_post_discussion()
{
global $CFG, $DB;
$this->resetAfterTest(true);
// Create course to add the module.
$course = self::getDataGenerator()->create_course(array('groupmode' => SEPARATEGROUPS, 'groupmodeforce' => 1));
$user = self::getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($user->id, $course->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);
$context = context_module::instance($cm->id);
self::setUser($user);
// The user is not enroled in any group, try to post in a forum with separate groups.
$can = forum_user_can_post_discussion($forum, null, -1, $cm, $context);
$this->assertFalse($can);
// Create a group.
$group = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
// Try to post in a group the user is not enrolled.
$can = forum_user_can_post_discussion($forum, $group->id, -1, $cm, $context);
$this->assertFalse($can);
// Add the user to a group.
groups_add_member($group->id, $user->id);
// Try to post in a group the user is not enrolled.
$can = forum_user_can_post_discussion($forum, $group->id + 1, -1, $cm, $context);
$this->assertFalse($can);
// Now try to post in the user group. (null means it will guess the group).
$can = forum_user_can_post_discussion($forum, null, -1, $cm, $context);
$this->assertTrue($can);
$can = forum_user_can_post_discussion($forum, $group->id, -1, $cm, $context);
$this->assertTrue($can);
// Test all groups.
$can = forum_user_can_post_discussion($forum, -1, -1, $cm, $context);
$this->assertFalse($can);
$this->setAdminUser();
$can = forum_user_can_post_discussion($forum, -1, -1, $cm, $context);
$this->assertTrue($can);
// Change forum type.
$forum->type = 'news';
$DB->update_record('forum', $forum);
// Admin can post news.
$can = forum_user_can_post_discussion($forum, null, -1, $cm, $context);
$this->assertTrue($can);
// Normal users don't.
self::setUser($user);
$can = forum_user_can_post_discussion($forum, null, -1, $cm, $context);
$this->assertFalse($can);
// Change forum type.
$forum->type = 'eachuser';
$DB->update_record('forum', $forum);
// I didn't post yet, so I should be able to post.
$can = forum_user_can_post_discussion($forum, null, -1, $cm, $context);
$this->assertTrue($can);
// Post now.
$record = new stdClass();
$record->course = $course->id;
$record->userid = $user->id;
$record->forum = $forum->id;
$discussion = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
// I already posted, I shouldn't be able to post.
$can = forum_user_can_post_discussion($forum, null, -1, $cm, $context);
$this->assertFalse($can);
// Last check with no groups, normal forum and course.
$course->groupmode = NOGROUPS;
$course->groupmodeforce = 0;
$DB->update_record('course', $course);
$forum->type = 'general';
$forum->groupmode = NOGROUPS;
$DB->update_record('forum', $forum);
$can = forum_user_can_post_discussion($forum, null, -1, $cm, $context);
$this->assertTrue($can);
}
示例7: definition
/**
* Form definition
*
* @return void
*/
function definition()
{
global $CFG, $OUTPUT;
$mform =& $this->_form;
$course = $this->_customdata['course'];
$cm = $this->_customdata['cm'];
$coursecontext = $this->_customdata['coursecontext'];
$modcontext = $this->_customdata['modcontext'];
$forum = $this->_customdata['forum'];
$post = $this->_customdata['post'];
$edit = $this->_customdata['edit'];
$thresholdwarning = $this->_customdata['thresholdwarning'];
$mform->addElement('header', 'general', '');
//fill in the data depending on page params later using set_data
// 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 display a warning if they can still post but have reached the warning threshold.
if ($thresholdwarning->canpost) {
$message = get_string($thresholdwarning->errorcode, $thresholdwarning->module, $thresholdwarning->additional);
$mform->addElement('html', $OUTPUT->notification($message));
}
}
$mform->addElement('text', 'subject', get_string('subject', 'forum'), 'size="48"');
$mform->setType('subject', PARAM_TEXT);
$mform->addRule('subject', get_string('required'), 'required', null, 'client');
$mform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addElement('editor', 'message', get_string('message', 'forum'), null, self::editor_options($modcontext, empty($post->id) ? null : $post->id));
$mform->setType('message', PARAM_RAW);
$mform->addRule('message', get_string('required'), 'required', null, 'client');
if (isset($forum->id) && forum_is_forcesubscribed($forum)) {
$mform->addElement('static', 'subscribemessage', get_string('subscription', 'forum'), get_string('everyoneissubscribed', 'forum'));
$mform->addElement('hidden', 'subscribe');
$mform->setType('subscribe', PARAM_INT);
$mform->addHelpButton('subscribemessage', 'subscription', 'forum');
} else {
if (isset($forum->forcesubscribe) && $forum->forcesubscribe != FORUM_DISALLOWSUBSCRIBE || has_capability('moodle/course:manageactivities', $coursecontext)) {
$options = array();
$options[0] = get_string('subscribestop', 'forum');
$options[1] = get_string('subscribestart', 'forum');
$mform->addElement('select', 'subscribe', get_string('subscription', 'forum'), $options);
$mform->addHelpButton('subscribe', 'subscription', 'forum');
} else {
if ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE) {
$mform->addElement('static', 'subscribemessage', get_string('subscription', 'forum'), get_string('disallowsubscribe', 'forum'));
$mform->addElement('hidden', 'subscribe');
$mform->setType('subscribe', PARAM_INT);
$mform->addHelpButton('subscribemessage', 'subscription', 'forum');
}
}
}
if (!empty($forum->maxattachments) && $forum->maxbytes != 1 && has_capability('mod/forum:createattachment', $modcontext)) {
// 1 = No attachments at all
$mform->addElement('filemanager', 'attachments', get_string('attachment', 'forum'), null, self::attachment_options($forum));
$mform->addHelpButton('attachments', 'attachment', 'forum');
}
if (empty($post->id) && has_capability('moodle/course:manageactivities', $coursecontext)) {
// hack alert
$mform->addElement('checkbox', 'mailnow', get_string('mailnow', 'forum'));
}
if (!empty($CFG->forum_enabletimedposts) && !$post->parent && has_capability('mod/forum:viewhiddentimedposts', $coursecontext)) {
// hack alert
$mform->addElement('header', 'displayperiod', get_string('displayperiod', 'forum'));
$mform->addElement('date_selector', 'timestart', get_string('displaystart', 'forum'), array('optional' => true));
$mform->addHelpButton('timestart', 'displaystart', 'forum');
$mform->addElement('date_selector', 'timeend', get_string('displayend', 'forum'), array('optional' => true));
$mform->addHelpButton('timeend', 'displayend', 'forum');
} else {
$mform->addElement('hidden', 'timestart');
$mform->setType('timestart', PARAM_INT);
$mform->addElement('hidden', 'timeend');
$mform->setType('timeend', PARAM_INT);
$mform->setConstants(array('timestart' => 0, 'timeend' => 0));
}
if ($groupmode = groups_get_activity_groupmode($cm, $course)) {
// hack alert
$groupdata = groups_get_activity_allowed_groups($cm);
$groupcount = count($groupdata);
$groupinfo = array();
$modulecontext = context_module::instance($cm->id);
// Check whether the user has access to all groups in this forum from the accessallgroups cap.
if ($groupmode == VISIBLEGROUPS || has_capability('moodle/site:accessallgroups', $modulecontext)) {
// Only allow posting to all groups if the user has access to all groups.
$groupdata[] = (object) array('id' => 0, 'name' => get_string('allparticipants'));
$groupcount++;
}
$contextcheck = has_capability('mod/forum:movediscussions', $modulecontext) && empty($post->parent) && $groupcount > 1;
if ($contextcheck) {
foreach ($groupdata as $grouptemp) {
if (!forum_user_can_post_discussion($forum, $grouptemp->id, -1, $cm, $modcontext)) {
continue;
}
$groupinfo[$grouptemp->id] = $grouptemp->name;
}
}
if (count($groupinfo) > 1) {
//.........这里部分代码省略.........
示例8: can_add_discussion
/**
* Check if the current user can add discussions in the given forum (and optionally for the given group).
*
* @param int $forumid the forum instance id
* @param int $groupid the group to check, default to active group. Use -1 to check if the user can post in all the groups.
* @return array of warnings and the status (true if the user can add discussions)
* @since Moodle 3.1
* @throws moodle_exception
*/
public static function can_add_discussion($forumid, $groupid = null)
{
global $DB, $CFG;
require_once $CFG->dirroot . "/mod/forum/lib.php";
$params = self::validate_parameters(self::can_add_discussion_parameters(), array('forumid' => $forumid, 'groupid' => $groupid));
$warnings = array();
// Request and permission validation.
$forum = $DB->get_record('forum', array('id' => $params['forumid']), '*', MUST_EXIST);
list($course, $cm) = get_course_and_cm_from_instance($forum, 'forum');
$context = context_module::instance($cm->id);
self::validate_context($context);
$status = forum_user_can_post_discussion($forum, $params['groupid'], -1, $cm, $context);
$result = array();
$result['status'] = $status;
$result['warnings'] = $warnings;
return $result;
}
示例9: definition
/**
* Form definition
*
* @return void
*/
function definition()
{
global $CFG, $OUTPUT;
$mform =& $this->_form;
$course = $this->_customdata['course'];
$cm = $this->_customdata['cm'];
$coursecontext = $this->_customdata['coursecontext'];
$modcontext = $this->_customdata['modcontext'];
$forum = $this->_customdata['forum'];
$post = $this->_customdata['post'];
$subscribe = $this->_customdata['subscribe'];
$edit = $this->_customdata['edit'];
$thresholdwarning = $this->_customdata['thresholdwarning'];
$mform->addElement('header', 'general', '');
//fill in the data depending on page params later using set_data
// 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 display a warning if they can still post but have reached the warning threshold.
if ($thresholdwarning->canpost) {
$message = get_string($thresholdwarning->errorcode, $thresholdwarning->module, $thresholdwarning->additional);
$mform->addElement('html', $OUTPUT->notification($message));
}
}
$mform->addElement('text', 'subject', get_string('subject', 'forum'), 'size="48"');
$mform->setType('subject', PARAM_TEXT);
$mform->addRule('subject', get_string('required'), 'required', null, 'client');
$mform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addElement('editor', 'message', get_string('message', 'forum'), null, self::editor_options($modcontext, empty($post->id) ? null : $post->id));
$mform->setType('message', PARAM_RAW);
$mform->addRule('message', get_string('required'), 'required', null, 'client');
$manageactivities = has_capability('moodle/course:manageactivities', $coursecontext);
if (\mod_forum\subscriptions::is_forcesubscribed($forum)) {
$mform->addElement('checkbox', 'discussionsubscribe', get_string('discussionsubscription', 'forum'));
$mform->freeze('discussionsubscribe');
$mform->setDefaults('discussionsubscribe', 0);
$mform->addHelpButton('discussionsubscribe', 'forcesubscribed', 'forum');
} else {
if (\mod_forum\subscriptions::subscription_disabled($forum) && !$manageactivities) {
$mform->addElement('checkbox', 'discussionsubscribe', get_string('discussionsubscription', 'forum'));
$mform->freeze('discussionsubscribe');
$mform->setDefaults('discussionsubscribe', 0);
$mform->addHelpButton('discussionsubscribe', 'disallowsubscription', 'forum');
} else {
$mform->addElement('checkbox', 'discussionsubscribe', get_string('discussionsubscription', 'forum'));
$mform->addHelpButton('discussionsubscribe', 'discussionsubscription', 'forum');
}
}
if (!empty($forum->maxattachments) && $forum->maxbytes != 1 && has_capability('mod/forum:createattachment', $modcontext)) {
// 1 = No attachments at all
$mform->addElement('filemanager', 'attachments', get_string('attachment', 'forum'), null, self::attachment_options($forum));
$mform->addHelpButton('attachments', 'attachment', 'forum');
}
if (empty($post->id) && $manageactivities) {
$mform->addElement('checkbox', 'mailnow', get_string('mailnow', 'forum'));
}
if (!empty($CFG->forum_enabletimedposts) && !$post->parent && has_capability('mod/forum:viewhiddentimedposts', $coursecontext)) {
// hack alert
$mform->addElement('header', 'displayperiod', get_string('displayperiod', 'forum'));
$mform->addElement('date_time_selector', 'timestart', get_string('displaystart', 'forum'), array('optional' => true));
$mform->addHelpButton('timestart', 'displaystart', 'forum');
$mform->addElement('date_time_selector', 'timeend', get_string('displayend', 'forum'), array('optional' => true));
$mform->addHelpButton('timeend', 'displayend', 'forum');
} else {
$mform->addElement('hidden', 'timestart');
$mform->setType('timestart', PARAM_INT);
$mform->addElement('hidden', 'timeend');
$mform->setType('timeend', PARAM_INT);
$mform->setConstants(array('timestart' => 0, 'timeend' => 0));
}
if ($groupmode = groups_get_activity_groupmode($cm, $course)) {
$groupdata = groups_get_activity_allowed_groups($cm);
$groupinfo = array();
foreach ($groupdata as $groupid => $group) {
// Check whether this user can post in this group.
// We must make this check because all groups are returned for a visible grouped activity.
if (forum_user_can_post_discussion($forum, $groupid, null, $cm, $modcontext)) {
// Build the data for the groupinfo select.
$groupinfo[$groupid] = $group->name;
} else {
unset($groupdata[$groupid]);
}
}
$groupcount = count($groupinfo);
// Check whether a user can post to all of their own groups.
// Posts to all of my groups are copied to each group that the user is a member of. Certain conditions must be met.
// 1) It only makes sense to allow this when a user is in more than one group.
// Note: This check must come before we consider adding accessallgroups, because that is not a real group.
$canposttoowngroups = empty($post->edit) && $groupcount > 1;
// 2) Important: You can *only* post to multiple groups for a top level post. Never any reply.
$canposttoowngroups = $canposttoowngroups && empty($post->parent);
// 3) You also need the canposttoowngroups capability.
$canposttoowngroups = $canposttoowngroups && has_capability('mod/forum:canposttomygroups', $modcontext);
if ($canposttoowngroups) {
// This user is in multiple groups, and can post to all of their own groups.
// Note: This is not the same as accessallgroups. This option will copy a post to all groups that a
//.........这里部分代码省略.........
示例10: leaf_frontpage_carrousel
public function leaf_frontpage_carrousel($device)
{
global $COURSE, $CFG;
if (isloggedin() && !is_siteadmin() && $COURSE->id != 1) {
return '';
}
if (!($this->page->bodyid == 'page-login-index' || $this->page->bodyid == 'page-my-index')) {
return '';
}
require_once $CFG->dirroot . '/mod/forum/lib.php';
// We'll need this
$content = '';
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];
if (!$cm->uservisible) {
return '';
}
$context = context_module::instance($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);
if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm)) {
$link = '<li><a href="' . $CFG->wwwroot . '/mod/forum/post.php?forum=' . $forum->id . '">' . get_string('addsitenews', 'theme_leaf') . '</a></li>';
return $link;
}
if (!($discussions = leaf_forum_get_discussions($cm, 'p.modified DESC', true, $currentgroup, $COURSE->newsitems))) {
return '';
}
$strftimerecent = get_string('strftimerecent');
$indicators = '';
$carousel_items = '';
$extra = 'active ';
$count = 0;
$prev = html_writer::link('#myCarousel' . $device, "‹", array('class' => 'carousel-control left', 'data-slide' => 'prev'));
$next = html_writer::link('#myCarousel' . $device, "›", array('class' => 'carousel-control right', 'data-slide' => 'next'));
foreach ($discussions as $discussion) {
$strmore = get_string('read_more', 'theme_leaf');
if (isset($discussion->message)) {
if (strlen(strip_tags($discussion->message)) > 400) {
$message = substr(strip_tags($discussion->message), 0, 400) . '..';
} else {
$message = $discussion->message;
$strmore = '';
}
} else {
$message = '';
}
$discussion->subject = format_string($discussion->subject, true, $forum->course);
$carousel_items .= '<div class="' . $extra . 'item forumpost ">' . '<div class="head clearfix">' . '<div class="info"><h2>' . get_string('sitenews', 'theme_leaf') . '</h2></div>' . '<h3>' . $discussion->subject . '</h3>' . userdate($discussion->modified, $strftimerecent) . '
</div><br>' . '<div class="message">' . $message . ' </div>' . '<div class="readmore"><a href="' . $CFG->wwwroot . '/theme/leaf/layout/index.php?d=' . $discussion->discussion . '">' . $strmore . '</a></div>' . "</div>\n";
$extra = '';
}
// Carrousel markup
$content .= html_writer::start_tag('div', array('class' => 'sitenews' . $device));
$content .= html_writer::start_tag('div', array('id' => 'myCarousel' . $device, 'class' => 'carousel slide'));
$content .= html_writer::start_tag('div', array('class' => 'carousel-inner'));
$content .= '<div class="newscontrols">' . $next . $prev . '</div>';
$content .= $carousel_items;
$content .= html_writer::end_tag('div');
$content .= html_writer::end_tag('div');
$content .= html_writer::end_tag('div');
return $content;
}
示例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>";
}
//.........这里部分代码省略.........
示例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;
}
示例13: forum_print_latest_discussions
/**
* Prints the discussion view screen for a forum.
*
* @global object
* @global object
* @param object $course The current course object.
* @param object $forum Forum to be printed.
* @param int $maxdiscussions .
* @param string $displayformat The display format to use (optional).
* @param string $sort Sort arguments for database query (optional).
* @param int $groupmode Group mode of the forum (optional).
* @param void $unused (originally current group)
* @param int $page Page mode, page to display (optional).
* @param int $perpage The maximum number of discussions per page(optional)
*
*/
function forum_print_latest_discussions($course, $forum, $maxdiscussions=-1, $displayformat='plain', $sort='',
$currentgroup=-1, $groupmode=-1, $page=-1, $perpage=100, $cm=NULL) {
global $CFG, $USER, $OUTPUT;
if (!$cm) {
if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course)) {
print_error('invalidcoursemodule');
}
}
$context = context_module::instance($cm->id);
if (empty($sort)) {
$sort = "d.timemodified DESC";
}
$olddiscussionlink = false;
// Sort out some defaults
if ($perpage <= 0) {
$perpage = 0;
$page = -1;
}
if ($maxdiscussions == 0) {
// all discussions - backwards compatibility
$page = -1;
$perpage = 0;
if ($displayformat == 'plain') {
$displayformat = 'header'; // Abbreviate display by default
}
} else if ($maxdiscussions > 0) {
$page = -1;
$perpage = $maxdiscussions;
}
$fullpost = false;
if ($displayformat == 'plain') {
$fullpost = true;
}
// Decide if current user is allowed to see ALL the current discussions or not
// First check the group stuff
if ($currentgroup == -1 or $groupmode == -1) {
$groupmode = groups_get_activity_groupmode($cm, $course);
$currentgroup = groups_get_activity_group($cm);
}
$groups = array(); //cache
// If the user can post discussions, then this is a good place to put the
// button for it. We do not show the button if we are showing site news
// and the current user is a guest.
$canstart = forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context);
if (!$canstart and $forum->type !== 'news') {
if (isguestuser() or !isloggedin()) {
$canstart = true;
}
if (!is_enrolled($context) and !is_viewing($context)) {
// allow guests and not-logged-in to see the button - they are prompted to log in after clicking the link
// normal users with temporary guest access see this button too, they are asked to enrol instead
// do not show the button to users with suspended enrolments here
$canstart = enrol_selfenrol_available($course->id);
}
}
if ($canstart) {
echo '<div class="singlebutton forumaddnew">';
echo "<form id=\"newdiscussionform\" method=\"get\" action=\"$CFG->wwwroot/mod/forum/post.php\">";
echo '<div>';
echo "<input type=\"hidden\" name=\"forum\" value=\"$forum->id\" />";
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');
//.........这里部分代码省略.........
示例14: add_discussion
/**
* Add a new discussion into an existing forum.
*
* @param int $forumid the forum instance id
* @param string $subject new discussion subject
* @param string $message new discussion message (only html format allowed)
* @param int $groupid the user course group
* @param array $options optional settings
* @return array of warnings and the new discussion id
* @since Moodle 3.0
* @throws moodle_exception
*/
public static function add_discussion($forumid, $subject, $message, $groupid = -1, $options = array()) {
global $DB, $CFG;
require_once($CFG->dirroot . "/mod/forum/lib.php");
$params = self::validate_parameters(self::add_discussion_parameters(),
array(
'forumid' => $forumid,
'subject' => $subject,
'message' => $message,
'groupid' => $groupid,
'options' => $options
));
// Validate options.
$options = array(
'discussionsubscribe' => true
);
foreach ($params['options'] as $option) {
$name = trim($option['name']);
switch ($name) {
case 'discussionsubscribe':
$value = clean_param($option['value'], PARAM_BOOL);
break;
default:
throw new moodle_exception('errorinvalidparam', 'webservice', '', $name);
}
$options[$name] = $value;
}
$warnings = array();
// Request and permission validation.
$forum = $DB->get_record('forum', array('id' => $params['forumid']), '*', MUST_EXIST);
list($course, $cm) = get_course_and_cm_from_instance($forum, 'forum');
$context = context_module::instance($cm->id);
self::validate_context($context);
// Normalize group.
if (!groups_get_activity_groupmode($cm)) {
// Groups not supported, force to -1.
$groupid = -1;
} else {
// Check if we receive the default or and empty value for groupid,
// in this case, get the group for the user in the activity.
if ($groupid === -1 or empty($params['groupid'])) {
$groupid = groups_get_activity_group($cm);
} else {
// Here we rely in the group passed, forum_user_can_post_discussion will validate the group.
$groupid = $params['groupid'];
}
}
if (!forum_user_can_post_discussion($forum, $groupid, -1, $cm, $context)) {
throw new moodle_exception('cannotcreatediscussion', 'forum');
}
$thresholdwarning = forum_check_throttling($forum, $cm);
forum_check_blocking_threshold($thresholdwarning);
// Create the discussion.
$discussion = new stdClass();
$discussion->course = $course->id;
$discussion->forum = $forum->id;
$discussion->message = $params['message'];
$discussion->messageformat = FORMAT_HTML; // Force formatting for now.
$discussion->messagetrust = trusttext_trusted($context);
$discussion->itemid = 0;
$discussion->groupid = $groupid;
$discussion->mailnow = 0;
$discussion->subject = $params['subject'];
$discussion->name = $discussion->subject;
$discussion->timestart = 0;
$discussion->timeend = 0;
if ($discussionid = forum_add_discussion($discussion)) {
$discussion->id = $discussionid;
// Trigger events and completion.
$params = array(
'context' => $context,
'objectid' => $discussion->id,
'other' => array(
'forumid' => $forum->id,
)
);
$event = \mod_forum\event\discussion_created::create($params);
//.........这里部分代码省略.........
示例15: forum_print_latest_discussions
/**
* Prints the discussion view screen for a forum.
*
* @param object $course The current course object.
* @param object $forum Forum to be printed.
* @param int $maxdiscussions .
* @param string $displayformat The display format to use (optional).
* @param string $sort Sort arguments for database query (optional).
* @param int $groupmode Group mode of the forum (optional).
* @param void $unused (originally current group)
* @param int $page Page mode, page to display (optional).
* @param int perpage The maximum number of discussions per page(optional)
*
*/
function forum_print_latest_discussions($course, $forum, $maxdiscussions = -1, $displayformat = 'plain', $sort = '', $currentgroup = -1, $groupmode = -1, $page = -1, $perpage = 100, $cm = NULL)
{
global $CFG, $USER;
if (!$cm) {
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($sort)) {
$sort = "d.timemodified DESC";
}
$olddiscussionlink = false;
// Sort out some defaults
if ($perpage <= 0) {
$perpage = 0;
$page = -1;
}
if ($maxdiscussions == 0) {
// all discussions - backwards compatibility
$page = -1;
$perpage = 0;
if ($displayformat == 'plain') {
$displayformat = 'header';
// Abbreviate display by default
}
} else {
if ($maxdiscussions > 0) {
$page = -1;
$perpage = $maxdiscussions;
}
}
$fullpost = false;
if ($displayformat == 'plain') {
$fullpost = true;
}
// Decide if current user is allowed to see ALL the current discussions or not
// First check the group stuff
if ($currentgroup == -1 or $groupmode == -1) {
$groupmode = groups_get_activity_groupmode($cm, $course);
$currentgroup = groups_get_activity_group($cm);
}
// If the user can post discussions, then this is a good place to put the
// button for it. We do not show the button if we are showing site news
// and the current user is a guest.
// MARCOND: Modificado para não mostrar o botão de inclusão de noticias
// quando mostrando forums pertencentes a front page
if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context) || ($forum->type != 'news' and $forum->course != '1' and (isguestuser() or !isloggedin() or has_capability('moodle/legacy:guest', $context, NULL, false)))) {
echo '<div class="singlebutton forumaddnew">';
echo "<form id=\"newdiscussionform\" method=\"get\" action=\"{$CFG->wwwroot}/mod/forum/post.php\">";
echo '<div>';
echo "<input type=\"hidden\" name=\"forum\" value=\"{$forum->id}\" />";
echo '<input type="submit" value="';
echo $forum->type == 'news' ? get_string('addanewtopic', 'forum') : ($forum->type == 'qanda' ? get_string('addanewquestion', 'forum') : get_string('addanewdiscussion', 'forum'));
echo '" />';
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) {
notify(get_string('cannotadddiscussion', 'forum'));
} else {
notify(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";
//.........这里部分代码省略.........