|
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 00025 require_once($CFG->dirroot.'/backup/util/xml/parser/processors/grouped_parser_processor.class.php'); 00026 00037 class restore_questions_parser_processor extends grouped_parser_processor { 00038 00039 protected $restoreid; 00040 protected $lastcatid; 00041 00042 public function __construct($restoreid) { 00043 $this->restoreid = $restoreid; 00044 $this->lastcatid = 0; 00045 parent::__construct(array()); 00046 // Set the paths we are interested on 00047 $this->add_path('/question_categories/question_category'); 00048 $this->add_path('/question_categories/question_category/questions/question'); 00049 } 00050 00051 protected function dispatch_chunk($data) { 00052 // Prepare question_category record 00053 if ($data['path'] == '/question_categories/question_category') { 00054 $info = (object)$data['tags']; 00055 $itemname = 'question_category'; 00056 $itemid = $info->id; 00057 $parentitemid = $info->contextid; 00058 $this->lastcatid = $itemid; 00059 00060 // Prepare question record 00061 } else if ($data['path'] == '/question_categories/question_category/questions/question') { 00062 $info = (object)$data['tags']; 00063 $itemname = 'question'; 00064 $itemid = $info->id; 00065 $parentitemid = $this->lastcatid; 00066 00067 // Not question_category nor question, impossible. Throw exception. 00068 } else { 00069 throw new progressive_parser_exception('restore_questions_parser_processor_unexpected_path', $data['path']); 00070 } 00071 00072 // Only load it if needed (exist same question_categoryref itemid in table) 00073 if (restore_dbops::get_backup_ids_record($this->restoreid, 'question_categoryref', $this->lastcatid)) { 00074 restore_dbops::set_backup_ids_record($this->restoreid, $itemname, $itemid, 0, $parentitemid, $info); 00075 } 00076 } 00077 00078 protected function notify_path_start($path) { 00079 // nothing to do 00080 } 00081 00082 protected function notify_path_end($path) { 00083 // nothing to do 00084 } 00085 00089 public function process_cdata($cdata) { 00090 if ($cdata === '$@NULL@$') { 00091 return null; 00092 } 00093 return $cdata; 00094 } 00095 }