original_string: public static function create_from_user_competency_viewed_in_course(user_competency_course $usercompetencycourse) {
          if (!$usercompetencycourse->get('id')) {
              throw new \coding_exception('The user competency course ID must be set.');
          }
          $params = array(
              'objectid' => $usercompetencycourse->get('id'),
              'relateduserid' => $usercompetencycourse->get('userid'),
              'other' => array(
                  'competencyid' => $usercompetencycourse->get('competencyid')
              )
          );
          $coursecontext = context_course::instance($usercompetencycourse->get('courseid'));
          $params['contextid'] = $coursecontext->id;
          $params['courseid'] = $usercompetencycourse->get('courseid');
  
          $event = static::create($params);
          $event->add_record_snapshot(user_competency_course::TABLE, $usercompetencycourse->to_record());
          return $event;
      }
code: public static function create_from_user_competency_viewed_in_course(user_competency_course $usercompetencycourse) {
          if (!$usercompetencycourse->get('id')) {
              throw new \coding_exception('The user competency course ID must be set.');
          }
          $params = array(
              'objectid' => $usercompetencycourse->get('id'),
              'relateduserid' => $usercompetencycourse->get('userid'),
              'other' => array(
                  'competencyid' => $usercompetencycourse->get('competencyid')
              )
          );
          $coursecontext = context_course::instance($usercompetencycourse->get('courseid'));
          $params['contextid'] = $coursecontext->id;
          $params['courseid'] = $usercompetencycourse->get('courseid');
  
          $event = static::create($params);
          $event->add_record_snapshot(user_competency_course::TABLE, $usercompetencycourse->to_record());
          return $event;
      }
code_tokens: public static function create_from_user_competency_viewed_in_course ( user_competency_course $ usercompetencycourse ) { if ( ! $ usercompetencycourse -> get ( 'id' ) ) { throw new \ coding_exception ( 'The user competency course ID must be set.' ) ; } $ params = array ( 'objectid' => $ usercompetencycourse -> get ( 'id' ) , 'relateduserid' => $ usercompetencycourse -> get ( 'userid' ) , 'other' => array ( 'competencyid' => $ usercompetencycourse -> get ( 'competencyid' ) ) ) ; $ coursecontext = context_course :: instance ( $ usercompetencycourse -> get ( 'courseid' ) ) ; $ params [ 'contextid' ] = $ coursecontext -> id ; $ params [ 'courseid' ] = $ usercompetencycourse -> get ( 'courseid' ) ; $ event = static :: create ( $ params ) ; $ event -> add_record_snapshot ( user_competency_course :: TABLE , $ usercompetencycourse -> to_record ( ) ) ; return $ event ; }
docstring: Convenience method to instantiate the event in course.
  
  @param user_competency_course $usercompetencycourse The user competency for the course.
  @return self
docstring_tokens: Convenience method to instantiate the event in course .