original_string: public function validate_submission_data($data) {
          global $DB, $USER;
  
          $errors = array();
          if (empty($data['id']) and empty($data['example'])) {
              // Make sure there is no submission saved meanwhile from another browser window.
              $sql = "SELECT COUNT(s.id)
                        FROM {workshop_submissions} s
                        JOIN {workshop} w ON (s.workshopid = w.id)
                        JOIN {course_modules} cm ON (w.id = cm.instance)
                        JOIN {modules} m ON (m.name = 'workshop' AND m.id = cm.module)
                       WHERE cm.id = ? AND s.authorid = ? AND s.example = 0";
  
              if ($DB->count_records_sql($sql, array($data['cmid'], $USER->id))) {
                  $errors['title'] = get_string('err_multiplesubmissions', 'mod_workshop');
              }
          }
          // Get the workshop record by id or cmid, depending on whether we're creating or editing a submission.
          if (empty($data['workshopid'])) {
              $workshop = $DB->get_record_select('workshop', 'id = (SELECT instance FROM {course_modules} WHERE id = ?)',
                      [$data['cmid']]);
          } else {
              $workshop = $DB->get_record('workshop', ['id' => $data['workshopid']]);
          }
  
          if (isset($data['attachment_filemanager'])) {
              $getfiles = file_get_drafarea_files($data['attachment_filemanager']);
              $attachments = $getfiles->list;
          } else {
              $attachments = array();
          }
  
          if ($workshop->submissiontypefile == WORKSHOP_SUBMISSION_TYPE_REQUIRED) {
              if (empty($attachments)) {
                  $errors['attachment_filemanager'] = get_string('err_required', 'form');
              }
          } else if ($workshop->submissiontypefile == WORKSHOP_SUBMISSION_TYPE_DISABLED && !empty($data['attachment_filemanager'])) {
              $errors['attachment_filemanager'] = get_string('submissiontypedisabled', 'mod_workshop');
          }
  
          if ($workshop->submissiontypetext == WORKSHOP_SUBMISSION_TYPE_REQUIRED && html_is_blank($data['content_editor']['text'])) {
              $errors['content_editor'] = get_string('err_required', 'form');
          } else if ($workshop->submissiontypetext == WORKSHOP_SUBMISSION_TYPE_DISABLED && !empty($data['content_editor']['text'])) {
              $errors['content_editor'] = get_string('submissiontypedisabled', 'mod_workshop');
          }
  
          // If neither type is explicitly required, one or the other must be submitted.
          if ($workshop->submissiontypetext != WORKSHOP_SUBMISSION_TYPE_REQUIRED
                  && $workshop->submissiontypefile != WORKSHOP_SUBMISSION_TYPE_REQUIRED
                  && empty($attachments) && html_is_blank($data['content_editor']['text'])) {
              $errors['content_editor'] = get_string('submissionrequiredcontent', 'mod_workshop');
              $errors['attachment_filemanager'] = get_string('submissionrequiredfile', 'mod_workshop');
          }
  
          return $errors;
      }
code: public function validate_submission_data($data) {
          global $DB, $USER;
  
          $errors = array();
          if (empty($data['id']) and empty($data['example'])) {
              // Make sure there is no submission saved meanwhile from another browser window.
              $sql = "SELECT COUNT(s.id)
                        FROM {workshop_submissions} s
                        JOIN {workshop} w ON (s.workshopid = w.id)
                        JOIN {course_modules} cm ON (w.id = cm.instance)
                        JOIN {modules} m ON (m.name = 'workshop' AND m.id = cm.module)
                       WHERE cm.id = ? AND s.authorid = ? AND s.example = 0";
  
              if ($DB->count_records_sql($sql, array($data['cmid'], $USER->id))) {
                  $errors['title'] = get_string('err_multiplesubmissions', 'mod_workshop');
              }
          }
          // Get the workshop record by id or cmid, depending on whether we're creating or editing a submission.
          if (empty($data['workshopid'])) {
              $workshop = $DB->get_record_select('workshop', 'id = (SELECT instance FROM {course_modules} WHERE id = ?)',
                      [$data['cmid']]);
          } else {
              $workshop = $DB->get_record('workshop', ['id' => $data['workshopid']]);
          }
  
          if (isset($data['attachment_filemanager'])) {
              $getfiles = file_get_drafarea_files($data['attachment_filemanager']);
              $attachments = $getfiles->list;
          } else {
              $attachments = array();
          }
  
          if ($workshop->submissiontypefile == WORKSHOP_SUBMISSION_TYPE_REQUIRED) {
              if (empty($attachments)) {
                  $errors['attachment_filemanager'] = get_string('err_required', 'form');
              }
          } else if ($workshop->submissiontypefile == WORKSHOP_SUBMISSION_TYPE_DISABLED && !empty($data['attachment_filemanager'])) {
              $errors['attachment_filemanager'] = get_string('submissiontypedisabled', 'mod_workshop');
          }
  
          if ($workshop->submissiontypetext == WORKSHOP_SUBMISSION_TYPE_REQUIRED && html_is_blank($data['content_editor']['text'])) {
              $errors['content_editor'] = get_string('err_required', 'form');
          } else if ($workshop->submissiontypetext == WORKSHOP_SUBMISSION_TYPE_DISABLED && !empty($data['content_editor']['text'])) {
              $errors['content_editor'] = get_string('submissiontypedisabled', 'mod_workshop');
          }
  
          // If neither type is explicitly required, one or the other must be submitted.
          if ($workshop->submissiontypetext != WORKSHOP_SUBMISSION_TYPE_REQUIRED
                  && $workshop->submissiontypefile != WORKSHOP_SUBMISSION_TYPE_REQUIRED
                  && empty($attachments) && html_is_blank($data['content_editor']['text'])) {
              $errors['content_editor'] = get_string('submissionrequiredcontent', 'mod_workshop');
              $errors['attachment_filemanager'] = get_string('submissionrequiredfile', 'mod_workshop');
          }
  
          return $errors;
      }
