/**
  * Validates the submitted discussion and any submitted files
  *
  * @param object $cm
  * @param object $forum
  * @param \context_module $context
  * @param object $discussion
  * @param upload_file $uploader
  * @return moodle_exception[]
  */
 public function validate_discussion($cm, $forum, $context, $discussion, upload_file $uploader)
 {
     $errors = array();
     if (!hsuforum_user_can_post_discussion($forum, $discussion->groupid, -1, $cm, $context)) {
         $errors[] = new \moodle_exception('nopostforum', 'hsuforum');
     }
     $thresholdwarning = hsuforum_check_throttling($forum, $cm);
     if ($thresholdwarning !== false && $thresholdwarning->canpost === false) {
         $errors[] = new \moodle_exception($thresholdwarning->errorcode, $thresholdwarning->module, $thresholdwarning->additional);
     }
     $subject = trim($discussion->subject);
     if (empty($subject)) {
         $errors[] = new \moodle_exception('subjectisrequired', 'hsuforum');
     }
     if (hsuforum_str_empty($discussion->message)) {
         $errors[] = new \moodle_exception('messageisrequired', 'hsuforum');
     }
     if ($uploader->was_file_uploaded()) {
         try {
             $uploader->validate_files();
         } catch (\Exception $e) {
             $errors[] = $e;
         }
     }
     return $errors;
 }
 /**
  * Validates the submitted post and any submitted files
  *
  * @param object $course
  * @param object $cm
  * @param object $forum
  * @param \context_module $context
  * @param object $discussion
  * @param object $post
  * @param upload_file $uploader
  * @return moodle_exception[]
  */
 public function validate_post($course, $cm, $forum, $context, $discussion, $post, upload_file $uploader)
 {
     global $USER;
     $errors = array();
     if (!hsuforum_user_can_post($forum, $discussion, null, $cm, $course, $context)) {
         $errors[] = new \moodle_exception('nopostforum', 'hsuforum');
     }
     if (!empty($post->id)) {
         if (!($post->userid == $USER->id && (has_capability('mod/hsuforum:replypost', $context) || has_capability('mod/hsuforum:startdiscussion', $context)) || has_capability('mod/hsuforum:editanypost', $context))) {
             $errors[] = new \moodle_exception('cannotupdatepost', 'hsuforum');
         }
     }
     if (empty($post->id)) {
         $thresholdwarning = hsuforum_check_throttling($forum, $cm);
         if ($thresholdwarning !== false && $thresholdwarning->canpost === false) {
             $errors[] = new \moodle_exception($thresholdwarning->errorcode, $thresholdwarning->module, $thresholdwarning->additional);
         }
     }
     if (hsuforum_str_empty($post->subject)) {
         $errors[] = new \moodle_exception('subjectisrequired', 'hsuforum');
     }
     if (hsuforum_str_empty($post->message)) {
         $errors[] = new \moodle_exception('messageisrequired', 'hsuforum');
     }
     if ($post->privatereply) {
         if (!has_capability('mod/hsuforum:allowprivate', $context) || !$forum->allowprivatereplies) {
             $errors[] = new \moodle_exception('cannotmakeprivatereplies', 'hsuforum');
         }
     }
     if ($uploader->was_file_uploaded()) {
         try {
             $uploader->validate_files(empty($post->id) ? 0 : $post->id);
         } catch (\Exception $e) {
             $errors[] = $e;
         }
     }
     return $errors;
 }