MDL-35373 mod_assign Add functionality to enforce onlinetext word limit
Signed-off-by: Tony Butler <[email protected]>
This commit is contained in:
committed by
Damyon Wiese
parent
dc66404bf6
commit
651b7f179a
@@ -37,4 +37,6 @@ $string['numwords'] = '({$a} words)';
|
||||
$string['numwordsforlog'] = 'Submission word count: {$a} words';
|
||||
$string['wordlimit'] = 'Word limit';
|
||||
$string['wordlimit_help'] = 'If online text submissions are enabled, this is the maximum number ' .
|
||||
'of words that each student will be allowed to submit.';
|
||||
'of words that each student will be allowed to submit.';
|
||||
$string['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.';
|
||||
@@ -211,6 +211,13 @@ class assign_submission_onlinetext extends assign_submission_plugin {
|
||||
'id',
|
||||
false);
|
||||
|
||||
// Check word count before submitting anything.
|
||||
$exceeded = $this->check_word_count(trim($data->onlinetext));
|
||||
if ($exceeded) {
|
||||
$this->set_error($exceeded);
|
||||
return false;
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'context' => context_module::instance($this->assignment->get_course_module()->id),
|
||||
'courseid' => $this->assignment->get_course()->id,
|
||||
@@ -597,6 +604,33 @@ class assign_submission_onlinetext extends assign_submission_plugin {
|
||||
return array('onlinetext_editor' => $editorstructure);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare word count of onlinetext submission to word limit, and return result.
|
||||
*
|
||||
* @param string $submissiontext Onlinetext submission text from editor
|
||||
* @return string Error message if limit is enabled and exceeded, otherwise null
|
||||
*/
|
||||
public function check_word_count($submissiontext) {
|
||||
global $OUTPUT;
|
||||
|
||||
$wordlimitenabled = $this->get_config('wordlimitenabled');
|
||||
$wordlimit = $this->get_config('wordlimit');
|
||||
|
||||
if ($wordlimitenabled == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Count words and compare to limit.
|
||||
$wordcount = count_words($submissiontext);
|
||||
if ($wordcount <= $wordlimit) {
|
||||
return null;
|
||||
} else {
|
||||
$errormsg = get_string('wordlimitexceeded', 'assignsubmission_onlinetext',
|
||||
array('limit' => $wordlimit, 'count' => $wordcount));
|
||||
return $OUTPUT->error_text($errormsg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user