code_tokens: public function validate_submission_data ( $ data ) { global $ DB , $ USER ; $ errors = array ( ) ; if ( empty ( $ data [ 'id' ] ) and empty ( $ data [ 'example' ] ) ) { // Make sure there is no submission saved meanwhile from another browser window. $ sql = "SELECT COUNT(s.id)
                        FROM {workshop_submissions} s
                        JOIN {workshop} w ON (s.workshopid = w.id)
                        JOIN {course_modules} cm ON (w.id = cm.instance)
                        JOIN {modules} m ON (m.name = 'workshop' AND m.id = cm.module)
                       WHERE cm.id = ? AND s.authorid = ? AND s.example = 0" ; if ( $ DB -> count_records_sql ( $ sql , array ( $ data [ 'cmid' ] , $ USER -> id ) ) ) { $ errors [ 'title' ] = get_string ( 'err_multiplesubmissions' , 'mod_workshop' ) ; } } // Get the workshop record by id or cmid, depending on whether we're creating or editing a submission. if ( empty ( $ data [ 'workshopid' ] ) ) { $ workshop = $ DB -> get_record_select ( 'workshop' , 'id = (SELECT instance FROM {course_modules} WHERE id = ?)' , [ $ data [ 'cmid' ] ] ) ; } else { $ workshop = $ DB -> get_record ( 'workshop' , [ 'id' => $ data [ 'workshopid' ] ] ) ; } if ( isset ( $ data [ 'attachment_filemanager' ] ) ) { $ getfiles = file_get_drafarea_files ( $ data [ 'attachment_filemanager' ] ) ; $ attachments = $ getfiles -> list ; } else { $ attachments = array ( ) ; } if ( $ workshop -> submissiontypefile == WORKSHOP_SUBMISSION_TYPE_REQUIRED ) { if ( empty ( $ attachments ) ) { $ errors [ 'attachment_filemanager' ] = get_string ( 'err_required' , 'form' ) ; } } else if ( $ workshop -> submissiontypefile == WORKSHOP_SUBMISSION_TYPE_DISABLED && ! empty ( $ data [ 'attachment_filemanager' ] ) ) { $ errors [ 'attachment_filemanager' ] = get_string ( 'submissiontypedisabled' , 'mod_workshop' ) ; } if ( $ workshop -> submissiontypetext == WORKSHOP_SUBMISSION_TYPE_REQUIRED && html_is_blank ( $ data [ 'content_editor' ] [ 'text' ] ) ) { $ errors [ 'content_editor' ] = get_string ( 'err_required' , 'form' ) ; } else if ( $ workshop -> submissiontypetext == WORKSHOP_SUBMISSION_TYPE_DISABLED && ! empty ( $ data [ 'content_editor' ] [ 'text' ] ) ) { $ errors [ 'content_editor' ] = get_string ( 'submissiontypedisabled' , 'mod_workshop' ) ; } // If neither type is explicitly required, one or the other must be submitted. if ( $ workshop -> submissiontypetext != WORKSHOP_SUBMISSION_TYPE_REQUIRED && $ workshop -> submissiontypefile != WORKSHOP_SUBMISSION_TYPE_REQUIRED && empty ( $ attachments ) && html_is_blank ( $ data [ 'content_editor' ] [ 'text' ] ) ) { $ errors [ 'content_editor' ] = get_string ( 'submissionrequiredcontent' , 'mod_workshop' ) ; $ errors [ 'attachment_filemanager' ] = get_string ( 'submissionrequiredfile' , 'mod_workshop' ) ; } return $ errors ; }
docstring: Validates the submission form or WS data.
  
  @param  array $data the data to be validated
  @return array       the validation errors (if any)
  @since  Moodle 3.4
docstring_tokens: Validates the submission form or WS data .