Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/quiz/backup/moodle1/lib.php
Go to the documentation of this file.
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 
00027 defined('MOODLE_INTERNAL') || die();
00028 
00032 class moodle1_mod_quiz_handler extends moodle1_mod_handler {
00033 
00035     protected $fileman = null;
00036 
00038     protected $moduleid = null;
00039 
00053     public function get_paths() {
00054         return array(
00055             new convert_path(
00056                 'quiz', '/MOODLE_BACKUP/COURSE/MODULES/MOD/QUIZ',
00057                 array(
00058                     'newfields' => array(
00059                         'showuserpicture'   => 0,
00060                         'questiondecimalpoints' => -2,
00061                         'introformat'   => 0,
00062                         'showblocks'    => 0,
00063                     )
00064                 )
00065             ),
00066             new convert_path('quiz_question_instances',
00067                     '/MOODLE_BACKUP/COURSE/MODULES/MOD/QUIZ/QUESTION_INSTANCES'),
00068             new convert_path('quiz_question_instance',
00069                     '/MOODLE_BACKUP/COURSE/MODULES/MOD/QUIZ/QUESTION_INSTANCES/QUESTION_INSTANCE'),
00070             new convert_path('quiz_feedbacks',
00071                     '/MOODLE_BACKUP/COURSE/MODULES/MOD/QUIZ/FEEDBACKS'),
00072             new convert_path('quiz_feedback',
00073                     '/MOODLE_BACKUP/COURSE/MODULES/MOD/QUIZ/FEEDBACKS/FEEDBACK',
00074                 array(
00075                     'newfields' => array(
00076                         'feedbacktextformat' => 0
00077                     )
00078                 )
00079             )
00080         );
00081     }
00082 
00087     public function process_quiz($data) {
00088         global $CFG;
00089 
00090         // replay the upgrade step 2008081501
00091         if (is_null($data['sumgrades'])) {
00092             $data['sumgrades'] = 0;
00093             //@todo for user data: quiz_attempts SET sumgrades=0 WHERE sumgrades IS NULL
00094             //@todo for user data: quiz_grades.grade should be not be null , convert to default 0
00095         }
00096 
00097         // replay the upgrade step 2009042000
00098         if ($CFG->texteditors !== 'textarea') {
00099             $data['intro']       = text_to_html($data['intro'], false, false, true);
00100             $data['introformat'] = FORMAT_HTML;
00101         }
00102 
00103         // replay the upgrade step 2009031001
00104         $data['timelimit'] *= 60;
00105 
00106         // get the course module id and context id
00107         $instanceid     = $data['id'];
00108         $cminfo         = $this->get_cminfo($instanceid);
00109         $this->moduleid = $cminfo['id'];
00110         $contextid      = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
00111 
00112         // get a fresh new file manager for this instance
00113         $this->fileman = $this->converter->get_file_manager($contextid, 'mod_quiz');
00114 
00115         // convert course files embedded into the intro
00116         $this->fileman->filearea = 'intro';
00117         $this->fileman->itemid   = 0;
00118         $data['intro'] = moodle1_converter::migrate_referenced_files(
00119                 $data['intro'], $this->fileman);
00120 
00121         // start writing quiz.xml
00122         $this->open_xml_writer("activities/quiz_{$this->moduleid}/quiz.xml");
00123         $this->xmlwriter->begin_tag('activity', array('id' => $instanceid,
00124                 'moduleid' => $this->moduleid, 'modulename' => 'quiz',
00125                 'contextid' => $contextid));
00126         $this->xmlwriter->begin_tag('quiz', array('id' => $instanceid));
00127 
00128         foreach ($data as $field => $value) {
00129             if ($field <> 'id') {
00130                 $this->xmlwriter->full_tag($field, $value);
00131             }
00132         }
00133 
00134         return $data;
00135     }
00136 
00137     public function on_quiz_question_instances_start() {
00138         $this->xmlwriter->begin_tag('question_instances');
00139     }
00140 
00141     public function on_quiz_question_instances_end() {
00142         $this->xmlwriter->end_tag('question_instances');
00143     }
00144 
00145     public function process_quiz_question_instance($data) {
00146         $this->write_xml('question_instance', $data, array('/question_instance/id'));
00147     }
00148 
00149     public function on_quiz_feedbacks_start() {
00150         $this->xmlwriter->begin_tag('feedbacks');
00151     }
00152 
00153     public function on_quiz_feedbacks_end() {
00154         $this->xmlwriter->end_tag('feedbacks');
00155     }
00156 
00157     public function process_quiz_feedback($data) {
00158         // replay the upgrade step 2010122302
00159         if (is_null($data['mingrade'])) {
00160             $data['mingrade'] = 0;
00161         }
00162         if (is_null($data['maxgrade'])) {
00163             $data['maxgrade'] = 0;
00164         }
00165 
00166         $this->write_xml('feedback', $data, array('/feedback/id'));
00167     }
00168 
00172     public function on_quiz_end() {
00173 
00174         // append empty <overrides> subpath element
00175         $this->write_xml('overrides', array());
00176 
00177         // finish writing quiz.xml
00178         $this->xmlwriter->end_tag('quiz');
00179         $this->xmlwriter->end_tag('activity');
00180         $this->close_xml_writer();
00181 
00182         // write inforef.xml
00183         $this->open_xml_writer("activities/quiz_{$this->moduleid}/inforef.xml");
00184         $this->xmlwriter->begin_tag('inforef');
00185         $this->xmlwriter->begin_tag('fileref');
00186         foreach ($this->fileman->get_fileids() as $fileid) {
00187             $this->write_xml('file', array('id' => $fileid));
00188         }
00189         $this->xmlwriter->end_tag('fileref');
00190         $this->xmlwriter->end_tag('inforef');
00191         $this->close_xml_writer();
00192     }
00193 }
 All Data Structures Namespaces Files Functions Variables Enumerations