예제 #1
0
     if ($subscribemessage = twf_post_subscription($fromform, $twf, $discussion)) {
         $timemessage = 4;
     }
     if ($twf->type == 'single') {
         // Single discussion twfs are an exception. We show
         // the twf itself since it only has one discussion
         // thread.
         $discussionurl = "view.php?f={$twf->id}";
     } else {
         $discussionurl = "discuss.php?d={$discussion->id}#p{$fromform->id}";
     }
     $params = array('context' => $modcontext, 'objectid' => $fromform->id, 'other' => array('discussionid' => $discussion->id, 'twfid' => $twf->id, 'twftype' => $twf->type));
     if ($realpost->userid !== $USER->id) {
         $params['relateduserid'] = $realpost->userid;
     }
     $event = \mod_twf\event\post_updated::create($params);
     $event->add_record_snapshot('twf_discussions', $discussion);
     $event->trigger();
     redirect(twf_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.
         twf_check_blocking_threshold($thresholdwarning);
         unset($fromform->groupid);
         $message = '';
         $addpost = $fromform;
         $addpost->twf = $twf->id;
         if ($fromform->id = twf_add_new_post($addpost, $mform_post, $message)) {
             $timemessage = 2;
예제 #2
0
 /**
  * Test post_updated event.
  */
 public function test_post_updated_single()
 {
     // Setup test data.
     $course = $this->getDataGenerator()->create_course();
     $twf = $this->getDataGenerator()->create_module('twf', array('course' => $course->id, 'type' => 'single'));
     $user = $this->getDataGenerator()->create_user();
     // Add a discussion.
     $record = array();
     $record['course'] = $course->id;
     $record['twf'] = $twf->id;
     $record['userid'] = $user->id;
     $discussion = $this->getDataGenerator()->get_plugin_generator('mod_twf')->create_discussion($record);
     // Add a post.
     $record = array();
     $record['discussion'] = $discussion->id;
     $record['userid'] = $user->id;
     $post = $this->getDataGenerator()->get_plugin_generator('mod_twf')->create_post($record);
     $context = context_module::instance($twf->cmid);
     $params = array('context' => $context, 'objectid' => $post->id, 'other' => array('discussionid' => $discussion->id, 'twfid' => $twf->id, 'twftype' => $twf->type));
     $event = \mod_twf\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_twf\\event\\post_updated', $event);
     $this->assertEquals($context, $event->get_context());
     $expected = array($course->id, 'twf', 'update post', "view.php?f={$twf->id}#p{$post->id}", $post->id, $twf->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $url = new \moodle_url('/mod/twf/view.php', array('f' => $twf->id));
     $url->set_anchor('p' . $post->id);
     $this->assertEquals($url, $event->get_url());
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
 }