-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignments.php
More file actions
120 lines (103 loc) · 4.07 KB
/
assignments.php
File metadata and controls
120 lines (103 loc) · 4.07 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
<?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/>.
namespace tool_corruptpdfdetector\table;
use html_table;
use html_table_cell;
use html_table_row;
use moodle_url;
use html_writer;
/**
* Corrupt pdf assignment list.
*
* @package tool_corruptpdfdetector
* @author John Yao <johnyao@catalyst-au.net>
* @copyright 2019 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assignments extends html_table {
/**
* Constructor
*/
public function __construct() {
parent::__construct();
$this->attributes['class'] = 'admintable generaltable';
$headers = [
get_string('course'),
get_string('assignmentheader', 'tool_corruptpdfdetector'),
get_string('userfullnameheader', 'tool_corruptpdfdetector'),
get_string('email'),
get_string('reasonheader', 'tool_corruptpdfdetector'),
get_string('submittedheader', 'tool_corruptpdfdetector'),
get_string('detectedheader', 'tool_corruptpdfdetector'),
get_string('fixedheader', 'tool_corruptpdfdetector'),
];
$data = [];
$records = $this->get_detected_assignments();
foreach ($records as $record) {
$cm = get_coursemodule_from_instance('assign', $record->assignid);
$assignurl = new moodle_url('/mod/assign/view.php', [
'id' => $cm->id,
'action' => 'grader',
]);
$linktoassign = html_writer::link($assignurl, $record->assignname);
$row = new html_table_row([
new html_table_cell($record->coursename),
new html_table_cell($linktoassign),
new html_table_cell($record->userfullname),
new html_table_cell($record->email),
new html_table_cell($record->message),
new html_table_cell(userdate($record->submitted, '%Y-%m-%d %H:%M:%S', 99, false, false)),
new html_table_cell(userdate($record->detected, '%Y-%m-%d %H:%M:%S', 99, false, false)),
new html_table_cell($record->fixed ? 'Yes' : 'No'),
]);
$data[] = $row;
}
$this->head = $headers;
$this->data = $data;
}
/**
* Obtain an array of all the currently detected assignments.
*
* @return array
*/
private function get_detected_assignments() {
global $DB;
$records = $DB->get_records('tool_corruptpdfdetector_assigns', [], 'detected ASC');
return $records;
}
/**
* Calculates the percentage of assignments with unresolved issues.
* This method determines the proportion of submissions with detected, unresolved issues
* out of the total number of submissions as a percentage.
* If there are no submissions or no unresolved issues, it returns "0" as the percentage.
*
* @return string The percentage of unresolved issues, formatted as a string with a "%" sign.
*/
public function get_percentage() {
global $DB;
$submissioncount = $DB->count_records('assign_submission');
$filecount = $DB->count_records_select(
'tool_corruptpdfdetector_assigns',
'fixed = ?',
[false],
'COUNT(DISTINCT submissionid)'
);
if ($filecount === 0 || $submissioncount === 0) {
return '0';
}
return round($filecount * 100 / $submissioncount) . '%';
}
}