Esempio n. 1
0
     $fromform->groupid = -1;
 }
 $fromform->mailnow = empty($fromform->mailnow) ? 0 : 1;
 $fromform->reveal = empty($fromform->reveal) ? 0 : 1;
 $discussion = $fromform;
 $discussion->name = $fromform->subject;
 $newstopic = false;
 if ($forum->type == 'news' && !$fromform->parent) {
     $newstopic = true;
 }
 $discussion->timestart = $fromform->timestart;
 $discussion->timeend = $fromform->timeend;
 $message = '';
 if ($discussion->id = hsuforum_add_discussion($discussion, $mform_post, $message)) {
     $params = array('context' => $modcontext, 'objectid' => $discussion->id, 'other' => array('forumid' => $forum->id));
     $event = \mod_hsuforum\event\discussion_created::create($params);
     $event->add_record_snapshot('hsuforum_discussions', $discussion);
     $event->trigger();
     $timemessage = 2;
     if (!empty($message)) {
         // if we're printing stuff about the file upload
         $timemessage = 4;
     }
     if ($fromform->mailnow) {
         $message .= get_string("postmailnow", "hsuforum");
         $timemessage = 4;
     } else {
         $message .= '<p>' . get_string("postaddedsuccess", "hsuforum") . '</p>';
         $message .= '<p>' . get_string("postaddedtimeleft", "hsuforum", format_time($CFG->maxeditingtime)) . '</p>';
     }
     if ($subscribemessage = hsuforum_post_subscription($discussion, $forum)) {
 /**
  * Log, update completion info and trigger event
  *
  * @param object $course
  * @param \context_module $context
  * @param object $cm
  * @param object $forum
  * @param object $discussion
  */
 public function trigger_discussion_created($course, \context_module $context, $cm, $forum, $discussion)
 {
     global $CFG;
     require_once $CFG->libdir . '/completionlib.php';
     $completion = new \completion_info($course);
     if ($completion->is_enabled($cm) && ($forum->completiondiscussions || $forum->completionposts)) {
         $completion->update_state($cm, COMPLETION_COMPLETE);
     }
     $params = array('context' => $context, 'objectid' => $discussion->id, 'other' => array('forumid' => $forum->id));
     $event = discussion_created::create($params);
     $event->add_record_snapshot('hsuforum_discussions', $discussion);
     $event->trigger();
 }
 /**
  * Test discussion_created event.
  */
 public function test_discussion_created()
 {
     // Setup test data.
     $course = $this->getDataGenerator()->create_course();
     $forum = $this->getDataGenerator()->create_module('hsuforum', 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_hsuforum')->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_hsuforum\event\discussion_created::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_hsuforum\\event\\discussion_created', $event);
     $this->assertEquals($context, $event->get_context());
     $expected = array($course->id, 'hsuforum', 'add discussion', "discuss.php?d={$discussion->id}", $discussion->id, $forum->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
 }