-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchoosesupporters.php
More file actions
168 lines (151 loc) · 6.93 KB
/
choosesupporters.php
File metadata and controls
168 lines (151 loc) · 6.93 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
<?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/>.
/**
* @package local_edusupport
* @copyright 2020 Center for Learningmanagement (www.lernmanagement.at)
* @author Robert Schrenk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_edusupport;
use moodle_url;
require_once('../../config.php');
require_once($CFG->libdir . '/adminlib.php');
$id = optional_param('id', 0, PARAM_INT);
$userid = optional_param('userid', 0, PARAM_INT);
$supportlevel = optional_param('supportlevel', '', PARAM_TEXT);
$remove = optional_param('remove', 0, PARAM_BOOL);
// The next param is not used yet. We could select supporters, that are resposible for certain courses only.
$courseid = optional_param('courseid', \local_edusupport\lib::SYSTEM_COURSE_ID, PARAM_INT);
$context = \context_system::instance();
$PAGE->set_context($context);
require_login();
$PAGE->set_url(new \moodle_url('/local/edusupport/choosesupporters.php', ['id' => $id, 'userid' => $userid]));
$title = get_string('supporters', 'local_edusupport');
$PAGE->set_title($title);
$PAGE->set_heading($title);
$url = new \moodle_url('/admin/search.php', [ ]);
$PAGE->navbar->add(get_string('administrationsite'), $url);
$url = new \moodle_url('/admin/category.php', [ 'category' => 'modules']);
$PAGE->navbar->add(get_string('plugins', 'core_admin'), $url);
$url = new \moodle_url('/admin/category.php', [ 'category' => 'localplugins']);
$PAGE->navbar->add(get_string('localplugins'), $url);
$url = new \moodle_url('/admin/settings.php', [ 'section' => 'local_edusupport_settings' ]);
$PAGE->navbar->add(get_string('pluginname', 'local_edusupport'), $url);
$PAGE->navbar->add(get_string('supporters', 'local_edusupport'), $PAGE->url);
echo $OUTPUT->header();
if (!is_siteadmin()) {
$tourl = new moodle_url('/my', []);
echo $OUTPUT->render_from_template('local_edusupport/alert', [
'content' => get_string('missing_permission', 'local_edusupport'),
'type' => 'danger',
'url' => $tourl->__toString(),
]);
} else {
if (!empty($userid)) {
$success = false;
if (!empty($id)) {
$record = $DB->get_record('local_edusupport_supporters', ['id' => $id]);
if (!empty($remove)) {
$success = $DB->delete_records('local_edusupport_supporters', ['id' => $id]);
if ($success) {
$event = \local_edusupport\event\supportuser_deleted::create(
[
'objectid' => $id,
'context' => $context,
'relateduserid' => $record->userid,
'other' => ['supportuserid' => $record->userid, 'supportlevel' => $record->supportlevel],
]
);
$event->trigger();
}
} else {
$success = $DB->update_record('local_edusupport_supporters', [
'id' => $id,
'courseid' => $courseid,
'userid' => $userid,
'supportlevel' => $supportlevel,
]);
if ($success) {
$event = \local_edusupport\event\supportuser_changed::create(
[
'objectid' => $id,
'context' => $context,
'relateduserid' => $record->userid,
'other' => [
'oldsupportuserid' => $record->userid,
'newsupportuserid' => $userid,
'oldsupportlevel' => $record->supportlevel,
'newsupportlevel' => $supportlevel,
],
]
);
$event->trigger();
}
}
} else if (!$DB->record_exists('local_edusupport_supporters', ['courseid' => $courseid, 'userid' => $userid])) {
$success = $DB->insert_record('local_edusupport_supporters', [
'courseid' => $courseid,
'userid' => $userid,
'supportlevel' => $supportlevel,
]);
if ($success) {
$event = \local_edusupport\event\supportuser_added::create(
[
'objectid' => $success,
'context' => $context,
'relateduserid' => $userid,
'other' => ['supportuserid' => $userid,
'supportlevel' => $supportlevel]]
);
$event->trigger();
}
}
if ($success) {
\local_edusupport\lib::supportforum_rolecheck();
if (!empty($remove)) {
$chk = $DB->get_record('local_edusupport_supporters', ['userid' => $userid]);
if (empty($chk->id)) {
// This supporter left the team. We remove all assignments.
$DB->delete_records('local_edusupport_subscr', ['userid' => $userid]);
}
} else if (empty($supportlevel)) {
$issues = $DB->get_records('local_edusupport_issues', ['currentsupporter' => 0]);
foreach ($issues as $issue) {
$DB->insert_record('local_edusupport_subscr', [
'issueid' => $issue->id,
'discussionid' => $issue->discussionid,
'userid' => $userid,
]);
}
}
}
echo $OUTPUT->render_from_template('local_edusupport/alert', [
'content' => get_string(($success) ? 'changes_saved_successfully' : 'changes_saved_fail', 'local_edusupport'),
'type' => ($success) ? 'success' : 'danger',
]);
}
$sql = "SELECT bes.*,u.firstname,u.lastname
FROM {local_edusupport_supporters} bes, {user} u
WHERE u.id = bes.userid
AND u.deleted != 1
ORDER BY u.lastname ASC, u.firstname ASC, bes.supportlevel ASC";
$supporters = array_values($DB->get_records_sql($sql, []));
echo $OUTPUT->render_from_template(
'local_edusupport/choosesupporters',
['supporters' => $supporters, 'wwwroot' => $CFG->wwwroot]
);
}
echo $OUTPUT->footer();