Exemplo n.º 1
0
 /**
  * Test to ensure that event data is being stored correctly.
  */
 public function test_report_downloaded()
 {
     global $USER;
     $this->resetAfterTest();
     // Generate user data.
     $this->setAdminUser();
     $eventdata = array();
     $eventdata['context'] = $this->context;
     $eventdata['courseid'] = $this->course->id;
     $eventdata['other']['content'] = 'choicereportcontentviewed';
     $eventdata['other']['format'] = 'csv';
     $eventdata['other']['choiceid'] = $this->choice->id;
     // This is fired in a page view so we can't run this through a function.
     $event = \mod_choice\event\report_downloaded::create($eventdata);
     // Redirect event.
     $sink = $this->redirectEvents();
     $event->trigger();
     $event = $sink->get_events();
     // Data checking.
     $this->assertCount(1, $event);
     $this->assertInstanceOf('\\mod_choice\\event\\report_downloaded', $event[0]);
     $this->assertEquals($USER->id, $event[0]->userid);
     $this->assertEquals(context_module::instance($this->choice->cmid), $event[0]->get_context());
     $this->assertEquals('csv', $event[0]->other['format']);
     $this->assertEquals($this->choice->id, $event[0]->other['choiceid']);
     $this->assertEventContextNotUsed($event[0]);
     $sink->close();
 }
Exemplo n.º 2
0
    /// Check to see if groups are being used in this choice
    $groupmode = groups_get_activity_groupmode($cm);
    if ($groupmode) {
        groups_get_activity_group($cm, true);
        groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/choice/report.php?id=' . $id);
    }
} else {
    $groupmode = groups_get_activity_groupmode($cm);
    // Trigger the report downloaded event.
    $eventdata = array();
    $eventdata['context'] = $context;
    $eventdata['courseid'] = $course->id;
    $eventdata['other']['content'] = 'choicereportcontentviewed';
    $eventdata['other']['format'] = $download;
    $eventdata['other']['choiceid'] = $choice->id;
    $event = \mod_choice\event\report_downloaded::create($eventdata);
    $event->trigger();
}
// Check if we want to include responses from inactive users.
$onlyactive = $choice->includeinactive ? false : true;
$users = choice_get_response_data($choice, $cm, $groupmode, $onlyactive);
if ($download == "ods" && has_capability('mod/choice:downloadresponses', $context)) {
    require_once "{$CFG->libdir}/odslib.class.php";
    /// Calculate file name
    $filename = clean_filename("{$course->shortname} " . strip_tags(format_string($choice->name, true))) . '.ods';
    /// Creating a workbook
    $workbook = new MoodleODSWorkbook("-");
    /// Send HTTP headers
    $workbook->send($filename);
    /// Creating the first worksheet
    $myxls = $workbook->add_worksheet($strresponses);