/**
  * Attach to $element (usually attempts) the needed backup structures
  * for question_usages and all the associated data.
  */
 protected function add_question_usages($element, $usageidname)
 {
     global $CFG;
     require_once $CFG->dirroot . '/question/engine/lib.php';
     // Check $element is one nested_backup_element
     if (!$element instanceof backup_nested_element) {
         throw new backup_step_exception('question_states_bad_parent_element', $element);
     }
     if (!$element->get_final_element($usageidname)) {
         throw new backup_step_exception('question_states_bad_question_attempt_element', $usageidname);
     }
     $quba = new backup_nested_element('question_usage', array('id'), array('component', 'preferredbehaviour'));
     $qas = new backup_nested_element('question_attempts');
     $qa = new backup_nested_element('question_attempt', array('id'), array('slot', 'behaviour', 'questionid', 'maxmark', 'minfraction', 'flagged', 'questionsummary', 'rightanswer', 'responsesummary', 'timemodified'));
     $steps = new backup_nested_element('steps');
     $step = new backup_nested_element('step', array('id'), array('sequencenumber', 'state', 'fraction', 'timecreated', 'userid'));
     $response = new backup_nested_element('response');
     $variable = new backup_nested_element('variable', null, array('name', 'value'));
     // Build the tree
     $element->add_child($quba);
     $quba->add_child($qas);
     $qas->add_child($qa);
     $qa->add_child($steps);
     $steps->add_child($step);
     $step->add_child($response);
     $response->add_child($variable);
     // Set the sources
     $quba->set_source_table('question_usages', array('id' => '../' . $usageidname));
     $qa->set_source_sql('
             SELECT *
             FROM {question_attempts}
             WHERE questionusageid = :questionusageid
             ORDER BY slot', array('questionusageid' => backup::VAR_PARENTID));
     $step->set_source_sql('
             SELECT *
             FROM {question_attempt_steps}
             WHERE questionattemptid = :questionattemptid
             ORDER BY sequencenumber', array('questionattemptid' => backup::VAR_PARENTID));
     $variable->set_source_table('question_attempt_step_data', array('attemptstepid' => backup::VAR_PARENTID));
     // Annotate ids
     $qa->annotate_ids('question', 'questionid');
     $step->annotate_ids('user', 'userid');
     // Annotate files
     $fileareas = question_engine::get_all_response_file_areas();
     foreach ($fileareas as $filearea) {
         $step->annotate_files('question', $filearea, 'id');
     }
 }
Exemple #2
0
 protected function after_execute()
 {
     parent::after_execute();
     // Restore any files belonging to responses.
     foreach (question_engine::get_all_response_file_areas() as $filearea) {
         $this->add_related_files('question', $filearea, 'question_attempt_step');
     }
 }
Exemple #3
0
 /**
  * Delete all the files belonging to the response variables in the gives
  * question attempt steps.
  * @param int $contextid the context these attempts belong to.
  * @param string $itemidstest a bit of SQL that can be used in a
  *      WHERE itemid $itemidstest clause. Must use named params.
  * @param array $params any query parameters used in $itemidstest.
  */
 protected function delete_response_files($contextid, $itemidstest, $params)
 {
     $fs = get_file_storage();
     foreach (question_engine::get_all_response_file_areas() as $filearea) {
         $fs->delete_area_files_select($contextid, 'question', $filearea, $itemidstest, $params);
     }
 }