本文整理匯總了PHP中mod_forum\subscriptions::get_subscription_mode方法的典型用法代碼示例。如果您正苦於以下問題:PHP subscriptions::get_subscription_mode方法的具體用法?PHP subscriptions::get_subscription_mode怎麽用?PHP subscriptions::get_subscription_mode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mod_forum\subscriptions
的用法示例。
在下文中一共展示了subscriptions::get_subscription_mode方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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 = context_module::instance($PAGE->cm->instance);
}
// for some actions you need to be enrolled, beiing admin is not enough sometimes here
$enrolled = is_enrolled($PAGE->cm->context, $USER, '', false);
$activeenrolled = is_enrolled($PAGE->cm->context, $USER, '', true);
$canmanage = has_capability('mod/forum:managesubscriptions', $PAGE->cm->context);
$subscriptionmode = \mod_forum\subscriptions::get_subscription_mode($forumobject);
$cansubscribe = $activeenrolled && !\mod_forum\subscriptions::is_forcesubscribed($forumobject) && (!\mod_forum\subscriptions::subscription_disabled($forumobject) || $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' => FORUM_CHOOSESUBSCRIBE, 'sesskey' => sesskey())), navigation_node::TYPE_SETTING);
$forceforever = $mode->add(get_string("subscriptionforced", "forum"), new moodle_url('/mod/forum/subscribe.php', array('id' => $forumobject->id, 'mode' => FORUM_FORCESUBSCRIBE, 'sesskey' => sesskey())), navigation_node::TYPE_SETTING);
$forceinitially = $mode->add(get_string("subscriptionauto", "forum"), new moodle_url('/mod/forum/subscribe.php', array('id' => $forumobject->id, 'mode' => FORUM_INITIALSUBSCRIBE, 'sesskey' => sesskey())), navigation_node::TYPE_SETTING);
$disallowchoice = $mode->add(get_string('subscriptiondisabled', 'forum'), new moodle_url('/mod/forum/subscribe.php', array('id' => $forumobject->id, 'mode' => FORUM_DISALLOWSUBSCRIBE, 'sesskey' => sesskey())), 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 ($activeenrolled) {
switch ($subscriptionmode) {
case FORUM_CHOOSESUBSCRIBE:
// 0
$notenode = $forumnode->add(get_string('subscriptionoptional', 'forum'));
break;
case FORUM_FORCESUBSCRIBE:
// 1
$notenode = $forumnode->add(get_string('subscriptionforced', 'forum'));
break;
case FORUM_INITIALSUBSCRIBE:
// 2
$notenode = $forumnode->add(get_string('subscriptionauto', 'forum'));
break;
case FORUM_DISALLOWSUBSCRIBE:
// 3
$notenode = $forumnode->add(get_string('subscriptiondisabled', 'forum'));
break;
}
}
}
if ($cansubscribe) {
if (\mod_forum\subscriptions::is_subscribed($USER->id, $forumobject)) {
$linktext = get_string('unsubscribe', 'forum');
} else {
$linktext = get_string('subscribe', 'forum');
}
$url = new moodle_url('/mod/forum/subscribe.php', array('id' => $forumobject->id, 'sesskey' => sesskey()));
$forumnode->add($linktext, $url, navigation_node::TYPE_SETTING);
}
if (has_capability('mod/forum:viewsubscribers', $PAGE->cm->context)) {
$url = new moodle_url('/mod/forum/subscribers.php', array('id' => $forumobject->id));
$forumnode->add(get_string('showsubscribers', 'forum'), $url, navigation_node::TYPE_SETTING);
}
if ($enrolled && forum_tp_can_track_forums($forumobject)) {
// keep tracking info for users with suspended enrolments
if ($forumobject->trackingtype == FORUM_TRACKING_OPTIONAL || !$CFG->forum_allowforcedreadtracking && $forumobject->trackingtype == FORUM_TRACKING_FORCED) {
if (forum_tp_is_tracked($forumobject)) {
$linktext = get_string('notrackforum', 'forum');
} else {
$linktext = get_string('trackforum', 'forum');
}
$url = new moodle_url('/mod/forum/settracking.php', array('id' => $forumobject->id));
$forumnode->add($linktext, $url, navigation_node::TYPE_SETTING);
}
}
if (!isloggedin() && $PAGE->course->id == SITEID) {
$userid = guest_user()->id;
} else {
$userid = $USER->id;
}
$hascourseaccess = $PAGE->course->id == SITEID || can_access_course($PAGE->course, $userid);
//.........這裏部分代碼省略.........
示例2: forum_get_forcesubscribed
/**
* Get the current subscription mode for the forum.
*
* @param int|stdClass $forumid
* @param mixed $value
* @return bool
* @deprecated since Moodle 2.8 use \mod_forum\subscriptions::get_subscription_mode() instead
*/
function forum_get_forcesubscribed($forum)
{
debugging("forum_get_forcesubscribed() has been deprecated, please use \\mod_forum\\subscriptions::get_subscription_mode() instead.", DEBUG_DEVELOPER);
global $DB;
if (!isset($forum->forcesubscribe)) {
$forum = $DB->get_field('forum', 'forcesubscribe', array('id' => $forum));
}
return \mod_forum\subscriptions::get_subscription_mode($forumid, $value);
}
示例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: 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);
// Create a user enrolled in the course as a student.
list($user) = $this->helper_create_users($course, 1);
// Must be logged in as the current user.
$this->setUser($user);
\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));
}