original_string: protected static function prepare_assessment_for_external($assessment, workshop $workshop) {
          global $USER;
          static $canviewallassessments = null;
          static $canviewreviewers = null;
          static $canoverridegrades = null;
  
          // Remove all the properties that does not belong to the assessment table.
          $properties = assessment_exporter::properties_definition();
          foreach ($assessment as $key => $value) {
              if (!isset($properties[$key])) {
                  unset($assessment->{$key});
              }
          }
  
          if (is_null($canviewallassessments)) {
              $canviewallassessments = has_capability('mod/workshop:viewallassessments', $workshop->context);
          }
          if (is_null($canviewreviewers)) {
              $canviewreviewers = has_capability('mod/workshop:viewreviewernames', $workshop->context);
          }
          if (is_null($canoverridegrades)) {
              $canoverridegrades = has_capability('mod/workshop:overridegrades', $workshop->context);
          }
  
          $isreviewer = $assessment->reviewerid == $USER->id;
  
          if (!$isreviewer && is_null($assessment->grade) && !$canviewallassessments) {
              // Students do not see peer-assessment that are not graded yet.
              return null;
          }
  
          // Remove the feedback for the reviewer if:
          // I can't see it in the evaluation phase because I'm not a teacher or the reviewer AND
          // I can't see it in the assessment phase because I'm not a teacher.
          if (($workshop->phase < workshop::PHASE_EVALUATION || !($isreviewer || $canviewallassessments)) &&
                  ($workshop->phase < workshop::PHASE_ASSESSMENT || !$canviewallassessments) ) {
              // Remove all the feedback information (all the optional fields).
              foreach ($properties as $attribute => $settings) {
                  if (!empty($settings['optional'])) {
                      unset($assessment->{$attribute});
                  }
              }
          }
  
          if (!$isreviewer && !$canviewreviewers) {
              $assessment->reviewerid = 0;
          }
  
          return $assessment;
      }
code: protected static function prepare_assessment_for_external($assessment, workshop $workshop) {
          global $USER;
          static $canviewallassessments = null;
          static $canviewreviewers = null;
          static $canoverridegrades = null;
  
          // Remove all the properties that does not belong to the assessment table.
          $properties = assessment_exporter::properties_definition();
          foreach ($assessment as $key => $value) {
              if (!isset($properties[$key])) {
                  unset($assessment->{$key});
              }
          }
  
          if (is_null($canviewallassessments)) {
              $canviewallassessments = has_capability('mod/workshop:viewallassessments', $workshop->context);
          }
          if (is_null($canviewreviewers)) {
              $canviewreviewers = has_capability('mod/workshop:viewreviewernames', $workshop->context);
          }
          if (is_null($canoverridegrades)) {
              $canoverridegrades = has_capability('mod/workshop:overridegrades', $workshop->context);
          }
  
          $isreviewer = $assessment->reviewerid == $USER->id;
  
          if (!$isreviewer && is_null($assessment->grade) && !$canviewallassessments) {
              // Students do not see peer-assessment that are not graded yet.
              return null;
          }
  
          // Remove the feedback for the reviewer if:
          // I can't see it in the evaluation phase because I'm not a teacher or the reviewer AND
          // I can't see it in the assessment phase because I'm not a teacher.
          if (($workshop->phase < workshop::PHASE_EVALUATION || !($isreviewer || $canviewallassessments)) &&
                  ($workshop->phase < workshop::PHASE_ASSESSMENT || !$canviewallassessments) ) {
              // Remove all the feedback information (all the optional fields).
              foreach ($properties as $attribute => $settings) {
                  if (!empty($settings['optional'])) {
                      unset($assessment->{$attribute});
                  }
              }
          }
  
          if (!$isreviewer && !$canviewreviewers) {
              $assessment->reviewerid = 0;
          }
  
          return $assessment;
      }
code_tokens: protected static function prepare_assessment_for_external ( $ assessment , workshop $ workshop ) { global $ USER ; static $ canviewallassessments = null ; static $ canviewreviewers = null ; static $ canoverridegrades = null ; // Remove all the properties that does not belong to the assessment table. $ properties = assessment_exporter :: properties_definition ( ) ; foreach ( $ assessment as $ key => $ value ) { if ( ! isset ( $ properties [ $ key ] ) ) { unset ( $ assessment -> { $ key } ) ; } } if ( is_null ( $ canviewallassessments ) ) { $ canviewallassessments = has_capability ( 'mod/workshop:viewallassessments' , $ workshop -> context ) ; } if ( is_null ( $ canviewreviewers ) ) { $ canviewreviewers = has_capability ( 'mod/workshop:viewreviewernames' , $ workshop -> context ) ; } if ( is_null ( $ canoverridegrades ) ) { $ canoverridegrades = has_capability ( 'mod/workshop:overridegrades' , $ workshop -> context ) ; } $ isreviewer = $ assessment -> reviewerid == $ USER -> id ; if ( ! $ isreviewer && is_null ( $ assessment -> grade ) && ! $ canviewallassessments ) { // Students do not see peer-assessment that are not graded yet. return null ; } // Remove the feedback for the reviewer if: // I can't see it in the evaluation phase because I'm not a teacher or the reviewer AND // I can't see it in the assessment phase because I'm not a teacher. if ( ( $ workshop -> phase < workshop :: PHASE_EVALUATION || ! ( $ isreviewer || $ canviewallassessments ) ) && ( $ workshop -> phase < workshop :: PHASE_ASSESSMENT || ! $ canviewallassessments ) ) { // Remove all the feedback information (all the optional fields). foreach ( $ properties as $ attribute => $ settings ) { if ( ! empty ( $ settings [ 'optional' ] ) ) { unset ( $ assessment -> { $ attribute } ) ; } } } if ( ! $ isreviewer && ! $ canviewreviewers ) { $ assessment -> reviewerid = 0 ; } return $ assessment ; }
docstring: Helper method for returning the assessment data according the current user capabilities and current phase.
  
  @param  stdClass $assessment the assessment data
  @param  workshop $workshop   the workshop class
  @return stdClass object with the assessment data filtered or null if is not viewable yet
  @since Moodle 3.4
docstring_tokens: Helper method for returning the assessment data according the current user capabilities and current phase .