[ Index ]

PHP Cross Reference of moodle-2.8

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', 'attempts_number',
  45              'attemptonlast', 'grademethod', 'decimalpoints', 'questiondecimalpoints',
  46              'reviewattempt', 'reviewcorrectness', 'reviewmarks',
  47              'reviewspecificfeedback', 'reviewgeneralfeedback',
  48              'reviewrightanswer', 'reviewoverallfeedback',
  49              'questionsperpage', 'navmethod', 'shufflequestions', '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', 'questionid', 'maxmark'));
  61  
  62          $feedbacks = new backup_nested_element('feedbacks');
  63  
  64          $feedback = new backup_nested_element('feedback', array('id'), array(
  65              'feedbacktext', 'feedbacktextformat', 'mingrade', 'maxgrade'));
  66  
  67          $overrides = new backup_nested_element('overrides');
  68  
  69          $override = new backup_nested_element('override', array('id'), array(
  70              'userid', 'groupid', 'timeopen', 'timeclose',
  71              'timelimit', 'attempts', 'password'));
  72  
  73          $grades = new backup_nested_element('grades');
  74  
  75          $grade = new backup_nested_element('grade', array('id'), array(
  76              'userid', 'gradeval', 'timemodified'));
  77  
  78          $attempts = new backup_nested_element('attempts');
  79  
  80          $attempt = new backup_nested_element('attempt', array('id'), array(
  81              'userid', 'attemptnum', 'uniqueid', 'layout', 'currentpage', 'preview',
  82              'state', 'timestart', 'timefinish', 'timemodified', 'timecheckstate', 'sumgrades'));
  83  
  84          // This module is using questions, so produce the related question states and sessions
  85          // attaching them to the $attempt element based in 'uniqueid' matching.
  86          $this->add_question_usages($attempt, 'uniqueid');
  87  
  88          // Define elements for access rule subplugin attempt data.
  89          $this->add_subplugin_structure('quizaccess', $attempt, true);
  90  
  91          // Build the tree.
  92          $quiz->add_child($qinstances);
  93          $qinstances->add_child($qinstance);
  94  
  95          $quiz->add_child($feedbacks);
  96          $feedbacks->add_child($feedback);
  97  
  98          $quiz->add_child($overrides);
  99          $overrides->add_child($override);
 100  
 101          $quiz->add_child($grades);
 102          $grades->add_child($grade);
 103  
 104          $quiz->add_child($attempts);
 105          $attempts->add_child($attempt);
 106  
 107          // Define sources.
 108          $quiz->set_source_table('quiz', array('id' => backup::VAR_ACTIVITYID));
 109  
 110          $qinstance->set_source_table('quiz_slots',
 111                  array('quizid' => backup::VAR_PARENTID));
 112  
 113          $feedback->set_source_table('quiz_feedback',
 114                  array('quizid' => backup::VAR_PARENTID));
 115  
 116          // Quiz overrides to backup are different depending of user info.
 117          $overrideparams = array('quiz' => backup::VAR_PARENTID);
 118          if (!$userinfo) { //  Without userinfo, skip user overrides.
 119              $overrideparams['userid'] = backup_helper::is_sqlparam(null);
 120  
 121          }
 122          $override->set_source_table('quiz_overrides', $overrideparams);
 123  
 124          // All the rest of elements only happen if we are including user info.
 125          if ($userinfo) {
 126              $grade->set_source_table('quiz_grades', array('quiz' => backup::VAR_PARENTID));
 127              $attempt->set_source_sql('
 128                      SELECT *
 129                      FROM {quiz_attempts}
 130                      WHERE quiz = :quiz AND preview = 0',
 131                      array('quiz' => backup::VAR_PARENTID));
 132          }
 133  
 134          // Define source alias.
 135          $quiz->set_source_alias('attempts', 'attempts_number');
 136          $grade->set_source_alias('grade', 'gradeval');
 137          $attempt->set_source_alias('attempt', 'attemptnum');
 138  
 139          // Define id annotations.
 140          $qinstance->annotate_ids('question', 'questionid');
 141          $override->annotate_ids('user', 'userid');
 142          $override->annotate_ids('group', 'groupid');
 143          $grade->annotate_ids('user', 'userid');
 144          $attempt->annotate_ids('user', 'userid');
 145  
 146          // Define file annotations.
 147          $quiz->annotate_files('mod_quiz', 'intro', null); // This file area hasn't itemid.
 148          $feedback->annotate_files('mod_quiz', 'feedback', 'id');
 149  
 150          // Return the root element (quiz), wrapped into standard activity structure.
 151          return $this->prepare_activity_structure($quiz);
 152      }
 153  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1