コード例 #1
0
ファイル: events_test.php プロジェクト: Gavinthisisit/Moodle
 /**
  * Test to ensure that event data is being stored correctly.
  */
 public function test_answer_updated()
 {
     // Generate user data.
     $user = $this->getDataGenerator()->create_user();
     // Create the first answer.
     randchoice_user_submit_response(2, $this->randchoice, $user->id, $this->course, $this->cm);
     // Redirect event.
     $sink = $this->redirectEvents();
     // Now choose a different answer.
     randchoice_user_submit_response(3, $this->randchoice, $user->id, $this->course, $this->cm);
     $events = $sink->get_events();
     // Data checking.
     $this->assertCount(1, $events);
     $this->assertInstanceOf('\\mod_randchoice\\event\\answer_updated', $events[0]);
     $this->assertEquals($user->id, $events[0]->userid);
     $this->assertEquals(context_module::instance($this->randchoice->cmid), $events[0]->get_context());
     $this->assertEquals($this->randchoice->id, $events[0]->other['randchoiceid']);
     $this->assertEquals(3, $events[0]->other['optionid']);
     $expected = array($this->course->id, "randchoice", "choose again", 'view.php?id=' . $this->cm->id, $this->randchoice->id, $this->cm->id);
     $this->assertEventLegacyLogData($expected, $events[0]);
     $this->assertEventContextNotUsed($events[0]);
     $sink->close();
 }
コード例 #2
0
ファイル: view.php プロジェクト: Gavinthisisit/Moodle
    $timenow = time();
    if (has_capability('mod/randchoice:deleteresponses', $context) && $action == 'delete') {
        //some responses need to be deleted
        randchoice_delete_responses($attemptids, $randchoice, $cm, $course);
        //delete responses.
        redirect("view.php?id={$cm->id}");
    }
    // Redirection after all POSTs breaks block editing, we need to be more specific!
    if ($randchoice->allowmultiple) {
        $answer = optional_param_array('answer', array(), PARAM_INT);
    } else {
        $answer = optional_param('answer', '', PARAM_INT);
    }
    if ($answer) {
        $answer = rand(1, $answer);
        randchoice_user_submit_response($answer, $randchoice, $USER->id, $course, $cm);
        redirect(new moodle_url('/mod/randchoice/view.php', array('id' => $cm->id, 'notify' => 'randchoicesaved', 'sesskey' => sesskey())));
    } else {
        if (empty($answer) and $action === 'makerandchoice') {
            // We cannot use the 'makerandchoice' alone because there might be some legacy renderers without it,
            // outdated renderers will not get the 'mustchoose' message - bad luck.
            redirect(new moodle_url('/mod/randchoice/view.php', array('id' => $cm->id, 'notify' => 'mustchooseone', 'sesskey' => sesskey())));
        }
    }
}
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($randchoice->name), 2, null);
if ($notify and confirm_sesskey()) {
    if ($notify === 'randchoicesaved') {
        echo $OUTPUT->notification(get_string('randchoicesaved', 'randchoice'), 'notifysuccess');
    } else {