An error occurred while loading the file. Please try again.
-
Kurzenberger authored4e16f800
<?php
namespace assignsubmission_dta;
// 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/>.
/**
* utility class for DTA submission plugin result display
*
* @package assignsubmission_dta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use assignsubmission_dta\db_utils;
use assignsubmission_dta\dta_backend_utils;
use assignsubmission_dta\models\dta_result;
use assignsubmission_dta\models\dta_result_summary;
use assignsubmission_dta\models\dta_recommendation;
class view_submission_utils {
/**
* Broadly used in logic, parametrized for easier change.
*/
const COMPONENT_NAME = "assignsubmission_dta";
/**
* generates a short summary html
*
* @param int $assignmentid assignment
* @param int $submissionid submission to create a report for
* @return string html
*/
public static function generate_summary_html(
int $assignmentid,
int $submissionid
): string {
// Fetch data.
$summary = db_utils::get_Result_Summary_From_Database($assignmentid, $submissionid);
$html = "";
// Calculate success rate, if no unknown result states or compilation errors.
$successrate = "?";
if ($summary->unknownCount() == 0 && $summary->compilationErrorCount() == 0) {
$successrate = round(($summary->successfulCount() / $summary->resultCount()) * 100, 2 );
}
// Generate html.
$html .= $summary->successfulCount() . "/";
$html .= ($summary->compilationErrorCount() == 0 && $summary->unknownCount() == 0)
? $summary->result_Count() . " (" . $successrate . "%)"
: "?";
$html .= get_string("tests_successful", self::COMPONENT_NAME) . "<br />";
if ($summary->compilationErrorCount() > 0) {
$html .= $summary->compilationErrorCount() . get_string("compilation_errors", self::COMPONENT_NAME) . "<br />";
}
if ($summary->unknownCount() > 0) {
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
$html .= $summary->unknownCount() . get_string("unknown_state", self::COMPONENT_NAME) . "<br />";
}
$showncompetencies = explode(";", $summary->successfultestcompetencies);
$overallcompetencies = explode(";", $summary->overalltestcompetencies);
$tmp = "";
for ($index = 0, $size = count($showncompetencies); $index < $size; $index++) {
$shown = $showncompetencies[$index];
$comp = $overallcompetencies[$index];
// If the competency was actually assessed by the assignment and tests, add a summary entry.
if ($shown != "0") {
$tmp .= get_string("comp" . $index, self::COMPONENT_NAME) .
" " . 100 * floatval($shown) / floatval($comp) . "% " . "<br />";
}
}
$html .= get_string("success_competencies", self::COMPONENT_NAME) . "<br />" . $tmp . "<br />";
return \html_writer::div($html, "dtaSubmissionSummary");
}
/**
* Generiert die detaillierte HTML-Ansicht, einschließlich Zusammenfassung, Kompetenzen, Details und Empfehlungen.
*
* @param int $assignmentid Assignment-ID
* @param int $submissionid Submission-ID, für die der Bericht erstellt wird
* @return string HTML-Code
*/
public static function generate_detail_html(
int $assignmentid,
int $submissionid
): string {
// HTML-Inhalt initialisieren
$html = "";
// Daten abrufen
$summary = db_utils::get_Result_Summary_From_Database($assignmentid, $submissionid);
// CSS-Klassen und HTML-Attributarrays definieren
$tableheaderrowattributes = ["class" => "dtaTableHeaderRow"];
$tablerowattributes = ["class" => "dtaTableRow"];
$attributes = ["class" => "dtaTableData"];
$unknownattributes = 'dtaResultUnknown';
$successattributes = 'dtaResultSuccess';
$failureattributes = 'dtaResultFailure';
$compilationerrorattributes = 'dtaResultCompilationError';
// **Zusammenfassungstabelle erstellen**
// (Ihr bisheriger Code bleibt unverändert)
// **Abstand zwischen Tabellen**
$html .= \html_writer::empty_tag("div", ["class" => "dtaSpacer"]);
// **Empfehlungstabelle hinzufügen**
// Empfehlungen für die Submission abrufen
$recommendations = db_utils::get_recommendations_from_database($assignmentid, $submissionid);
if (!empty($recommendations)) {
// **Sortierparameter abrufen**
$allowed_sort_fields = ['topic', 'exercise_name', 'difficulty', 'score'];
$allowed_sort_dirs = ['asc', 'desc'];
// Sortierparameter aus POST-Daten abrufen
$sortby = isset($_POST['sortby']) ? $_POST['sortby'] : 'score';
$sortdir = isset($_POST['sortdir']) ? $_POST['sortdir'] : 'asc';
// Sortierparameter validieren
if (!in_array($sortby, $allowed_sort_fields)) {
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
$sortby = 'score';
}
if (!in_array($sortdir, $allowed_sort_dirs)) {
$sortdir = 'asc';
}
// Empfehlungen sortieren
usort($recommendations, function($a, $b) use ($sortby, $sortdir) {
$valueA = $a->{$sortby};
$valueB = $b->{$sortby};
if (is_numeric($valueA) && is_numeric($valueB)) {
$comparison = $valueA - $valueB;
} else {
$comparison = strnatcasecmp($valueA, $valueB);
}
if ($comparison == 0) {
return 0;
}
if ($sortdir == 'asc') {
return ($comparison < 0) ? -1 : 1;
} else {
return ($comparison < 0) ? 1 : -1;
}
});
// Überschrift für Empfehlungen
$html .= \html_writer::tag('h3', get_string('recommendations', self::COMPONENT_NAME));
// Helper-Funktion zum Generieren von sortierbaren Headern
$generate_sortable_header = function($column_name, $display_name) use ($sortby, $sortdir) {
$new_sortdir = ($sortby == $column_name && $sortdir == 'asc') ? 'desc' : 'asc';
$class = 'dtaTableHeader';
if ($sortby == $column_name) {
$class .= ' sorted ' . $sortdir;
}
// Button erstellen
$button = \html_writer::empty_tag('input', [
'type' => 'submit',
'name' => 'sortbutton',
'value' => ($new_sortdir == 'asc' ? '↑' : '↓'),
'class' => 'sort-button'
]);
// Hidden Inputs für Sortierparameter
$hidden_inputs = \html_writer::empty_tag('input', [
'type' => 'hidden',
'name' => 'sortby',
'value' => $column_name
]);
$hidden_inputs .= \html_writer::empty_tag('input', [
'type' => 'hidden',
'name' => 'sortdir',
'value' => $new_sortdir
]);
// Formular für den Button erstellen
$form = \html_writer::start_tag('form', ['method' => 'post', 'style' => 'display:inline']);
$form .= $hidden_inputs;
$form .= $display_name . ' ' . $button;
$form .= \html_writer::end_tag('form');
return \html_writer::tag("th", $form, ["class" => $class]);
};
// Tabellenkopf für Empfehlungen
$tableheader = "";
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
$tableheader .= $generate_sortable_header('topic', get_string("topic", self::COMPONENT_NAME));
$tableheader .= $generate_sortable_header('exercise_name', get_string("exercise_name", self::COMPONENT_NAME));
$tableheader .= \html_writer::tag("th", get_string("url", self::COMPONENT_NAME), ["class" => "dtaTableHeader"]);
$tableheader .= $generate_sortable_header('difficulty', get_string("difficulty", self::COMPONENT_NAME));
$tableheader .= $generate_sortable_header('score', get_string("score", self::COMPONENT_NAME));
$tableheader = \html_writer::tag("tr", $tableheader, ["class" => "dtaTableHeaderRow"]);
$tableheader = \html_writer::tag("thead", $tableheader);
// Tabellenkörper für Empfehlungen
$tablebody = "";
foreach ($recommendations as $recommendation) {
$tablerow = "";
$tablerow .= \html_writer::tag("td", $recommendation->topic, $attributes);
$tablerow .= \html_writer::tag("td", $recommendation->exercise_name, $attributes);
$tablerow .= \html_writer::tag("td", \html_writer::link($recommendation->url, $recommendation->url), $attributes);
$tablerow .= \html_writer::tag("td", $recommendation->difficulty, $attributes);
$tablerow .= \html_writer::tag("td", $recommendation->score, $attributes);
$tablebody .= \html_writer::tag("tr", $tablerow, $tablerowattributes);
}
$tablebody = \html_writer::tag("tbody", $tablebody);
// Empfehlungstabelle zusammenstellen
$html .= \html_writer::tag("table", $tableheader . $tablebody, ["class" => "dtaTable"]);
}
// Abschließendes Div für die gesamte HTML-Ausgabe
$html = \html_writer::div($html, "dtaSubmissionDetails");
return $html;
}
}