original_string: public static function create_user_evidence_competency($userevidenceorid, $competencyid) {
          global $USER;
          static::require_enabled();
  
          $userevidence = $userevidenceorid;
          if (!is_object($userevidence)) {
              $userevidence = self::read_user_evidence($userevidence);
          }
  
          // Perform user evidence capability checks.
          if (!$userevidence->can_manage()) {
              $context = $userevidence->get_context();
              throw new required_capability_exception($context, 'moodle/competency:userevidencemanage', 'nopermissions', '');
          }
  
          // Perform competency capability checks.
          $competency = self::read_competency($competencyid);
  
          // Get (and create) the relation.
          $relation = user_evidence_competency::get_relation($userevidence->get('id'), $competency->get('id'));
          if (!$relation->get('id')) {
              $relation->create();
  
              $link = url::user_evidence($userevidence->get('id'));
              self::add_evidence(
                  $userevidence->get('userid'),
                  $competency,
                  $userevidence->get_context(),
                  evidence::ACTION_LOG,
                  'evidence_evidenceofpriorlearninglinked',
                  'core_competency',
                  $userevidence->get('name'),
                  false,
                  $link->out(false),
                  null,
                  $USER->id
              );
          }
  
          return $relation;
      }
code: public static function create_user_evidence_competency($userevidenceorid, $competencyid) {
          global $USER;
          static::require_enabled();
  
          $userevidence = $userevidenceorid;
          if (!is_object($userevidence)) {
              $userevidence = self::read_user_evidence($userevidence);
          }
  
          // Perform user evidence capability checks.
          if (!$userevidence->can_manage()) {
              $context = $userevidence->get_context();
              throw new required_capability_exception($context, 'moodle/competency:userevidencemanage', 'nopermissions', '');
          }
  
          // Perform competency capability checks.
          $competency = self::read_competency($competencyid);
  
          // Get (and create) the relation.
          $relation = user_evidence_competency::get_relation($userevidence->get('id'), $competency->get('id'));
          if (!$relation->get('id')) {
              $relation->create();
  
              $link = url::user_evidence($userevidence->get('id'));
              self::add_evidence(
                  $userevidence->get('userid'),
                  $competency,
                  $userevidence->get_context(),
                  evidence::ACTION_LOG,
                  'evidence_evidenceofpriorlearninglinked',
                  'core_competency',
                  $userevidence->get('name'),
                  false,
                  $link->out(false),
                  null,
                  $USER->id
              );
          }
  
          return $relation;
      }
code_tokens: public static function create_user_evidence_competency ( $ userevidenceorid , $ competencyid ) { global $ USER ; static :: require_enabled ( ) ; $ userevidence = $ userevidenceorid ; if ( ! is_object ( $ userevidence ) ) { $ userevidence = self :: read_user_evidence ( $ userevidence ) ; } // Perform user evidence capability checks. if ( ! $ userevidence -> can_manage ( ) ) { $ context = $ userevidence -> get_context ( ) ; throw new required_capability_exception ( $ context , 'moodle/competency:userevidencemanage' , 'nopermissions' , '' ) ; } // Perform competency capability checks. $ competency = self :: read_competency ( $ competencyid ) ; // Get (and create) the relation. $ relation = user_evidence_competency :: get_relation ( $ userevidence -> get ( 'id' ) , $ competency -> get ( 'id' ) ) ; if ( ! $ relation -> get ( 'id' ) ) { $ relation -> create ( ) ; $ link = url :: user_evidence ( $ userevidence -> get ( 'id' ) ) ; self :: add_evidence ( $ userevidence -> get ( 'userid' ) , $ competency , $ userevidence -> get_context ( ) , evidence :: ACTION_LOG , 'evidence_evidenceofpriorlearninglinked' , 'core_competency' , $ userevidence -> get ( 'name' ) , false , $ link -> out ( false ) , null , $ USER -> id ) ; } return $ relation ; }
docstring: Link a user evidence with a competency.
  
  @param  user_evidence|int $userevidenceorid User evidence or its ID.
  @param  int $competencyid Competency ID.
  @return user_evidence_competency
docstring_tokens: Link a user evidence with a competency .