diff --git a/scripts/langindex.json b/scripts/langindex.json index 5c2eb5227..2b2ebb48f 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -432,6 +432,7 @@ "addon.mod_assign.overdue": "assign", "addon.mod_assign.submission": "assign", "addon.mod_assign.submissioneditable": "assign", + "addon.mod_assign.submissionempty": "assign", "addon.mod_assign.submissionnoteditable": "assign", "addon.mod_assign.submissionnotsupported": "local_moodlemobileapp", "addon.mod_assign.submissionslocked": "assign", diff --git a/src/addons/mod/assign/lang.json b/src/addons/mod/assign/lang.json index 6806d8ad0..fa94b86fc 100644 --- a/src/addons/mod/assign/lang.json +++ b/src/addons/mod/assign/lang.json @@ -84,6 +84,7 @@ "overdue": "Assignment is overdue by: {{$a}}", "submission": "Submission", "submissioneditable": "Student can edit this submission", + "submissionempty": "Nothing was submitted", "submissionnoteditable": "Student cannot edit this submission", "submissionnotsupported": "This submission is not supported by the app and may not contain all the information.", "submissionslocked": "This assignment is not accepting submissions", diff --git a/src/addons/mod/assign/pages/edit/edit.ts b/src/addons/mod/assign/pages/edit/edit.ts index d11712cd6..5949a7446 100644 --- a/src/addons/mod/assign/pages/edit/edit.ts +++ b/src/addons/mod/assign/pages/edit/edit.ts @@ -398,6 +398,10 @@ export class AddonModAssignEditPage implements OnInit, OnDestroy, CanLeave { throw Translate.instant('addon.mod_assign.acceptsubmissionstatement'); } + if (AddonModAssignHelper.isSubmissionEmptyForEdit(this.assign!, this.userSubmission!, inputData)) { + throw Translate.instant('addon.mod_assign.submissionempty'); + } + let modal = await CoreLoadings.show(); let size = -1; diff --git a/src/addons/mod/assign/services/assign-helper.ts b/src/addons/mod/assign/services/assign-helper.ts index c191c8013..8c5d55b35 100644 --- a/src/addons/mod/assign/services/assign-helper.ts +++ b/src/addons/mod/assign/services/assign-helper.ts @@ -237,6 +237,31 @@ export class AddonModAssignHelperProvider { return true; } + /** + * Check whether the edited submission has no content. + * + * @param assign Assignment object. + * @param submission Submission to inspect. + * @param inputData Data entered in the submission form. + * @returns Whether the submission is empty. + */ + isSubmissionEmptyForEdit( + assign: AddonModAssignAssign, + submission: AddonModAssignSubmission, + inputData: CoreFormFields, + ): boolean { + const anyNotEmpty = submission.plugins?.some((plugin) => + !AddonModAssignSubmissionDelegate.isPluginEmptyForEdit(assign, plugin, inputData)); + + // If any plugin is not empty, we consider that the submission is not empty either. + if (anyNotEmpty) { + return false; + } + + // If all the plugins were empty (or there were no plugins), we consider the submission to be empty. + return true; + } + /** * List the participants for a single assignment, with some summary info about their submissions. * diff --git a/src/addons/mod/assign/services/handlers/default-submission.ts b/src/addons/mod/assign/services/handlers/default-submission.ts index e78516b57..2365c122e 100644 --- a/src/addons/mod/assign/services/handlers/default-submission.ts +++ b/src/addons/mod/assign/services/handlers/default-submission.ts @@ -50,6 +50,17 @@ export class AddonModAssignDefaultSubmissionHandler implements AddonModAssignSub return true; } + /** + * @inheritdoc + */ + isEmptyForEdit( + assign: AddonModAssignAssign, // eslint-disable-line @typescript-eslint/no-unused-vars + plugin: AddonModAssignPlugin, // eslint-disable-line @typescript-eslint/no-unused-vars + inputData: CoreFormFields, // eslint-disable-line @typescript-eslint/no-unused-vars + ): boolean { + return true; + } + /** * @inheritdoc */ diff --git a/src/addons/mod/assign/services/submission-delegate.ts b/src/addons/mod/assign/services/submission-delegate.ts index 872fe75f1..f50e718fc 100644 --- a/src/addons/mod/assign/services/submission-delegate.ts +++ b/src/addons/mod/assign/services/submission-delegate.ts @@ -62,6 +62,20 @@ export interface AddonModAssignSubmissionHandler extends CoreDelegateHandler { plugin: AddonModAssignPlugin, ): boolean; + /** + * Check if a plugin has no data in the edit form. + * + * @param assign The assignment. + * @param plugin The plugin object. + * @param inputData Data entered by the user for the submission. + * @returns Whether the plugin is empty. + */ + isEmptyForEdit?( + assign: AddonModAssignAssign, + plugin: AddonModAssignPlugin, + inputData: CoreFormFields, + ): boolean; + /** * Should clear temporary data for a cancelled submission. * @@ -502,6 +516,22 @@ export class AddonModAssignSubmissionDelegateService extends CoreDelegate 0) { + return false; + } + + // Check if the online text submission contains video, audio or image elements + // that can be ignored and stripped by count_words(). + if (/<\s*((video|audio)[^>]*>(.*?)<\s*\/\s*(video|audio)>)|(img[^>]*>)/.test(text)) { + return false; + } + + return true; + } + /** * @inheritdoc */