-
Notifications
You must be signed in to change notification settings - Fork 182
/
view.php
147 lines (127 loc) · 5.94 KB
/
view.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This main view page for a questionnaire.
*
* @package mod_questionnaire
* @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org)
* @author Mike Churchward
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
*/
require_once("../../config.php");
require_once($CFG->dirroot.'/mod/questionnaire/locallib.php');
require_once($CFG->libdir . '/completionlib.php');
require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php');
if (!isset($SESSION->questionnaire)) {
$SESSION->questionnaire = new stdClass();
}
$SESSION->questionnaire->current_tab = 'view';
$id = optional_param('id', null, PARAM_INT); // Course Module ID.
$a = optional_param('a', null, PARAM_INT); // Or questionnaire ID.
$sid = optional_param('sid', null, PARAM_INT); // Survey id.
list($cm, $course, $questionnaire) = questionnaire_get_standard_page_items($id, $a);
// Check login and get context.
require_course_login($course, true, $cm);
$context = context_module::instance($cm->id);
$url = new moodle_url($CFG->wwwroot.'/mod/questionnaire/view.php');
if (isset($id)) {
$url->param('id', $id);
} else {
$url->param('a', $a);
}
if (isset($sid)) {
$url->param('sid', $sid);
}
$PAGE->set_url($url);
$PAGE->set_context($context);
$questionnaire = new questionnaire($course, $cm, 0, $questionnaire);
// Add renderer and page objects to the questionnaire object for display use.
$questionnaire->add_renderer($PAGE->get_renderer('mod_questionnaire'));
$questionnaire->add_page(new \mod_questionnaire\output\viewpage());
$PAGE->set_title(format_string($questionnaire->name));
$PAGE->set_heading(format_string($course->fullname));
echo $questionnaire->renderer->header();
// No need to print out intro or name in Moodle 4 and above.
$cm = $questionnaire->cm;
$currentgroupid = groups_get_activity_group($cm);
if (!groups_is_member($currentgroupid, $USER->id)) {
$currentgroupid = 0;
}
$message = $questionnaire->user_access_messages($USER->id);
if ($message !== false) {
$questionnaire->page->add_to_page('message', $message);
} else if ($questionnaire->user_can_take($USER->id)) {
if ($questionnaire->questions) { // Sanity check.
if (!$questionnaire->user_has_saved_response($USER->id)) {
$questionnaire->page->add_to_page('complete',
'<a href="'.$CFG->wwwroot.htmlspecialchars('/mod/questionnaire/complete.php?' .
'id=' . $questionnaire->cm->id) . '" class="btn btn-primary">' .
get_string('answerquestions', 'questionnaire') . '</a>');
} else {
$resumesurvey = get_string('resumesurvey', 'questionnaire');
$questionnaire->page->add_to_page('complete',
'<a href="'.$CFG->wwwroot.htmlspecialchars('/mod/questionnaire/complete.php?' .
'id='.$questionnaire->cm->id.'&resume=1').'" title="'.$resumesurvey.
'" class="btn btn-primary">'.$resumesurvey.'</a>');
}
} else {
$questionnaire->page->add_to_page('message', get_string('noneinuse', 'questionnaire'));
}
}
if ($questionnaire->capabilities->editquestions && !$questionnaire->questions && $questionnaire->is_active()) {
$questionnaire->page->add_to_page('complete',
'<a href="'.$CFG->wwwroot.htmlspecialchars('/mod/questionnaire/questions.php?'.
'id=' . $questionnaire->cm->id) . '" class="btn btn-primary">' .
get_string('addquestions', 'questionnaire') . '</a>');
}
if (isguestuser()) {
$guestno = html_writer::tag('p', get_string('noteligible', 'questionnaire'));
$liketologin = html_writer::tag('p', get_string('liketologin'));
$questionnaire->page->add_to_page('guestuser',
$questionnaire->renderer->confirm($guestno."\n\n".$liketologin."\n", get_login_url(), get_local_referer(false)));
}
// Log this course module view.
// Needed for the event logging.
$context = context_module::instance($questionnaire->cm->id);
$anonymous = $questionnaire->respondenttype == 'anonymous';
$event = \mod_questionnaire\event\course_module_viewed::create(array(
'objectid' => $questionnaire->id,
'anonymous' => $anonymous,
'context' => $context
));
$event->trigger();
$usernumresp = $questionnaire->count_submissions($USER->id);
if ($questionnaire->capabilities->readownresponses && ($usernumresp > 0)) {
$argstr = 'instance='.$questionnaire->id.'&user='.$USER->id;
if ($usernumresp > 1) {
$titletext = get_string('viewyourresponses', 'questionnaire', $usernumresp);
} else {
$titletext = get_string('yourresponse', 'questionnaire');
$argstr .= '&byresponse=1&action=vresp';
}
$questionnaire->page->add_to_page('yourresponse',
'<a href="' .$CFG->wwwroot.htmlspecialchars('/mod/questionnaire/myreport.php?' . $argstr).
'" class="btn btn-primary">' . $titletext . '</a>');
}
if ($questionnaire->can_view_all_responses($usernumresp)) {
$argstr = 'instance='.$questionnaire->id.'&group='.$currentgroupid;
$questionnaire->page->add_to_page('allresponses',
'<a href="'.$CFG->wwwroot.htmlspecialchars('/mod/questionnaire/report.php?'.$argstr).'" class="btn btn-primary">'.
get_string('viewallresponses', 'questionnaire').'</a>');
}
echo $questionnaire->renderer->render($questionnaire->page);
echo $questionnaire->renderer->footer();