[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 3 // This file is part of Moodle - http://moodle.org/ 4 // 5 // Moodle is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Moodle is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 17 18 /** 19 * This file contains the backup structure for the lesson module 20 * 21 * This is the "graphical" structure of the lesson module: 22 * 23 * lesson ------------>---------------|-------------->-----------|------------->------------| 24 * (CL,pk->id) | | | 25 * | | | | 26 * | lesson_grades lesson_high_scores lesson_timer 27 * | (UL, pk->id,fk->lessonid) (UL, pk->id,fk->lessonid) (UL, pk->id,fk->lessonid) 28 * | | 29 * | | 30 * | | 31 * | | 32 * lesson_pages----------->---------lesson_branch 33 * (CL,pk->id,fk->lessonid) (UL, pk->id,fk->pageid) 34 * | 35 * | 36 * | 37 * lesson_answers 38 * (CL,pk->id,fk->pageid) 39 * | 40 * | 41 * | 42 * lesson_attempts 43 * (UL,pk->id,fk->answerid) 44 * 45 * Meaning: pk->primary key field of the table 46 * fk->foreign key to link with parent 47 * nt->nested field (recursive data) 48 * CL->course level info 49 * UL->user level info 50 * files->table may have files) 51 * 52 * @package mod_lesson 53 * @copyright 2010 Sam Hemelryk 54 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 55 */ 56 57 /** 58 * Structure step class that informs a backup task how to backup the lesson module. 59 * 60 * @copyright 2010 Sam Hemelryk 61 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 62 */ 63 class backup_lesson_activity_structure_step extends backup_activity_structure_step { 64 65 protected function define_structure() { 66 67 // The lesson table 68 // This table contains all of the goodness for the lesson module, quite 69 // alot goes into it but nothing relational other than course when will 70 // need to be corrected upon restore 71 $lesson = new backup_nested_element('lesson', array('id'), array( 72 'course','name','practice','modattempts','usepassword','password', 73 'dependency','conditions','grade','custom','ongoing','usemaxgrade', 74 'maxanswers','maxattempts','review','nextpagedefault','feedback', 75 'minquestions','maxpages','timed','maxtime','retake','activitylink', 76 'mediafile','mediaheight','mediawidth','mediaclose','slideshow', 77 'width','height','bgcolor','displayleft','displayleftif','progressbar', 78 'showhighscores','maxhighscores','available','deadline','timemodified' 79 )); 80 // Tell the lesson element about the showhighscores elements mapping to the highscores 81 // database field. 82 $lesson->set_source_alias('highscores', 'showhighscores'); 83 84 // The lesson_pages table 85 // Grouped within a `pages` element, important to note that page is relational 86 // to the lesson, and also to the previous/next page in the series. 87 // Upon restore prevpageid and nextpageid will need to be corrected. 88 $pages = new backup_nested_element('pages'); 89 $page = new backup_nested_element('page', array('id'), array( 90 'prevpageid','nextpageid','qtype','qoption','layout', 91 'display','timecreated','timemodified','title','contents', 92 'contentsformat' 93 )); 94 95 // The lesson_answers table 96 // Grouped within an answers `element`, the lesson_answers table relates 97 // to the page and lesson with `pageid` and `lessonid` that will both need 98 // to be corrected during restore. 99 $answers = new backup_nested_element('answers'); 100 $answer = new backup_nested_element('answer', array('id'), array( 101 'jumpto','grade','score','flags','timecreated','timemodified','answer_text', 102 'response', 'answerformat', 'responseformat' 103 )); 104 // Tell the answer element about the answer_text elements mapping to the answer 105 // database field. 106 $answer->set_source_alias('answer', 'answer_text'); 107 108 // The lesson_attempts table 109 // Grouped by an `attempts` element this is relational to the page, lesson, 110 // and user. 111 $attempts = new backup_nested_element('attempts'); 112 $attempt = new backup_nested_element('attempt', array('id'), array( 113 'userid','retry','correct','useranswer','timeseen' 114 )); 115 116 // The lesson_branch table 117 // Grouped by a `branch` element this is relational to the page, lesson, 118 // and user. 119 $branches = new backup_nested_element('branches'); 120 $branch = new backup_nested_element('branch', array('id'), array( 121 'userid','retry','flag','timeseen' 122 )); 123 124 // The lesson_grades table 125 // Grouped by a grades element this is relational to the lesson and user. 126 $grades = new backup_nested_element('grades'); 127 $grade = new backup_nested_element('grade', array('id'), array( 128 'userid','grade','late','completed' 129 )); 130 131 // The lesson_high_scores table 132 // Grouped by a highscores element this is relational to the lesson, user, 133 // and possibly a grade. 134 $highscores = new backup_nested_element('highscores'); 135 $highscore = new backup_nested_element('highscore', array('id'), array( 136 'gradeid','userid','nickname' 137 )); 138 139 // The lesson_timer table 140 // Grouped by a `timers` element this is relational to the lesson and user. 141 $timers = new backup_nested_element('timers'); 142 $timer = new backup_nested_element('timer', array('id'), array( 143 'userid','starttime','lessontime' 144 )); 145 146 // Now that we have all of the elements created we've got to put them 147 // together correctly. 148 $lesson->add_child($pages); 149 $pages->add_child($page); 150 $page->add_child($answers); 151 $answers->add_child($answer); 152 $answer->add_child($attempts); 153 $attempts->add_child($attempt); 154 $page->add_child($branches); 155 $branches->add_child($branch); 156 $lesson->add_child($grades); 157 $grades->add_child($grade); 158 $lesson->add_child($highscores); 159 $highscores->add_child($highscore); 160 $lesson->add_child($timers); 161 $timers->add_child($timer); 162 163 // Set the source table for the elements that aren't reliant on the user 164 // at this point (lesson, lesson_pages, lesson_answers) 165 $lesson->set_source_table('lesson', array('id' => backup::VAR_ACTIVITYID)); 166 //we use SQL here as it must be ordered by prevpageid so that restore gets the pages in the right order. 167 $page->set_source_table('lesson_pages', array('lessonid' => backup::VAR_PARENTID), 'prevpageid ASC'); 168 169 // We use SQL here as answers must be ordered by id so that the restore gets them in the right order 170 $answer->set_source_table('lesson_answers', array('pageid' => backup::VAR_PARENTID), 'id ASC'); 171 172 // Check if we are also backing up user information 173 if ($this->get_setting_value('userinfo')) { 174 // Set the source table for elements that are reliant on the user 175 // lesson_attempts, lesson_branch, lesson_grades, lesson_high_scores, lesson_timer 176 $attempt->set_source_table('lesson_attempts', array('answerid' => backup::VAR_PARENTID)); 177 $branch->set_source_table('lesson_branch', array('pageid' => backup::VAR_PARENTID)); 178 $grade->set_source_table('lesson_grades', array('lessonid'=>backup::VAR_PARENTID)); 179 $highscore->set_source_table('lesson_high_scores', array('lessonid' => backup::VAR_PARENTID)); 180 $timer->set_source_table('lesson_timer', array('lessonid' => backup::VAR_PARENTID)); 181 } 182 183 // Annotate the user id's where required. 184 $attempt->annotate_ids('user', 'userid'); 185 $branch->annotate_ids('user', 'userid'); 186 $grade->annotate_ids('user', 'userid'); 187 $highscore->annotate_ids('user', 'userid'); 188 $timer->annotate_ids('user', 'userid'); 189 190 // Annotate the file areas in user by the lesson module. 191 $lesson->annotate_files('mod_lesson', 'mediafile', null); 192 $page->annotate_files('mod_lesson', 'page_contents', 'id'); 193 $answer->annotate_files('mod_lesson', 'page_answers', 'id'); 194 $answer->annotate_files('mod_lesson', 'page_responses', 'id'); 195 196 // Prepare and return the structure we have just created for the lesson module. 197 return $this->prepare_activity_structure($lesson); 198 } 199 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |