original_string: public static function add_submission($workshopid, $title, $content = '', $contentformat = FORMAT_MOODLE,
              $inlineattachmentsid = 0, $attachmentsid = 0) {
          global $USER;
  
          $params = self::validate_parameters(self::add_submission_parameters(), array(
              'workshopid' => $workshopid,
              'title' => $title,
              'content' => $content,
              'contentformat' => $contentformat,
              'inlineattachmentsid' => $inlineattachmentsid,
              'attachmentsid' => $attachmentsid,
          ));
          $warnings = array();
  
          // Get and validate the workshop.
          list($workshop, $course, $cm, $context) = self::validate_workshop($params['workshopid']);
          require_capability('mod/workshop:submit', $context);
  
          // Check if we can submit now.
          $canaddsubmission = $workshop->creating_submission_allowed($USER->id);
          $canaddsubmission = $canaddsubmission && $workshop->check_examples_assessed_before_submission($USER->id);
          if (!$canaddsubmission) {
              throw new moodle_exception('nopermissions', 'error', '', 'add submission');
          }
  
          // Prepare the submission object.
          $submission = new stdClass;
          $submission->id = null;
          $submission->cmid = $cm->id;
          $submission->example = 0;
          $submission->title = trim($params['title']);
          $submission->content_editor = array(
              'text' => $params['content'],
              'format' => $params['contentformat'],
              'itemid' => $params['inlineattachmentsid'],
          );
          $submission->attachment_filemanager = $params['attachmentsid'];
  
          if (empty($submission->title)) {
              throw new moodle_exception('errorinvalidparam', 'webservice', '', 'title');
          }
  
          $errors = $workshop->validate_submission_data((array) $submission);
          // We can get several errors, return them in warnings.
          if (!empty($errors)) {
              $submission->id = 0;
              foreach ($errors as $itemname => $message) {
                  $warnings[] = array(
                      'item' => $itemname,
                      'itemid' => 0,
                      'warningcode' => 'fielderror',
                      'message' => s($message)
                  );
              }
              return array(
                  'status' => false,
                  'warnings' => $warnings
              );
          } else {
              $submission->id = $workshop->edit_submission($submission);
              return array(
                  'status' => true,
                  'submissionid' => $submission->id,
                  'warnings' => $warnings
              );
          }
      }
code: public static function add_submission($workshopid, $title, $content = '', $contentformat = FORMAT_MOODLE,
              $inlineattachmentsid = 0, $attachmentsid = 0) {
          global $USER;
  
          $params = self::validate_parameters(self::add_submission_parameters(), array(
              'workshopid' => $workshopid,
              'title' => $title,
              'content' => $content,
              'contentformat' => $contentformat,
              'inlineattachmentsid' => $inlineattachmentsid,
              'attachmentsid' => $attachmentsid,
          ));
          $warnings = array();
  
          // Get and validate the workshop.
          list($workshop, $course, $cm, $context) = self::validate_workshop($params['workshopid']);
          require_capability('mod/workshop:submit', $context);
  
          // Check if we can submit now.
          $canaddsubmission = $workshop->creating_submission_allowed($USER->id);
          $canaddsubmission = $canaddsubmission && $workshop->check_examples_assessed_before_submission($USER->id);
          if (!$canaddsubmission) {
              throw new moodle_exception('nopermissions', 'error', '', 'add submission');
          }
  
          // Prepare the submission object.
          $submission = new stdClass;
          $submission->id = null;
          $submission->cmid = $cm->id;
          $submission->example = 0;
          $submission->title = trim($params['title']);
          $submission->content_editor = array(
              'text' => $params['content'],
              'format' => $params['contentformat'],
              'itemid' => $params['inlineattachmentsid'],
          );
          $submission->attachment_filemanager = $params['attachmentsid'];
  
          if (empty($submission->title)) {
              throw new moodle_exception('errorinvalidparam', 'webservice', '', 'title');
          }
  
          $errors = $workshop->validate_submission_data((array) $submission);
          // We can get several errors, return them in warnings.
          if (!empty($errors)) {
              $submission->id = 0;
              foreach ($errors as $itemname => $message) {
                  $warnings[] = array(
                      'item' => $itemname,
                      'itemid' => 0,
                      'warningcode' => 'fielderror',
                      'message' => s($message)
                  );
              }
              return array(
                  'status' => false,
                  'warnings' => $warnings
              );
          } else {
              $submission->id = $workshop->edit_submission($submission);
              return array(
                  'status' => true,
                  'submissionid' => $submission->id,
                  'warnings' => $warnings
              );
          }
      }
code_tokens: public static function add_submission ( $ workshopid , $ title , $ content = '' , $ contentformat = FORMAT_MOODLE , $ inlineattachmentsid = 0 , $ attachmentsid = 0 ) { global $ USER ; $ params = self :: validate_parameters ( self :: add_submission_parameters ( ) , array ( 'workshopid' => $ workshopid , 'title' => $ title , 'content' => $ content , 'contentformat' => $ contentformat , 'inlineattachmentsid' => $ inlineattachmentsid , 'attachmentsid' => $ attachmentsid , ) ) ; $ warnings = array ( ) ; // Get and validate the workshop. list ( $ workshop , $ course , $ cm , $ context ) = self :: validate_workshop ( $ params [ 'workshopid' ] ) ; require_capability ( 'mod/workshop:submit' , $ context ) ; // Check if we can submit now. $ canaddsubmission = $ workshop -> creating_submission_allowed ( $ USER -> id ) ; $ canaddsubmission = $ canaddsubmission && $ workshop -> check_examples_assessed_before_submission ( $ USER -> id ) ; if ( ! $ canaddsubmission ) { throw new moodle_exception ( 'nopermissions' , 'error' , '' , 'add submission' ) ; } // Prepare the submission object. $ submission = new stdClass ; $ submission -> id = null ; $ submission -> cmid = $ cm -> id ; $ submission -> example = 0 ; $ submission -> title = trim ( $ params [ 'title' ] ) ; $ submission -> content_editor = array ( 'text' => $ params [ 'content' ] , 'format' => $ params [ 'contentformat' ] , 'itemid' => $ params [ 'inlineattachmentsid' ] , ) ; $ submission -> attachment_filemanager = $ params [ 'attachmentsid' ] ; if ( empty ( $ submission -> title ) ) { throw new moodle_exception ( 'errorinvalidparam' , 'webservice' , '' , 'title' ) ; } $ errors = $ workshop -> validate_submission_data ( ( array ) $ submission ) ; // We can get several errors, return them in warnings. if ( ! empty ( $ errors ) ) { $ submission -> id = 0 ; foreach ( $ errors as $ itemname => $ message ) { $ warnings [ ] = array ( 'item' => $ itemname , 'itemid' => 0 , 'warningcode' => 'fielderror' , 'message' => s ( $ message ) ) ; } return array ( 'status' => false , 'warnings' => $ warnings ) ; } else { $ submission -> id = $ workshop -> edit_submission ( $ submission ) ; return array ( 'status' => true , 'submissionid' => $ submission -> id , 'warnings' => $ warnings ) ; } }
docstring: Add a new submission to a given workshop.
  
  @param int $workshopid the workshop id
  @param string $title             the submission title
  @param string  $content          the submission text content
  @param int  $contentformat       the format used for the content
  @param int $inlineattachmentsid  the draft file area id for inline attachments in the content
  @param int $attachmentsid        the draft file area id for attachments
  @return array Containing the new created submission id and warnings.
  @since Moodle 3.4
  @throws moodle_exception
docstring_tokens: Add a new submission to a given workshop .