original_string: protected static function prepare_submission_for_external($submission, workshop $workshop, $canviewauthorpublished = null,
              $canviewauthornames = null, $canviewallsubmissions = null) {
          global $USER;
  
          if (is_null($canviewauthorpublished)) {
              $canviewauthorpublished = has_capability('mod/workshop:viewauthorpublished', $workshop->context);
          }
          if (is_null($canviewauthornames)) {
              $canviewauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
          }
          if (is_null($canviewallsubmissions)) {
              $canviewallsubmissions = has_capability('mod/workshop:viewallsubmissions', $workshop->context);
          }
  
          $ownsubmission = $submission->authorid == $USER->id;
          if (!$canviewauthornames && !$ownsubmission) {
              $submission->authorid = 0;
          }
  
          // Remove grade, gradeover, gradeoverby, feedbackauthor and timegraded for non-teachers or invalid phase.
          // WS mod_workshop_external::get_grades should be used for retrieving grades by students.
          if ($workshop->phase < workshop::PHASE_EVALUATION || !$canviewallsubmissions) {
              $properties = submission_exporter::properties_definition();
              foreach ($properties as $attribute => $settings) {
                  // Special case, the feedbackauthor (and who did it) should be returned if the workshop is closed and
                  // the user can view it.
                  if (($attribute == 'feedbackauthor' || $attribute == 'gradeoverby') &&
                          $workshop->phase == workshop::PHASE_CLOSED && $ownsubmission) {
                      continue;
                  }
                  if (!empty($settings['optional'])) {
                      unset($submission->{$attribute});
                  }
              }
          }
          return $submission;
      }
code: protected static function prepare_submission_for_external($submission, workshop $workshop, $canviewauthorpublished = null,
              $canviewauthornames = null, $canviewallsubmissions = null) {
          global $USER;
  
          if (is_null($canviewauthorpublished)) {
              $canviewauthorpublished = has_capability('mod/workshop:viewauthorpublished', $workshop->context);
          }
          if (is_null($canviewauthornames)) {
              $canviewauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
          }
          if (is_null($canviewallsubmissions)) {
              $canviewallsubmissions = has_capability('mod/workshop:viewallsubmissions', $workshop->context);
          }
  
          $ownsubmission = $submission->authorid == $USER->id;
          if (!$canviewauthornames && !$ownsubmission) {
              $submission->authorid = 0;
          }
  
          // Remove grade, gradeover, gradeoverby, feedbackauthor and timegraded for non-teachers or invalid phase.
          // WS mod_workshop_external::get_grades should be used for retrieving grades by students.
          if ($workshop->phase < workshop::PHASE_EVALUATION || !$canviewallsubmissions) {
              $properties = submission_exporter::properties_definition();
              foreach ($properties as $attribute => $settings) {
                  // Special case, the feedbackauthor (and who did it) should be returned if the workshop is closed and
                  // the user can view it.
                  if (($attribute == 'feedbackauthor' || $attribute == 'gradeoverby') &&
                          $workshop->phase == workshop::PHASE_CLOSED && $ownsubmission) {
                      continue;
                  }
                  if (!empty($settings['optional'])) {
                      unset($submission->{$attribute});
                  }
              }
          }
          return $submission;
      }
code_tokens: protected static function prepare_submission_for_external ( $ submission , workshop $ workshop , $ canviewauthorpublished = null , $ canviewauthornames = null , $ canviewallsubmissions = null ) { global $ USER ; if ( is_null ( $ canviewauthorpublished ) ) { $ canviewauthorpublished = has_capability ( 'mod/workshop:viewauthorpublished' , $ workshop -> context ) ; } if ( is_null ( $ canviewauthornames ) ) { $ canviewauthornames = has_capability ( 'mod/workshop:viewauthornames' , $ workshop -> context ) ; } if ( is_null ( $ canviewallsubmissions ) ) { $ canviewallsubmissions = has_capability ( 'mod/workshop:viewallsubmissions' , $ workshop -> context ) ; } $ ownsubmission = $ submission -> authorid == $ USER -> id ; if ( ! $ canviewauthornames && ! $ ownsubmission ) { $ submission -> authorid = 0 ; } // Remove grade, gradeover, gradeoverby, feedbackauthor and timegraded for non-teachers or invalid phase. // WS mod_workshop_external::get_grades should be used for retrieving grades by students. if ( $ workshop -> phase < workshop :: PHASE_EVALUATION || ! $ canviewallsubmissions ) { $ properties = submission_exporter :: properties_definition ( ) ; foreach ( $ properties as $ attribute => $ settings ) { // Special case, the feedbackauthor (and who did it) should be returned if the workshop is closed and // the user can view it. if ( ( $ attribute == 'feedbackauthor' || $ attribute == 'gradeoverby' ) && $ workshop -> phase == workshop :: PHASE_CLOSED && $ ownsubmission ) { continue ; } if ( ! empty ( $ settings [ 'optional' ] ) ) { unset ( $ submission -> { $ attribute } ) ; } } } return $ submission ; }
docstring: Helper method for returning the submission data according the current user capabilities and current phase.
  
  @param  stdClass $submission the submission data
  @param  workshop $workshop   the workshop class
  @param  bool $canviewauthorpublished whether the user has the capability mod/workshop:viewauthorpublished on
  @param  bool $canviewauthornames whether the user has the capability mod/workshop:vviewauthornames on
  @param  bool $canviewallsubmissions whether the user has the capability mod/workshop:viewallsubmissions on
  @return stdClass object with the submission data filtered
  @since Moodle 3.4
docstring_tokens: Helper method for returning the submission data according the current user capabilities and current phase .