original_string: public static function export_question_usage(
              int $userid,
              \context $context,
              array $usagecontext,
              int $usage,
              \question_display_options $options,
              bool $isowner
          ) {
          // Determine the questions in this usage.
          $quba = \question_engine::load_questions_usage_by_activity($usage);
  
          $basepath = $usagecontext;
          $questionscontext = array_merge($usagecontext, [
              get_string('questions', 'core_question'),
          ]);
  
          foreach ($quba->get_attempt_iterator() as $qa) {
              $question = $qa->get_question();
              $slotno = $qa->get_slot();
              $questionnocontext = array_merge($questionscontext, [$slotno]);
  
              if ($isowner) {
                  // This user is the overal owner of the question attempt and all data wil therefore be exported.
                  //
                  // Respect _some_ of the question_display_options to ensure that they don't have access to
                  // generalfeedback and mark if the display options prevent this.
                  // This is defensible because they can submit questions without completing a quiz and perform an SAR to
                  // get prior access to the feedback and mark to improve upon it.
                  // Export the response.
                  $data = (object) [
                      'name' => $question->name,
                      'question' => $qa->get_question_summary(),
                      'answer' => $qa->get_response_summary(),
                      'timemodified' => transform::datetime($qa->timemodified),
                  ];
  
                  if ($options->marks >= \question_display_options::MARK_AND_MAX) {
                      $data->mark = $qa->format_mark($options->markdp);
                  }
  
                  if ($options->flags != \question_display_options::HIDDEN) {
                      $data->flagged = transform::yesno($qa->is_flagged());
                  }
  
                  if ($options->generalfeedback != \question_display_options::HIDDEN) {
                      $data->generalfeedback = $question->format_generalfeedback($qa);
                  }
  
                  if ($options->manualcomment != \question_display_options::HIDDEN) {
                      $behaviour = $qa->get_behaviour();
                      if ($qa->has_manual_comment()) {
                          // Note - the export of the step data will ensure that the files are exported.
                          // No need to do it again here.
                          list($comment, $commentformat, $step) = $qa->get_manual_comment();
  
                          $comment = writer::with_context($context)
                              ->rewrite_pluginfile_urls(
                                  $questionnocontext,
                                  'question',
                                  'response_bf_comment',
                                  $step->get_id(),
                                  $comment
                              );
                          $data->comment = $behaviour->format_comment($comment, $commentformat);
                      }
                  }
  
                  writer::with_context($context)
                      ->export_data($questionnocontext, $data);
  
                  // Export the step data.
                  static::export_question_attempt_steps($userid, $context, $questionnocontext, $qa, $options, $isowner);
              }
          }
      }
code: public static function export_question_usage(
              int $userid,
              \context $context,
              array $usagecontext,
              int $usage,
              \question_display_options $options,
              bool $isowner
          ) {
          // Determine the questions in this usage.
          $quba = \question_engine::load_questions_usage_by_activity($usage);
  
          $basepath = $usagecontext;
          $questionscontext = array_merge($usagecontext, [
              get_string('questions', 'core_question'),
          ]);
  
          foreach ($quba->get_attempt_iterator() as $qa) {
              $question = $qa->get_question();
              $slotno = $qa->get_slot();
              $questionnocontext = array_merge($questionscontext, [$slotno]);
  
              if ($isowner) {
                  // This user is the overal owner of the question attempt and all data wil therefore be exported.
                  //
                  // Respect _some_ of the question_display_options to ensure that they don't have access to
                  // generalfeedback and mark if the display options prevent this.
                  // This is defensible because they can submit questions without completing a quiz and perform an SAR to
                  // get prior access to the feedback and mark to improve upon it.
                  // Export the response.
                  $data = (object) [
                      'name' => $question->name,
                      'question' => $qa->get_question_summary(),
                      'answer' => $qa->get_response_summary(),
                      'timemodified' => transform::datetime($qa->timemodified),
                  ];
  
                  if ($options->marks >= \question_display_options::MARK_AND_MAX) {
                      $data->mark = $qa->format_mark($options->markdp);
                  }
  
                  if ($options->flags != \question_display_options::HIDDEN) {
                      $data->flagged = transform::yesno($qa->is_flagged());
                  }
  
                  if ($options->generalfeedback != \question_display_options::HIDDEN) {
                      $data->generalfeedback = $question->format_generalfeedback($qa);
                  }
  
                  if ($options->manualcomment != \question_display_options::HIDDEN) {
                      $behaviour = $qa->get_behaviour();
                      if ($qa->has_manual_comment()) {
                          // Note - the export of the step data will ensure that the files are exported.
                          // No need to do it again here.
                          list($comment, $commentformat, $step) = $qa->get_manual_comment();
  
                          $comment = writer::with_context($context)
                              ->rewrite_pluginfile_urls(
                                  $questionnocontext,
                                  'question',
                                  'response_bf_comment',
                                  $step->get_id(),
                                  $comment
                              );
                          $data->comment = $behaviour->format_comment($comment, $commentformat);
                      }
                  }
  
                  writer::with_context($context)
                      ->export_data($questionnocontext, $data);
  
                  // Export the step data.
                  static::export_question_attempt_steps($userid, $context, $questionnocontext, $qa, $options, $isowner);
              }
          }
      }
