Example #1
0
     if ($subscribemessage = forum_post_subscription($fromform, $forum, $discussion)) {
         $timemessage = 4;
     }
     if ($forum->type == 'single') {
         // Single discussion forums are an exception. We show
         // the forum itself since it only has one discussion
         // thread.
         $discussionurl = "view.php?f={$forum->id}";
     } else {
         $discussionurl = "discuss.php?d={$discussion->id}#p{$fromform->id}";
     }
     $params = array('context' => $modcontext, 'objectid' => $fromform->id, 'other' => array('discussionid' => $discussion->id, 'forumid' => $forum->id, 'forumtype' => $forum->type));
     if ($realpost->userid !== $USER->id) {
         $params['relateduserid'] = $realpost->userid;
     }
     $event = \mod_forum\event\post_updated::create($params);
     $event->add_record_snapshot('forum_discussions', $discussion);
     $event->trigger();
     redirect(forum_go_back_to("{$discussionurl}"), $message . $subscribemessage, $timemessage);
     exit;
 } else {
     if ($fromform->discussion) {
         // Adding a new post to an existing discussion
         // Before we add this we must check that the user will not exceed the blocking threshold.
         forum_check_blocking_threshold($thresholdwarning);
         unset($fromform->groupid);
         $message = '';
         $addpost = $fromform;
         $addpost->forum = $forum->id;
         if ($fromform->id = forum_add_new_post($addpost, $mform_post, $message)) {
             $timemessage = 2;
Example #2
0
 /**
  * Test post_updated event.
  */
 public function test_post_updated_single()
 {
     // Setup test data.
     $course = $this->getDataGenerator()->create_course();
     $forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id, 'type' => 'single'));
     $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);
     // Add a post.
     $record = array();
     $record['discussion'] = $discussion->id;
     $record['userid'] = $user->id;
     $post = $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
     $context = context_module::instance($forum->cmid);
     $params = array('context' => $context, 'objectid' => $post->id, 'other' => array('discussionid' => $discussion->id, 'forumid' => $forum->id, 'forumtype' => $forum->type));
     $event = \mod_forum\event\post_updated::create($params);
     // Trigger and capturing the event.
     $sink = $this->redirectEvents();
     $event->trigger();
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = reset($events);
     // Checking that the event contains the expected values.
     $this->assertInstanceOf('\\mod_forum\\event\\post_updated', $event);
     $this->assertEquals($context, $event->get_context());
     $expected = array($course->id, 'forum', 'update post', "view.php?f={$forum->id}#p{$post->id}", $post->id, $forum->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $url = new \moodle_url('/mod/forum/view.php', array('f' => $forum->id));
     $url->set_anchor('p' . $post->id);
     $this->assertEquals($url, $event->get_url());
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
 }