本文整理匯總了PHP中mod_forum\subscriptions::is_subscribable方法的典型用法代碼示例。如果您正苦於以下問題:PHP subscriptions::is_subscribable方法的具體用法?PHP subscriptions::is_subscribable怎麽用?PHP subscriptions::is_subscribable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mod_forum\subscriptions
的用法示例。
在下文中一共展示了subscriptions::is_subscribable方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: forum_print_latest_discussions
//.........這裏部分代碼省略.........
// 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 (has_capability('mod/forum:viewdiscussion', $context)) {
if (\mod_forum\subscriptions::is_subscribable($forum)) {
echo '<th class="header discussionsubscription" scope="col"> </th>';
}
}
echo '</tr>';
echo '</thead>';
echo '<tbody>';
}
foreach ($discussions as $discussion) {
if ($forum->type == 'qanda' && !has_capability('mod/forum:viewqandawithoutposting', $context) && !forum_user_has_posted($forum->id, $discussion->discussion, $USER->id)) {
$canviewparticipants = false;
}
if (!empty($replies[$discussion->discussion])) {
$discussion->replies = $replies[$discussion->discussion]->replies;
$discussion->lastpostid = $replies[$discussion->discussion]->lastpostid;
} else {
$discussion->replies = 0;
}
// SPECIAL CASE: The front page can display a news item post to non-logged in users.
// All posts are read in this case.
if (!$forumtracked) {
$discussion->unread = '-';
} else {
if (empty($USER)) {
$discussion->unread = 0;
} else {
if (empty($unreads[$discussion->discussion])) {
$discussion->unread = 0;
} else {
$discussion->unread = $unreads[$discussion->discussion];
}
}
}
示例2: foreach
}
// Can proceed now, the user is not guest and is enrolled
foreach ($modinfo->get_instances_of('forum') as $forumid => $cm) {
$forum = $forums[$forumid];
$modcontext = context_module::instance($cm->id);
$cansub = false;
if (has_capability('mod/forum:viewdiscussion', $modcontext)) {
$cansub = true;
}
if ($cansub && $cm->visible == 0 && !has_capability('mod/forum:managesubscriptions', $modcontext)) {
$cansub = false;
}
if (!\mod_forum\subscriptions::is_forcesubscribed($forum)) {
$subscribed = \mod_forum\subscriptions::is_subscribed($USER->id, $forum, null, $cm);
$canmanageactivities = has_capability('moodle/course:manageactivities', $coursecontext, $USER->id);
if (($canmanageactivities || \mod_forum\subscriptions::is_subscribable($forum)) && $subscribe && !$subscribed && $cansub) {
\mod_forum\subscriptions::subscribe_user($USER->id, $forum, $modcontext, true);
} else {
if (!$subscribe && $subscribed) {
\mod_forum\subscriptions::unsubscribe_user($USER->id, $forum, $modcontext, true);
}
}
}
}
$returnto = forum_go_back_to("index.php?id={$course->id}");
$shortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
if ($subscribe) {
redirect($returnto, get_string('nowallsubscribed', 'forum', $shortname), 1);
} else {
redirect($returnto, get_string('nowallunsubscribed', 'forum', $shortname), 1);
}
示例3: test_subscription_modes
public function test_subscription_modes()
{
global $DB;
$this->resetAfterTest(true);
// Create a course, with a forum.
$course = $this->getDataGenerator()->create_course();
$options = array('course' => $course->id);
$forum = $this->getDataGenerator()->create_module('forum', $options);
\mod_forum\subscriptions::set_subscription_mode($forum->id, FORUM_FORCESUBSCRIBE);
$forum = $DB->get_record('forum', array('id' => $forum->id));
$this->assertEquals(FORUM_FORCESUBSCRIBE, \mod_forum\subscriptions::get_subscription_mode($forum));
$this->assertTrue(\mod_forum\subscriptions::is_forcesubscribed($forum));
$this->assertFalse(\mod_forum\subscriptions::is_subscribable($forum));
$this->assertFalse(\mod_forum\subscriptions::subscription_disabled($forum));
\mod_forum\subscriptions::set_subscription_mode($forum->id, FORUM_DISALLOWSUBSCRIBE);
$forum = $DB->get_record('forum', array('id' => $forum->id));
$this->assertEquals(FORUM_DISALLOWSUBSCRIBE, \mod_forum\subscriptions::get_subscription_mode($forum));
$this->assertTrue(\mod_forum\subscriptions::subscription_disabled($forum));
$this->assertFalse(\mod_forum\subscriptions::is_subscribable($forum));
$this->assertFalse(\mod_forum\subscriptions::is_forcesubscribed($forum));
\mod_forum\subscriptions::set_subscription_mode($forum->id, FORUM_INITIALSUBSCRIBE);
$forum = $DB->get_record('forum', array('id' => $forum->id));
$this->assertEquals(FORUM_INITIALSUBSCRIBE, \mod_forum\subscriptions::get_subscription_mode($forum));
$this->assertTrue(\mod_forum\subscriptions::is_subscribable($forum));
$this->assertFalse(\mod_forum\subscriptions::subscription_disabled($forum));
$this->assertFalse(\mod_forum\subscriptions::is_forcesubscribed($forum));
\mod_forum\subscriptions::set_subscription_mode($forum->id, FORUM_CHOOSESUBSCRIBE);
$forum = $DB->get_record('forum', array('id' => $forum->id));
$this->assertEquals(FORUM_CHOOSESUBSCRIBE, \mod_forum\subscriptions::get_subscription_mode($forum));
$this->assertTrue(\mod_forum\subscriptions::is_subscribable($forum));
$this->assertFalse(\mod_forum\subscriptions::subscription_disabled($forum));
$this->assertFalse(\mod_forum\subscriptions::is_forcesubscribed($forum));
}
示例4: format_string
$node->display = false;
if ($node && $post->id != $discussion->firstpost) {
$node->add(format_string($post->subject), $PAGE->url);
}
$PAGE->set_title("{$course->shortname}: " . format_string($discussion->name));
$PAGE->set_heading($course->fullname);
$PAGE->set_button($searchform);
$renderer = $PAGE->get_renderer('mod_forum');
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($forum->name), 2);
echo $OUTPUT->heading(format_string($discussion->name), 3, 'discussionname');
// is_guest should be used here as this also checks whether the user is a guest in the current course.
// Guests and visitors cannot subscribe - only enrolled users.
if (!is_guest($modcontext, $USER) && isloggedin() && has_capability('mod/forum:viewdiscussion', $modcontext)) {
// Discussion subscription.
if (\mod_forum\subscriptions::is_subscribable($forum)) {
echo html_writer::div(forum_get_discussion_subscription_icon($forum, $post->discussion, null, true), 'discussionsubscription');
echo forum_get_discussion_subscription_icon_preloaders();
}
}
/// Check to see if groups are being used in this forum
/// If so, make sure the current person is allowed to see this discussion
/// Also, if we know they should be able to reply, then explicitly set $canreply for performance reasons
$canreply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext);
if (!$canreply and $forum->type !== 'news') {
if (isguestuser() or !isloggedin()) {
$canreply = true;
}
if (!is_enrolled($modcontext) and !is_viewing($modcontext)) {
// allow guests and not-logged-in to see the link - they are prompted to log in after clicking the link
// normal users with temporary guest access see this link too, they are asked to enrol instead
示例5: test_is_subscribable_loggedin
/**
* @dataProvider is_subscribable_loggedin_provider
*/
public function test_is_subscribable_loggedin($options, $expect)
{
$this->resetAfterTest(true);
// Create a course, with a forum.
$course = $this->getDataGenerator()->create_course();
$options['course'] = $course->id;
$forum = $this->getDataGenerator()->create_module('forum', $options);
$user = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($user->id, $course->id);
$this->setUser($user);
$this->assertEquals($expect, \mod_forum\subscriptions::is_subscribable($forum));
}
示例6: get_unsubscribediscussionlink
/**
* Get the link to unsubscribe from the discussion.
*
* @return string
*/
public function get_unsubscribediscussionlink()
{
if (!\mod_forum\subscriptions::is_subscribable($this->forum)) {
return null;
}
$link = new \moodle_url('/mod/forum/subscribe.php', array('id' => $this->forum->id, 'd' => $this->discussion->id));
return $link->out(false);
}