MDL-61168 mod_assign: Truncate only the online text submission

This commit is contained in:
Jun Pataleta
2018-02-02 09:21:41 +08:00
parent 7517f9ea50
commit 2cda43b3bd
2 changed files with 16 additions and 7 deletions
+6 -2
View File
@@ -2998,13 +2998,14 @@ class assign {
* Render the content in editor that is often used by plugin.
*
* @param string $filearea
* @param int $submissionid
* @param int $submissionid
* @param string $plugintype
* @param string $editor
* @param string $component
* @param bool $shortentext Whether to shorten the text content.
* @return string
*/
public function render_editor_content($filearea, $submissionid, $plugintype, $editor, $component) {
public function render_editor_content($filearea, $submissionid, $plugintype, $editor, $component, $shortentext = false) {
global $CFG;
$result = '';
@@ -3012,6 +3013,9 @@ class assign {
$plugin = $this->get_submission_plugin_by_type($plugintype);
$text = $plugin->get_editor_text($editor, $submissionid);
if ($shortentext) {
$text = shorten_text($text, 140);
}
$format = $plugin->get_editor_format($editor, $submissionid);
$finaltext = file_rewrite_pluginfile_urls($text,
+10 -5
View File
@@ -346,14 +346,18 @@ class assign_submission_onlinetext extends assign_submission_plugin {
$showviewlink = true;
if ($onlinetextsubmission) {
// This contains the shortened version of the text plus an optional 'Export to portfolio' button.
$text = $this->assignment->render_editor_content(ASSIGNSUBMISSION_ONLINETEXT_FILEAREA,
$onlinetextsubmission->submission,
$this->get_type(),
'onlinetext',
'assignsubmission_onlinetext');
'assignsubmission_onlinetext', true);
// The actual submission text.
$onlinetext = trim($onlinetextsubmission->onlinetext);
$shorttext = shorten_text($text, 140);
// The shortened version of the submission text.
$shorttext = shorten_text($onlinetext, 140);
$plagiarismlinks = '';
if (!empty($CFG->enableplagiarism)) {
@@ -365,12 +369,13 @@ class assign_submission_onlinetext extends assign_submission_plugin {
'course' => $this->assignment->get_course()->id,
'assignment' => $submission->assignment));
}
if ($text != $shorttext) {
// We compare the actual text submission and the shortened version. If they are not equal, we show the word count.
if ($onlinetext != $shorttext) {
$wordcount = get_string('numwords', 'assignsubmission_onlinetext', count_words($onlinetext));
return $plagiarismlinks . $wordcount . $shorttext;
return $plagiarismlinks . $wordcount . $text;
} else {
return $plagiarismlinks . $shorttext;
return $plagiarismlinks . $text;
}
}
return '';