|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00025 defined('MOODLE_INTERNAL') || die(); 00026 00027 00034 class backup_quiz_activity_structure_step extends backup_questions_activity_structure_step { 00035 00036 protected function define_structure() { 00037 00038 // To know if we are including userinfo 00039 $userinfo = $this->get_setting_value('userinfo'); 00040 00041 // Define each element separated 00042 $quiz = new backup_nested_element('quiz', array('id'), array( 00043 'name', 'intro', 'introformat', 'timeopen', 00044 'timeclose', 'preferredbehaviour', 'attempts_number', 00045 'attemptonlast', 'grademethod', 'decimalpoints', 'questiondecimalpoints', 00046 'reviewattempt', 'reviewcorrectness', 'reviewmarks', 00047 'reviewspecificfeedback', 'reviewgeneralfeedback', 00048 'reviewrightanswer', 'reviewoverallfeedback', 00049 'questionsperpage', 'shufflequestions', 'shuffleanswers', 00050 'questions', 'sumgrades', 'grade', 'timecreated', 00051 'timemodified', 'timelimit', 'password', 'subnet', 00052 'browsersecurity', 'delay1', 'delay2', 'showuserpicture', 00053 'showblocks')); 00054 00055 // Define elements for access rule subplugin settings. 00056 $this->add_subplugin_structure('quizaccess', $quiz, true); 00057 00058 $qinstances = new backup_nested_element('question_instances'); 00059 00060 $qinstance = new backup_nested_element('question_instance', array('id'), array( 00061 'question', 'grade')); 00062 00063 $feedbacks = new backup_nested_element('feedbacks'); 00064 00065 $feedback = new backup_nested_element('feedback', array('id'), array( 00066 'feedbacktext', 'feedbacktextformat', 'mingrade', 'maxgrade')); 00067 00068 $overrides = new backup_nested_element('overrides'); 00069 00070 $override = new backup_nested_element('override', array('id'), array( 00071 'userid', 'groupid', 'timeopen', 'timeclose', 00072 'timelimit', 'attempts', 'password')); 00073 00074 $grades = new backup_nested_element('grades'); 00075 00076 $grade = new backup_nested_element('grade', array('id'), array( 00077 'userid', 'gradeval', 'timemodified')); 00078 00079 $attempts = new backup_nested_element('attempts'); 00080 00081 $attempt = new backup_nested_element('attempt', array('id'), array( 00082 'uniqueid', 'userid', 'attemptnum', 'sumgrades', 00083 'timestart', 'timefinish', 'timemodified', 'layout', 00084 'preview')); 00085 00086 // This module is using questions, so produce the related question states and sessions 00087 // attaching them to the $attempt element based in 'uniqueid' matching 00088 $this->add_question_usages($attempt, 'uniqueid'); 00089 00090 // Define elements for access rule subplugin attempt data. 00091 $this->add_subplugin_structure('quizaccess', $attempt, true); 00092 00093 // Build the tree 00094 00095 $quiz->add_child($qinstances); 00096 $qinstances->add_child($qinstance); 00097 00098 $quiz->add_child($feedbacks); 00099 $feedbacks->add_child($feedback); 00100 00101 $quiz->add_child($overrides); 00102 $overrides->add_child($override); 00103 00104 $quiz->add_child($grades); 00105 $grades->add_child($grade); 00106 00107 $quiz->add_child($attempts); 00108 $attempts->add_child($attempt); 00109 00110 // Define sources 00111 $quiz->set_source_table('quiz', array('id' => backup::VAR_ACTIVITYID)); 00112 00113 $qinstance->set_source_table('quiz_question_instances', 00114 array('quiz' => backup::VAR_PARENTID)); 00115 00116 $feedback->set_source_table('quiz_feedback', 00117 array('quizid' => backup::VAR_PARENTID)); 00118 00119 // Quiz overrides to backup are different depending of user info 00120 $overrideparams = array('quiz' => backup::VAR_PARENTID); 00121 if (!$userinfo) { // Without userinfo, skip user overrides 00122 $overrideparams['userid'] = backup_helper::is_sqlparam(null); 00123 00124 } 00125 $override->set_source_table('quiz_overrides', $overrideparams); 00126 00127 // All the rest of elements only happen if we are including user info 00128 if ($userinfo) { 00129 $grade->set_source_table('quiz_grades', array('quiz' => backup::VAR_PARENTID)); 00130 $attempt->set_source_sql(' 00131 SELECT * 00132 FROM {quiz_attempts} 00133 WHERE quiz = :quiz AND preview = 0', 00134 array('quiz' => backup::VAR_PARENTID)); 00135 } 00136 00137 // Define source alias 00138 $quiz->set_source_alias('attempts', 'attempts_number'); 00139 $grade->set_source_alias('grade', 'gradeval'); 00140 $attempt->set_source_alias('attempt', 'attemptnum'); 00141 00142 // Define id annotations 00143 $qinstance->annotate_ids('question', 'question'); 00144 $override->annotate_ids('user', 'userid'); 00145 $override->annotate_ids('group', 'groupid'); 00146 $grade->annotate_ids('user', 'userid'); 00147 $attempt->annotate_ids('user', 'userid'); 00148 00149 // Define file annotations 00150 $quiz->annotate_files('mod_quiz', 'intro', null); // This file area hasn't itemid 00151 $feedback->annotate_files('mod_quiz', 'feedback', 'id'); 00152 00153 // Return the root element (quiz), wrapped into standard activity structure 00154 return $this->prepare_activity_structure($quiz); 00155 } 00156 }