本文整理汇总了PHP中forum_tp_stop_tracking函数的典型用法代码示例。如果您正苦于以下问题:PHP forum_tp_stop_tracking函数的具体用法?PHP forum_tp_stop_tracking怎么用?PHP forum_tp_stop_tracking使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了forum_tp_stop_tracking函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_forum_tp_get_untracked_forums
/**
* Test the logic in the test_forum_tp_get_untracked_forums() function.
*/
public function test_forum_tp_get_untracked_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;
// On user with force on.
$result = forum_tp_get_untracked_forums($useron->id, $course->id);
$this->assertEquals(1, count($result));
$this->assertEquals(true, isset($result[$forumoff->id]));
// Off user with force on.
$result = forum_tp_get_untracked_forums($useroff->id, $course->id);
$this->assertEquals(2, count($result));
$this->assertEquals(true, isset($result[$forumoff->id]));
$this->assertEquals(true, isset($result[$forumoptional->id]));
// Don't allow force.
$CFG->forum_allowforcedreadtracking = 0;
// On user with force off.
$result = forum_tp_get_untracked_forums($useron->id, $course->id);
$this->assertEquals(1, count($result));
$this->assertEquals(true, isset($result[$forumoff->id]));
// Off user with force off.
$result = forum_tp_get_untracked_forums($useroff->id, $course->id);
$this->assertEquals(3, count($result));
$this->assertEquals(true, isset($result[$forumoff->id]));
$this->assertEquals(true, isset($result[$forumoptional->id]));
$this->assertEquals(true, isset($result[$forumforce->id]));
// Stop tracking so we can test again.
forum_tp_stop_tracking($forumforce->id, $useron->id);
forum_tp_stop_tracking($forumoptional->id, $useron->id);
forum_tp_stop_tracking($forumforce->id, $useroff->id);
forum_tp_stop_tracking($forumoptional->id, $useroff->id);
// Allow force.
$CFG->forum_allowforcedreadtracking = 1;
// On user with force on.
$result = forum_tp_get_untracked_forums($useron->id, $course->id);
$this->assertEquals(2, count($result));
$this->assertEquals(true, isset($result[$forumoff->id]));
$this->assertEquals(true, isset($result[$forumoptional->id]));
// Off user with force on.
$result = forum_tp_get_untracked_forums($useroff->id, $course->id);
$this->assertEquals(2, count($result));
$this->assertEquals(true, isset($result[$forumoff->id]));
$this->assertEquals(true, isset($result[$forumoptional->id]));
// Don't allow force.
$CFG->forum_allowforcedreadtracking = 0;
// On user with force off.
$result = forum_tp_get_untracked_forums($useron->id, $course->id);
$this->assertEquals(3, count($result));
$this->assertEquals(true, isset($result[$forumoff->id]));
$this->assertEquals(true, isset($result[$forumoptional->id]));
$this->assertEquals(true, isset($result[$forumforce->id]));
// Off user with force off.
$result = forum_tp_get_untracked_forums($useroff->id, $course->id);
$this->assertEquals(3, count($result));
$this->assertEquals(true, isset($result[$forumoff->id]));
$this->assertEquals(true, isset($result[$forumoptional->id]));
$this->assertEquals(true, isset($result[$forumforce->id]));
}
示例2: print_error
}
if (!($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id))) {
print_error('invalidcoursemodule');
}
require_login($course, false, $cm);
$returnpageurl = new moodle_url('/mod/forum/' . $returnpage, array('id' => $course->id, 'f' => $forum->id));
$returnto = forum_go_back_to($returnpageurl);
if (!forum_tp_can_track_forums($forum)) {
redirect($returnto);
}
$info = new stdClass();
$info->name = fullname($USER);
$info->forum = format_string($forum->name);
$eventparams = array('context' => context_module::instance($cm->id), 'relateduserid' => $USER->id, 'other' => array('forumid' => $forum->id));
if (forum_tp_is_tracked($forum)) {
if (forum_tp_stop_tracking($forum->id)) {
$event = \mod_forum\event\readtracking_disabled::create($eventparams);
$event->trigger();
redirect($returnto, get_string("nownottracking", "forum", $info), 1);
} else {
print_error('cannottrack', '', get_local_referer(false));
}
} else {
// subscribe
if (forum_tp_start_tracking($forum->id)) {
$event = \mod_forum\event\readtracking_enabled::create($eventparams);
$event->trigger();
redirect($returnto, get_string("nowtracking", "forum", $info), 1);
} else {
print_error('cannottrack', '', get_local_referer(false));
}
示例3: test_observers
/**
* Test mod_forum_observer methods.
*/
public function test_observers()
{
global $DB, $CFG;
require_once $CFG->dirroot . '/mod/forum/lib.php';
$forumgen = $this->getDataGenerator()->get_plugin_generator('mod_forum');
$course = $this->getDataGenerator()->create_course();
$trackedrecord = array('course' => $course->id, 'type' => 'general', 'forcesubscribe' => FORUM_INITIALSUBSCRIBE);
$untrackedrecord = array('course' => $course->id, 'type' => 'general');
$trackedforum = $this->getDataGenerator()->create_module('forum', $trackedrecord);
$untrackedforum = $this->getDataGenerator()->create_module('forum', $untrackedrecord);
// Used functions don't require these settings; adding
// them just in case there are APIs changes in future.
$user = $this->getDataGenerator()->create_user(array('maildigest' => 1, 'trackforums' => 1));
$manplugin = enrol_get_plugin('manual');
$manualenrol = $DB->get_record('enrol', array('courseid' => $course->id, 'enrol' => 'manual'));
$student = $DB->get_record('role', array('shortname' => 'student'));
// The role_assign observer does it's job adding the forum_subscriptions record.
$manplugin->enrol_user($manualenrol, $user->id, $student->id);
// They are not required, but in a real environment they are supposed to be required;
// adding them just in case there are APIs changes in future.
set_config('forum_trackingtype', 1);
set_config('forum_trackreadposts', 1);
$record = array();
$record['course'] = $course->id;
$record['forum'] = $trackedforum->id;
$record['userid'] = $user->id;
$discussion = $forumgen->create_discussion($record);
$record = array();
$record['discussion'] = $discussion->id;
$record['userid'] = $user->id;
$post = $forumgen->create_post($record);
forum_tp_add_read_record($user->id, $post->id);
forum_set_user_maildigest($trackedforum, 2, $user);
forum_tp_stop_tracking($untrackedforum->id, $user->id);
$this->assertEquals(1, $DB->count_records('forum_subscriptions'));
$this->assertEquals(1, $DB->count_records('forum_digests'));
$this->assertEquals(1, $DB->count_records('forum_track_prefs'));
$this->assertEquals(1, $DB->count_records('forum_read'));
// The course_module_created observer does it's job adding a subscription.
$forumrecord = array('course' => $course->id, 'type' => 'general', 'forcesubscribe' => FORUM_INITIALSUBSCRIBE);
$extraforum = $this->getDataGenerator()->create_module('forum', $forumrecord);
$this->assertEquals(2, $DB->count_records('forum_subscriptions'));
$manplugin->unenrol_user($manualenrol, $user->id);
$this->assertEquals(0, $DB->count_records('forum_digests'));
$this->assertEquals(0, $DB->count_records('forum_subscriptions'));
$this->assertEquals(0, $DB->count_records('forum_track_prefs'));
$this->assertEquals(0, $DB->count_records('forum_read'));
}