forked from thanhtri/plagiarism_programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.php
216 lines (187 loc) · 8.05 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
<?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/>.
/**
* Report viewing page, when the user click to see the report
*
* @package plagiarism_programming
* @copyright 2015 thanhtri, 2019 Benedikt Schneider (@Nullmann)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../config.php');
require_once(__DIR__ . '/programming_plag_result_form.php');
require_once(__DIR__ . '/reportlib.php');
global $DB, $USER, $PAGE, $OUTPUT, $CFG;
// Standard settings when no filters are selected.
$cmid = required_param('cmid', PARAM_INT);
$studentid = optional_param('student', null, PARAM_TEXT);
$lowerthreshold = optional_param('lower_threshold', 0, PARAM_FLOAT); // Rate will be above this similarity.
$upperthreshold = optional_param('upper_threshold', 100, PARAM_FLOAT);
$tool = optional_param('tool', '', PARAM_TEXT);
$reportversion = optional_param('version', -1, PARAM_INT);
$ratetype = optional_param('rate_type', 'max', PARAM_TEXT);
$includerepository = optional_param('include_repository', 1, PARAM_INT);
// Display_mode is either table (similar to JPlag style) or a group (similar to MOSS style).
$displaymode = optional_param('display_mode', 'group', PARAM_TEXT);
if (!$coursemodule = $DB->get_record('course_modules', array(
'id' => $cmid
))) {
redirect($CFG->wwwroot, 'Invalid course module id');
}
$course = $DB->get_record('course', array('id' => $coursemodule->course));
if (!$course) {
redirect($CFG->wwwroot, 'Invalid course id');
}
require_login($course, true, $coursemodule);
// If the user is a student (does not have grade capability), he can only see the report on his assignment.
$context = context_module::instance($cmid);
$isteacher = has_capability('mod/assignment:grade', $context);
if (!$isteacher) {
// Check if he is allowed to see the assignment.
if (!has_capability('mod/assignment:submit', $context) || !$DB->get_field('plagiarism_programming', 'auto_publish', array(
'cmid' => $cmid
))) {
redirect($CFG->wwwroot, get_string('permission_denied', 'plagiarism_programming'));
}
$studentid = $USER->id;
}
if ($studentid != null) {
// Students are only allowed to see table mode, not matrix mode.
$displaymode = 'table';
}
$PAGE->set_url(new moodle_url('/plagiarism/programming/view.php', array('cmid' => $cmid)));
// Verify the version.
if (!empty($tool) && $reportversion > 0) {
$report = $DB->get_record('plagiarism_programming_rpt', array(
'cmid' => $cmid,
'detector' => $tool,
'version' => $reportversion
));
} else if (empty($tool)) { // If tool empty, assume report version empty.
$report = plagiarism_programming_get_latest_report($cmid, 'jplag');
if ($report) {
$tool = 'jplag';
} else {
$report = plagiarism_programming_get_latest_report($cmid, 'moss');
$tool = 'moss';
}
} else if ($reportversion <= 0) {
$report = plagiarism_programming_get_latest_report($cmid, $tool);
}
if (!$report) { // At this point, we don't have a report available.
redirect("$CFG->wwwroot/mod/assignment/view.php?id=" . $cmid, get_string('report_not_available', 'plagiarism_programming'));
}
// Construct the query based on filtering criteria.
if ($ratetype == 'max') {
$similarity = 'greatest(similarity1,similarity2)';
} else {
$similarity = '(similarity1+similarity2)/2';
}
$select = "SELECT result.*, $similarity AS similarity
FROM {plagiarism_programming_reslt} result
WHERE reportid=:report_id AND $similarity>=:lower_threshold AND $similarity<=:upper_threshold";
$params = array(
'report_id' => $report->id,
'lower_threshold' => $lowerthreshold,
'upper_threshold' => $upperthreshold
);
if ($studentid != null) { // Filter by studentid if the user is a student.
if (ctype_digit($studentid)) {
$select .= " AND (student1_id=:student1_id OR student2_id=:student2_id)";
$params['student1_id'] = $params['student2_id'] = $studentid;
} else {
$select .= " AND additional_codefile_name = :student_id ";
$params['student_id'] = $studentid;
}
}
if (!$includerepository) {
$select .= " AND additional_codefile_name IS NULL ";
}
$select .= ' ORDER BY similarity DESC';
$result = $DB->get_records_sql($select, $params);
$result = plagiarism_programming_transform_similarity_pair($result);
$header = get_string('result', 'plagiarism_programming');
$PAGE->set_title($header);
$PAGE->set_heading($header);
$PAGE->navbar->add($header);
echo $OUTPUT->header();
// Display the filtering on top.
$filterforms = new programming_plag_result_form($cmid, $tool, $isteacher);
$filterforms->set_data(array(
'cmid' => $cmid,
'student' => $studentid,
'lower_threshold' => $lowerthreshold,
'tool' => $tool,
'rate_type' => $ratetype,
'display_mode' => $displaymode,
'include_repository' => $includerepository
));
$filterforms->display();
if ($isteacher) {
// Display the bar chart with links.
echo "<br>";
echo html_writer::tag('h2', get_string('chart_legend', 'plagiarism_programming'));
echo html_writer::tag('div', plagiarism_programming_create_chart($report->id, $ratetype, $lowerthreshold, $upperthreshold),
array('class' => 'programming_result_chart'));
}
echo "<br>";
// Add button to reset the table if it was filtered in any way.
if ($upperthreshold != 100 OR $lowerthreshold != 0 OR ($studentid && $isteacher)) {
echo html_writer::tag('a', get_string('resetfilter', 'tag'), array('href' => $PAGE->url, 'class' => 'btn btn-default'));
echo "<br><br>";
}
// Display the table with students and their similarities.
$studentnames = null;
plagiarism_programming_create_student_lookup_table($result, $isteacher, $studentnames, $coursemodule->course); // Creates the array id=>name in $studentnames.
$seemark = $DB->get_record('plagiarism_programming', array('cmid' => $coursemodule->id), 'see_mark')->see_mark; // If students are allowed to see the markings.
if ($displaymode == 'group') {
$table = plagiarism_programming_create_table_grouping_mode($result, $studentnames); // Matrix mode.
} else {
$table = plagiarism_programming_create_table_list_mode($result, $studentnames, $studentid, $isteacher, $seemark);
}
echo html_writer::tag('div', html_writer::table($table), array(
'class' => 'programming_result_table'
));
// Show the legend if user is a teacher or if the student is allowed to see the markings (to not confuse them).
if ($isteacher or $seemark) {
echo '<div class="col-2 float-right">'.get_string('legend', 'plagiarism_programming').': ';
echo '<div class = "legend_suspicious">'.get_string('marked_as', 'plagiarism_programming').' '.get_string('suspicious', 'plagiarism_programming').'</div>';
echo '<div class = "legend_nonsuspicious">'.get_string('marked_as', 'plagiarism_programming').' '.get_string('nonsuspicious', 'plagiarism_programming').'</div>';
echo '</div><br><br><br>';
}
// Include Javascript, for displaying of similarity history.
$jsmodule = array(
'name' => 'plagiarism_programming',
'fullpath' => '/plagiarism/programming/view_report.js',
'requires' => array(
'base',
'overlay',
'node',
'json',
'io-base'
),
'strings' => array(
array(
'date',
'moodle'
),
array(
'similarity_history',
'plagiarism_programming'
)
)
);
$PAGE->requires->js_init_call('M.plagiarism_programming.view_report.init', array(), false, $jsmodule);
echo $OUTPUT->footer();