original_string: protected static function export_user_data_in_module_contexts($userid, array $contexts) {
          global $DB;
  
          $contexts = array_filter($contexts, function($context) {
              return $context->contextlevel == CONTEXT_MODULE;
          });
          if (empty($contexts)) {
              return;
          }
  
          $path = [get_string('competencies', 'core_competency')];
          $cmids = array_map(function($context) {
              return $context->instanceid;
          }, $contexts);
  
          // Fetch all the modules with associations we created or modified.
          $compfields = competency::get_sql_fields('c', 'c_');
          $cmcfields = course_module_competency::get_sql_fields('cmc', 'cmc_');
          $ctxfields = context_helper::get_preload_record_columns_sql('ctx');
          list($insql, $inparams) = $DB->get_in_or_equal($cmids, SQL_PARAMS_NAMED);
          $sql = "
              SELECT $compfields, $cmcfields, $ctxfields
                FROM {" . course_module_competency::TABLE . "} cmc
                JOIN {" . competency::TABLE . "} c
                  ON c.id = cmc.competencyid
                JOIN {" . competency_framework::TABLE . "} f
                  ON f.id = c.competencyframeworkid
                JOIN {context} ctx
                  ON ctx.id = f.contextid
               WHERE cmc.usermodified = :userid
                 AND cmc.cmid $insql
            ORDER BY cmc.cmid";
          $params = array_merge($inparams, ['userid' => $userid]);
  
          // Export the data.
          $recordset = $DB->get_recordset_sql($sql, $params);
          static::recordset_loop_and_export($recordset, 'cmc_cmid', [], function($carry, $record) {
              context_helper::preload_from_record($record);
              $competency = new competency(null, competency::extract_record($record, 'c_'));
              $cmc = new course_module_competency(null, course_module_competency::extract_record($record, 'cmc_'));
              $carry[] = array_merge(static::transform_competency_brief($competency), [
                  'timecreated' => transform::datetime($cmc->get('timecreated')),
                  'timemodified' => transform::datetime($cmc->get('timemodified')),
                  'created_or_modified_by_you' => transform::yesno(true)
              ]);
              return $carry;
  
          }, function($cmid, $data) use ($path) {
              $context = context_module::instance($cmid);
              writer::with_context($context)->export_data($path, (object) ['associations' => $data]);
          });
      }
code: protected static function export_user_data_in_module_contexts($userid, array $contexts) {
          global $DB;
  
          $contexts = array_filter($contexts, function($context) {
              return $context->contextlevel == CONTEXT_MODULE;
          });
          if (empty($contexts)) {
              return;
          }
  
          $path = [get_string('competencies', 'core_competency')];
          $cmids = array_map(function($context) {
              return $context->instanceid;
          }, $contexts);
  
          // Fetch all the modules with associations we created or modified.
          $compfields = competency::get_sql_fields('c', 'c_');
          $cmcfields = course_module_competency::get_sql_fields('cmc', 'cmc_');
          $ctxfields = context_helper::get_preload_record_columns_sql('ctx');
          list($insql, $inparams) = $DB->get_in_or_equal($cmids, SQL_PARAMS_NAMED);
          $sql = "
              SELECT $compfields, $cmcfields, $ctxfields
                FROM {" . course_module_competency::TABLE . "} cmc
                JOIN {" . competency::TABLE . "} c
                  ON c.id = cmc.competencyid
                JOIN {" . competency_framework::TABLE . "} f
                  ON f.id = c.competencyframeworkid
                JOIN {context} ctx
                  ON ctx.id = f.contextid
               WHERE cmc.usermodified = :userid
                 AND cmc.cmid $insql
            ORDER BY cmc.cmid";
          $params = array_merge($inparams, ['userid' => $userid]);
  
          // Export the data.
          $recordset = $DB->get_recordset_sql($sql, $params);
          static::recordset_loop_and_export($recordset, 'cmc_cmid', [], function($carry, $record) {
              context_helper::preload_from_record($record);
              $competency = new competency(null, competency::extract_record($record, 'c_'));
              $cmc = new course_module_competency(null, course_module_competency::extract_record($record, 'cmc_'));
              $carry[] = array_merge(static::transform_competency_brief($competency), [
                  'timecreated' => transform::datetime($cmc->get('timecreated')),
                  'timemodified' => transform::datetime($cmc->get('timemodified')),
                  'created_or_modified_by_you' => transform::yesno(true)
              ]);
              return $carry;
  
          }, function($cmid, $data) use ($path) {
              $context = context_module::instance($cmid);
              writer::with_context($context)->export_data($path, (object) ['associations' => $data]);
          });
      }
code_tokens: protected static function export_user_data_in_module_contexts ( $ userid , array $ contexts ) { global $ DB ; $ contexts = array_filter ( $ contexts , function ( $ context ) { return $ context -> contextlevel == CONTEXT_MODULE ; } ) ; if ( empty ( $ contexts ) ) { return ; } $ path = [ get_string ( 'competencies' , 'core_competency' ) ] ; $ cmids = array_map ( function ( $ context ) { return $ context -> instanceid ; } , $ contexts ) ; // Fetch all the modules with associations we created or modified. $ compfields = competency :: get_sql_fields ( 'c' , 'c_' ) ; $ cmcfields = course_module_competency :: get_sql_fields ( 'cmc' , 'cmc_' ) ; $ ctxfields = context_helper :: get_preload_record_columns_sql ( 'ctx' ) ; list ( $ insql , $ inparams ) = $ DB -> get_in_or_equal ( $ cmids , SQL_PARAMS_NAMED ) ; $ sql = "
              SELECT $compfields, $cmcfields, $ctxfields
                FROM {" . course_module_competency :: TABLE . "} cmc
                JOIN {" . competency :: TABLE . "} c
                  ON c.id = cmc.competencyid
                JOIN {" . competency_framework :: TABLE . "} f
                  ON f.id = c.competencyframeworkid
                JOIN {context} ctx
                  ON ctx.id = f.contextid
               WHERE cmc.usermodified = :userid
                 AND cmc.cmid $insql
            ORDER BY cmc.cmid" ; $ params = array_merge ( $ inparams , [ 'userid' => $ userid ] ) ; // Export the data. $ recordset = $ DB -> get_recordset_sql ( $ sql , $ params ) ; static :: recordset_loop_and_export ( $ recordset , 'cmc_cmid' , [ ] , function ( $ carry , $ record ) { context_helper :: preload_from_record ( $ record ) ; $ competency = new competency ( null , competency :: extract_record ( $ record , 'c_' ) ) ; $ cmc = new course_module_competency ( null , course_module_competency :: extract_record ( $ record , 'cmc_' ) ) ; $ carry [ ] = array_merge ( static :: transform_competency_brief ( $ competency ) , [ 'timecreated' => transform :: datetime ( $ cmc -> get ( 'timecreated' ) ) , 'timemodified' => transform :: datetime ( $ cmc -> get ( 'timemodified' ) ) , 'created_or_modified_by_you' => transform :: yesno ( true ) ] ) ; return $ carry ; } , function ( $ cmid , $ data ) use ( $ path ) { $ context = context_module :: instance ( $ cmid ) ; writer :: with_context ( $ context ) -> export_data ( $ path , ( object ) [ 'associations' => $ data ] ) ; } ) ; }
docstring: Export the user data in module contexts.
  
  @param int $userid The user whose data we're exporting.
  @param array $contexts A list of contexts.
  @return void
docstring_tokens: Export the user data in module contexts .