"dta/classes/view.php" did not exist on "2f9156e1f8b92de9f9fe1033d175d367dd7edbdd"
Commit 207e72b6 authored by Kurzenberger's avatar Kurzenberger
Browse files

fixed the code checker requierments

parent 51e12764
1 merge request!1Coding style and recommendations
Pipeline #10966 passed with stage
Showing with 181 additions and 157 deletions
+181 -157
<?php <?php
// This file is part of Moodle - http://moodle.org/. // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
...@@ -14,6 +14,14 @@ ...@@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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
*/
namespace assignsubmission_dta; namespace assignsubmission_dta;
use assignsubmission_dta\dta_db_utils; use assignsubmission_dta\dta_db_utils;
...@@ -42,19 +50,17 @@ class dta_view_submission_utils { ...@@ -42,19 +50,17 @@ class dta_view_submission_utils {
* @param int $submissionid The submission ID to create a report for. * @param int $submissionid The submission ID to create a report for.
* @return string The HTML summary. * @return string The HTML summary.
*/ */
public static function assignsubmission_dta_generate_summary_html( public static function assignsubmission_dta_generate_summary_html(
int $assignmentid, int $assignmentid,
int $submissionid int $submissionid
): string { ): string {
// 1) Retrieve the summary data from the DB (adjust your DB-utils class as needed). // 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); $summary = dta_db_utils::assignsubmission_dta_get_result_summary_from_database($assignmentid, $submissionid);
// 2) Prepare an HTML buffer. // 2) Prepare an HTML buffer.
$html = ''; $html = '';
// 3) Extract counts from your new method names: // 3) Extract counts from your new method names.
$unknowncount = $summary->assignsubmission_dta_unknown_count(); $unknowncount = $summary->assignsubmission_dta_unknown_count();
$compilecount = $summary->assignsubmission_dta_compilation_error_count(); $compilecount = $summary->assignsubmission_dta_compilation_error_count();
$successcount = $summary->assignsubmission_dta_successful_count(); $successcount = $summary->assignsubmission_dta_successful_count();
...@@ -67,9 +73,8 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -67,9 +73,8 @@ public static function assignsubmission_dta_generate_summary_html(
$successrate = round(($successcount / $totalcount) * 100, 2); $successrate = round(($successcount / $totalcount) * 100, 2);
} }
// 5) “X/Y (Z%) tests successful” line: // 5) "X/Y (Z%) tests successful" line:
// If either compile errors or unknown exist -> we show "?" // If either compile errors or unknown exist -> show "?", else X/Y (rate%).
// else X/Y (rate%).
$html .= $successcount . '/'; $html .= $successcount . '/';
if ($compilecount === 0 && $unknowncount === 0) { if ($compilecount === 0 && $unknowncount === 0) {
$html .= ($totalcount > 0) $html .= ($totalcount > 0)
...@@ -80,28 +85,28 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -80,28 +85,28 @@ public static function assignsubmission_dta_generate_summary_html(
} }
$html .= get_string('tests_successful', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME) . "<br />"; $html .= get_string('tests_successful', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME) . "<br />";
// 6) If there are compilation errors, show them: // 6) If there are compilation errors, show them.
if ($compilecount > 0) { if ($compilecount > 0) {
$html .= $compilecount $html .= $compilecount
. get_string('compilation_errors', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME) . get_string('compilation_errors', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)
. "<br />"; . "<br />";
} }
// 7) If there are unknown results, show them: // 7) If there are unknown results, show them.
if ($unknowncount > 0) { if ($unknowncount > 0) {
$html .= $unknowncount $html .= $unknowncount
. get_string('unknown_state', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME) . get_string('unknown_state', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)
. "<br />"; . "<br />";
} }
// If there are failed tests, show them.
if ($failcount > 0) { if ($failcount > 0) {
$html .= $failcount $html .= $failcount
. get_string('tests_failed', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME) . get_string('tests_failed', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)
. "<br />"; . "<br />";
} }
// 8) Competencies (like your old snippet).
// 8) Competencies (like your old snippet):
$showncompetencies = explode(';', $summary->successfultestcompetencies); $showncompetencies = explode(';', $summary->successfultestcompetencies);
$overallcompetencies = explode(';', $summary->overalltestcompetencies); $overallcompetencies = explode(';', $summary->overalltestcompetencies);
...@@ -113,16 +118,16 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -113,16 +118,16 @@ public static function assignsubmission_dta_generate_summary_html(
// If the competency was actually used (non-zero?), show a row. // If the competency was actually used (non-zero?), show a row.
if ($shown !== '0') { if ($shown !== '0') {
$shownval = floatval($shown); $shownval = (float) $shown;
$compval = floatval($comp); $compval = (float) $comp;
// Guard division by zero: // Guard division by zero.
$pct = 0; $pct = 0;
if ($compval > 0) { if ($compval > 0) {
$pct = 100.0 * $shownval / $compval; $pct = 100.0 * $shownval / $compval;
} }
// compX XX%<br /> // "compX XX%<br />"
$tmp .= get_string('comp' . $i, self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME) $tmp .= get_string('comp' . $i, self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)
. ' ' . round($pct, 2) . '%<br />'; . ' ' . round($pct, 2) . '%<br />';
} }
...@@ -132,8 +137,8 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -132,8 +137,8 @@ public static function assignsubmission_dta_generate_summary_html(
. "<br />" . $tmp . "<br />"; . "<br />" . $tmp . "<br />";
// 9) Wrap it in a DIV for styling, and return. // 9) Wrap it in a DIV for styling, and return.
return \html_writer::div($html, "dtaSubmissionSummary"); return \html_writer::div($html, 'dtaSubmissionSummary');
} }
/** /**
* Generates detailed view HTML. * Generates detailed view HTML.
...@@ -158,7 +163,7 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -158,7 +163,7 @@ public static function assignsubmission_dta_generate_summary_html(
$html = ''; $html = '';
// *** Summary Table *** // Summary table.
$tableheaderrowattributes = ['class' => 'dtaTableHeaderRow']; $tableheaderrowattributes = ['class' => 'dtaTableHeaderRow'];
$tablerowattributes = ['class' => 'dtaTableRow']; $tablerowattributes = ['class' => 'dtaTableRow'];
$resultrowattributes = $tablerowattributes; $resultrowattributes = $tablerowattributes;
...@@ -188,21 +193,19 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -188,21 +193,19 @@ public static function assignsubmission_dta_generate_summary_html(
$unknowncount = $summary->assignsubmission_dta_unknown_count(); $unknowncount = $summary->assignsubmission_dta_unknown_count();
// Total items. // Total items.
$tmp = ''; $tmp = \html_writer::tag(
$tmp .= \html_writer::tag(
'td', 'td',
get_string('total_items', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME), get_string('total_items', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
$attributes $attributes
); );
$tmp .= \html_writer::tag('td', $resultcount, $attributes); $tmp .= \html_writer::tag('td', $resultcount, $attributes);
$resultrowattributes = $tablerowattributes; $resultrowattributes = $tablerowattributes;
// Original code colors this row as unknown by default: // Original code colors this row as unknown by default.
$resultrowattributes['class'] .= ' ' . $unknownattributes; $resultrowattributes['class'] .= ' ' . $unknownattributes;
$body .= \html_writer::tag('tr', $tmp, $resultrowattributes); $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);
// Tests successful. // Tests successful.
$tmp = ''; $tmp = \html_writer::tag(
$tmp .= \html_writer::tag(
'td', 'td',
get_string('tests_successful', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME), get_string('tests_successful', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
$attributes $attributes
...@@ -228,8 +231,7 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -228,8 +231,7 @@ public static function assignsubmission_dta_generate_summary_html(
$body .= \html_writer::tag('tr', $tmp, $resultrowattributes); $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);
// Failures. // Failures.
$tmp = ''; $tmp = \html_writer::tag(
$tmp .= \html_writer::tag(
'td', 'td',
get_string('failures', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME), get_string('failures', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
$attributes $attributes
...@@ -244,8 +246,7 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -244,8 +246,7 @@ public static function assignsubmission_dta_generate_summary_html(
$body .= \html_writer::tag('tr', $tmp, $resultrowattributes); $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);
// Compilation errors. // Compilation errors.
$tmp = ''; $tmp = \html_writer::tag(
$tmp .= \html_writer::tag(
'td', 'td',
get_string('compilation_errors', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME), get_string('compilation_errors', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
$attributes $attributes
...@@ -260,8 +261,7 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -260,8 +261,7 @@ public static function assignsubmission_dta_generate_summary_html(
$body .= \html_writer::tag('tr', $tmp, $resultrowattributes); $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);
// Unknown state. // Unknown state.
$tmp = ''; $tmp = \html_writer::tag(
$tmp .= \html_writer::tag(
'td', 'td',
get_string('unknown_state', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME), get_string('unknown_state', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
$attributes $attributes
...@@ -276,8 +276,7 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -276,8 +276,7 @@ public static function assignsubmission_dta_generate_summary_html(
$body .= \html_writer::tag('tr', $tmp, $resultrowattributes); $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);
// Success rate row. // Success rate row.
$tmp = ''; $tmp = \html_writer::tag(
$tmp .= \html_writer::tag(
'td', 'td',
\html_writer::tag('b', get_string('success_rate', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)), \html_writer::tag('b', get_string('success_rate', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)),
$attributes $attributes
...@@ -291,7 +290,6 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -291,7 +290,6 @@ public static function assignsubmission_dta_generate_summary_html(
\html_writer::tag('b', $successfulcount . '/' . $suffix), \html_writer::tag('b', $successfulcount . '/' . $suffix),
$attributes $attributes
); );
$resultrowattributes = $tablerowattributes; $resultrowattributes = $tablerowattributes;
if ($compilationcount == 0 && $unknowncount == 0 && $resultcount > 0) { if ($compilationcount == 0 && $unknowncount == 0 && $resultcount > 0) {
if ($successrate !== '?' && $successrate < 50) { if ($successrate !== '?' && $successrate < 50) {
...@@ -314,11 +312,12 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -314,11 +312,12 @@ public static function assignsubmission_dta_generate_summary_html(
// Spacing after the summary table. // Spacing after the summary table.
$html .= \html_writer::empty_tag('div', ['class' => 'dtaSpacer']); $html .= \html_writer::empty_tag('div', ['class' => 'dtaSpacer']);
// *** Recommendations Table *** // Recommendations table.
if (!empty($recommendations)) { if (!empty($recommendations)) {
$allowedsortfields = ['topic', 'exercise_name', 'difficulty', 'score']; $allowedsortfields = ['topic', 'exercise_name', 'difficulty', 'score'];
$allowedsortdirs = ['asc', 'desc']; $allowedsortdirs = ['asc', 'desc'];
// Make sure only one space before ??
$sortby = $_POST['sortby'] ?? 'score'; $sortby = $_POST['sortby'] ?? 'score';
$sortdir = $_POST['sortdir'] ?? 'asc'; $sortdir = $_POST['sortdir'] ?? 'asc';
...@@ -443,10 +442,9 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -443,10 +442,9 @@ public static function assignsubmission_dta_generate_summary_html(
$html .= \html_writer::empty_tag('div', ['class' => 'dtaSpacer']); $html .= \html_writer::empty_tag('div', ['class' => 'dtaSpacer']);
} }
// *** Competency Assessment Table *** // Competency assessment table.
$body = ''; $body = '';
$tmp = ''; $tmp = \html_writer::tag(
$tmp .= \html_writer::tag(
'th', 'th',
get_string('competencies', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME), get_string('competencies', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
['class' => 'dtaTableHeader'] ['class' => 'dtaTableHeader']
...@@ -462,12 +460,12 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -462,12 +460,12 @@ public static function assignsubmission_dta_generate_summary_html(
$comp = $overallcompetencies[$index]; $comp = $overallcompetencies[$index];
$shown = $showncompetencies[$index]; $shown = $showncompetencies[$index];
// If the competency was actually assessed, add a row in the table. // If the competency was actually assessed, add a row.
if ($comp !== '0') { if ($comp !== '0') {
$compval = floatval($comp); $compval = (float) $comp;
$shownval = floatval($shown); $shownval = (float) $shown;
// Guard division by zero: // Guard division by zero.
$pct = 0; $pct = 0;
if ($compval > 0) { if ($compval > 0) {
$pct = (100.0 * $shownval / $compval); $pct = (100.0 * $shownval / $compval);
...@@ -499,7 +497,7 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -499,7 +497,7 @@ public static function assignsubmission_dta_generate_summary_html(
// Add empty div for spacing. // Add empty div for spacing.
$html .= \html_writer::empty_tag('div', ['class' => 'dtaSpacer']); $html .= \html_writer::empty_tag('div', ['class' => 'dtaSpacer']);
// *** Details Table *** // Details table.
$tmp = ''; $tmp = '';
$tmp .= \html_writer::tag( $tmp .= \html_writer::tag(
'th', 'th',
...@@ -513,7 +511,7 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -513,7 +511,7 @@ public static function assignsubmission_dta_generate_summary_html(
$body = ''; $body = '';
$spacerrow = null; $spacerrow = null;
foreach ($summary->results as $r) { foreach ($summary->results as $r) {
// Add spacer first if not null. // Add spacer row before each new entry (after the first).
if (!is_null($spacerrow)) { if (!is_null($spacerrow)) {
$body .= $spacerrow; $body .= $spacerrow;
} }
...@@ -565,7 +563,7 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -565,7 +563,7 @@ public static function assignsubmission_dta_generate_summary_html(
); );
$body .= \html_writer::tag('tr', $tmp, $resultrowattributes); $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);
// If state != 1, show additional info. // If state != 1 (not successful), show additional info.
if ($r->state !== 1) { if ($r->state !== 1) {
$tmp = ''; $tmp = '';
$tmp .= \html_writer::tag( $tmp .= \html_writer::tag(
...@@ -633,6 +631,7 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -633,6 +631,7 @@ public static function assignsubmission_dta_generate_summary_html(
} }
if (is_null($spacerrow)) { if (is_null($spacerrow)) {
// Reuse this spacer row between subsequent items.
$spacerrow = \html_writer::empty_tag('tr', ['class' => 'dtaTableSpacer']); $spacerrow = \html_writer::empty_tag('tr', ['class' => 'dtaTableSpacer']);
} }
} }
......
...@@ -39,9 +39,9 @@ class dta_recommendation { ...@@ -39,9 +39,9 @@ class dta_recommendation {
public $topic; public $topic;
/** /**
* @var string $exerciseName Name of the exercise. * @var string $exercisename Name of the exercise.
*/ */
public $exerciseName; public $exercisename;
/** /**
* @var string $url URL of the exercise. * @var string $url URL of the exercise.
...@@ -73,8 +73,9 @@ class dta_recommendation { ...@@ -73,8 +73,9 @@ class dta_recommendation {
foreach ($response->recommendations as $recommendation) { foreach ($response->recommendations as $recommendation) {
$rec = new dta_recommendation(); $rec = new dta_recommendation();
$rec->topic = $recommendation->topic ?? null; $rec->topic = $recommendation->topic ?? null;
// Map correct fields to the renamed variable names:
$rec->exerciseName = $recommendation->url ?? null; // Map correct fields to the renamed variable names.
$rec->exercisename = $recommendation->url ?? null;
$rec->url = $recommendation->exerciseName ?? null; $rec->url = $recommendation->exerciseName ?? null;
$rec->difficulty = $recommendation->difficulty ?? null; $rec->difficulty = $recommendation->difficulty ?? null;
$rec->score = $recommendation->score ?? null; $rec->score = $recommendation->score ?? null;
......
<?php <?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 the DTA submission plugin result summary entity class.
*
* @package assignsubmission_dta
* @copyright 2023 Your Name
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace assignsubmission_dta\models; namespace assignsubmission_dta\models;
/** /**
...@@ -7,9 +30,11 @@ namespace assignsubmission_dta\models; ...@@ -7,9 +30,11 @@ namespace assignsubmission_dta\models;
* This class holds: * This class holds:
* - A timestamp for when the summary was generated. * - A timestamp for when the summary was generated.
* - An optional global stack trace (in case the entire process failed). * - An optional global stack trace (in case the entire process failed).
* - A competency profile of how many tests passed for each competency (successfulTestCompetencyProfile). * - A competency profile of how many tests passed for each competency.
* - A competency profile of the total coverage for each competency (overallTestCompetencyProfile). * - A competency profile of the total coverage for each competency.
* - An array of DTA result objects that detail individual test results. * - An array of dta_result objects that detail individual test results.
*
* @package assignsubmission_dta
*/ */
class dta_result_summary { class dta_result_summary {
...@@ -41,7 +66,7 @@ class dta_result_summary { ...@@ -41,7 +66,7 @@ class dta_result_summary {
$summary->timestamp = $response->timestamp ?? 0; $summary->timestamp = $response->timestamp ?? 0;
$summary->globalstacktrace = $response->globalstacktrace ?? ''; $summary->globalstacktrace = $response->globalstacktrace ?? '';
// If your JSON keys are 'successfulTestCompetencyProfile' and 'overallTestCompetencyProfile': // If your JSON keys are 'successfulTestCompetencyProfile' and 'overallTestCompetencyProfile'.
$summary->successfultestcompetencies = $response->successfulTestCompetencyProfile ?? ''; $summary->successfultestcompetencies = $response->successfulTestCompetencyProfile ?? '';
$summary->overalltestcompetencies = $response->overallTestCompetencyProfile ?? ''; $summary->overalltestcompetencies = $response->overallTestCompetencyProfile ?? '';
...@@ -151,7 +176,7 @@ class dta_result_summary { ...@@ -151,7 +176,7 @@ class dta_result_summary {
/** /**
* Computes the success rate as a percentage of all results (0..100). * Computes the success rate as a percentage of all results (0..100).
* Note: This includes tests that might have compile errors, unknown states, etc. * Note: This includes tests that might have compile errors or unknown states.
* *
* @return float A floating percentage between 0.0 and 100.0. * @return float A floating percentage between 0.0 and 100.0.
*/ */
......
...@@ -306,8 +306,7 @@ class assign_submission_dta extends assign_submission_plugin { ...@@ -306,8 +306,7 @@ class assign_submission_dta extends assign_submission_plugin {
$file = reset($files); $file = reset($files);
// Send file to backend (split across lines to avoid exceeding length). // Send file to backend (split across lines to avoid exceeding length).
$response = \assignsubmission_dta\dta_backend_utils:: $response = \assignsubmission_dta\dta_backend_utils::assignsubmission_dta_send_submission_to_backend(
assignsubmission_dta_send_submission_to_backend(
$this->assignment, $this->assignment,
$submission->id, $submission->id,
$file $file
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment