コード例 #1
0
ファイル: events_test.php プロジェクト: evltuma/moodle
 /**
  * Test report downloaded event.
  */
 public function test_report_downloaded()
 {
     // There is no proper API to call to generate chapters for a book, so what we are
     // doing here is simply making sure that the events returns the right information.
     $course = $this->getDataGenerator()->create_course();
     $survey = $this->getDataGenerator()->create_module('survey', array('course' => $course->id));
     $params = array('objectid' => $survey->id, 'context' => context_module::instance($survey->cmid), 'courseid' => $course->id, 'other' => array('type' => 'xls'));
     $event = \mod_survey\event\report_downloaded::create($params);
     // Triggering 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_survey\\event\\report_downloaded', $event);
     $this->assertEquals(context_module::instance($survey->cmid), $event->get_context());
     $this->assertEquals($survey->id, $event->objectid);
     $url = new moodle_url('/mod/survey/download.php', array('id' => $survey->cmid, 'type' => 'xls'));
     $expected = array($course->id, "survey", "download", $url->out(), $survey->id, $survey->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $this->assertEventContextNotUsed($event);
 }
コード例 #2
0
ファイル: download.php プロジェクト: evltuma/moodle
$group = optional_param('group', 0, PARAM_INT);
if (!($cm = get_coursemodule_from_id('survey', $id))) {
    print_error('invalidcoursemodule');
}
if (!($course = $DB->get_record("course", array("id" => $cm->course)))) {
    print_error('coursemisconf');
}
$context = context_module::instance($cm->id);
$PAGE->set_url('/mod/survey/download.php', array('id' => $id, 'type' => $type, 'group' => $group));
require_login($course, false, $cm);
require_capability('mod/survey:download', $context);
if (!($survey = $DB->get_record("survey", array("id" => $cm->instance)))) {
    print_error('invalidsurveyid', 'survey');
}
$params = array('objectid' => $survey->id, 'context' => $context, 'courseid' => $course->id, 'other' => array('type' => $type, 'groupid' => $group));
$event = \mod_survey\event\report_downloaded::create($params);
$event->trigger();
/// Check to see if groups are being used in this survey
$groupmode = groups_get_activity_groupmode($cm);
// Groups are being used
if ($groupmode and $group) {
    $users = get_users_by_capability($context, 'mod/survey:participate', '', '', '', '', $group, null, false);
} else {
    $users = get_users_by_capability($context, 'mod/survey:participate', '', '', '', '', '', null, false);
    $group = false;
}
// The order of the questions
$order = explode(",", $survey->questions);
// Get the actual questions from the database
$questions = $DB->get_records_list("survey_questions", "id", $order);
// Get an ordered array of questions