-
Notifications
You must be signed in to change notification settings - Fork 43
/
view.php
241 lines (198 loc) · 9.43 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<?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/>.
/**
* Prints information about the reengagement to the user.
*
* @package mod_reengagement
* @author Peter Bulmer <[email protected]>
* @copyright 2016 Catalyst IT {@link http://www.catalyst.net.nz}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use core_table\local\filter\filter;
use core_table\local\filter\integer_filter;
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
require_once(dirname(__FILE__) . '/lib.php');
define('DEFAULT_PAGE_SIZE', 20);
define('SHOW_ALL_PAGE_SIZE', 5000);
$id = optional_param('id', 0, PARAM_INT); // Course_module ID.
$a = optional_param('a', 0, PARAM_INT); // Reengagement instance ID.
$page = optional_param('page', 0, PARAM_INT); // Which page to show.
$perpage = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT); // How many per page.
$selectall = optional_param('selectall', false, PARAM_BOOL); // When rendering checkboxes against users mark them all checked.
$params = array();
if ($id) {
$params['id'] = $id;
} else {
$params['a'] = $a;
}
$PAGE->set_url('/mod/reengagement/view.php', $params);
if ($id) {
$cm = get_coursemodule_from_id('reengagement', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$reengagement = $DB->get_record('reengagement', array('id' => $cm->instance), '*', MUST_EXIST);
} else if ($a) {
$reengagement = $DB->get_record('reengagement', array('id' => $a), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $reengagement->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('reengagement', $reengagement->id, $course->id, false, MUST_EXIST);
} else {
throw new moodle_exception('errornoid', 'mod_reengagement');
}
require_login($course, true, $cm);
// Make sure completion and restriction is enabled.
if (empty($CFG->enablecompletion) || empty($CFG->enableavailability)) {
throw new moodle_exception('mustenablecompletionavailability', 'mod_reengagement');
}
$context = context_module::instance($cm->id);
$event = \mod_reengagement\event\course_module_viewed::create(array(
'objectid' => $reengagement->id,
'context' => $context,
));
$event->add_record_snapshot('course', $course);
$event->add_record_snapshot('reengagement', $reengagement);
$event->trigger();
// Print the page header.
$strreengagements = get_string('modulenameplural', 'reengagement');
$strreengagement = get_string('modulename', 'reengagement');
$PAGE->set_title(format_string($reengagement->name));
$PAGE->set_heading(format_string($course->fullname));
echo $OUTPUT->header();
// Print the main part of the page.
$PAGE->set_context($context);
$canstart = has_capability('mod/reengagement:startreengagement', $context, null, false);
$canedit = has_capability('mod/reengagement:editreengagementduration', $context);
$bulkoperations = has_capability('mod/reengagement:bulkactions', $context);
if (empty($canstart) && empty($canedit)) {
throw new moodle_exception('errorreengagementnotvalid', 'mod_reengagement');
}
if ($canstart) {
// Check reengagement record for this user.
echo reengagement_checkstart($course, $cm, $reengagement);
}
if ($canedit) {
$task = \core\task\manager::get_scheduled_task('\mod_reengagement\task\cron_task');
$lastrun = $task->get_last_run_time();
if ($lastrun < time() - 28800) { // Check if cron run in last 8hrs.
echo $OUTPUT->notification(get_string('cronwarning', 'reengagement'));
}
$filterset = new \mod_reengagement\table\reengagement_participants_filterset();
// We pretend the courseid is the cmid, because the core Moodle participants filter doesn't allow adding new filter types.
$filterset->add_filter(new integer_filter('courseid', filter::JOINTYPE_DEFAULT, [(int) $cm->id]));
$participanttable = new \mod_reengagement\table\reengagement_participants("reengagement-index-participants-{$cm->id}");
echo '<div class="userlist">';
// Should use this variable so that we don't break stuff every time a variable is added or changed.
$baseurl = new moodle_url('/mod/reengagement/view.php', array(
'contextid' => $context->id,
'id' => $cm->id,
'perpage' => $perpage));
$participanttable->set_filterset($filterset);
ob_start();
$participanttable->out($perpage, true);
$participanttablehtml = ob_get_contents();
ob_end_clean();
echo html_writer::start_tag('form', [
'action' => 'bulkchange.php',
'method' => 'post',
'id' => 'participantsform',
'data-course-id' => $cm->id,
'data-table-unique-id' => $participanttable->uniqueid,
'data-table-default-per-page' => ($perpage < DEFAULT_PAGE_SIZE) ? $perpage : DEFAULT_PAGE_SIZE,
]);
echo '<div>';
echo '<input type="hidden" name="id" value="' . $cm->id . '" />';
echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
echo '<input type="hidden" name="returnto" value="' . s($PAGE->url->out(false)) . '" />';
echo html_writer::tag(
'p',
get_string('countparticipantsfound', 'core_user', $participanttable->totalrows),
[
'data-region' => 'participant-count',
]
);
echo $participanttablehtml;
$perpagevisible = '';
$perpagestring = '';
$perpagesize = '';
$perpageurl = clone($baseurl);
$perpageurl->remove_params('perpage');
if ($perpage == SHOW_ALL_PAGE_SIZE && $participanttable->totalrows > DEFAULT_PAGE_SIZE) {
$perpageurl->param('perpage', $participanttable->totalrows);
$perpagesize = SHOW_ALL_PAGE_SIZE;
$perpagevisible = true;
$perpagestring = get_string('showperpage', '', DEFAULT_PAGE_SIZE);
} else if ($participanttable->get_page_size() < $participanttable->totalrows) {
$perpageurl->param('perpage', SHOW_ALL_PAGE_SIZE);
$perpagesize = SHOW_ALL_PAGE_SIZE;
$perpagevisible = true;
$perpagestring = get_string('showall', '', $participanttable->totalrows);
}
$perpageclasses = '';
if (!$perpagevisible) {
$perpageclasses = 'hidden';
}
echo $OUTPUT->container(html_writer::link(
$perpageurl,
$perpagestring,
[
'data-action' => 'showcount',
'data-target-page-size' => $perpagesize,
'class' => $perpageclasses,
]
), [], 'showall');
$options = new stdClass();
$options->courseid = $cm->id;
$options->uniqueid = $participanttable->uniqueid;
$options->stateHelpIcon = $OUTPUT->help_icon('publishstate', 'notes');
if ($bulkoperations) {
echo '<br /><div class="buttons"><div class="form-inline">';
if ($participanttable->get_page_size() < $participanttable->totalrows) {
// Select all users, refresh table showing all users and mark them all selected.
$label = get_string('selectalluserswithcount', 'moodle', $participanttable->totalrows);
echo html_writer::empty_tag('input', [
'type' => 'button',
'id' => 'checkall',
'class' => 'btn btn-secondary',
'value' => $label,
'data-target-page-size' => $participanttable->totalrows,
]);
}
echo html_writer::end_tag('div');
$displaylist = array();
$displaylist['#messageselect'] = get_string('messageselectadd');
$pluginoptions = [];
$params = ['operation' => 'resetbyfirstcourseaccess'];
$url = new moodle_url('bulkchange.php', $params);
list ($periodcount, $period) = reengagement_get_readable_duration($reengagement->duration, true);
$duration = $periodcount . " " . $period;
$pluginoptions['resetbyfirstaccess'] = get_string('resetbyfirstaccess', 'mod_reengagement', $duration);
$pluginoptions['resetbyenrolment'] = get_string('resetbyenrolment', 'mod_reengagement', $duration);
$pluginoptions['resetbyspecificdate'] = get_string('resetbyspecificdate', 'mod_reengagement');
$name = get_string('resetcompletion', 'mod_reengagement');
$displaylist[] = [$name => $pluginoptions];
echo $OUTPUT->help_icon('withselectedusers', 'mod_reengagement');
echo html_writer::tag('label', get_string("withselectedusers"), array('for' => 'formactionid'));
echo html_writer::select($displaylist, 'formaction', '', array('' => 'choosedots'), array('id' => 'formactionid'));
echo '<noscript style="display:inline">';
echo '<div><input type="submit" value="' . get_string('ok') . '" /></div>';
echo '</noscript>';
echo '</div></div>';
$options->noteStateNames = note_get_state_names();
}
echo '</form>';
$PAGE->requires->js_call_amd('core_user/participants', 'init', [$options]);
echo '</div>'; // Userlist.
}
// Finish the page.
echo $OUTPUT->footer($course);