original_string: protected static function export_user_data_competencies(context_user $context) {
          global $DB;
  
          $userid = $context->instanceid;
          $path = [get_string('competencies', 'core_competency'), get_string('competencies', 'core_competency')];
          $helper = new performance_helper();
          $cfields = competency::get_sql_fields('c', 'c_');
          $ucfields = user_competency::get_sql_fields('uc', 'uc_');
          $efields = evidence::get_sql_fields('e', 'e_');
  
          $makecomppath = function($competencyid, $data) use ($path) {
              return array_merge($path, [$data['name'] . ' (' . $competencyid . ')']);
          };
  
          $sql = "
              SELECT $cfields, $ucfields, $efields
                FROM {" . user_competency::TABLE . "} uc
                JOIN {" . competency::TABLE . "} c
                  ON c.id = uc.competencyid
           LEFT JOIN {" . evidence::TABLE . "} e
                  ON uc.id = e.usercompetencyid
               WHERE uc.userid = :userid
            ORDER BY c.id, e.timecreated DESC, e.id DESC";
          $params = ['userid' => $userid];
  
          $recordset = $DB->get_recordset_sql($sql, $params);
          static::recordset_loop_and_export($recordset, 'c_id', null, function($carry, $record)
                  use ($context, $userid, $helper, $makecomppath) {
  
              $competency = new competency(null, competency::extract_record($record, 'c_'));
  
              if ($carry === null) {
                  $uc = new user_competency(null, user_competency::extract_record($record, 'uc_'));
                  $carry = array_merge(static::transform_competency_brief($competency), [
                      'rating' => static::transform_user_competency($userid, $uc, $competency, $helper),
                      'evidence' => []
                  ]);
                  \core_comment\privacy\provider::export_comments($context, 'competency', 'user_competency',
                      $uc->get('id'), $makecomppath($competency->get('id'), $carry), false);
              }
  
              // There is an evidence in this record.
              if (!empty($record->e_id)) {
                  $evidence = new evidence(null, evidence::extract_record($record, 'e_'));
                  $carry['evidence'][] = static::transform_evidence($userid, $evidence, $competency, $helper);
              }
  
              return $carry;
  
          }, function($competencyid, $data) use ($makecomppath, $context) {
              writer::with_context($context)->export_data($makecomppath($competencyid, $data), (object) $data);
          });
      }
code: protected static function export_user_data_competencies(context_user $context) {
          global $DB;
  
          $userid = $context->instanceid;
          $path = [get_string('competencies', 'core_competency'), get_string('competencies', 'core_competency')];
          $helper = new performance_helper();
          $cfields = competency::get_sql_fields('c', 'c_');
          $ucfields = user_competency::get_sql_fields('uc', 'uc_');
          $efields = evidence::get_sql_fields('e', 'e_');
  
          $makecomppath = function($competencyid, $data) use ($path) {
              return array_merge($path, [$data['name'] . ' (' . $competencyid . ')']);
          };
  
          $sql = "
              SELECT $cfields, $ucfields, $efields
                FROM {" . user_competency::TABLE . "} uc
                JOIN {" . competency::TABLE . "} c
                  ON c.id = uc.competencyid
           LEFT JOIN {" . evidence::TABLE . "} e
                  ON uc.id = e.usercompetencyid
               WHERE uc.userid = :userid
            ORDER BY c.id, e.timecreated DESC, e.id DESC";
          $params = ['userid' => $userid];
  
          $recordset = $DB->get_recordset_sql($sql, $params);
          static::recordset_loop_and_export($recordset, 'c_id', null, function($carry, $record)
                  use ($context, $userid, $helper, $makecomppath) {
  
              $competency = new competency(null, competency::extract_record($record, 'c_'));
  
              if ($carry === null) {
                  $uc = new user_competency(null, user_competency::extract_record($record, 'uc_'));
                  $carry = array_merge(static::transform_competency_brief($competency), [
                      'rating' => static::transform_user_competency($userid, $uc, $competency, $helper),
                      'evidence' => []
                  ]);
                  \core_comment\privacy\provider::export_comments($context, 'competency', 'user_competency',
                      $uc->get('id'), $makecomppath($competency->get('id'), $carry), false);
              }
  
              // There is an evidence in this record.
              if (!empty($record->e_id)) {
                  $evidence = new evidence(null, evidence::extract_record($record, 'e_'));
                  $carry['evidence'][] = static::transform_evidence($userid, $evidence, $competency, $helper);
              }
  
              return $carry;
  
          }, function($competencyid, $data) use ($makecomppath, $context) {
              writer::with_context($context)->export_data($makecomppath($competencyid, $data), (object) $data);
          });
      }
code_tokens: protected static function export_user_data_competencies ( context_user $ context ) { global $ DB ; $ userid = $ context -> instanceid ; $ path = [ get_string ( 'competencies' , 'core_competency' ) , get_string ( 'competencies' , 'core_competency' ) ] ; $ helper = new performance_helper ( ) ; $ cfields = competency :: get_sql_fields ( 'c' , 'c_' ) ; $ ucfields = user_competency :: get_sql_fields ( 'uc' , 'uc_' ) ; $ efields = evidence :: get_sql_fields ( 'e' , 'e_' ) ; $ makecomppath = function ( $ competencyid , $ data ) use ( $ path ) { return array_merge ( $ path , [ $ data [ 'name' ] . ' (' . $ competencyid . ')' ] ) ; } ; $ sql = "
              SELECT $cfields, $ucfields, $efields
                FROM {" . user_competency :: TABLE . "} uc
                JOIN {" . competency :: TABLE . "} c
                  ON c.id = uc.competencyid
           LEFT JOIN {" . evidence :: TABLE . "} e
                  ON uc.id = e.usercompetencyid
               WHERE uc.userid = :userid
            ORDER BY c.id, e.timecreated DESC, e.id DESC" ; $ params = [ 'userid' => $ userid ] ; $ recordset = $ DB -> get_recordset_sql ( $ sql , $ params ) ; static :: recordset_loop_and_export ( $ recordset , 'c_id' , null , function ( $ carry , $ record ) use ( $ context , $ userid , $ helper , $ makecomppath ) { $ competency = new competency ( null , competency :: extract_record ( $ record , 'c_' ) ) ; if ( $ carry === null ) { $ uc = new user_competency ( null , user_competency :: extract_record ( $ record , 'uc_' ) ) ; $ carry = array_merge ( static :: transform_competency_brief ( $ competency ) , [ 'rating' => static :: transform_user_competency ( $ userid , $ uc , $ competency , $ helper ) , 'evidence' => [ ] ] ) ; \ core_comment \ privacy \ provider :: export_comments ( $ context , 'competency' , 'user_competency' , $ uc -> get ( 'id' ) , $ makecomppath ( $ competency -> get ( 'id' ) , $ carry ) , false ) ; } // There is an evidence in this record. if ( ! empty ( $ record -> e_id ) ) { $ evidence = new evidence ( null , evidence :: extract_record ( $ record , 'e_' ) ) ; $ carry [ 'evidence' ] [ ] = static :: transform_evidence ( $ userid , $ evidence , $ competency , $ helper ) ; } return $ carry ; } , function ( $ competencyid , $ data ) use ( $ makecomppath , $ context ) { writer :: with_context ( $ context ) -> export_data ( $ makecomppath ( $ competencyid , $ data ) , ( object ) $ data ) ; } ) ; }
docstring: Export a user's competencies.
  
  @param context_user $context The context of the user requesting the export.
  @return void
docstring_tokens: Export a user s competencies .