/** * Test survey_view * @return void */ public function test_survey_view() { global $CFG; $CFG->enablecompletion = 1; $this->resetAfterTest(); $this->setAdminUser(); // Setup test data. $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); $survey = $this->getDataGenerator()->create_module('survey', array('course' => $course->id), array('completion' => 2, 'completionview' => 1)); $context = context_module::instance($survey->cmid); $cm = get_coursemodule_from_instance('survey', $survey->id); // Trigger and capture the event. $sink = $this->redirectEvents(); survey_view($survey, $course, $cm, $context, 'form'); $events = $sink->get_events(); // 2 additional events thanks to completion. $this->assertCount(3, $events); $event = array_shift($events); // Checking that the event contains the expected values. $this->assertInstanceOf('\\mod_survey\\event\\course_module_viewed', $event); $this->assertEquals($context, $event->get_context()); $moodleurl = new \moodle_url('/mod/survey/view.php', array('id' => $cm->id)); $this->assertEquals($moodleurl, $event->get_url()); $this->assertEquals('form', $event->other['viewed']); $this->assertEventContextNotUsed($event); $this->assertNotEmpty($event->get_name()); // Check completion status. $completion = new completion_info($course); $completiondata = $completion->get_data($cm); $this->assertEquals(1, $completiondata->completionstate); }
$tpl->assign('survey', $umfrage); ob_start(); $tpl->display(DESIGN . '/tpl/survey/overview.html'); $content = ob_get_contents(); ob_end_clean(); main_content(SURVEY, $content, '', 1); } else { table(INFO, NO_ENTRIES_ID); } } $conditions = array('LIMIT' => LIMIT_COMMENTS, 'ORDER' => COMMENTS_ORDER, 'SPAM' => SPAM_SURVEY_COMMENTS, 'section' => 'survey'); if (isset($_GET['action'])) { switch ($_GET['action']) { case 'viewsurvey': if (@$_SESSION['rights']['public']['survey']['com_view'] or @$_SESSION['rights']['superadmin']) { survey_view((int) $_GET['id']); $conditions['action'] = 'add'; $conditions['link'] = '?section=survey&action=viewsurvey&id=' . (int) $_GET['id']; comments_get('survey', (int) $_GET['id'], $conditions); } else { echo table(ACCESS_DENIED, NO_ACCESS_RIGHTS); } break; case 'vote': if (@$_SESSION['rights']['public']['survey']['view'] or @$_SESSION['rights']['superadmin']) { survey_vote((int) $_GET['id']); } else { echo table(ACCESS_DENIED, NO_ACCESS_RIGHTS); } break; case 'addcomment':
$trimmedintro = trim($survey->intro); if (empty($trimmedintro)) { $tempo = $DB->get_field("survey", "intro", array("id" => $survey->template)); $survey->intro = get_string($tempo, "survey"); } if (!($template = $DB->get_record("survey", array("id" => $survey->template)))) { print_error('invalidtmptid', 'survey'); } $showscales = $template->name != 'ciqname'; // Check the survey hasn't already been filled out. $surveyalreadydone = survey_already_done($survey->id, $USER->id); if ($surveyalreadydone) { // Trigger course_module_viewed event and completion. survey_view($survey, $course, $cm, $context, 'graph'); } else { survey_view($survey, $course, $cm, $context, 'form'); } $strsurvey = get_string("modulename", "survey"); $PAGE->set_title($survey->name); $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); echo $OUTPUT->heading($survey->name); // Check to see if groups are being used in this survey. if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used. $currentgroup = groups_get_activity_group($cm); } else { $currentgroup = 0; } $groupingid = $cm->groupingid; if (has_capability('mod/survey:readresponses', $context) or $groupmode == VISIBLEGROUPS) {
/** * Trigger the course module viewed event and update the module completion status. * * @param int $surveyid the survey instance id * @return array of warnings and status result * @since Moodle 3.0 * @throws moodle_exception */ public static function view_survey($surveyid) { global $DB, $USER; $params = self::validate_parameters(self::view_survey_parameters(), array('surveyid' => $surveyid)); $warnings = array(); // Request and permission validation. $survey = $DB->get_record('survey', array('id' => $params['surveyid']), '*', MUST_EXIST); list($course, $cm) = get_course_and_cm_from_instance($survey, 'survey'); $context = context_module::instance($cm->id); self::validate_context($context); require_capability('mod/survey:participate', $context); $viewed = survey_already_done($survey->id, $USER->id) ? 'graph' : 'form'; // Trigger course_module_viewed event and completion. survey_view($survey, $course, $cm, $context, $viewed); $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }