/** * Test mod_twf_observer methods. */ public function test_observers() { global $DB, $CFG; require_once $CFG->dirroot . '/mod/twf/lib.php'; $twfgen = $this->getDataGenerator()->get_plugin_generator('mod_twf'); $course = $this->getDataGenerator()->create_course(); $trackedrecord = array('course' => $course->id, 'type' => 'general', 'forcesubscribe' => FORUM_INITIALSUBSCRIBE); $untrackedrecord = array('course' => $course->id, 'type' => 'general'); $trackedtwf = $this->getDataGenerator()->create_module('twf', $trackedrecord); $untrackedtwf = $this->getDataGenerator()->create_module('twf', $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, 'tracktwfs' => 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 twf_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('twf_trackingtype', 1); set_config('twf_trackreadposts', 1); $record = array(); $record['course'] = $course->id; $record['twf'] = $trackedtwf->id; $record['userid'] = $user->id; $discussion = $twfgen->create_discussion($record); $record = array(); $record['discussion'] = $discussion->id; $record['userid'] = $user->id; $post = $twfgen->create_post($record); twf_tp_add_read_record($user->id, $post->id); twf_set_user_maildigest($trackedtwf, 2, $user); twf_tp_stop_tracking($untrackedtwf->id, $user->id); $this->assertEquals(1, $DB->count_records('twf_subscriptions')); $this->assertEquals(1, $DB->count_records('twf_digests')); $this->assertEquals(1, $DB->count_records('twf_track_prefs')); $this->assertEquals(1, $DB->count_records('twf_read')); // The course_module_created observer does it's job adding a subscription. $twfrecord = array('course' => $course->id, 'type' => 'general', 'forcesubscribe' => FORUM_INITIALSUBSCRIBE); $extratwf = $this->getDataGenerator()->create_module('twf', $twfrecord); $this->assertEquals(2, $DB->count_records('twf_subscriptions')); $manplugin->unenrol_user($manualenrol, $user->id); $this->assertEquals(0, $DB->count_records('twf_digests')); $this->assertEquals(0, $DB->count_records('twf_subscriptions')); $this->assertEquals(0, $DB->count_records('twf_track_prefs')); $this->assertEquals(0, $DB->count_records('twf_read')); }
if ($displaymode == FORUM_MODE_FLATOLDEST or $displaymode == FORUM_MODE_FLATNEWEST) { $displaymode = FORUM_MODE_NESTED; } } else { $parent = $discussion->firstpost; } if (!($post = twf_get_post_full($parent))) { print_error("notexists", 'twf', "{$CFG->wwwroot}/mod/twf/view.php?f={$twf->id}"); } if (!twf_user_can_see_post($twf, $discussion, $post, null, $cm)) { print_error('noviewdiscussionspermission', 'twf', "{$CFG->wwwroot}/mod/twf/view.php?id={$twf->id}"); } if ($mark == 'read' or $mark == 'unread') { if ($CFG->twf_usermarksread && twf_tp_can_track_twfs($twf) && twf_tp_is_tracked($twf)) { if ($mark == 'read') { twf_tp_add_read_record($USER->id, $postid); } else { // unread twf_tp_delete_read_records($USER->id, $postid); } } } $searchform = twf_search_form($course); $twfnode = $PAGE->navigation->find($cm->id, navigation_node::TYPE_ACTIVITY); if (empty($twfnode)) { $twfnode = $PAGE->navbar; } else { $twfnode->make_active(); } $node = $twfnode->add(format_string($discussion->name), new moodle_url('/mod/twf/discuss.php', array('d' => $discussion->id))); $node->display = false;
/** * If its an old post, do nothing. If the record exists, the maintenance will clear it up later. * * @return bool */ function twf_tp_mark_post_read($userid, $post, $twfid) { if (!twf_tp_is_post_old($post)) { return twf_tp_add_read_record($userid, $post->id); } else { return true; } }