dta_view_submission_utils.php 25.8 KB
Newer Older
1
<?php
2
3
// This file is part of Moodle - http://moodle.org/
//
4
5
6
7
8
9
10
11
12
13
14
15
// 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/>.
16

17
18
19
20
21
22
23
24
/**
 * This file contains the backend webservice contact functionality for the DTA plugin.
 *
 * @package   assignsubmission_dta
 * @copyright 2023 Your Name
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

25
26
namespace assignsubmission_dta;

27
use assignsubmission_dta\dta_db_utils;
28
29
30
31
32
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;

33
34
35
/**
 * Utility class for DTA submission plugin result display.
 *
36
37
 * @package   assignsubmission_dta
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 */
39
class dta_view_submission_utils {
Lückemeyer's avatar
Lückemeyer committed
40

Lückemeyer's avatar
Lückemeyer committed
41
    /**
Lückemeyer's avatar
Lückemeyer committed
42
43
     * Broadly used in logic, parametrized for easier change.
     */
44
    public const ASSIGNSUBMISSION_DTA_COMPONENT_NAME = 'assignsubmission_dta';
45

46
47
48
49
50
51
52
53
54
55
56
57
58
    /**
     * Generates a short summary HTML (like your old plugin).
     *
     * @param int $assignmentid The assignment ID.
     * @param int $submissionid The submission ID to create a report for.
     * @return string The HTML summary.
     */
    public static function assignsubmission_dta_generate_summary_html(
        int $assignmentid,
        int $submissionid
    ): string {
        // 1) Retrieve the summary data from the DB (adjust your DB-utils class as needed).
        $summary = dta_db_utils::assignsubmission_dta_get_result_summary_from_database($assignmentid, $submissionid);
59

60
61
        // 2) Prepare an HTML buffer.
        $html = '';
62

63
64
65
66
67
68
        // 3) Extract counts from your new method names.
        $unknowncount = $summary->assignsubmission_dta_unknown_count();
        $compilecount = $summary->assignsubmission_dta_compilation_error_count();
        $successcount = $summary->assignsubmission_dta_successful_count();
        $failcount    = $summary->assignsubmission_dta_failed_count();
        $totalcount   = $summary->assignsubmission_dta_result_count();
69

70
71
72
73
74
        // 4) Compute success rate if no unknown/compile errors and total>0.
        $successrate = '?';
        if ($unknowncount === 0 && $compilecount === 0 && $totalcount > 0) {
            $successrate = round(($successcount / $totalcount) * 100, 2);
        }
Lückemeyer's avatar
Lückemeyer committed
75

76
77
78
79
80
81
82
83
84
85
86
        // 5) "X/Y (Z%) tests successful" line:
        // If either compile errors or unknown exist -> show "?", else X/Y (rate%).
        $html .= $successcount . '/';
        if ($compilecount === 0 && $unknowncount === 0) {
            $html .= ($totalcount > 0)
                ? ($totalcount . ' (' . $successrate . '%)')
                : ('0 (' . $successrate . ')');
        } else {
            $html .= '?';
        }
        $html .= get_string('tests_successful', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME) . "<br />";
87

88
89
90
91
92
        // 6) If there are compilation errors, show them.
        if ($compilecount > 0) {
            $html .= $compilecount
                  . get_string('compilation_errors', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)
                  . "<br />";
Lückemeyer's avatar
Lückemeyer committed
93
        }
Lückemeyer's avatar
Lückemeyer committed
94

95
96
97
98
99
100
        // 7) If there are unknown results, show them.
        if ($unknowncount > 0) {
            $html .= $unknowncount
                  . get_string('unknown_state', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)
                  . "<br />";
        }
101

102
103
104
        // If there are failed tests, show them.
        if ($failcount > 0) {
            $html .= $failcount
Kurzenberger's avatar
Kurzenberger committed
105
                  . get_string('failures', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)
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
                  . "<br />";
        }

        // 8) Competencies (like your old snippet).
        $showncompetencies   = explode(';', $summary->successfultestcompetencies);
        $overallcompetencies = explode(';', $summary->overalltestcompetencies);

        $tmp  = '';
        $size = count($showncompetencies);
        for ($i = 0; $i < $size; $i++) {
            $shown = $showncompetencies[$i];
            $comp  = $overallcompetencies[$i];

            // If the competency was actually used (non-zero?), show a row.
            if ($shown !== '0') {
                $shownval = (float) $shown;
                $compval  = (float) $comp;

                // Guard division by zero.
                $pct = 0;
                if ($compval > 0) {
                    $pct = 100.0 * $shownval / $compval;
                }

                // "compX XX%<br />"
                $tmp .= get_string('comp' . $i, self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)
                    . ' ' . round($pct, 2) . '%<br />';
            }
        }

        $html .= get_string('success_competencies', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)
            . "<br />" . $tmp . "<br />";

        // 9) Wrap it in a DIV for styling, and return.
        return \html_writer::div($html, 'dtaSubmissionSummary');
    }
142

143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
    /**
     * Generates detailed view HTML.
     *
     * @param int $assignmentid The assignment ID.
     * @param int $submissionid The submission to create a report for.
     * @return string HTML detail view.
     */
    public static function assignsubmission_dta_generate_detail_html(
        int $assignmentid,
        int $submissionid
    ): string {
        // Fetch data.
        $summary = dta_db_utils::assignsubmission_dta_get_result_summary_from_database(
            $assignmentid,
            $submissionid
        );
        $recommendations = dta_db_utils::assignsubmission_dta_get_recommendations_from_database(
            $assignmentid,
            $submissionid
        );

        $html = '';

166
        // Summary table.
167
        $tableheaderrowattributes = ['class' => 'dtaTableHeaderRow'];
168
169
170
171
172
        $tablerowattributes       = ['class' => 'dtaTableRow'];
        $resultrowattributes      = $tablerowattributes;
        $unknownattributes        = 'dtaResultUnknown';
        $successattributes        = 'dtaResultSuccess';
        $failureattributes        = 'dtaResultFailure';
173
        $compilationerrorattributes = 'dtaResultCompilationError';
174
        $attributes               = ['class' => 'dtaTableData'];
175

176
        // Build the summary table header.
177
178
179
180
181
182
183
184
185
186
187
        $tmp = \html_writer::tag(
            'th',
            get_string('summary', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
            ['class' => 'dtaTableHeader']
        );
        $tmp .= \html_writer::empty_tag('th', ['class' => 'dtaTableHeader']);
        $header = \html_writer::tag('tr', $tmp, $tableheaderrowattributes);
        $header = \html_writer::tag('thead', $header);

        $body = '';

188
189
190
191
192
193
194
        // Pull the counters from the summary object.
        $resultcount      = $summary->assignsubmission_dta_result_count();
        $successfulcount  = $summary->assignsubmission_dta_successful_count();
        $failedcount      = $summary->assignsubmission_dta_failed_count();
        $compilationcount = $summary->assignsubmission_dta_compilation_error_count();
        $unknowncount     = $summary->assignsubmission_dta_unknown_count();

195
        // Total items.
196
        $tmp = \html_writer::tag(
197
198
199
200
            'td',
            get_string('total_items', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
            $attributes
        );
201
        $tmp .= \html_writer::tag('td', $resultcount, $attributes);
202
        $resultrowattributes = $tablerowattributes;
203
        // Original code colors this row as unknown by default.
204
205
206
207
        $resultrowattributes['class'] .= ' ' . $unknownattributes;
        $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);

        // Tests successful.
208
        $tmp = \html_writer::tag(
209
210
211
212
            'td',
            get_string('tests_successful', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
            $attributes
        );
213
        $tmp .= \html_writer::tag('td', $successfulcount, $attributes);
214
        $resultrowattributes = $tablerowattributes;
215
216

        // Compute success rate if no unknown or compilation errors, and resultcount > 0.
217
        $successrate = '?';
218
219
        if ($unknowncount == 0 && $compilationcount == 0 && $resultcount > 0) {
            $successrate = round(($successfulcount / $resultcount) * 100, 2);
220
221
222
223
224
225
226
            if ($successrate < 50) {
                $resultrowattributes['class'] .= ' ' . $compilationerrorattributes;
            } else if ($successrate < 75) {
                $resultrowattributes['class'] .= ' ' . $failureattributes;
            } else {
                $resultrowattributes['class'] .= ' ' . $successattributes;
            }
227
228
229
        } else {
            // If unknown or compilation errors => highlight as unknown.
            $resultrowattributes['class'] .= ' ' . $unknownattributes;
Kurzenberger's avatar
Kurzenberger committed
230
        }
231
232
233
        $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);

        // Failures.
234
        $tmp = \html_writer::tag(
235
236
237
238
            'td',
            get_string('failures', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
            $attributes
        );
239
        $tmp .= \html_writer::tag('td', $failedcount, $attributes);
240
        $resultrowattributes = $tablerowattributes;
241
        if ($failedcount > 0) {
242
            $resultrowattributes['class'] .= ' ' . $failureattributes;
Kurzenberger's avatar
Kurzenberger committed
243
        } else {
244
            $resultrowattributes['class'] .= ' ' . $successattributes;
Kurzenberger's avatar
Kurzenberger committed
245
        }
246
247
248
        $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);

        // Compilation errors.
249
        $tmp = \html_writer::tag(
250
251
252
253
            'td',
            get_string('compilation_errors', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
            $attributes
        );
254
        $tmp .= \html_writer::tag('td', $compilationcount, $attributes);
255
        $resultrowattributes = $tablerowattributes;
256
        if ($compilationcount > 0) {
257
258
259
260
261
262
263
            $resultrowattributes['class'] .= ' ' . $compilationerrorattributes;
        } else {
            $resultrowattributes['class'] .= ' ' . $successattributes;
        }
        $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);

        // Unknown state.
264
        $tmp = \html_writer::tag(
265
266
267
268
            'td',
            get_string('unknown_state', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
            $attributes
        );
269
        $tmp .= \html_writer::tag('td', $unknowncount, $attributes);
270
        $resultrowattributes = $tablerowattributes;
271
        if ($unknowncount > 0) {
272
273
274
275
276
277
            $resultrowattributes['class'] .= ' ' . $unknownattributes;
        } else {
            $resultrowattributes['class'] .= ' ' . $successattributes;
        }
        $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);

278
        // Success rate row.
279
        $tmp = \html_writer::tag(
280
            'td',
281
            \html_writer::tag('b', get_string('success_rate', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)),
282
283
            $attributes
        );
284
285
286
287
        // If no compilation errors or unknown => show successrate, else "?".
        $suffix = ($compilationcount == 0 && $unknowncount == 0 && $resultcount > 0)
            ? ($resultcount . ' (' . $successrate . '%)')
            : '?';
288
289
        $tmp .= \html_writer::tag(
            'td',
290
            \html_writer::tag('b', $successfulcount . '/' . $suffix),
291
292
293
            $attributes
        );
        $resultrowattributes = $tablerowattributes;
294
        if ($compilationcount == 0 && $unknowncount == 0 && $resultcount > 0) {
295
296
297
298
            if ($successrate !== '?' && $successrate < 50) {
                $resultrowattributes['class'] .= ' ' . $compilationerrorattributes;
            } else if ($successrate !== '?' && $successrate < 75) {
                $resultrowattributes['class'] .= ' ' . $failureattributes;
299
            } else {
300
301
                $resultrowattributes['class'] .= ' ' . $successattributes;
            }
302
303
        } else {
            $resultrowattributes['class'] .= ' ' . $unknownattributes;
304
305
        }
        $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);
306

307
308
        // Finalize the summary table.
        $body  = \html_writer::tag('tbody', $body);
309
310
        $table = \html_writer::tag('table', $header . $body, ['class' => 'dtaTable']);
        $html .= $table;
Kurzenberger's avatar
Kurzenberger committed
311

312
        // Spacing after the summary table.
313
        $html .= \html_writer::empty_tag('div', ['class' => 'dtaSpacer']);
314

315
        // Recommendations table.
316
317
        if (!empty($recommendations)) {
            $allowedsortfields = ['topic', 'exercise_name', 'difficulty', 'score'];
318
            $allowedsortdirs   = ['asc', 'desc'];
319

320
321
            // Make sure only one space before ??
            $sortby  = $_POST['sortby'] ?? 'score';
322
            $sortdir = $_POST['sortdir'] ?? 'asc';
323

324
325
            if (!in_array($sortby, $allowedsortfields)) {
                $sortby = 'score';
Kurzenberger's avatar
Kurzenberger committed
326
            }
327
328
            if (!in_array($sortdir, $allowedsortdirs)) {
                $sortdir = 'asc';
Kurzenberger's avatar
Kurzenberger committed
329
            }
330

331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
            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;
                }
            });

            $html .= \html_writer::tag(
                'h3',
                get_string('recommendations', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)
            );

            $generatesortableheader = function ($columnname, $displayname) use ($sortby, $sortdir) {
                $newsortdir = ($sortby === $columnname && $sortdir === 'asc') ? 'desc' : 'asc';
                $class = 'dtaTableHeader';
                if ($sortby === $columnname) {
                    $class .= ' sorted ' . $sortdir;
                }

                // Sort button.
                $button = \html_writer::empty_tag('input', [
365
366
                    'type'  => 'submit',
                    'name'  => 'sortbutton',
367
368
369
370
371
                    'value' => ($newsortdir === 'asc' ? '↑' : '↓'),
                    'class' => 'sort-button',
                ]);

                // Hidden inputs.
372
                $hiddeninputs  = \html_writer::empty_tag('input', [
373
374
                    'type'  => 'hidden',
                    'name'  => 'sortby',
375
376
377
                    'value' => $columnname,
                ]);
                $hiddeninputs .= \html_writer::empty_tag('input', [
378
379
                    'type'  => 'hidden',
                    'name'  => 'sortdir',
380
381
382
                    'value' => $newsortdir,
                ]);

383
                $form  = \html_writer::start_tag('form', [
384
                    'method' => 'post',
385
                    'style'  => 'display:inline',
386
387
388
389
390
391
392
393
                ]);
                $form .= $hiddeninputs;
                $form .= $displayname . ' ' . $button;
                $form .= \html_writer::end_tag('form');

                return \html_writer::tag('th', $form, ['class' => $class]);
            };

