diff --git a/scripts/langindex.json b/scripts/langindex.json index 4c0f0bc57..d86efa26d 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -344,6 +344,7 @@ "addon.mod_assign_submission_comments.pluginname": "assignsubmission_comments", "addon.mod_assign_submission_file.pluginname": "assignsubmission_file", "addon.mod_assign_submission_onlinetext.pluginname": "assignsubmission_onlinetext", + "addon.mod_assign_submission_onlinetext.wordlimitexceeded": "assignsubmission_onlinetext", "addon.mod_book.errorchapter": "book", "addon.mod_book.modulenameplural": "book", "addon.mod_book.toc": "book", diff --git a/src/addon/mod/assign/providers/assign.ts b/src/addon/mod/assign/providers/assign.ts index 72320b5f7..93e8204f0 100644 --- a/src/addon/mod/assign/providers/assign.ts +++ b/src/addon/mod/assign/providers/assign.ts @@ -379,9 +379,13 @@ export class AddonModAssignProvider { * * @param {any} assign Assign. * @param {any} attempt Attempt. - * @return {any} Submission object. + * @return {any} Submission object or null. */ getSubmissionObjectFromAttempt(assign: any, attempt: any): any { + if (!attempt) { + return null; + } + return assign.teamsubmission ? attempt.teamsubmission : attempt.submission; } diff --git a/src/addon/mod/assign/submission/onlinetext/lang/en.json b/src/addon/mod/assign/submission/onlinetext/lang/en.json index 9b8a3d9f9..e49362133 100644 --- a/src/addon/mod/assign/submission/onlinetext/lang/en.json +++ b/src/addon/mod/assign/submission/onlinetext/lang/en.json @@ -1,3 +1,4 @@ { - "pluginname": "Online text submissions" + "pluginname": "Online text submissions", + "wordlimitexceeded": "The word limit for this assignment is {{$a.limit}} words and you are attempting to submit {{$a.count}} words. Please review your submission and try again." } \ No newline at end of file diff --git a/src/addon/mod/assign/submission/onlinetext/providers/handler.ts b/src/addon/mod/assign/submission/onlinetext/providers/handler.ts index 718a13f51..80745907b 100644 --- a/src/addon/mod/assign/submission/onlinetext/providers/handler.ts +++ b/src/addon/mod/assign/submission/onlinetext/providers/handler.ts @@ -14,6 +14,7 @@ // limitations under the License. import { Injectable, Injector } from '@angular/core'; +import { TranslateService } from '@ngx-translate/core'; import { CoreSitesProvider } from '@providers/sites'; import { CoreWSProvider } from '@providers/ws'; import { CoreTextUtilsProvider } from '@providers/utils/text'; @@ -31,7 +32,7 @@ export class AddonModAssignSubmissionOnlineTextHandler implements AddonModAssign name = 'AddonModAssignSubmissionOnlineTextHandler'; type = 'onlinetext'; - constructor(private sitesProvider: CoreSitesProvider, private wsProvider: CoreWSProvider, + constructor(private translate: TranslateService, private sitesProvider: CoreSitesProvider, private wsProvider: CoreWSProvider, private textUtils: CoreTextUtilsProvider, private assignProvider: AddonModAssignProvider, private assignOfflineProvider: AddonModAssignOfflineProvider, private assignHelper: AddonModAssignHelperProvider) { } @@ -238,6 +239,19 @@ export class AddonModAssignSubmissionOnlineTextHandler implements AddonModAssign let text = this.getTextToSubmit(plugin, inputData); + // Check word limit. + const configs = this.assignHelper.getPluginConfig(assign, 'assignsubmission', plugin.type); + if (parseInt(configs.wordlimitenabled, 10)) { + const words = this.textUtils.countWords(text); + const wordlimit = parseInt(configs.wordlimit, 10); + if (words > wordlimit) { + const params = {$a: {count: words, limit: wordlimit}}; + const message = this.translate.instant('addon.mod_assign_submission_onlinetext.wordlimitexceeded', params); + + return Promise.reject(message); + } + } + // Add some HTML to the text if needed. text = this.textUtils.formatHtmlLines(text); diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index e0c8c523a..8fd9e1499 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -344,6 +344,7 @@ "addon.mod_assign_submission_comments.pluginname": "Submission comments", "addon.mod_assign_submission_file.pluginname": "File submissions", "addon.mod_assign_submission_onlinetext.pluginname": "Online text submissions", + "addon.mod_assign_submission_onlinetext.wordlimitexceeded": "The word limit for this assignment is {{$a.limit}} words and you are attempting to submit {{$a.count}} words. Please review your submission and try again.", "addon.mod_book.errorchapter": "Error reading chapter of book.", "addon.mod_book.modulenameplural": "Books", "addon.mod_book.toc": "Table of contents",