code_tokens: public static function export_question_usage ( int $ userid , \ context $ context , array $ usagecontext , int $ usage , \ question_display_options $ options , bool $ isowner ) { // Determine the questions in this usage. $ quba = \ question_engine :: load_questions_usage_by_activity ( $ usage ) ; $ basepath = $ usagecontext ; $ questionscontext = array_merge ( $ usagecontext , [ get_string ( 'questions' , 'core_question' ) , ] ) ; foreach ( $ quba -> get_attempt_iterator ( ) as $ qa ) { $ question = $ qa -> get_question ( ) ; $ slotno = $ qa -> get_slot ( ) ; $ questionnocontext = array_merge ( $ questionscontext , [ $ slotno ] ) ; if ( $ isowner ) { // This user is the overal owner of the question attempt and all data wil therefore be exported. // // Respect _some_ of the question_display_options to ensure that they don't have access to // generalfeedback and mark if the display options prevent this. // This is defensible because they can submit questions without completing a quiz and perform an SAR to // get prior access to the feedback and mark to improve upon it. // Export the response. $ data = ( object ) [ 'name' => $ question -> name , 'question' => $ qa -> get_question_summary ( ) , 'answer' => $ qa -> get_response_summary ( ) , 'timemodified' => transform :: datetime ( $ qa -> timemodified ) , ] ; if ( $ options -> marks >= \ question_display_options :: MARK_AND_MAX ) { $ data -> mark = $ qa -> format_mark ( $ options -> markdp ) ; } if ( $ options -> flags != \ question_display_options :: HIDDEN ) { $ data -> flagged = transform :: yesno ( $ qa -> is_flagged ( ) ) ; } if ( $ options -> generalfeedback != \ question_display_options :: HIDDEN ) { $ data -> generalfeedback = $ question -> format_generalfeedback ( $ qa ) ; } if ( $ options -> manualcomment != \ question_display_options :: HIDDEN ) { $ behaviour = $ qa -> get_behaviour ( ) ; if ( $ qa -> has_manual_comment ( ) ) { // Note - the export of the step data will ensure that the files are exported. // No need to do it again here. list ( $ comment , $ commentformat , $ step ) = $ qa -> get_manual_comment ( ) ; $ comment = writer :: with_context ( $ context ) -> rewrite_pluginfile_urls ( $ questionnocontext , 'question' , 'response_bf_comment' , $ step -> get_id ( ) , $ comment ) ; $ data -> comment = $ behaviour -> format_comment ( $ comment , $ commentformat ) ; } } writer :: with_context ( $ context ) -> export_data ( $ questionnocontext , $ data ) ; // Export the step data. static :: export_question_attempt_steps ( $ userid , $ context , $ questionnocontext , $ qa , $ options , $ isowner ) ; } } }
docstring: Export the data for all question attempts on this question usage.
  
  Where a user is the owner of the usage, then the full detail of that usage will be included.
  Where a user has been involved in the usage, but it is not their own usage, then only their specific
  involvement will be exported.
  
  @param   int             $userid     The userid to export.
  @param   \context        $context    The context that the question was used within.
  @param   array           $usagecontext  The subcontext of this usage.
  @param   int             $usage      The question usage ID.
  @param   \question_display_options   $options    The display options used for formatting.
  @param   bool            $isowner    Whether the user being exported is the user who used the question.
docstring_tokens: Export the data for all question attempts on this question usage .