Commit d721c1ab authored by Lückemeyer's avatar Lückemeyer
Browse files

changed variable name camel caps and inline comments according to moodle approval guidelines

1 merge request!1Coding style and recommendations
Showing with 240 additions and 277 deletions
+240 -277
No preview for this file type
......@@ -21,8 +21,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Stub for upgrade code
* @param int $oldversion
......
......@@ -20,7 +20,6 @@
* @package assignsubmission_dta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Serves assignment submissions and other files.
......@@ -85,4 +84,4 @@ function assignsubmission_dta_pluginfile(
// Download MUST be forced - security!
send_stored_file($file, 0, 0, true);
}
\ No newline at end of file
}
......@@ -16,7 +16,7 @@
defined('MOODLE_INTERNAL') || die();
// import various files logic is organized in
//Import various entity and application logic files.
require_once($CFG->dirroot . '/mod/assign/submission/dta/models/DtaResult.php');
require_once($CFG->dirroot . '/mod/assign/submission/dta/utils/database.php');
require_once($CFG->dirroot . '/mod/assign/submission/dta/utils/backend.php');
......@@ -30,18 +30,15 @@ require_once($CFG->dirroot . '/mod/assign/submission/dta/utils/view.php');
*/
class assign_submission_dta extends assign_submission_plugin {
// broadly used in logic, parametrized for easier change
//Broadly used in logic, parametrized for easier change.
const COMPONENT_NAME = "assignsubmission_dta";
// draft file area for dta tests to be uploaded by the teacher
//Draft file area for dta tests to be uploaded by the teacher.
const ASSIGNSUBMISSION_DTA_DRAFT_FILEAREA_TEST = "tests_draft_dta";
// file area for dta tests to be uploaded by the teacher
//File area for dta tests to be uploaded by the teacher.
const ASSIGNSUBMISSION_DTA_FILEAREA_TEST = "tests_dta";
// file area for dta submission assignment
//File area for dta submission assignment.
const ASSIGNSUBMISSION_DTA_FILEAREA_SUBMISSION = "submissions_dta";
// ========== abstract methods to be implemented ========== //
/**
* get plugin name
* @return string
......@@ -50,11 +47,6 @@ class assign_submission_dta extends assign_submission_plugin {
return get_string("pluginname", self::COMPONENT_NAME);
}
// ========== end of section ========== //
// ========== parent methods overloaded ========== //
// ===== assignment settings ===== //
/**
* Get default settings for assignment submission settings
*
......@@ -62,37 +54,31 @@ class assign_submission_dta extends assign_submission_plugin {
* @return void
*/
public function get_settings(MoodleQuickForm $mform): void {
// add draft filemanager to form
//Add draft filemanager to form.
$mform->addElement(
// filemanager
"filemanager",
// unique element name in form
self::ASSIGNSUBMISSION_DTA_DRAFT_FILEAREA_TEST,
// label shown to user left of filemanager
get_string("submission_settings_label", self::COMPONENT_NAME),
// attributes
null,
// options array
$this->get_file_options(true)
);
// add help button to added filemanager
//Add help button to added filemanager.
$mform->addHelpButton(
// form-unique element id to add button to
//Form-unique element id to which to add button.
self::ASSIGNSUBMISSION_DTA_DRAFT_FILEAREA_TEST,
// key to search for
"submission_settings_label",
// language file to use
//Language file to use.
self::COMPONENT_NAME
);
// only show filemanager, if our plugin is enabled
//Only show filemanager if plugin is enabled.
$mform->hideIf(
// form-unique element id to hide
//Form-unique element id to hide.
self::ASSIGNSUBMISSION_DTA_DRAFT_FILEAREA_TEST,
// condition to check
//Condition to check.
self::COMPONENT_NAME . '_enabled',
// state to match for hiding
//State to match for hiding.
'notchecked'
);
}
......@@ -104,21 +90,16 @@ class assign_submission_dta extends assign_submission_plugin {
* @param array $defaultvalues
*/
public function data_preprocessing(&$defaultvalues): void {
$draftitemid = file_get_submitted_draft_itemid(self::ASSIGNSUBMISSION_DTA_DRAFT_FILEAREA_TEST);
//Get id of draft area for file manager creation.
$draftitemid = file_get_submitted_draft_itemid(self::ASSIGNSUBMISSION_DTA_DRAFT_FILEAREA_TEST);
// prepare draft area with created draft filearea
//Prepare draft area with created draft filearea.
file_prepare_draft_area(
// draft filemanager form-unique id
$draftitemid,
// id of current assignment
$this->assignment->get_context()->id,
// component name
self::COMPONENT_NAME,
// proper filearea
self::ASSIGNSUBMISSION_DTA_FILEAREA_TEST,
// entry id
0,
// options array?
array('subdirs' => 0)
);
......@@ -133,69 +114,59 @@ class assign_submission_dta extends assign_submission_plugin {
*/
public function save_settings(stdClass $data): bool {
// if the assignment has no filemanager for our plugin just leave
$draftFileManagerId = self::ASSIGNSUBMISSION_DTA_DRAFT_FILEAREA_TEST;
if (!isset($data->$draftFileManagerId)) {
//If the assignment has no filemanager for our plugin just leave.
$draftfilemanagerid = self::ASSIGNSUBMISSION_DTA_DRAFT_FILEAREA_TEST;
if (!isset($data->$draftfilemanagerid)) {
return true;
}
// store files from draft filearea to proper one
//Store files from draft filearea to final one.
file_save_draft_area_files(
// form-unique element id of draft filemanager from the edit
$data->$draftFileManagerId,
// id of the assignment we edit right now
//Form-unique element id of draft filemanager from the edit.
$data->$draftfilemanagerid,
//Id of the assignment in edit.
$this->assignment->get_context()->id,
// component name
self::COMPONENT_NAME,
// proper file area
self::ASSIGNSUBMISSION_DTA_FILEAREA_TEST,
// entry id
0
);
// get files from proper filearea
//Get files from proper filearea.
$fs = get_file_storage();
$files = $fs->get_area_files(
// id of current assignment
//Id of the current assignment.
$this->assignment->get_context()->id,
// component name
self::COMPONENT_NAME,
// proper filearea
self::ASSIGNSUBMISSION_DTA_FILEAREA_TEST,
// entry id
0,
// ?
'id',
// ?
false
);
// check if a file is uploaded
//Check if a file was uploaded.
if (empty($files)) {
\core\notification::error(get_string("no_testfile_warning", self::COMPONENT_NAME));
return true;
}
// get file
//Get the file.
$file = reset($files);
// send file to backend
//Send file to backend.
return DtaBackendUtils::sendTestConfigToBackend($this->assignment, $file);
}
// ===== student submission ===== //
/**
* Add elements to submission form
*
* @param mixed $submission stdClass|null
* @param MoodleQuickForm $mform
* @param stdClass $data
* @param int $userid
* @param int $userid
* @return bool
*/
public function get_form_elements_for_user($submissionorgrade, MoodleQuickForm $mform, stdClass $data, $userid): bool {
// prepare submission filearea
//Prepare submission filearea.
$data = file_prepare_standard_filemanager(
$data,
'tasks',
......@@ -206,27 +177,26 @@ class assign_submission_dta extends assign_submission_plugin {
$submissionorgrade ? $submissionorgrade->id : 0
);
// add filemanager to form
//Add filemanager to form.
$mform->addElement(
// filemanager
'filemanager',
// form-unique identifier
//Form-unique identifier.
'tasks_filemanager',
// label to show next to filemanager
//Label to show next to the filemanager.
get_string("submission_label", self::COMPONENT_NAME),
// attributes
//Attributes.
null,
// options
//Options.
$this->get_file_options(false)
);
// add help button
//Add help button.
$mform->addHelpButton(
// what form item to add a helpbutton
//Related form item.
"tasks_filemanager",
// what key to use
//Key.
"submission_label",
// in which language file to look in
//Language file.
self::COMPONENT_NAME
);
......@@ -239,21 +209,21 @@ class assign_submission_dta extends assign_submission_plugin {
*/
public function is_empty(stdClass $submission): bool {
return $this->count_files($submission->id, self::ASSIGNSUBMISSION_DTA_FILEAREA_SUBMISSION) == 0;
}
}
/**
* Count the number of files in a filearea
*
* @param int $submissionId submission id to check
* @param string $areaId filearea id to count
* @param int $submissionid submission id to check
* @param string $areaid filearea id to count
* @return int
*/
private function count_files($submissionId, $areaId) {
private function count_files($submissionid, $areaid) {
$fs = get_file_storage();
$files = $fs->get_area_files($this->assignment->get_context()->id,
self::COMPONENT_NAME,
$areaId,
$submissionId,
$areaid,
$submissionid,
'id',
false);
......@@ -278,55 +248,49 @@ class assign_submission_dta extends assign_submission_plugin {
$submission->id
);
// if submission is empty leave directly
//If submission is empty leave directly.
if ($this->is_empty($submission)) {
return true;
}
// get submitted files
//Get submitted files.
$fs = get_file_storage();
$files = $fs->get_area_files(
// id of current assignment
//Id of current assignment.
$this->assignment->get_context()->id,
// component name
self::COMPONENT_NAME,
// proper filearea
self::ASSIGNSUBMISSION_DTA_FILEAREA_SUBMISSION,
// entry id
$submission->id,
// ?
'id',
// ?
false
);
// check if a file is uploaded
//Check if a file is uploaded.
if (empty($files)) {
\core\notification::error(get_string("no_submissionfile_warning", self::COMPONENT_NAME));
return true;
}
// Get the file and post it to our backend.
//Get the file.
$file = reset($files);
//Send file to backend.
$response = DtaBackendUtils::sendSubmissionToBackend($this->assignment, $file);
// if we got a null response, return with error
//With a null response, return an error.
if (is_null($response)) {
return false;
}
// convert received json to valid class instances
$resultSummary = DtaResultSummary::decodeJson($response);
//Convert received json to valid class instances.
$resultsummary = DtaResultSummary::decodeJson($response);
// persist new results to database
DbUtils::storeResultSummaryToDatabase($this->assignment->get_instance()->id, $submission->id, $resultSummary);
//Persist new results to database.
DbUtils::storeResultSummaryToDatabase($this->assignment->get_instance()->id, $submission->id, $resultsummary);
return true;
}
// ===== view submission results ===== //
/**
* Display a short summary of the test results of the submission
* This is diplayed as default view, with the option to expand
......@@ -358,8 +322,6 @@ class assign_submission_dta extends assign_submission_plugin {
);
}
// ========== end of section ========== //
/**
* generate array of allowed filetypes to upload.
*
......@@ -371,7 +333,7 @@ class assign_submission_dta extends assign_submission_plugin {
private function get_file_options(bool $settings): array {
$fileoptions = array('subdirs' => 0,
"maxfiles" => 1,
'accepted_types' => ($settings ? array(".txt") : array(".txt",".zip")),
'accepted_types' => ($settings ? array(".txt") : array(".txt", ".zip")),
'return_types' => FILE_INTERNAL);
return $fileoptions;
}
......@@ -405,7 +367,7 @@ class assign_submission_dta extends assign_submission_plugin {
false);
foreach ($files as $file) {
// Do we return the full folder path or just the file name?
//Do we return the full folder path or just the file name?
if (isset($submission->exportfullpath) && $submission->exportfullpath == false) {
$result[$file->get_filename()] = $file;
} else {
......
......@@ -14,10 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') || die();
class DtaResult {
public $packageName;
public $className;
public $packageName;
public $className;
public $name;
/**
......@@ -66,41 +68,41 @@ class DtaResultSummary {
* @param string $jsonString jsonString containing DtaResultSummary
* @return DtaResultSummary
*/
public static function decodeJson($jsonString): DtaResultSummary {
$response = json_decode($jsonString);
public static function decodeJson($jsonstring): DtaResultSummary {
$response = json_decode($jsonstring);
$summary = new DtaResultSummary();
$summary->timestamp = $response->timestamp;
$summary->globalStacktrace = $response->globalStacktrace;
$summary->successfulTestCompetencyProfile = $response->successfulTestCompetencyProfile;
$summary->overallTestCompetencyProfile = $response->overallTestCompetencyProfile;
$summary->globalStacktrace = $response->globalStacktrace;
$summary->successfulTestCompetencyProfile = $response->successfulTestCompetencyProfile;
$summary->overallTestCompetencyProfile = $response->overallTestCompetencyProfile;
$summary->results = self::decodeJsonResultArray($response->results);
return $summary;
}
private static function decodeJsonCompetencyArray($jsonArray): array {
private static function decodeJsonCompetencyArray($jsonarray): array {
$ret = array();
foreach ($jsonArray as $entry) {
$ret[] = $entry;
}
return $ret;
foreach ($jsonarray as $entry) {
$ret[] = $entry;
}
return $ret;
}
/**
* @param array $jsonArray decoded json array of results array
* @return array of DtaResult
*/
private static function decodeJsonResultArray($jsonArray): array {
private static function decodeJsonResultArray($jsonarray): array {
$ret = array();
foreach ($jsonArray as $entry) {
foreach ($jsonarray as $entry) {
$value = new DtaResult();
$value->packageName = $entry->packageName;
$value->className = $entry->className;
$value->name = $entry->name;
$value->className = $entry->className;
$value->name = $entry->name;
$value->state = $entry->state;
$value->failureType = $entry->failureType;
......@@ -122,7 +124,7 @@ class DtaResultSummary {
*/
public function stateOccurenceCount(int $state): int {
$num = 0;
foreach($this->results as $r) {
foreach ($this->results as $r) {
if ($r->state == $state) {
$num++;
}
......
......@@ -20,13 +20,13 @@ class DtaBackendUtils {
* @return string backend host base url
*/
private static function getBackendBaseUrl(): string {
$backendAddress = get_config(assign_submission_dta::COMPONENT_NAME, "backendHost");
$backendaddress = get_config(assign_submission_dta::COMPONENT_NAME, "backendHost");
if (empty($backendAddress)) {
if (empty($backendaddress)) {
\core\notification::error(get_string("backendHost_not_set", assign_submission_dta::COMPONENT_NAME));
}
return $backendAddress;
return $backendaddress;
}
/**
......@@ -38,21 +38,21 @@ class DtaBackendUtils {
* @return bool true if no error occurred
*/
public static function sendTestConfigToBackend($assignment, $file): bool {
$backendAddress = self::getBackendBaseUrl();
if (empty($backendAddress)) {
$backendaddress = self::getBackendBaseUrl();
if (empty($backendaddress)) {
return true;
}
// set endpoint for test upload
$url = $backendAddress . "/v1/unittest";
//Set endpoint for test upload.
$url = $backendaddress . "/v1/unittest";
// prepare params
//Prepare params.
$params = array(
"unitTestFile" => $file,
"assignmentId" => $assignment->get_instance()->id
);
// if request returned null, return false to indicate failure
//If request returned null, return false to indicate failure.
if (is_null(self::post($url, $params))) {
return false;
} else {
......@@ -69,15 +69,15 @@ class DtaBackendUtils {
* @return string json string with testresults or null on error
*/
public static function sendSubmissionToBackend($assignment, $file): ?string {
$backendAddress = self::getBackendBaseUrl();
if (empty($backendAddress)) {
$backendaddress = self::getBackendBaseUrl();
if (empty($backendaddress)) {
return true;
}
// set endpoint for test upload
$url = $backendAddress . "/v1/task";
//Set endpoint for test upload.
$url = $backendaddress . "/v1/task";
// prepare params
//Prepare params.
$params = array(
"taskFile" => $file,
"assignmentId" => $assignment->get_instance()->id
......@@ -104,14 +104,15 @@ class DtaBackendUtils {
$curl = new curl();
$response = $curl->post($url, $params, $options);
// check state of request, if response code is a 2xx return the answer
//Check state of request, if response code is a 2xx return the answer.
$info = $curl->get_info();
if ($info["http_code"] >= 200 && $info["http_code"] < 300) {
return $response;
}
// Something went wrong, return null and give an error msg
debugging(assign_submission_dta::COMPONENT_NAME . ": Post file to server was not successful: http_code=" . $info["http_code"]);
//Something went wrong, return null and give an error message.
debugging(assign_submission_dta::COMPONENT_NAME . ": Post file to server was not successful: http_code=" .
$info["http_code"]);
if ($info['http_code'] >= 400 && $info['http_code'] < 500) {
\core\notification::error(get_string("http_client_error_msg", assign_submission_dta::COMPONENT_NAME));
......@@ -120,7 +121,8 @@ class DtaBackendUtils {
\core\notification::error(get_string("http_server_error_msg", assign_submission_dta::COMPONENT_NAME));
return null;
} else {
\core\notification::error(get_string("http_unknown_error_msg", assign_submission_dta::COMPONENT_NAME) . $info["http_code"] . $response);
\core\notification::error(get_string("http_unknown_error_msg", assign_submission_dta::COMPONENT_NAME) .
$info["http_code"] . $response);
return null;
}
}
......
......@@ -24,39 +24,39 @@ class DbUtils {
/**
* get's summary with all corresponding result entries
*
* @param int $assignmentId assignment id to search for
* @param int $submissionId submission id to search for
* @param int $assignmentid assignment id to search for
* @param int $submissionid submission id to search for
* @return DttResultSummary representing given submission
*/
public static function getResultSummaryFromDatabase(
int $assignmentId,
int $submissionId
int $assignmentid,
int $submissionid
): DtaResultSummary {
global $DB;
// fetch data from database
$summaryDbRecord = $DB->get_record(self::TABLE_SUMMARY, array(
"assignment_id" => $assignmentId,
"submission_id" => $submissionId
//Fetch data from database.
$summary_record = $DB->get_record(self::TABLE_SUMMARY, array(
"assignment_id" => $assignmentid,
"submission_id" => $submissionid
));
$resultsDbArray = $DB->get_records(self::TABLE_RESULT, array(
"assignment_id" => $assignmentId,
"submission_id" => $submissionId
$results_array = $DB->get_records(self::TABLE_RESULT, array(
"assignment_id" => $assignmentid,
"submission_id" => $submissionid
));
// create summary instance
//Create a summary instance.
$summary = new DtaResultSummary();
$summary->timestamp = $summaryDbRecord->timestamp;
$summary->globalStacktrace = $summaryDbRecord->global_stacktrace;
$summary->successfulTestCompetencyProfile = $summaryDbRecord->successful_competencies;
$summary->overallTestCompetencyProfile = $summaryDbRecord->tested_competencies;
$summary->timestamp = $summary_record->timestamp;
$summary->globalStacktrace = $summary_record->global_stacktrace;
$summary->successfulTestCompetencyProfile = $summary_record->successful_competencies;
$summary->overallTestCompetencyProfile = $summary_record->tested_competencies;
$summary->results = array();
// create result instances and add to array of summary instance
foreach($resultsDbArray as $rr) {
//Create result instances and add to array of summary instance.
foreach($results_array as $rr) {
$result = new DtaResult();
$result->packageName = $rr->package_name;
$result->packageName = $rr->package_name;
$result->className = $rr->class_name;
$result->name = $rr->name;
$result->state = $rr->state;
......@@ -77,33 +77,33 @@ class DbUtils {
* save given result summary and single results to database
* under given assignment and submission id
*
* @param int assignmentId assigment this is submission is linked to
* @param int submissionId submission of this result
* @param int assignmentid assigment this is submission is linked to
* @param int submissionid submission of this result
* @param DttResultSummary instance to persist
*/
public static function storeResultSummaryToDatabase(
int $assignmentId,
int $submissionId,
int $assignmentid,
int $submissionid,
DtaResultSummary $summary
): void {
global $DB;
// prepare new database entries
$summaryRecord = new stdClass();
$summaryRecord->assignment_id = $assignmentId;
$summaryRecord->submission_id = $submissionId;
$summaryRecord->successful_competencies = $summary->successfulTestCompetencyProfile;
$summaryRecord->tested_competencies = $summary->overallTestCompetencyProfile;
$summaryRecord->timestamp = $summary->timestamp;
$summaryRecord->global_stacktrace = $summary->globalStacktrace;
// prepare results to persist to array
$resultRecordArray = array();
//Prepare new database entries.
$summary_record = new stdClass();
$summary_record->assignment_id = $assignmentid;
$summary_record->submission_id = $submissionid;
$summary_record->successful_competencies = $summary->successfulTestCompetencyProfile;
$summary_record->tested_competencies = $summary->overallTestCompetencyProfile;
$summary_record->timestamp = $summary->timestamp;
$summary_record->global_stacktrace = $summary->globalStacktrace;
//Prepare results to persist to array.
$result_records = array();
foreach($summary->results as $r) {
$record = new stdClass();
$record->assignment_id = $assignmentId;
$record->submission_id = $submissionId;
$record->package_name = $r->packageName;
$record->assignment_id = $assignmentid;
$record->submission_id = $submissionid;
$record->package_name = $r->packageName;
$record->class_name = $r->className;
$record->name = $r->name;
$record->state = $r->state;
......@@ -113,30 +113,30 @@ class DbUtils {
$record->column_number = $r->columnNumber;
$record->line_number = $r->lineNumber;
$record->position = $r->position;
$resultRecordArray[] = $record;
$result_records[] = $record;
}
// if results exist yet, delete old values beforehand
//If results already exist, delete old values beforehand.
$submission = $DB->get_record(self::TABLE_SUMMARY, array(
'assignment_id' => $assignmentId,
'submission_id' => $submissionId
'assignment_id' => $assignmentid,
'submission_id' => $submissionid
));
if ($submission) {
$DB->delete_records(self::TABLE_RESULT, array(
'assignment_id' => $assignmentId,
'submission_id' => $submissionId
'assignment_id' => $assignmentid,
'submission_id' => $submissionid
));
$DB->delete_records(self::TABLE_SUMMARY, array(
'assignment_id' => $assignmentId,
'submission_id' => $submissionId
'assignment_id' => $assignmentid,
'submission_id' => $submissionid
));
}
// create summary and single result entries
$DB->insert_record(self::TABLE_SUMMARY, $summaryRecord);
foreach($resultRecordArray as $rr) {
//Create summary and single result entries.
$DB->insert_record(self::TABLE_SUMMARY, $summary_record);
foreach($result_records as $rr) {
$DB->insert_record(self::TABLE_RESULT, $rr);
}
}
......
......@@ -19,29 +19,29 @@ class ViewSubmissionUtils {
/**
* generates a short summary html
*
* @param int assignmentId assignment
* @param int submissionId submission to create a report for
* @param int assignmentid assignment
* @param int submissionid submission to create a report for
* @return string html
*/
public static function generateSummaryHtml(
int $assignmentId,
int $submissionId
int $assignmentid,
int $submissionid
): string {
// fetch data
$summary = DbUtils::getResultSummaryFromDatabase($assignmentId, $submissionId);
//Fetch data.
$summary = DbUtils::getResultSummaryFromDatabase($assignmentid, $submissionid);
$html = "";
// calculate success rate, if no unknown result states or compilation errors
$successRate = "?";
//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 );
$successrate = round(($summary->successfulCount() / $summary->resultCount()) * 100, 2 );
}
// generate html
//Generate html.
$html .= $summary->successfulCount() . "/";
$html .= ($summary->compilationErrorCount() == 0 && $summary->unknownCount() == 0)
? $summary->resultCount() . " (" . $successRate . "%)"
? $summary->resultCount() . " (" . $successrate . "%)"
: "?";
$html .= " tests successful<br>";
......@@ -61,32 +61,32 @@ class ViewSubmissionUtils {
/**
* generates detailed view html
*
* @param int assignmentId assignment
* @param int submissionId submission to create a report for
* @param int assignmentid assignment
* @param int submissionid submission to create a report for
*/
public static function generateDetailHtml(
int $assignmentId,
int $submissionId
int $assignmentid,
int $submissionid
): string {
// fetch data
$summary = DbUtils::getResultSummaryFromDatabase($assignmentId, $submissionId);
//Fetch data.
$summary = DbUtils::getResultSummaryFromDatabase($assignmentid, $submissionid);
$html = "";
// define a few css classes and prepare html attribute arrays
$tableHeaderRowAttributes = array("class" => "dtaTableHeaderRow");
$tableRowAttributes = array("class" => "dtaTableRow");
$resultRowAttributes = $tableRowAttributes;
$unknownAttrib = 'dtaResultUnknown';
$successAttrib = 'dtaResultSuccess';
$failureAttrib = 'dtaResultFailure';
$compErrorAttrib = 'dtaResultCompilationError';
//Define a few css classes and prepare html attribute arrays to beautify the output.
$tableheaderrow_attributes = array("class" => "dtaTableHeaderRow");
$tablerow_attributes = array("class" => "dtaTableRow");
$resultrow_attributes = $tablerow_attributes;
$unknown_attributes = 'dtaResultUnknown';
$success_attributes = 'dtaResultSuccess';
$failure_attributes = 'dtaResultFailure';
$compilationerror_attributes = 'dtaResultCompilationError';
// summary table
//Summary table.
$tmp = "";
$tmp .= html_writer::tag("th", "Summary", array("class" => "dtaTableHeader"));
$tmp .= html_writer::empty_tag("th", array("class" => "dtaTableHeader"));
$header = html_writer::tag("tr", $tmp, $tableHeaderRowAttributes);
$header = html_writer::tag("tr", $tmp, $tableheaderrow_attributes);
$header = html_writer::tag("thead", $header);
$body = "";
......@@ -102,67 +102,67 @@ class ViewSubmissionUtils {
$summary->resultCount(),
$attributes);
$resultRowAttributes = $tableRowAttributes;
$resultRowAttributes['class'] = $resultRowAttributes['class'] . " " . $unknownAttrib;
$resultrow_attributes = $tablerow_attributes;
$resultrow_attributes['class'] = $resultrow_attributes['class'] . " " . $unknown_attributes;
$body .= html_writer::tag("tr", $tmp, $resultRowAttributes);
$body .= html_writer::tag("tr", $tmp, $resultrow_attributes);
$tmp = "";
$tmp .= html_writer::tag("td", "successes", $attributes);
$tmp .= html_writer::tag( "td", $summary->successfulCount(), $attributes);
$resultRowAttributes = $tableRowAttributes;
$successRate = "?";
$resultrow_attributes = $tablerow_attributes;
$successrate = "?";
if ($summary->unknownCount() > 0 || $summary->compilationErrorCount() > 0) {
$resultRowAttributes['class'] = $resultRowAttributes['class'] . " " . $unknownAttrib;
$resultrow_attributes['class'] = $resultrow_attributes['class'] . " " . $unknown_attributes;
} else {
$successRate = round(($summary->successfulCount() / $summary->resultCount()) * 100, 2 );
if ($successRate < 50) {
$resultRowAttributes['class'] = $resultRowAttributes['class'] . " " . $compErrorAttrib;
} else if ($successRate < 75) {
$resultRowAttributes['class'] = $resultRowAttributes['class'] . " " . $failureAttrib;
$successrate = round(($summary->successfulCount() / $summary->resultCount()) * 100, 2 );
if ($successrate < 50) {
$resultrow_attributes['class'] = $resultrow_attributes['class'] . " " . $compilationerror_attributes;
} else if ($successrate < 75) {
$resultrow_attributes['class'] = $resultrow_attributes['class'] . " " . $failure_attributes;
} else {
$resultRowAttributes['class'] = $resultRowAttributes['class'] . " " . $successAttrib;
$resultrow_attributes['class'] = $resultrow_attributes['class'] . " " . $success_attributes;
}
}
$body .= html_writer::tag("tr", $tmp, $resultRowAttributes);
$body .= html_writer::tag("tr", $tmp, $resultrow_attributes);
$tmp = "";
$tmp .= html_writer::tag("td", "failures", $attributes);
$tmp .= html_writer::tag("td", $summary->failedCount(), $attributes);
$resultRowAttributes = $tableRowAttributes;
$resultrow_attributes = $tablerow_attributes;
if ($summary->failedCount() > 0) {
$resultRowAttributes['class'] = $resultRowAttributes['class'] . " " . $failureAttrib;
$resultrow_attributes['class'] = $resultrow_attributes['class'] . " " . $failure_attributes;
} else {
$resultRowAttributes['class'] = $resultRowAttributes['class'] . " " . $successAttrib;
$resultrow_attributes['class'] = $resultrow_attributes['class'] . " " . $success_attributes;
}
$body .= html_writer::tag("tr", $tmp, $resultRowAttributes);
$body .= html_writer::tag("tr", $tmp, $resultrow_attributes);
$tmp = "";
$tmp .= html_writer::tag("td", "compilation errors", $attributes);
$tmp .= html_writer::tag("td", $summary->compilationErrorCount(), $attributes);
$resultRowAttributes = $tableRowAttributes;
$resultrow_attributes = $tablerow_attributes;
if ($summary->compilationErrorCount() > 0) {
$resultRowAttributes['class'] = $resultRowAttributes['class'] . " " . $compErrorAttrib;
$resultrow_attributes['class'] = $resultrow_attributes['class'] . " " . $compilationerror_attributes;
} else {
$resultRowAttributes['class'] = $resultRowAttributes['class'] . " " . $successAttrib;
$resultrow_attributes['class'] = $resultrow_attributes['class'] . " " . $success_attributes;
}
$body .= html_writer::tag("tr", $tmp, $resultRowAttributes);
$body .= html_writer::tag("tr", $tmp, $resultrow_attributes);
$tmp = "";
$tmp .= html_writer::tag("td", "unknown state", $attributes);
$tmp .= html_writer::tag("td", $summary->unknownCount(), $attributes);
$resultRowAttributes = $tableRowAttributes;
$resultrow_attributes = $tablerow_attributes;
if ($summary->unknownCount() > 0) {
$resultRowAttributes['class'] = $resultRowAttributes['class'] . " " . $unknownAttrib;
$resultrow_attributes['class'] = $resultrow_attributes['class'] . " " . $unknown_attributes;
} else {
$resultRowAttributes['class'] = $resultRowAttributes['class'] . " " . $successAttrib;
$resultrow_attributes['class'] = $resultrow_attributes['class'] . " " . $success_attributes;
}
$body .= html_writer::tag("tr", $tmp, $resultRowAttributes);
$body .= html_writer::tag("tr", $tmp, $resultrow_attributes);
$tmp = "";
$tmp .= html_writer::tag("td", html_writer::tag("b","success rate"), $attributes);
......@@ -170,59 +170,59 @@ class ViewSubmissionUtils {
"td",
html_writer::tag("b", $summary->successfulCount()
. "/" . (($summary->compilationErrorCount() == 0 && $summary->unknownCount() == 0) ? $summary->resultCount()
. " (" . $successRate . "%)"
. " (" . $successrate . "%)"
: "?")),
$attributes);
$resultRowAttributes = $tableRowAttributes;
$resultrow_attributes = $tablerow_attributes;
if ($summary->unknownCount() > 0 || $summary->compilationErrorCount() > 0) {
$resultRowAttributes['class'] = $resultRowAttributes['class'] . " " . $unknownAttrib;
$resultrow_attributes['class'] = $resultrow_attributes['class'] . " " . $unknown_attributes;
} else {
if ($successRate < 50) {
$resultRowAttributes['class'] = $resultRowAttributes['class'] . " " . $compErrorAttrib;
} else if ($successRate < 75) {
$resultRowAttributes['class'] = $resultRowAttributes['class'] . " " . $failureAttrib;
if ($successrate < 50) {
$resultrow_attributes['class'] = $resultrow_attributes['class'] . " " . $compilationerror_attributes;
} else if ($successrate < 75) {
$resultrow_attributes['class'] = $resultrow_attributes['class'] . " " . $failure_attributes;
} else {
$resultRowAttributes['class'] = $resultRowAttributes['class'] . " " . $successAttrib;
$resultrow_attributes['class'] = $resultrow_attributes['class'] . " " . $success_attributes;
}
}
$body .= html_writer::tag("tr", $tmp, $resultRowAttributes);
$body .= html_writer::tag("tr", $tmp, $resultrow_attributes);
$body = html_writer::tag("tbody", $body);
$table = html_writer::tag("table", $header . $body, array("class" => "dtaTable"));
$html .= $table;
// add empty div for spacing between summary and details table
//Add empty div for spacing between summary and details table.
$html .= html_writer::empty_tag("div", array("class" => "dtaSpacer"));
// details table
//Details table.
$tmp = "";
$tmp .= html_writer::tag("th", "Details", array("class" => "dtaTableHeader"));
$tmp .= html_writer::empty_tag("th", array("class" => "dtaTableHeader"));
$header = html_writer::tag("tr", $tmp, $tableHeaderRowAttributes);
$header = html_writer::tag("tr", $tmp, $tableheaderrow_attributes);
$header = html_writer::tag("thead", $header);
$body = "";
$spacerRow = null;
$spacerrow = null;
foreach($summary->results as $r) {
// add spacer first, if not null
if (!is_null($spacerRow)) {
$body .= $spacerRow;
//Add spacer first if not null.
if (!is_null($spacerrow)) {
$body .= $spacerrow;
}
// new copy of base attributes array
$resultRowAttributes = $tableRowAttributes;
//New copy of base attributes array.
$resultrow_attributes = $tablerow_attributes;
// check which css class to add for the colored left-border according to resuls state
//Check which css class to add for the colored left-border according to resuls state.
if ($r->state == 0) {
$resultRowAttributes['class'] = $resultRowAttributes['class'] . ' dtaResultUnknown';
$resultrow_attributes['class'] = $resultrow_attributes['class'] . ' dtaResultUnknown';
} else if ($r->state == 1) {
$resultRowAttributes['class'] = $resultRowAttributes['class'] . ' dtaResultSuccess';
$resultrow_attributes['class'] = $resultrow_attributes['class'] . ' dtaResultSuccess';
} else if ($r->state == 2) {
$resultRowAttributes['class'] = $resultRowAttributes['class'] . ' dtaResultFailure';
$resultrow_attributes['class'] = $resultrow_attributes['class'] . ' dtaResultFailure';
} else if ($r->state == 3) {
$resultRowAttributes['class'] = $resultRowAttributes['class'] . ' dtaResultCompilationError';
$resultrow_attributes['class'] = $resultrow_attributes['class'] . ' dtaResultCompilationError';
}
$tmp = "";
......@@ -230,12 +230,12 @@ class ViewSubmissionUtils {
"td",
"name",
$attributes);
$tmp .= html_writer::tag(
"td",
$r->name,
$attributes);
$body .= html_writer::tag("tr", $tmp, $resultRowAttributes);
$body .= html_writer::tag("tr", $tmp, $resultrow_attributes);
$tmp = "";
$tmp .= html_writer::tag(
......@@ -247,9 +247,9 @@ class ViewSubmissionUtils {
"td",
DtaResult::getStateName($r->state),
$attributes);
$body .= html_writer::tag("tr", $tmp, $resultRowAttributes);
$body .= html_writer::tag("tr", $tmp, $resultrow_attributes);
// if state is something different than successful, show additional rows
//If state is something different than successful, show additional rows.
if ($r->state != 1) {
$tmp = "";
$tmp .= html_writer::tag(
......@@ -261,21 +261,21 @@ class ViewSubmissionUtils {
"td",
$r->failureType,
$attributes);
$body .= html_writer::tag("tr", $tmp, $resultRowAttributes);
$body .= html_writer::tag("tr", $tmp, $resultrow_attributes);
$tmp = "";
$tmp .= html_writer::tag(
"td",
"failure reason",
$attributes);
$tmp .= html_writer::tag(
"td",
$r->failureReason,
$attributes);
$body .= html_writer::tag("tr", $tmp, $resultRowAttributes);
$body .= html_writer::tag("tr", $tmp, $resultrow_attributes);
// only show line, column and position if they have useful values
//Only show line, column and position if they have useful values.
if (!is_null($r->lineNumber) && $r->lineNumber > 0) {
$tmp = "";
$tmp .= html_writer::tag(
......@@ -287,7 +287,7 @@ class ViewSubmissionUtils {
"td",
$r->lineNumber,
$attributes);
$body .= html_writer::tag("tr", $tmp, $resultRowAttributes);
$body .= html_writer::tag("tr", $tmp, $resultrow_attributes);
}
if (!is_null($r->columnNumber) && $r->columnNumber > 0) {
......@@ -301,7 +301,7 @@ class ViewSubmissionUtils {
"td",
$r->columnNumber,
$attributes);
$body .= html_writer::tag("tr", $tmp, $resultRowAttributes);
$body .= html_writer::tag("tr", $tmp, $resultrow_attributes);
}
if (!is_null($r->position) && $r->position > 0) {
......@@ -315,7 +315,7 @@ class ViewSubmissionUtils {
"td",
$r->position,
$attributes);
$body .= html_writer::tag("tr", $tmp, $resultRowAttributes);
$body .= html_writer::tag("tr", $tmp, $resultrow_attributes);
}
$tmp = "";
......@@ -328,12 +328,12 @@ class ViewSubmissionUtils {
"td",
html_writer::tag("details", $r->stacktrace, array("class" => "dtaStacktraceDetails")),
$attributes);
$body .= html_writer::tag("tr", $tmp, $resultRowAttributes);
$body .= html_writer::tag("tr", $tmp, $resultrow_attributes);
}
// set spacerRow value if null for next rount separation
if (is_null($spacerRow)) {
$spacerRow = html_writer::empty_tag("tr", array("class" => "dtaTableSpacer"));
//Set spacerrow value if null for next rount separation.
if (is_null($spacerrow)) {
$spacerrow = html_writer::empty_tag("tr", array("class" => "dtaTableSpacer"));
}
}
$html .= html_writer::tag("table", $header . $body, array("class" => "dtaTable"));
......
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