本文整理匯總了PHP中mod_forum\subscriptions::get_unsubscribable_forums方法的典型用法代碼示例。如果您正苦於以下問題:PHP subscriptions::get_unsubscribable_forums方法的具體用法?PHP subscriptions::get_unsubscribable_forums怎麽用?PHP subscriptions::get_unsubscribable_forums使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mod_forum\subscriptions
的用法示例。
在下文中一共展示了subscriptions::get_unsubscribable_forums方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: forum_get_optional_subscribed_forums
/**
* Returns an array of forums that the current user is subscribed to and is allowed to unsubscribe from
*
* @return array An array of unsubscribable forums
* @deprecated since Moodle 2.8 use \mod_forum\subscriptions::get_unsubscribable_forums() instead
*/
function forum_get_optional_subscribed_forums()
{
debugging("forum_get_optional_subscribed_forums() has been deprecated, please use \\mod_forum\\subscriptions::get_unsubscribable_forums() instead.", DEBUG_DEVELOPER);
return \mod_forum\subscriptions::get_unsubscribable_forums();
}
示例2: test_unsubscribable_forums
/**
* Test fetching unsubscribable forums.
*/
public function test_unsubscribable_forums()
{
global $DB;
$this->resetAfterTest(true);
// Create a course, with a forum.
$course = $this->getDataGenerator()->create_course();
// 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);
// Without any subscriptions, there should be nothing returned.
$result = \mod_forum\subscriptions::get_unsubscribable_forums();
$this->assertEquals(0, count($result));
// Create the forums.
$options = array('course' => $course->id, 'forcesubscribe' => FORUM_FORCESUBSCRIBE);
$forceforum = $this->getDataGenerator()->create_module('forum', $options);
$options = array('course' => $course->id, 'forcesubscribe' => FORUM_DISALLOWSUBSCRIBE);
$disallowforum = $this->getDataGenerator()->create_module('forum', $options);
$options = array('course' => $course->id, 'forcesubscribe' => FORUM_CHOOSESUBSCRIBE);
$chooseforum = $this->getDataGenerator()->create_module('forum', $options);
$options = array('course' => $course->id, 'forcesubscribe' => FORUM_INITIALSUBSCRIBE);
$initialforum = $this->getDataGenerator()->create_module('forum', $options);
// At present the user is only subscribed to the initial forum.
$result = \mod_forum\subscriptions::get_unsubscribable_forums();
$this->assertEquals(1, count($result));
// Ensure that the user is enrolled in all of the forums except force subscribed.
\mod_forum\subscriptions::subscribe_user($user->id, $disallowforum);
\mod_forum\subscriptions::subscribe_user($user->id, $chooseforum);
$result = \mod_forum\subscriptions::get_unsubscribable_forums();
$this->assertEquals(3, count($result));
// Hide the forums.
set_coursemodule_visible($forceforum->cmid, 0);
set_coursemodule_visible($disallowforum->cmid, 0);
set_coursemodule_visible($chooseforum->cmid, 0);
set_coursemodule_visible($initialforum->cmid, 0);
$result = \mod_forum\subscriptions::get_unsubscribable_forums();
$this->assertEquals(0, count($result));
// Add the moodle/course:viewhiddenactivities capability to the student user.
$roleids = $DB->get_records_menu('role', null, '', 'shortname, id');
$context = \context_course::instance($course->id);
assign_capability('moodle/course:viewhiddenactivities', CAP_ALLOW, $roleids['student'], $context);
$context->mark_dirty();
// All of the unsubscribable forums should now be listed.
$result = \mod_forum\subscriptions::get_unsubscribable_forums();
$this->assertEquals(3, count($result));
}
示例3: get_string
$strunsubscribeall = get_string('unsubscribeall', 'forum');
$PAGE->navbar->add(get_string('modulename', 'forum'));
$PAGE->navbar->add($strunsubscribeall);
$PAGE->set_title($strunsubscribeall);
$PAGE->set_heading($COURSE->fullname);
echo $OUTPUT->header();
echo $OUTPUT->heading($strunsubscribeall);
if (data_submitted() and $confirm and confirm_sesskey()) {
$forums = \mod_forum\subscriptions::get_unsubscribable_forums();
foreach ($forums as $forum) {
\mod_forum\subscriptions::unsubscribe_user($USER->id, $forum, context_module::instance($forum->cm), true);
}
$DB->set_field('user', 'autosubscribe', 0, array('id' => $USER->id));
echo $OUTPUT->box(get_string('unsubscribealldone', 'forum'));
echo $OUTPUT->continue_button($return);
echo $OUTPUT->footer();
die;
} else {
$a = count(\mod_forum\subscriptions::get_unsubscribable_forums());
if ($a) {
$msg = get_string('unsubscribeallconfirm', 'forum', $a);
echo $OUTPUT->confirm($msg, new moodle_url('unsubscribeall.php', array('confirm' => 1)), $return);
echo $OUTPUT->footer();
die;
} else {
echo $OUTPUT->box(get_string('unsubscribeallempty', 'forum'));
echo $OUTPUT->continue_button($return);
echo $OUTPUT->footer();
die;
}
}