|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00064 class backup_lesson_activity_structure_step extends backup_activity_structure_step { 00065 00066 protected function define_structure() { 00067 00068 // The lesson table 00069 // This table contains all of the goodness for the lesson module, quite 00070 // alot goes into it but nothing relational other than course when will 00071 // need to be corrected upon restore 00072 $lesson = new backup_nested_element('lesson', array('id'), array( 00073 'course','name','practice','modattempts','usepassword','password', 00074 'dependency','conditions','grade','custom','ongoing','usemaxgrade', 00075 'maxanswers','maxattempts','review','nextpagedefault','feedback', 00076 'minquestions','maxpages','timed','maxtime','retake','activitylink', 00077 'mediafile','mediaheight','mediawidth','mediaclose','slideshow', 00078 'width','height','bgcolor','displayleft','displayleftif','progressbar', 00079 'showhighscores','maxhighscores','available','deadline','timemodified' 00080 )); 00081 // Tell the lesson element about the showhighscores elements mapping to the highscores 00082 // database field. 00083 $lesson->set_source_alias('highscores', 'showhighscores'); 00084 00085 // The lesson_pages table 00086 // Grouped within a `pages` element, important to note that page is relational 00087 // to the lesson, and also to the previous/next page in the series. 00088 // Upon restore prevpageid and nextpageid will need to be corrected. 00089 $pages = new backup_nested_element('pages'); 00090 $page = new backup_nested_element('page', array('id'), array( 00091 'prevpageid','nextpageid','qtype','qoption','layout', 00092 'display','timecreated','timemodified','title','contents', 00093 'contentsformat' 00094 )); 00095 00096 // The lesson_answers table 00097 // Grouped within an answers `element`, the lesson_answers table relates 00098 // to the page and lesson with `pageid` and `lessonid` that will both need 00099 // to be corrected during restore. 00100 $answers = new backup_nested_element('answers'); 00101 $answer = new backup_nested_element('answer', array('id'), array( 00102 'jumpto','grade','score','flags','timecreated','timemodified','answer_text', 00103 'response', 'answerformat', 'responseformat' 00104 )); 00105 // Tell the answer element about the answer_text elements mapping to the answer 00106 // database field. 00107 $answer->set_source_alias('answer', 'answer_text'); 00108 00109 // The lesson_attempts table 00110 // Grouped by an `attempts` element this is relational to the page, lesson, 00111 // and user. 00112 $attempts = new backup_nested_element('attempts'); 00113 $attempt = new backup_nested_element('attempt', array('id'), array( 00114 'userid','retry','correct','useranswer','timeseen' 00115 )); 00116 00117 // The lesson_branch table 00118 // Grouped by a `branch` element this is relational to the page, lesson, 00119 // and user. 00120 $branches = new backup_nested_element('branches'); 00121 $branch = new backup_nested_element('branch', array('id'), array( 00122 'userid','retry','flag','timeseen' 00123 )); 00124 00125 // The lesson_grades table 00126 // Grouped by a grades element this is relational to the lesson and user. 00127 $grades = new backup_nested_element('grades'); 00128 $grade = new backup_nested_element('grade', array('id'), array( 00129 'userid','grade','late','completed' 00130 )); 00131 00132 // The lesson_high_scores table 00133 // Grouped by a highscores element this is relational to the lesson, user, 00134 // and possibly a grade. 00135 $highscores = new backup_nested_element('highscores'); 00136 $highscore = new backup_nested_element('highscore', array('id'), array( 00137 'gradeid','userid','nickname' 00138 )); 00139 00140 // The lesson_timer table 00141 // Grouped by a `timers` element this is relational to the lesson and user. 00142 $timers = new backup_nested_element('timers'); 00143 $timer = new backup_nested_element('timer', array('id'), array( 00144 'userid','starttime','lessontime' 00145 )); 00146 00147 // Now that we have all of the elements created we've got to put them 00148 // together correctly. 00149 $lesson->add_child($pages); 00150 $pages->add_child($page); 00151 $page->add_child($answers); 00152 $answers->add_child($answer); 00153 $answer->add_child($attempts); 00154 $attempts->add_child($attempt); 00155 $page->add_child($branches); 00156 $branches->add_child($branch); 00157 $lesson->add_child($grades); 00158 $grades->add_child($grade); 00159 $lesson->add_child($highscores); 00160 $highscores->add_child($highscore); 00161 $lesson->add_child($timers); 00162 $timers->add_child($timer); 00163 00164 // Set the source table for the elements that aren't reliant on the user 00165 // at this point (lesson, lesson_pages, lesson_answers) 00166 $lesson->set_source_table('lesson', array('id' => backup::VAR_ACTIVITYID)); 00167 //we use SQL here as it must be ordered by prevpageid so that restore gets the pages in the right order. 00168 $page->set_source_sql(" 00169 SELECT * 00170 FROM {lesson_pages} 00171 WHERE lessonid = ? ORDER BY prevpageid", 00172 array(backup::VAR_PARENTID)); 00173 00174 // We use SQL here as answers must be ordered by id so that the restore gets them in the right order 00175 $answer->set_source_sql(' 00176 SELECT * 00177 FROM {lesson_answers} 00178 WHERE pageid = :pageid 00179 ORDER BY id', 00180 array('pageid' => backup::VAR_PARENTID)); 00181 00182 // Check if we are also backing up user information 00183 if ($this->get_setting_value('userinfo')) { 00184 // Set the source table for elements that are reliant on the user 00185 // lesson_attempts, lesson_branch, lesson_grades, lesson_high_scores, lesson_timer 00186 $attempt->set_source_table('lesson_attempts', array('answerid' => backup::VAR_PARENTID)); 00187 $branch->set_source_table('lesson_branch', array('pageid' => backup::VAR_PARENTID)); 00188 $grade->set_source_table('lesson_grades', array('lessonid'=>backup::VAR_PARENTID)); 00189 $highscore->set_source_table('lesson_high_scores', array('lessonid' => backup::VAR_PARENTID)); 00190 $timer->set_source_table('lesson_timer', array('lessonid' => backup::VAR_PARENTID)); 00191 } 00192 00193 // Annotate the user id's where required. 00194 $attempt->annotate_ids('user', 'userid'); 00195 $branch->annotate_ids('user', 'userid'); 00196 $grade->annotate_ids('user', 'userid'); 00197 $highscore->annotate_ids('user', 'userid'); 00198 $timer->annotate_ids('user', 'userid'); 00199 00200 // Annotate the file areas in user by the lesson module. 00201 $lesson->annotate_files('mod_lesson', 'mediafile', null); 00202 $page->annotate_files('mod_lesson', 'page_contents', 'id'); 00203 00204 // Prepare and return the structure we have just created for the lesson module. 00205 return $this->prepare_activity_structure($lesson); 00206 } 00207 }