394
            // Build the recommendations table header.
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
            $tableheader = '';
            $tableheader .= $generatesortableheader(
                'topic',
                get_string('topic', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)
            );
            $tableheader .= $generatesortableheader(
                'exercise_name',
                get_string('exercise_name', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)
            );
            $tableheader .= \html_writer::tag(
                'th',
                get_string('url', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
                ['class' => 'dtaTableHeader']
            );
            $tableheader .= $generatesortableheader(
                'difficulty',
                get_string('difficulty', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)
            );
            $tableheader .= $generatesortableheader(
                'score',
                get_string('score', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)
            );

            $tableheader = \html_writer::tag('tr', $tableheader, ['class' => 'dtaTableHeaderRow']);
            $tableheader = \html_writer::tag('thead', $tableheader);

            // Table body for recommendations.
            $tablebody = '';
            foreach ($recommendations as $recommendation) {
                $row = '';
                $row .= \html_writer::tag('td', $recommendation->topic, $attributes);
                $row .= \html_writer::tag('td', $recommendation->exercise_name, $attributes);
                $row .= \html_writer::tag(
                    'td',
                    \html_writer::link($recommendation->url, $recommendation->url),
                    $attributes
                );
                $row .= \html_writer::tag('td', $recommendation->difficulty, $attributes);
                $row .= \html_writer::tag('td', $recommendation->score, $attributes);

                $tablebody .= \html_writer::tag('tr', $row, $tablerowattributes);
436
            }
437
            $tablebody = \html_writer::tag('tbody', $tablebody);
438

439
            $html .= \html_writer::tag('table', $tableheader . $tablebody, ['class' => 'dtaTable']);
Kurzenberger's avatar
Kurzenberger committed
440

441
            // Spacing after recommendations.
442
            $html .= \html_writer::empty_tag('div', ['class' => 'dtaSpacer']);
Kurzenberger's avatar
Kurzenberger committed
443
        }
