本文整理汇总了PHP中forum_tp_can_track_forums函数的典型用法代码示例。如果您正苦于以下问题:PHP forum_tp_can_track_forums函数的具体用法?PHP forum_tp_can_track_forums怎么用?PHP forum_tp_can_track_forums使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了forum_tp_can_track_forums函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ss_print_section
/**
* Prints a section full of activity modules
* @Overrides course/lib.php=>print_section
*/
function ss_print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false) {
#print_r($mods);
global $CFG, $USER, $DB, $PAGE, $OUTPUT;
static $initialised;
static $groupbuttons;
static $groupbuttonslink;
static $isediting;
static $ismoving;
static $strmovehere;
static $strmovefull;
static $strunreadpostsone;
static $usetracking;
static $groupings;
if (!isset($initialised)) {
$groupbuttons = ($course->groupmode or (!$course->groupmodeforce));
$groupbuttonslink = (!$course->groupmodeforce);
$isediting = $PAGE->user_is_editing();
$ismoving = $isediting && ismoving($course->id);
if ($ismoving) {
$strmovehere = get_string("movehere");
$strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'"));
}
include_once($CFG->dirroot.'/mod/forum/lib.php');
if ($usetracking = forum_tp_can_track_forums()) {
$strunreadpostsone = get_string('unreadpostsone', 'forum');
}
$initialised = true;
}
$labelformatoptions = new stdClass();
$labelformatoptions->noclean = true;
$labelformatoptions->overflowdiv = true;
/// Casting $course->modinfo to string prevents one notice when the field is null
$modinfo = get_fast_modinfo($course);
$completioninfo = new completion_info($course);
//Accessibility: replace table with list <ul>, but don't output empty list.
if (!empty($section->sequence)) {
// Fix bug #5027, don't want style=\"width:$width\".
echo "<ul class=\"section img-text\">\n";
$sectionmods = explode(",", $section->sequence);
foreach ($sectionmods as $modnumber) {
if (empty($mods[$modnumber])) {
continue;
}
$mod = $mods[$modnumber];
if ($ismoving and $mod->id == $USER->activitycopy) {
// do not display moving mod
continue;
}
if (isset($modinfo->cms[$modnumber])) {
// We can continue (because it will not be displayed at all)
// if:
// 1) The activity is not visible to users
// and
// 2a) The 'showavailability' option is not set (if that is set,
// we need to display the activity so we can show
// availability info)
// or
// 2b) The 'availableinfo' is empty, i.e. the activity was
// hidden in a way that leaves no info, such as using the
// eye icon.
if (!$modinfo->cms[$modnumber]->uservisible &&
(empty($modinfo->cms[$modnumber]->showavailability) ||
empty($modinfo->cms[$modnumber]->availableinfo))) {
// visibility shortcut
continue;
}
} else {
if (!file_exists("$CFG->dirroot/mod/$mod->modname/lib.php")) {
// module not installed
continue;
}
if (!coursemodule_visible_for_user($mod) &&
empty($mod->showavailability)) {
// full visibility check
continue;
}
}
// In some cases the activity is visible to user, but it is
// dimmed. This is done if viewhiddenactivities is true and if:
// 1. the activity is not visible, or
// 2. the activity has dates set which do not include current, or
// 3. the activity has any other conditions set (regardless of whether
// current user meets them)
//.........这里部分代码省略.........
示例2: 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
* @param int $limitfrom limit from SQL data
* @param int $limitnum limit number SQL data
*
* @return array the forum discussion details
* @since Moodle 2.5
*/
public static function get_forum_discussions($forumids, $limitfrom = 0, $limitnum = 0)
{
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, 'limitfrom' => $limitfrom, 'limitnum' => $limitnum));
$forumids = $params['forumids'];
$limitfrom = $params['limitfrom'];
$limitnum = $params['limitnum'];
// 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', '*', $limitfrom, $limitnum)) {
// 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[$discussion->userid]->imagealt;
$return->firstuserpicture = $arrusers[$discussion->userid]->picture;
$return->firstuseremail = $arrusers[$discussion->userid]->email;
$return->subject = $subject;
$return->numunread = '';
if ($cantrack && $forumtracked) {
if (isset($unreads[$discussion->id])) {
$return->numunread = (int) $unreads[$discussion->id];
}
}
//.........这里部分代码省略.........
示例3: 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') {
示例4: print_section_fn
function print_section_fn(&$section, $absolute = false, $width = "100%")
{
/// Prints a section full of activity modules
global $CFG, $USER, $THEME;
static $initialised;
static $groupbuttons;
static $groupbuttonslink;
static $isteacher, $isteacheredit;
static $isediting;
static $ismoving;
static $strmovehere;
static $strmovefull;
static $strunreadpostsone;
$labelformatoptions = new stdClass();
if (!isset($isteacher)) {
$groupbuttons = $this->course->groupmode;
$groupbuttonslink = !$this->course->groupmodeforce;
$isteacher = has_capability('moodle/grade:viewall', $this->context);
$isteacheredit = has_capability('moodle/course:manageactivities', $this->context);
$isediting = isediting($this->course->id);
$ismoving = ismoving($this->course->id);
if ($ismoving) {
$strmovehere = get_string("movehere");
$strmovefull = strip_tags(get_string("movefull", "", "'{$USER->activitycopyname}'"));
}
}
if (!isset($initialised)) {
include_once $CFG->dirroot . '/mod/forum/lib.php';
if ($usetracking = forum_tp_can_track_forums()) {
$strunreadpostsone = get_string('unreadpostsone', 'forum');
}
$initialised = true;
}
// Replace this with language file changes (eventually).
$link_title = array('resource' => 'Lesson', 'choice' => 'Opinion', 'lesson' => 'Reading');
$labelformatoptions->noclean = true;
$modinfo = unserialize($this->course->modinfo);
echo "<table cellpadding=\"1\" cellspacing=\"0\" align=\"center\" width=\"{$width}\">\n";
if (!empty($section->sequence)) {
$sectionmods = explode(",", $section->sequence);
foreach ($sectionmods as $modnumber) {
if (empty($this->mods[$modnumber])) {
continue;
}
$mod = $this->mods[$modnumber];
/// mrc - 20042312 - Begin G8 First Nations School Customization:
/// Added check for 'teacheredit' in order to hide invisible activities from
/// non-editing teachers.
/// if ($mod->visible or $isteacher) {
if ($mod->visible or $isteacheredit) {
/// mrc - 20042312 - End G8 First Nations School Customization:
if (right_to_left()) {
$tdalign = 'right';
} else {
$tdalign = 'left';
}
echo "<tr><td align=\"{$tdalign}\" class=\"activity{$mod->modname}\" width=\"{$width}\">";
if ($ismoving) {
if ($mod->id == $USER->activitycopy) {
continue;
}
echo "<a title=\"{$strmovefull}\"" . " href=\"{$CFG->wwwroot}/course/mod.php?moveto={$mod->id}&sesskey={$USER->sesskey}\">" . "<img height=\"16\" width=\"80\" src=\"{$CFG->pixpath}/movehere.gif\" " . " alt=\"{$strmovehere}\" border=\"0\"></a><br />\n";
}
$instancename = urldecode($modinfo[$modnumber]->name);
if (!empty($CFG->filterall)) {
$instancename = filter_text("<nolink>{$instancename}</nolink>", $this->course->id);
}
if (!empty($modinfo[$modnumber]->extra)) {
$extra = urldecode($modinfo[$modnumber]->extra);
} else {
$extra = "";
}
if (!empty($modinfo[$modnumber]->icon)) {
$icon = "{$CFG->pixpath}/" . urldecode($modinfo[$modnumber]->icon);
} else {
$icon = "{$CFG->modpixpath}/{$mod->modname}/icon.gif";
}
if ($mod->indent) {
print_spacer(12, 20 * $mod->indent, false);
}
// /// If the questionnaire is mandatory
// if (($mod->modname == 'questionnaire') && empty($mandatorypopup)) {
// $mandatorypopup = is_mod_mandatory($mod, $USER->id);
// }
if ($mod->modname == "label") {
if (empty($this->course->usemandatory) || empty($mod->mandatory)) {
if (!$mod->visible) {
echo "<span class=\"dimmed_text\">";
}
echo format_text($extra, FORMAT_HTML, $labelformatoptions);
if (!$mod->visible) {
echo "</span>";
}
} else {
if ($isediting) {
$linkcss = $mod->visible ? "" : " class=\"dimmed\" ";
$alttext = isset($link_title[$mod->modname]) ? $link_title[$mod->modname] : $mod->modfullname;
echo "<img src=\"{$icon}\"" . " height=16 width=16 alt=\"{$alttext}\">" . " <font size=2><a title=\"{$alttext}\" {$linkcss} {$extra}" . " href=\"{$CFG->wwwroot}/mod/{$mod->modname}/view.php?id={$mod->id}\">{$instancename}</a></font>";
}
}
//.........这里部分代码省略.........
示例5: test_forum_tp_can_track_forums
/**
* Test the logic in the forum_tp_can_track_forums() function.
*/
public function test_forum_tp_can_track_forums()
{
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_can_track_forums($forumoff, $useron);
$this->assertEquals(false, $result);
// User on, forum on, should be on.
$result = forum_tp_can_track_forums($forumforce, $useron);
$this->assertEquals(true, $result);
// User on, forum optional, should be on.
$result = forum_tp_can_track_forums($forumoptional, $useron);
$this->assertEquals(true, $result);
// User off, forum off, should be off.
$result = forum_tp_can_track_forums($forumoff, $useroff);
$this->assertEquals(false, $result);
// User off, forum force, should be on.
$result = forum_tp_can_track_forums($forumforce, $useroff);
$this->assertEquals(true, $result);
// User off, forum optional, should be off.
$result = forum_tp_can_track_forums($forumoptional, $useroff);
$this->assertEquals(false, $result);
// Don't allow force.
$CFG->forum_allowforcedreadtracking = 0;
// User on, forum off, should be off.
$result = forum_tp_can_track_forums($forumoff, $useron);
$this->assertEquals(false, $result);
// User on, forum on, should be on.
$result = forum_tp_can_track_forums($forumforce, $useron);
$this->assertEquals(true, $result);
// User on, forum optional, should be on.
$result = forum_tp_can_track_forums($forumoptional, $useron);
$this->assertEquals(true, $result);
// User off, forum off, should be off.
$result = forum_tp_can_track_forums($forumoff, $useroff);
$this->assertEquals(false, $result);
// User off, forum force, should be off.
$result = forum_tp_can_track_forums($forumforce, $useroff);
$this->assertEquals(false, $result);
// User off, forum optional, should be off.
$result = forum_tp_can_track_forums($forumoptional, $useroff);
$this->assertEquals(false, $result);
}
示例6: print_error
if ($parent) {
// If flat AND parent, then force nested display this time
if ($displaymode == FORUM_MODE_FLATOLDEST or $displaymode == FORUM_MODE_FLATNEWEST) {
$displaymode = FORUM_MODE_NESTED;
}
} else {
$parent = $discussion->firstpost;
}
if (!($post = forum_get_post_full($parent))) {
print_error("notexists", 'forum', "{$CFG->wwwroot}/mod/forum/view.php?f={$forum->id}");
}
if (!forum_user_can_see_post($forum, $discussion, $post, null, $cm)) {
print_error('noviewdiscussionspermission', 'forum', "{$CFG->wwwroot}/mod/forum/view.php?id={$forum->id}");
}
if ($mark == 'read' or $mark == 'unread') {
if ($CFG->forum_usermarksread && forum_tp_can_track_forums($forum) && forum_tp_is_tracked($forum)) {
if ($mark == 'read') {
forum_tp_add_read_record($USER->id, $postid);
} else {
// unread
forum_tp_delete_read_records($USER->id, $postid);
}
}
}
$searchform = forum_search_form($course);
$forumnode = $PAGE->navigation->find($cm->id, navigation_node::TYPE_ACTIVITY);
if (empty($forumnode)) {
$forumnode = $PAGE->navbar;
} else {
$forumnode->make_active();
}
示例7: forum_cm_info_view
/**
* Adds information about unread messages, that is only required for the course view page (and
* similar), to the course-module object.
* @param cm_info $cm Course-module object
*/
function forum_cm_info_view(cm_info $cm) {
global $CFG;
// Get tracking status (once per request)
static $initialised;
static $usetracking, $strunreadpostsone;
if (!isset($initialised)) {
if ($usetracking = forum_tp_can_track_forums()) {
$strunreadpostsone = get_string('unreadpostsone', 'forum');
}
$initialised = true;
}
if ($usetracking) {
if ($unread = forum_tp_count_forum_unread_posts($cm, $cm->get_course())) {
$out = '<span class="unread"> <a href="' . $cm->get_url() . '">';
if ($unread == 1) {
$out .= $strunreadpostsone;
} else {
$out .= get_string('unreadpostsnumber', 'forum', $unread);
}
$out .= '</a></span>';
$cm->set_after_link($out);
}
}
}
示例8: forum_tp_is_tracked
/**
* Tells whether a specific forum is tracked by the user. A user can optionally
* be specified. If not specified, the current user is assumed.
*
* @param mixed $forum If int, the id of the forum being checked; if object, the forum object
* @param int $userid The id of the user being checked (optional).
* @return boolean
*/
function forum_tp_is_tracked($forum, $user = false)
{
global $USER, $CFG;
if ($user === false) {
$user = $USER;
}
if (isguestuser($user) or empty($user->id)) {
return false;
}
// Work toward always passing an object...
if (is_numeric($forum)) {
debugging('Better use proper forum object.', DEBUG_DEVELOPER);
$forum = get_record('forum', 'id', $forum);
}
if (!forum_tp_can_track_forums($forum, $user)) {
return false;
}
$forumallows = $forum->trackingtype == FORUM_TRACKING_OPTIONAL;
$forumforced = $forum->trackingtype == FORUM_TRACKING_ON;
return $forumforced || $forumallows && get_record('forum_track_prefs', 'userid', $user->id, 'forumid', $forum->id) === false;
}
示例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;
//.........这里部分代码省略.........
示例10: print_topicstree_section
/**
* Own function to print one section in a tree way
*/
function print_topicstree_section($course, $section, $mods, $modnamesused, $absolute = false, $width = "100%")
{
/// Prints a section full of activity modules
global $CFG, $USER;
static $initialised;
static $groupbuttons;
static $groupbuttonslink;
static $strmovehere;
static $strmovefull;
static $strunreadpostsone;
static $usetracking;
static $groupings;
$spacer = ' ';
if (!isset($initialised)) {
$groupbuttons = ($course->groupmode or !$course->groupmodeforce);
$groupbuttonslink = !$course->groupmodeforce;
include_once $CFG->dirroot . '/mod/forum/lib.php';
if ($usetracking = forum_tp_can_track_forums()) {
$strunreadpostsone = get_string('unreadpostsone', 'forum');
}
$initialised = true;
}
$labelformatoptions = new object();
$labelformatoptions->noclean = true;
/// Casting $course->modinfo to string prevents one notice when the field is null
$modinfo = get_fast_modinfo($course);
//Acccessibility: replace table with list <ul>, but don't output empty list.
if (!empty($section->sequence)) {
$collapsablename = "collapsable-{$course->id}-{$section->id}";
echo '<script type="text/javascript">';
echo "//<![CDATA[\n";
/**
* Can use both:
* call a function: addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
* execute code: addLoadEvent(function() {
* // more code to run on page load
* });
*/
echo "addLoadEvent(function() {";
echo " compactMenu('{$collapsablename}',false,'{$spacer}± ');";
echo " stateToFromStr('{$collapsablename}', retrieveCookie('{$collapsablename}'));";
echo '});';
echo "addUnloadEvent(function() {";
echo " setCookie('{$collapsablename}',stateToFromStr('{$collapsablename}'));";
echo '});';
echo "//]]>\n";
echo '</script>';
// Fix bug #5027, don't want style=\"width:$width\".
echo "<ul id=\"{$collapsablename}\" class=\"section img-text treesection\">\n";
$sectionmods = explode(",", $section->sequence);
/// Preprocess all the mods, adding the necessary stuff to be able to
/// output nested lists later
preprocessmods4topicstree($sectionmods, $mods, $modinfo);
foreach ($sectionmods as $modnumber) {
if (empty($mods[$modnumber])) {
continue;
}
$mod = $mods[$modnumber];
if (isset($modinfo->cms[$modnumber])) {
if (!$modinfo->cms[$modnumber]->uservisible) {
// visibility shortcut
continue;
}
} else {
if (!file_exists("{$CFG->dirroot}/mod/{$mod->modname}/lib.php")) {
// module not installed
continue;
}
if (!coursemodule_visible_for_user($mod)) {
// full visibility check
continue;
}
}
$lastcss = '';
/// Close levels if necessary
if (!empty($mod->closelevel)) {
for ($n = 0; $n < $mod->closelevel; $n++) {
echo '</ul></li>' . "\n";
}
}
if (!empty($mod->islast)) {
$lastcss = 'last ';
}
echo '<li class="activity treeactivity ' . $lastcss . $mod->modname . '" id="module-' . $modnumber . '">';
// Unique ID
/// Add spacer for activities without collapse/expand button
if (empty($mod->openlevel)) {
echo $spacer;
}
$extra = '';
if (!empty($modinfo->cms[$modnumber]->extra)) {
$extra = $modinfo->cms[$modnumber]->extra;
}
if ($mod->modname == "label") {
if (!$mod->visible) {
echo "<span class=\"dimmed_text\">";
}
//.........这里部分代码省略.........
示例11: oc_forum_print_latest_discussions
//.........这里部分代码省略.........
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;
}
}
$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)) {
示例12: forum_extend_settings_navigation
/**
* Adds module specific settings to the settings block
*
* @param settings_navigation $settings The settings navigation object
* @param navigation_node $forumnode The node to add module settings to
*/
function forum_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $forumnode)
{
global $USER, $PAGE, $CFG, $DB, $OUTPUT;
$forumobject = $DB->get_record("forum", array("id" => $PAGE->cm->instance));
if (empty($PAGE->cm->context)) {
$PAGE->cm->context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->instance);
}
// for some actions you need to be enrolled, beiing admin is not enough sometimes here
$enrolled = is_enrolled($PAGE->cm->context);
$canmanage = has_capability('mod/forum:managesubscriptions', $PAGE->cm->context);
$subscriptionmode = forum_get_forcesubscribed($forumobject);
$cansubscribe = $enrolled && $subscriptionmode != FORUM_FORCESUBSCRIBE && ($subscriptionmode != FORUM_DISALLOWSUBSCRIBE || $canmanage);
if ($canmanage) {
$mode = $forumnode->add(get_string('subscriptionmode', 'forum'), null, navigation_node::TYPE_CONTAINER);
$allowchoice = $mode->add(get_string('subscriptionoptional', 'forum'), new moodle_url('/mod/forum/subscribe.php', array('id' => $forumobject->id, 'mode' => '0')), navigation_node::TYPE_SETTING);
$forceforever = $mode->add(get_string("subscriptionforced", "forum"), new moodle_url('/mod/forum/subscribe.php', array('id' => $forumobject->id, 'mode' => '1')), navigation_node::TYPE_SETTING);
$forceinitially = $mode->add(get_string("subscriptionauto", "forum"), new moodle_url('/mod/forum/subscribe.php', array('id' => $forumobject->id, 'mode' => '2')), navigation_node::TYPE_SETTING);
$disallowchoice = $mode->add(get_string('subscriptiondisabled', 'forum'), new moodle_url('/mod/forum/subscribe.php', array('id' => $forumobject->id, 'mode' => '3')), navigation_node::TYPE_SETTING);
switch ($subscriptionmode) {
case FORUM_CHOOSESUBSCRIBE:
// 0
$allowchoice->action = null;
$allowchoice->add_class('activesetting');
break;
case FORUM_FORCESUBSCRIBE:
// 1
$forceforever->action = null;
$forceforever->add_class('activesetting');
break;
case FORUM_INITIALSUBSCRIBE:
// 2
$forceinitially->action = null;
$forceinitially->add_class('activesetting');
break;
case FORUM_DISALLOWSUBSCRIBE:
// 3
$disallowchoice->action = null;
$disallowchoice->add_class('activesetting');
break;
}
} else {
if ($enrolled) {
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 (forum_is_subscribed($USER->id, $forumobject)) {
$linktext = get_string('unsubscribe', 'forum');
} else {
$linktext = get_string('subscribe', 'forum');
}
$url = new moodle_url('/mod/forum/subscribe.php', array('id' => $forumobject->id));
$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)) {
if ($forumobject->trackingtype != FORUM_TRACKING_OPTIONAL) {
//tracking forced on or off in forum settings so dont provide a link here to change it
//could add unclickable text like for forced subscription but not sure this justifies adding another menu item
} else {
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));
$forumnode->add($linktext, $url, navigation_node::TYPE_SETTING);
}
}
if ($enrolled && !empty($CFG->enablerssfeeds) && !empty($CFG->forum_enablerssfeeds) && $forumobject->rsstype && $forumobject->rssarticles) {
if (!function_exists('rss_get_url')) {
require_once "{$CFG->libdir}/rsslib.php";
}
if ($forumobject->rsstype == 1) {
//.........这里部分代码省略.........
示例13: get_string
echo '<span class="helplink">' . get_string("allowsallsubscribe", 'forum') . '</span><br />';
helpbutton("subscription", $strforcesubscribe, "forum");
echo ' ';
if (has_capability('mod/forum:managesubscriptions', $context)) {
echo "<span class=\"helplink\"><a title=\"{$strforcesubscribe}\" href=\"subscribe.php?id={$forum->id}&force=yes\">{$strforcesubscribe}</a></span>";
} else {
echo '<span class="helplink">' . $streveryonecannowchoose . '</span>';
}
if (has_capability('mod/forum:viewsubscribers', $context)) {
echo "<br />";
echo "<span class=\"helplink\"><a href=\"subscribers.php?id={$forum->id}\">{$strshowsubscribers}</a></span>";
}
echo '<div class="helplink" id="subscriptionlink">', forum_get_subscribe_link($forum, $context, array('forcesubscribed' => '', 'cantsubscribe' => '')), '</div>';
}
}
if (forum_tp_can_track_forums($forum)) {
echo '<div class="helplink" id="trackinglink">' . forum_get_tracking_link($forum) . '</div>';
}
}
/// 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 {
$tooltiptext = get_string("rsssubscriberssposts", "forum", format_string($forum->name));
}
if (empty($USER->id)) {
$userid = 0;
} else {
$userid = $USER->id;
}
示例14: print_section_newsroom
function print_section_newsroom($course, $section, $mods, $modnamesused, $absolute = false, $width = "100%")
{
/// Prints a section full of activity modules
global $CFG, $USER;
static $initialised;
static $groupbuttons;
static $groupbuttonslink;
static $isediting;
static $ismoving;
static $strmovehere;
static $strmovefull;
static $strunreadpostsone;
static $usetracking;
static $groupings;
if (!isset($initialised)) {
$groupbuttons = ($course->groupmode or !$course->groupmodeforce);
$groupbuttonslink = !$course->groupmodeforce;
$isediting = isediting($course->id);
$ismoving = $isediting && ismoving($course->id);
if ($ismoving) {
$strmovehere = get_string("movehere");
$strmovefull = strip_tags(get_string("movefull", "", "'{$USER->activitycopyname}'"));
}
include_once $CFG->dirroot . '/mod/forum/lib.php';
if ($usetracking = forum_tp_can_track_forums()) {
$strunreadpostsone = get_string('unreadpostsone', 'forum');
}
$initialised = true;
}
$labelformatoptions = new object();
$labelformatoptions->noclean = true;
/// Casting $course->modinfo to string prevents one notice when the field is null
$modinfo = get_fast_modinfo($course);
//Acccessibility: replace table with list <ul>, but don't output empty list.
if (!empty($section->sequence)) {
// Fix bug #5027, don't want style=\"width:$width\".
echo "<ul class=\"section img-text\">\n";
$sectionmods = explode(",", $section->sequence);
foreach ($sectionmods as $modnumber) {
if (empty($mods[$modnumber])) {
continue;
}
$mod = $mods[$modnumber];
if ($ismoving and $mod->id == $USER->activitycopy) {
// do not display moving mod
continue;
}
if (isset($modinfo->cms[$modnumber])) {
if (!$modinfo->cms[$modnumber]->uservisible) {
// visibility shortcut
continue;
}
} else {
if (!file_exists("{$CFG->dirroot}/mod/{$mod->modname}/lib.php")) {
// module not installed
continue;
}
if (!coursemodule_visible_for_user($mod)) {
// full visibility check
continue;
}
}
// The magic! ... if indent == 1 then ... hide module
if ($mod->indent == 1) {
$hiddemodule = 'hidden';
} else {
$hiddemodule = '';
}
echo '<li class="activity ' . $mod->modname . ' ' . $hiddemodule . '" id="module-' . $modnumber . '">';
// Unique ID
if ($ismoving) {
echo '<a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&sesskey=' . $USER->sesskey . '">' . '<img class="movetarget" src="' . $CFG->pixpath . '/movehere.gif" ' . ' alt="' . $strmovehere . '" /></a><br />
';
}
if ($mod->indent) {
print_spacer(12, 20 * $mod->indent, false);
}
$extra = '';
if (!empty($modinfo->cms[$modnumber]->extra)) {
$extra = $modinfo->cms[$modnumber]->extra;
}
if ($mod->modname == "label") {
echo "<span class=\"";
if (!$mod->visible) {
echo 'dimmed_text';
} else {
echo 'label';
}
echo '">';
echo format_text($extra, FORMAT_HTML, $labelformatoptions);
echo "</span>";
if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
if (!isset($groupings)) {
$groupings = groups_get_all_groupings($course->id);
}
echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>';
}
} else {
// Normal activity
$instancename = format_string($modinfo->cms[$modnumber]->name, true, $course->id);
//.........这里部分代码省略.........
示例15: forum_cm_info_view
/**
* Adds information about unread messages, that is only required for the course view page (and
* similar), to the course-module object.
* @param cm_info $cm Course-module object
*/
function forum_cm_info_view(cm_info $cm)
{
global $CFG;
if (forum_tp_can_track_forums()) {
if ($unread = forum_tp_count_forum_unread_posts($cm, $cm->get_course())) {
$out = '<span class="unread"> <a href="' . $cm->url . '">';
if ($unread == 1) {
$out .= get_string('unreadpostsone', 'forum');
} else {
$out .= get_string('unreadpostsnumber', 'forum', $unread);
}
$out .= '</a></span>';
$cm->set_after_link($out);
}
}
}