-
Notifications
You must be signed in to change notification settings - Fork 1
/
issue.php
155 lines (128 loc) · 4.44 KB
/
issue.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
148
149
150
151
152
153
154
155
<?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 file is used to render the qtracker block
*
* @package local_qtracker
* @author André Storhaug <andr3.storhaug@gmail.com>
* @copyright 2020 NTNU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_qtracker;
use core\check\performance\debugging;
use core\message\message;
use local_qtracker\issue;
use local_qtracker\output\question_issue_page;
use local_qtracker\output\email\issue_comment_email;
use mod_capquiz\capquiz;
require_once('../../config.php');
require_once($CFG->dirroot . '/local/qtracker/lib.php');
require_once($CFG->dirroot . '/local/qtracker/locallib.php');
global $DB, $OUTPUT, $PAGE, $USER;
// Check for all required variables.
$courseid = required_param('courseid', PARAM_INT);
$issueid = required_param('issueid', PARAM_INT);
$course = $DB->get_record('course', array('id' => $courseid));
if (!$course) {
print_error('invalidcourseid');
}
require_login($course);
$url = new \moodle_url('/local/qtracker/issue.php');
$url->param('courseid', $courseid);
$url->param('issueid', $issueid);
$returnurl = new \moodle_url('/local/qtracker/issues.php');
$returnurl->param('courseid', $courseid);
$PAGE->set_url($url);
$PAGE->set_pagelayout('incourse');
$PAGE->set_heading(get_string('pluginname', 'local_qtracker'));
// Return to issues list.
if (optional_param('return', false, PARAM_BOOL)) {
redirect($returnurl);
}
$issuesnode = $PAGE->navbar->add(
get_string('pluginname', 'local_qtracker'),
null,
\navigation_node::TYPE_CONTAINER,
null,
'qtracker'
);
$issuesnode->add(
get_string('issues', 'local_qtracker'),
new \moodle_url('/local/qtracker/view.php', array('courseid' => $courseid))
);
$issuesnode->add(get_string('issue', 'local_qtracker'));
// Load issue.
$issue = issue::load($issueid);
if (!$issue) {
$issuesurl = new \moodle_url('/local/qtracker/view.php', array('courseid' => $courseid));
redirect($issuesurl);
}
// Process issue actions.
$commentissue = optional_param('commentissue', false, PARAM_BOOL);
$commenttext = optional_param('commenteditor', false, PARAM_RAW);
$sendmessage = optional_param('sendmessage', false, PARAM_BOOL);
if ($commentissue) {
$comment = $issue->create_comment($commenttext);
if ($sendmessage) {
if (local_qtracker_send_comment($course, $issue, $comment)) {
$comment->mark_mailed();
}
}
redirect($PAGE->url);
}
$closeissue = optional_param('closeissue', false, PARAM_BOOL);
if ($closeissue) {
if ($commenttext != false) {
$comment = $issue->create_comment($commenttext);
if ($sendmessage) {
if (local_qtracker_send_comment($course, $issue, $comment)) {
$comment->mark_mailed();
}
}
}
$issue->close();
redirect($PAGE->url);
}
$reopenissue = optional_param('reopenissue', false, PARAM_BOOL);
if ($reopenissue) {
$issue->open();
redirect($PAGE->url);
}
$notifycommentid = optional_param('notifycommentid', null, PARAM_INT);
if (!is_null($notifycommentid)) {
$comment = issue_comment::load($notifycommentid);
if (local_qtracker_send_comment($course, $issue, $comment)) {
$comment->mark_mailed();
}
redirect($PAGE->url);
}
$deletecommentid = optional_param('deletecommentid', null, PARAM_INT);
if (!is_null($deletecommentid)) {
$comment = issue_comment::load($deletecommentid);
$comment->delete();
redirect($PAGE->url);
}
// Capability checking.
local_qtracker_issue_require_capability_on($issue->get_issue_obj(), 'view');
$renderer = $PAGE->get_renderer('local_qtracker');
$questionissuepage = new question_issue_page($issue, $courseid);
$data = $renderer->render($questionissuepage);
echo $OUTPUT->header();
echo $data;
echo $OUTPUT->footer();
if ($issue->get_state() == 'new') {
$issue->open();
}