-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.php
100 lines (86 loc) · 4.05 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
<?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/>.
use mod_feedbackbox\feedbackbox;
use mod_feedbackbox\output\viewpage;
require_once('./../../config.php');
require_once($CFG->dirroot . '/mod/feedbackbox/locallib.php');
require_once($CFG->libdir . '/completionlib.php');
if (!isset($SESSION->feedbackbox)) {
$SESSION->feedbackbox = new stdClass();
}
$id = optional_param('id', null, PARAM_INT); // Course Module ID.
$a = optional_param('a', null, PARAM_INT); // Or feedbackbox ID.
$sid = optional_param('sid', null, PARAM_INT); // Survey id.
[$cm, $course, $feedbackbox] = feedbackbox_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/feedbackbox/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);
$feedbackbox = new feedbackbox(0, $feedbackbox, $course, $cm);
// Add renderer and page objects to the feedbackbox object for display use.
$feedbackbox->add_renderer($PAGE->get_renderer('mod_feedbackbox'));
$feedbackbox->add_page(new viewpage());
$PAGE->set_title(format_string($feedbackbox->name));
$PAGE->set_heading(format_string($course->fullname));
$PAGE->requires->css('/mod/feedbackbox/style/styles.css');
echo $feedbackbox->renderer->header();
$feedbackbox->page->add_to_page('feedbackboxname', format_string($feedbackbox->name));
$message = $feedbackbox->user_access_messages($USER->id);
if ($message !== false) {
$feedbackbox->page->add_to_page('message', $message);
} else if ($feedbackbox->user_can_take($USER->id)) {
if ($feedbackbox->questions) { // Sanity check.
if (!$feedbackbox->user_has_saved_response($USER->id)) {
$feedbackbox->page->add_to_page('complete',
'<a href="' . $CFG->wwwroot . '/mod/feedbackbox/complete.php?id=' . intval($feedbackbox->cm->id) .
'" class="btn btn-primary">' . get_string('answerquestions', 'feedbackbox') . '</a>');
} else {
$resumesurvey = get_string('resumesurvey', 'feedbackbox');
$feedbackbox->page->add_to_page('complete',
'<a href="' . $CFG->wwwroot . '/mod/feedbackbox/complete.php?id=' . intval($feedbackbox->cm->id) .
'&resume=1' . '" title="' . $resumesurvey . '" class="btn btn-primary">' . $resumesurvey . '</a>');
}
} else {
$feedbackbox->page->add_to_page('message', get_string('noneinuse', 'feedbackbox'));
}
}
if (isguestuser()) {
$guestno = html_writer::tag('p', get_string('noteligible', 'feedbackbox'));
$liketologin = html_writer::tag('p', get_string('liketologin'));
$feedbackbox->page->add_to_page('guestuser',
$feedbackbox->renderer->confirm($guestno . "\n\n" . $liketologin . "\n",
get_login_url(),
get_local_referer(false)));
}
$context = context_module::instance($feedbackbox->cm->id);
if (has_capability('mod/feedbackbox:manage', $context)) {
$argstr = 'instance=' . intval($feedbackbox->id);
$feedbackbox->page->add_to_page('allresponses',
'<a href="' . $CFG->wwwroot . '/mod/feedbackbox/report.php?' . $argstr . '" class="btn btn-primary">' .
get_string('viewallresponses', 'feedbackbox') . '</a>');
}
echo $feedbackbox->renderer->render($feedbackbox->page);
echo $feedbackbox->renderer->footer();