1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* This page prints a particular instance of questionnaire.
|
|
|
19 |
*
|
|
|
20 |
* @package mod_questionnaire
|
|
|
21 |
* @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org)
|
|
|
22 |
* @author Mike Churchward
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*
|
|
|
25 |
*/
|
|
|
26 |
require_once("../../config.php");
|
|
|
27 |
require_once($CFG->libdir . '/completionlib.php');
|
|
|
28 |
require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php');
|
|
|
29 |
|
|
|
30 |
if (!isset($SESSION->questionnaire)) {
|
|
|
31 |
$SESSION->questionnaire = new stdClass();
|
|
|
32 |
}
|
|
|
33 |
$SESSION->questionnaire->current_tab = 'view';
|
|
|
34 |
|
|
|
35 |
$id = optional_param('id', null, PARAM_INT); // Course Module ID.
|
|
|
36 |
$a = optional_param('a', null, PARAM_INT); // Questionnaire ID.
|
|
|
37 |
|
|
|
38 |
$sid = optional_param('sid', null, PARAM_INT); // Survey id.
|
|
|
39 |
$resume = optional_param('resume', null, PARAM_INT); // Is this attempt a resume of a saved attempt?
|
|
|
40 |
|
|
|
41 |
list($cm, $course, $questionnaire) = questionnaire_get_standard_page_items($id, $a);
|
|
|
42 |
|
|
|
43 |
// Check login and get context.
|
|
|
44 |
require_course_login($course, true, $cm);
|
|
|
45 |
$context = context_module::instance($cm->id);
|
|
|
46 |
require_capability('mod/questionnaire:view', $context);
|
|
|
47 |
|
|
|
48 |
$url = new moodle_url($CFG->wwwroot.'/mod/questionnaire/complete.php');
|
|
|
49 |
if (isset($id)) {
|
|
|
50 |
$url->param('id', $id);
|
|
|
51 |
} else {
|
|
|
52 |
$url->param('a', $a);
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
$PAGE->set_url($url);
|
|
|
56 |
$PAGE->set_context($context);
|
|
|
57 |
$questionnaire = new questionnaire( $course, $cm, 0, $questionnaire);
|
|
|
58 |
// Add renderer and page objects to the questionnaire object for display use.
|
|
|
59 |
$questionnaire->add_renderer($PAGE->get_renderer('mod_questionnaire'));
|
|
|
60 |
$questionnaire->add_page(new \mod_questionnaire\output\completepage());
|
|
|
61 |
|
|
|
62 |
$questionnaire->strquestionnaires = get_string("modulenameplural", "questionnaire");
|
|
|
63 |
$questionnaire->strquestionnaire = get_string("modulename", "questionnaire");
|
|
|
64 |
|
|
|
65 |
// Mark as viewed.
|
|
|
66 |
$completion = new completion_info($course);
|
|
|
67 |
$completion->set_module_viewed($cm);
|
|
|
68 |
|
|
|
69 |
if ($resume) {
|
|
|
70 |
$context = context_module::instance($questionnaire->cm->id);
|
|
|
71 |
$anonymous = $questionnaire->respondenttype == 'anonymous';
|
|
|
72 |
|
|
|
73 |
$event = \mod_questionnaire\event\attempt_resumed::create(array(
|
|
|
74 |
'objectid' => $questionnaire->id,
|
|
|
75 |
'anonymous' => $anonymous,
|
|
|
76 |
'context' => $context
|
|
|
77 |
));
|
|
|
78 |
$event->trigger();
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
// Generate the view HTML in the page.
|
|
|
82 |
$questionnaire->view();
|
|
|
83 |
|
|
|
84 |
// Output the page.
|
|
|
85 |
echo $questionnaire->renderer->header();
|
|
|
86 |
echo $questionnaire->renderer->render($questionnaire->page);
|
|
|
87 |
echo $questionnaire->renderer->footer($course);
|