[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/quiz/backup/moodle2/ -> backup_quiz_stepslib.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * @package    mod_quiz
  19   * @subpackage backup-moodle2
  20   * @copyright  2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  21   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  
  28  /**
  29   * Define all the backup steps that will be used by the backup_quiz_activity_task
  30   *
  31   * @copyright  2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  32   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class backup_quiz_activity_structure_step extends backup_questions_activity_structure_step {
  35  
  36      protected function define_structure() {
  37  
  38          // To know if we are including userinfo.
  39          $userinfo = $this->get_setting_value('userinfo');
  40  
  41          // Define each element separated.
  42          $quiz = new backup_nested_element('quiz', array('id'), array(
  43              'name', 'intro', 'introformat', 'timeopen', 'timeclose', 'timelimit',
  44              'overduehandling', 'graceperiod', 'preferredbehaviour', 'canredoquestions', 'attempts_number',
  45              'attemptonlast', 'grademethod', 'decimalpoints', 'questiondecimalpoints',
  46              'reviewattempt', 'reviewcorrectness', 'reviewmarks',
  47              'reviewspecificfeedback', 'reviewgeneralfeedback',
  48              'reviewrightanswer', 'reviewoverallfeedback',
  49              'questionsperpage', 'navmethod', 'shuffleanswers',
  50              'sumgrades', 'grade', 'timecreated',
  51              'timemodified', 'password', 'subnet', 'browsersecurity',
  52              'delay1', 'delay2', 'showuserpicture', 'showblocks', 'completionattemptsexhausted', 'completionpass'));
  53  
  54          // Define elements for access rule subplugin settings.
  55          $this->add_subplugin_structure('quizaccess', $quiz, true);
  56  
  57          $qinstances = new backup_nested_element('question_instances');
  58  
  59          $qinstance = new backup_nested_element('question_instance', array('id'), array(
  60              'slot', 'page', 'requireprevious', 'questionid', 'maxmark'));
  61  
  62          $sections = new backup_nested_element('sections');
  63  
  64          $section = new backup_nested_element('section', array('id'), array(
  65              'firstslot', 'heading', 'shufflequestions'));
  66  
  67          $feedbacks = new backup_nested_element('feedbacks');
  68  
  69          $feedback = new backup_nested_element('feedback', array('id'), array(
  70              'feedbacktext', 'feedbacktextformat', 'mingrade', 'maxgrade'));
  71  
  72          $overrides = new backup_nested_element('overrides');
  73  
  74          $override = new backup_nested_element('override', array('id'), array(
  75              'userid', 'groupid', 'timeopen', 'timeclose',
  76              'timelimit', 'attempts', 'password'));
  77  
  78          $grades = new backup_nested_element('grades');
  79  
  80          $grade = new backup_nested_element('grade', array('id'), array(
  81              'userid', 'gradeval', 'timemodified'));
  82  
  83          $attempts = new backup_nested_element('attempts');
  84  
  85          $attempt = new backup_nested_element('attempt', array('id'), array(
  86              'userid', 'attemptnum', 'uniqueid', 'layout', 'currentpage', 'preview',
  87              'state', 'timestart', 'timefinish', 'timemodified', 'timecheckstate', 'sumgrades'));
  88  
  89          // This module is using questions, so produce the related question states and sessions
  90          // attaching them to the $attempt element based in 'uniqueid' matching.
  91          $this->add_question_usages($attempt, 'uniqueid');
  92  
  93          // Define elements for access rule subplugin attempt data.
  94          $this->add_subplugin_structure('quizaccess', $attempt, true);
  95  
  96          // Build the tree.
  97          $quiz->add_child($qinstances);
  98          $qinstances->add_child($qinstance);
  99  
 100          $quiz->add_child($sections);
 101          $sections->add_child($section);
 102  
 103          $quiz->add_child($feedbacks);
 104          $feedbacks->add_child($feedback);
 105  
 106          $quiz->add_child($overrides);
 107          $overrides->add_child($override);
 108  
 109          $quiz->add_child($grades);
 110          $grades->add_child($grade);
 111  
 112          $quiz->add_child($attempts);
 113          $attempts->add_child($attempt);
 114  
 115          // Define sources.
 116          $quiz->set_source_table('quiz', array('id' => backup::VAR_ACTIVITYID));
 117  
 118          $qinstance->set_source_table('quiz_slots',
 119                  array('quizid' => backup::VAR_PARENTID));
 120  
 121          $section->set_source_table('quiz_sections',
 122                  array('quizid' => backup::VAR_PARENTID));
 123  
 124          $feedback->set_source_table('quiz_feedback',
 125                  array('quizid' => backup::VAR_PARENTID));
 126  
 127          // Quiz overrides to backup are different depending of user info.
 128          $overrideparams = array('quiz' => backup::VAR_PARENTID);
 129          if (!$userinfo) { //  Without userinfo, skip user overrides.
 130              $overrideparams['userid'] = backup_helper::is_sqlparam(null);
 131  
 132          }
 133          $override->set_source_table('quiz_overrides', $overrideparams);
 134  
 135          // All the rest of elements only happen if we are including user info.
 136          if ($userinfo) {
 137              $grade->set_source_table('quiz_grades', array('quiz' => backup::VAR_PARENTID));
 138              $attempt->set_source_sql('
 139                      SELECT *
 140                      FROM {quiz_attempts}
 141                      WHERE quiz = :quiz AND preview = 0',
 142                      array('quiz' => backup::VAR_PARENTID));
 143          }
 144  
 145          // Define source alias.
 146          $quiz->set_source_alias('attempts', 'attempts_number');
 147          $grade->set_source_alias('grade', 'gradeval');
 148          $attempt->set_source_alias('attempt', 'attemptnum');
 149  
 150          // Define id annotations.
 151          $qinstance->annotate_ids('question', 'questionid');
 152          $override->annotate_ids('user', 'userid');
 153          $override->annotate_ids('group', 'groupid');
 154          $grade->annotate_ids('user', 'userid');
 155          $attempt->annotate_ids('user', 'userid');
 156  
 157          // Define file annotations.
 158          $quiz->annotate_files('mod_quiz', 'intro', null); // This file area hasn't itemid.
 159          $feedback->annotate_files('mod_quiz', 'feedback', 'id');
 160  
 161          // Return the root element (quiz), wrapped into standard activity structure.
 162          return $this->prepare_activity_structure($quiz);
 163      }
 164  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1