MDL-61650 assign: More consistent empty text
authorDamyon Wiese <damyon@moodle.com>
Fri, 3 Aug 2018 08:52:31 +0000 (16:52 +0800)
committerDamyon Wiese <damyon@moodle.com>
Fri, 3 Aug 2018 08:52:31 +0000 (16:52 +0800)
Consistently check for empty submissions with count_words(trim($text)).

mod/assign/submission/onlinetext/locallib.php

index 85ea4dc..0388172 100644 (file)
@@ -575,8 +575,13 @@ class assign_submission_onlinetext extends assign_submission_plugin {
      */
     public function is_empty(stdClass $submission) {
         $onlinetextsubmission = $this->get_onlinetext_submission($submission->id);
+        $wordcount = 0;
 
-        return empty($onlinetextsubmission->onlinetext);
+        if (isset($onlinetextsubmission->onlinetext)) {
+            $wordcount = count_words(trim($onlinetextsubmission->onlinetext));
+        }
+
+        return $wordcount == 0;
     }
 
     /**
@@ -592,7 +597,13 @@ class assign_submission_onlinetext extends assign_submission_plugin {
         if (!isset($data->onlinetext_editor)) {
             return true;
         }
-        return !strlen((string)$data->onlinetext_editor['text']);
+        $wordcount = 0;
+
+        if (isset($data->onlinetext_editor['text'])) {
+            $wordcount = count_words(trim((string)$data->onlinetext_editor['text']));
+        }
+
+        return $wordcount == 0;
     }
 
     /**