Пример #1
0
 /**
  * Test discussion_created event.
  */
 public function test_discussion_updated()
 {
     // Setup test data.
     $course = $this->getDataGenerator()->create_course();
     $quora = $this->getDataGenerator()->create_module('quora', array('course' => $course->id));
     $user = $this->getDataGenerator()->create_user();
     // Add a discussion.
     $record = array();
     $record['course'] = $course->id;
     $record['quora'] = $quora->id;
     $record['userid'] = $user->id;
     $discussion = $this->getDataGenerator()->get_plugin_generator('mod_quora')->create_discussion($record);
     $context = context_module::instance($quora->cmid);
     $params = array('context' => $context, 'objectid' => $discussion->id, 'other' => array('quoraid' => $quora->id));
     // Create the event.
     $event = \mod_quora\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_quora\\event\\discussion_updated', $event);
     $this->assertEquals($context, $event->get_context());
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
 }
Пример #2
0
     $newdiscussion->usermodified = $post->userid;
     $newdiscussion->timestart = $discussion->timestart;
     $newdiscussion->timeend = $discussion->timeend;
     $newid = $DB->insert_record('quora_discussions', $newdiscussion);
     $newpost = new stdClass();
     $newpost->id = $post->id;
     $newpost->parent = 0;
     $newpost->subject = $name;
     $DB->update_record("quora_posts", $newpost);
     quora_change_discussionid($post->id, $newid);
     // Update last post in each discussion.
     quora_discussion_update_last_post($discussion->id);
     quora_discussion_update_last_post($newid);
     // Fire events to reflect the split..
     $params = array('context' => $modcontext, 'objectid' => $discussion->id, 'other' => array('quoraid' => $quora->id));
     $event = \mod_quora\event\discussion_updated::create($params);
     $event->trigger();
     $params = array('context' => $modcontext, 'objectid' => $newid, 'other' => array('quoraid' => $quora->id));
     $event = \mod_quora\event\discussion_created::create($params);
     $event->trigger();
     $params = array('context' => $modcontext, 'objectid' => $post->id, 'other' => array('discussionid' => $newid, 'quoraid' => $quora->id, 'quoratype' => $quora->type));
     $event = \mod_quora\event\post_updated::create($params);
     $event->add_record_snapshot('quora_discussions', $discussion);
     $event->trigger();
     redirect(quora_go_back_to("discuss.php?d={$newid}"));
 } else {
     // Display the prune form.
     $course = $DB->get_record('course', array('id' => $quora->course));
     $PAGE->navbar->add(format_string($post->subject, true), new moodle_url('/mod/quora/discuss.php', array('d' => $discussion->id)));
     $PAGE->navbar->add(get_string("prune", "quora"));
     $PAGE->set_title(format_string($discussion->name) . ": " . format_string($post->subject));