示例#1
0
     $newdiscussion->usermodified = $post->userid;
     $newdiscussion->timestart = $discussion->timestart;
     $newdiscussion->timeend = $discussion->timeend;
     $newid = $DB->insert_record('forum_discussions', $newdiscussion);
     $newpost = new stdClass();
     $newpost->id = $post->id;
     $newpost->parent = 0;
     $newpost->subject = $name;
     $DB->update_record("forum_posts", $newpost);
     forum_change_discussionid($post->id, $newid);
     // update last post in each discussion
     forum_discussion_update_last_post($discussion->id);
     forum_discussion_update_last_post($newid);
     // Fire events to reflect the split..
     $params = array('context' => $modcontext, 'objectid' => $discussion->id, 'other' => array('forumid' => $forum->id));
     $event = \mod_forum\event\discussion_updated::create($params);
     $event->trigger();
     $params = array('context' => $modcontext, 'objectid' => $newid, 'other' => array('forumid' => $forum->id));
     $event = \mod_forum\event\discussion_created::create($params);
     $event->trigger();
     $params = array('context' => $modcontext, 'objectid' => $post->id, 'other' => array('discussionid' => $newid, 'forumid' => $forum->id, 'forumtype' => $forum->type));
     $event = \mod_forum\event\post_updated::create($params);
     $event->add_record_snapshot('forum_discussions', $discussion);
     $event->trigger();
     redirect(forum_go_back_to("discuss.php?d={$newid}"));
 } else {
     // User just asked to prune something
     $course = $DB->get_record('course', array('id' => $forum->course));
     $PAGE->set_cm($cm);
     $PAGE->set_context($modcontext);
     $PAGE->navbar->add(format_string($post->subject, true), new moodle_url('/mod/forum/discuss.php', array('d' => $discussion->id)));
示例#2
0
 /**
  * Test discussion_created event.
  */
 public function test_discussion_updated()
 {
     // Setup test data.
     $course = $this->getDataGenerator()->create_course();
     $forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id));
     $user = $this->getDataGenerator()->create_user();
     // Add a discussion.
     $record = array();
     $record['course'] = $course->id;
     $record['forum'] = $forum->id;
     $record['userid'] = $user->id;
     $discussion = $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
     $context = context_module::instance($forum->cmid);
     $params = array('context' => $context, 'objectid' => $discussion->id, 'other' => array('forumid' => $forum->id));
     // Create the event.
     $event = \mod_forum\event\discussion_updated::create($params);
     // Trigger and capturing the event.
     $sink = $this->redirectEvents();
     $event->trigger();
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = reset($events);
     // Check that the event contains the expected values.
     $this->assertInstanceOf('\\mod_forum\\event\\discussion_updated', $event);
     $this->assertEquals($context, $event->get_context());
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
 }