-
Notifications
You must be signed in to change notification settings - Fork 8
/
renderer.php
342 lines (309 loc) · 12.8 KB
/
renderer.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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<?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 contains a renderer for the checkmark class
*
* @package mod_checkmark
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* renderer.php
* This file contains a renderer for the checkmark class
*
* @package mod_checkmark
* @author Daniel Binder (Based on the work of NetSpot {@link http://www.netspot.com.au})
* @copyright 2020 Academic Moodle Cooperation {@link http://www.academic-moodle-cooperation.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/checkmark/locallib.php');
/**
* A custom renderer class that extends the plugin_renderer_base and is used by the checkmark module.
*
* @package mod_checkmark
* @author Daniel Binder (Based on the work of NetSpot {@link http://www.netspot.com.au})
* @copyright 2020 Academic Moodle Cooperation {@link http://www.academic-moodle-cooperation.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_checkmark_renderer extends plugin_renderer_base {
/**
* Rendering checkmark files
*
* @param context $context
* @param int $userid
* @param string $filearea
* @param string $component
* @return string
*/
public function checkmark_files(context $context, $userid, $filearea, $component) {
return $this->render(new checkmark_files($context, $userid, $filearea, $component));
}
/**
* Rendering checkmark files
*
* @param checkmark_files $tree
* @return string
*/
public function render_checkmark_files(checkmark_files $tree) {
$this->htmlid = html_writer::random_id('checkmark_files_tree');
$this->page->requires->js_init_call('M.mod_assign.init_tree', array(true, $this->htmlid));
$html = '<div id="' . $this->htmlid . '">';
$html .= $this->htmllize_tree($tree, $tree->dir);
$html .= '</div>';
return $html;
}
/**
* Internal function - creates htmls structure suitable for YUI tree.
*
* @param checkmark_files $tree
* @param array $dir
* @return string
*/
protected function htmllize_tree(checkmark_files $tree, $dir) {
global $CFG;
$yuiconfig = array();
$yuiconfig['type'] = 'html';
if (empty($dir['subdirs']) and empty($dir['files'])) {
return '';
}
$result = '<ul>';
foreach ($dir['subdirs'] as $subdir) {
$image = $this->output->pix_icon(file_folder_icon(),
$subdir['dirname'],
'moodle',
array('class' => 'icon'));
$result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' .
'<div>' . $image . ' ' . s($subdir['dirname']) . '</div> ' .
$this->htmllize_tree($tree, $subdir) .
'</li>';
}
foreach ($dir['files'] as $file) {
$filename = $file->get_filename();
$image = $this->output->pix_icon(file_file_icon($file),
$filename,
'moodle',
array('class' => 'icon'));
$result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' .
'<div>' .
'<div class="fileuploadsubmission">' . $image . ' ' .
$file->fileurl . ' ' .
'</div>' .
'<div class="fileuploadsubmissiontime">' . $file->timemodified . '</div>' .
'</div>' .
'</li>';
}
$result .= '</ul>';
return $result;
}
/**
* Utility function to add a row of data to a table with 2 columns where the first column is the table's header.
* Modified the table param and does not return a value.
*
* @param html_table $table The table to append the row of data to
* @param string $first The first column text
* @param string $second The second column text
* @param array $firstattributes The first column attributes (optional)
* @param array $secondattributes The second column attributes (optional)
* @return void
*/
private function add_table_row_tuple(html_table $table, $first, $second, $firstattributes = [],
$secondattributes = []) {
$row = new html_table_row();
$cell1 = new html_table_cell($first);
$cell1->header = true;
if (!empty($firstattributes)) {
$cell1->attributes = $firstattributes;
}
$cell2 = new html_table_cell($second);
if (!empty($secondattributes)) {
$cell2->attributes = $secondattributes;
}
$row->cells = array($cell1, $cell2);
$table->data[] = $row;
}
/**
* Render a table containing the current status of the grading process and attendance.
*
* @param \mod_checkmark\gradingsummary $summary Information that should be displayed in the grading summary
* @return string
*/
public function render_checkmark_grading_summary($summary) {
// Create a table for the data.
$o = '';
$o .= $this->output->container_start('gradingsummary');
$o .= $this->output->heading(get_string('gradingsummary', 'checkmark'), 3);
$o .= $this->output->box_start('boxaligncenter gradingsummarytable');
$t = new html_table();
// Visibility Status.
$cell1content = get_string('hiddenfromstudents');
$cell2content = (!$summary->isvisible) ? get_string('yes') : get_string('no');
$this->add_table_row_tuple($t, $cell1content, $cell2content);
// Status.
$cell1content = get_string('numberofparticipants', 'checkmark');
$cell2content = $summary->participantcount;
$this->add_table_row_tuple($t, $cell1content, $cell2content);
// Submitted for grading.
if (time() > $summary->timeavailable) {
$cell1content = get_string('numberofsubmittedassignments', 'checkmark');
$cell2content = $summary->submissionssubmittedcount;
$this->add_table_row_tuple($t, $cell1content, $cell2content);
$cell1content = get_string('numberofsubmissionsneedgrading', 'checkmark');
$cell2content = $summary->submissionsneedgradingcount;
$this->add_table_row_tuple($t, $cell1content, $cell2content);
} else {
$cell1content = get_string('allowsubmissionsfromdate', 'checkmark');
$cell2content = userdate($summary->timeavailable);
$this->add_table_row_tuple($t, $cell1content, $cell2content);
}
$time = time();
$duedate = null;
if ($summary->duedate) {
// Due date.
$cell1content = get_string('duedate', 'checkmark');
$duedate = $summary->duedate;
$cell2content = userdate($duedate);
$this->add_table_row_tuple($t, $cell1content, $cell2content);
// Time remaining.
$cell1content = get_string('timeremaining', 'checkmark');
if ($duedate - $time <= 0) {
$cell2content = get_string('checkmarkisdue', 'checkmark');
} else {
$cell2content = format_time($duedate - $time);
}
$this->add_table_row_tuple($t, $cell1content, $cell2content);
}
// Show late submissions info if regular due date was reached or is not present.
if ($duedate < $time || !$duedate) {
$cell1content = get_string('latesubmissions', 'checkmark');
$cutoffdate = $summary->cutoffdate;
if ($cutoffdate) {
if ($cutoffdate > $time) {
$cell2content = get_string('latesubmissionsaccepted', 'checkmark', userdate($summary->cutoffdate));
} else {
$cell2content = get_string('nomoresubmissionsaccepted', 'checkmark');
}
$this->add_table_row_tuple($t, $cell1content, $cell2content);
}
$this->print_attandance_info($t, $summary);
} else {
$this->print_attandance_info($t, $summary);
}
// Show count of presentationgradings if presenationgrading is active.
if ($summary->presentationgradingcount > 0) {
$cell1content = get_string('presentationgradingcount', 'checkmark');
$cell2content = $summary->presentationgradingcount;
$this->add_table_row_tuple($t, $cell1content, $cell2content);
}
// All done - write the table.
$o .= html_writer::table($t);
$o .= $this->output->box_end();
$o .= $this->output->container_end();
return $o;
}
/**
* Adds attendance/absence columns to the gradingsummary table if attendance is tracked
*
* @param html_table $table Table to add rows to
* @param \mod_checkmark\gradingsummary $summary Information that should be displayed in the grading summary
* @throws coding_exception
*/
private function print_attandance_info ($table, $summary) {
if ($summary->attendantcount > 0) {
$cell1content = get_string('attendance', 'checkmark');
$cell2content = $summary->attendantcount;
$this->add_table_row_tuple($table, $cell1content, $cell2content);
}
if ($summary->absencecount > 0) {
$cell1content = get_string('absent', 'checkmark');
$cell2content = $summary->absencecount;
$this->add_table_row_tuple($table, $cell1content, $cell2content);
}
if ($summary->needattendanceentrycount > 0) {
$cell1content = get_string('needattendanceentrycount', 'checkmark');
$cell2content = $summary->needattendanceentrycount;
$this->add_table_row_tuple($table, $cell1content, $cell2content);
}
}
}
/**
* A class that extends rendererable class and is used by the checkmark module.
*
* @package mod_checkmark
* @author Daniel Binder (Based on the work of NetSpot {@link http://www.netspot.com.au})
* @copyright 2020 Academic Moodle Cooperation {@link http://www.academic-moodle-cooperation.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class checkmark_files implements renderable {
/** @var context $context */
public $context;
/** @var string $context */
public $dir;
/** @var stdClass $cm course module */
public $cm;
/** @var stdClass $course */
public $course;
/**
* The constructor
*
* @param context $context
* @param int $sid
* @param string $filearea
* @param string $component
*/
public function __construct(context $context, $sid, $filearea, $component) {
global $CFG;
$this->context = $context;
list($context, $course, $cm) = get_context_info_array($context->id);
$this->cm = $cm;
$this->course = $course;
$fs = get_file_storage();
$this->dir = $fs->get_area_tree($context->id, $component, $filearea, $sid);
$files = $fs->get_area_files($context->id,
$component,
$filearea,
$sid,
'timemodified',
false);
$this->preprocess($this->dir, $filearea, $component);
}
/**
* Preprocessing the file list
*
* @param array $dir
* @param string $filearea
* @param string $component
* @return void
*/
public function preprocess($dir, $filearea, $component) {
global $CFG;
foreach ($dir['subdirs'] as $subdir) {
$this->preprocess($subdir, $filearea, $component);
}
foreach ($dir['files'] as $file) {
$file->timemodified = userdate(
$file->get_timemodified(),
get_string('strftimedatetime', 'langconfig')
);
$url = moodle_url::make_pluginfile_url($this->context->id, $component, $filearea, $file->get_itemid(),
$file->get_filepath(), $file->get_filename(), true);
$filename = $file->get_filename();
$file->fileurl = html_writer::link($url, $filename, [
'target' => '_blank',
]);
}
}
}