Kurzenberger's avatar
Kurzenberger committed
444

445
446
447
        // Competency assessment table.
        $body  = '';
        $tmp   = \html_writer::tag(
448
449
450
451
            'th',
            get_string('competencies', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
            ['class' => 'dtaTableHeader']
        );
452
        $tmp  .= \html_writer::empty_tag('th', ['class' => 'dtaTableHeader']);
453
454
455
        $header = \html_writer::tag('tr', $tmp, $tableheaderrowattributes);
        $header = \html_writer::tag('thead', $header);

456
        $showncompetencies   = explode(';', $summary->successfultestcompetencies);
457
458
459
        $overallcompetencies = explode(';', $summary->overalltestcompetencies);

        for ($index = 0, $size = count($overallcompetencies); $index < $size; $index++) {
460
            $comp  = $overallcompetencies[$index];
461
            $shown = $showncompetencies[$index];
462

463
            // If the competency was actually assessed, add a row.
464
            if ($comp !== '0') {
465
466
                $compval  = (float) $comp;
                $shownval = (float) $shown;
467

468
                // Guard division by zero.
469
470
471
472
473
                $pct = 0;
                if ($compval > 0) {
                    $pct = (100.0 * $shownval / $compval);
                }

474
475
476
477
478
479
480
481
482
                $resultrowattributes = $tablerowattributes;
                $tmp = '';
                $tmp .= \html_writer::tag(
                    'td',
                    get_string('comp' . $index, self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
                    $resultrowattributes
                );
                $tmp .= \html_writer::tag(
                    'td',
483
                    round($pct, 2) . '% (' . $shown . ' / ' . $comp . ')',
484
485
486
487
488
489
490
491
492
                    $resultrowattributes
                );
                $tmp .= \html_writer::tag(
                    'td',
                    get_string('comp_expl' . $index, self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
                    $resultrowattributes
                );
                $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);
            }
Kurzenberger's avatar
Kurzenberger committed
493
        }
494
495
        $body   = \html_writer::tag('tbody', $body);
        $html  .= \html_writer::tag('table', $header . $body, ['class' => 'dtaTable']);
496
497
498
499

        // Add empty div for spacing.
        $html .= \html_writer::empty_tag('div', ['class' => 'dtaSpacer']);

500
        // Details table.
501
502
503
504
505
506
507
508
509
510
        $tmp = '';
        $tmp .= \html_writer::tag(
            'th',
            get_string('details', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
            ['class' => 'dtaTableHeader']
        );
        $tmp .= \html_writer::empty_tag('th', ['class' => 'dtaTableHeader']);
        $header = \html_writer::tag('tr', $tmp, $tableheaderrowattributes);
        $header = \html_writer::tag('thead', $header);

511
        $body      = '';
512
513
        $spacerrow = null;
        foreach ($summary->results as $r) {
514
            // Add spacer row before each new entry (after the first).
515
516
517
            if (!is_null($spacerrow)) {
                $body .= $spacerrow;
            }
Kurzenberger's avatar
Kurzenberger committed
518

519
            $resultrowattributes = $tablerowattributes;
Kurzenberger's avatar
Kurzenberger committed
520

521
522
523
524
525
526
527
528
529
            // Set CSS class for colored left-border according to results state.
            if ($r->state === 0) {
                $resultrowattributes['class'] .= ' dtaResultUnknown';
            } else if ($r->state === 1) {
                $resultrowattributes['class'] .= ' dtaResultSuccess';
            } else if ($r->state === 2) {
                $resultrowattributes['class'] .= ' dtaResultFailure';
            } else if ($r->state === 3) {
                $resultrowattributes['class'] .= ' dtaResultCompilationError';
Kurzenberger's avatar
Kurzenberger committed
530
531
            }

532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
            $tmp = '';
            $tmp .= \html_writer::tag(
                'td',
                get_string('package_name', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
                $attributes
            );
            $tmp .= \html_writer::tag('td', $r->packagename, $attributes);
            $tmp .= \html_writer::tag(
                'td',
                get_string('unit_name', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
                $attributes
            );
            $tmp .= \html_writer::tag('td', $r->classname, $attributes);
            $tmp .= \html_writer::tag(
                'td',
                get_string('test_name', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
                $attributes
            );
            $tmp .= \html_writer::tag('td', $r->name, $attributes);
            $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);

            $tmp = '';
            $tmp .= \html_writer::tag(
                'td',
                get_string('status', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
                $attributes
            );
            $tmp .= \html_writer::tag(
                'td',
                dta_result::assignsubmission_dta_get_statename($r->state),
                $attributes
            );
            $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);

566
            // If state != 1 (not successful), show additional info.
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
            if ($r->state !== 1) {
                $tmp = '';
                $tmp .= \html_writer::tag(
                    'td',
                    get_string('failure_type', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
                    $attributes
                );
                $tmp .= \html_writer::tag('td', $r->failureType, $attributes);
                $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);

                $tmp = '';
                $tmp .= \html_writer::tag(
                    'td',
                    get_string('failure_reason', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
                    $attributes
                );
                $tmp .= \html_writer::tag('td', $r->failureReason, $attributes);
                $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);

                if (!is_null($r->lineNumber) && $r->lineNumber > 0) {
                    $tmp = '';
                    $tmp .= \html_writer::tag(
                        'td',
                        get_string('line_no', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
                        $attributes
                    );
                    $tmp .= \html_writer::tag('td', $r->lineNumber, $attributes);
                    $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);
                }

                if (!is_null($r->columnNumber) && $r->columnNumber > 0) {
                    $tmp = '';
                    $tmp .= \html_writer::tag(
                        'td',
                        get_string('col_no', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
                        $attributes
                    );
                    $tmp .= \html_writer::tag('td', $r->columnNumber, $attributes);
                    $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);
                }

                if (!is_null($r->position) && $r->position > 0) {
                    $tmp = '';
                    $tmp .= \html_writer::tag(
                        'td',
                        get_string('pos', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
                        $attributes
                    );
                    $tmp .= \html_writer::tag('td', $r->position, $attributes);
                    $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);
                }

                $tmp = '';
                $tmp .= \html_writer::tag(
                    'td',
                    get_string('stacktrace', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
                    $attributes
                );
                $tmp .= \html_writer::tag(
                    'td',
                    \html_writer::tag('details', $r->stacktrace, ['class' => 'dtaStacktraceDetails']),
                    $attributes
                );
                $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);
Kurzenberger's avatar
Kurzenberger committed
631
632
            }

633
            if (is_null($spacerrow)) {
634
                // Reuse this spacer row between subsequent items.
635
                $spacerrow = \html_writer::empty_tag('tr', ['class' => 'dtaTableSpacer']);
Kurzenberger's avatar
Kurzenberger committed
636
637
638
            }
        }

639
        $html .= \html_writer::tag('table', $header . $body, ['class' => 'dtaTable']);
640

641
642
        // Wrap generated HTML into final div.
        $html = \html_writer::div($html, 'dtaSubmissionDetails');
Kurzenberger's avatar
Kurzenberger committed
643

644
645
        return $html;
    }
646
}