Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/workshop/backup/moodle1/lib.php
Go to the documentation of this file.
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 
00027 defined('MOODLE_INTERNAL') || die();
00028 
00029 require_once($CFG->dirroot.'/mod/workshop/db/upgradelib.php');
00030 
00034 class moodle1_mod_workshop_handler extends moodle1_mod_handler {
00035 
00037     protected $currentworkshop = null;
00038 
00040     protected $currentcminfo = null;
00041 
00043     protected $newelementids = array();
00044 
00046     protected $fileman = null;
00047 
00049     protected $inforefman = null;
00050 
00052     private $strategyhandlers = null;
00053 
00055     private $currentelementid = null;
00056 
00071     public function get_paths() {
00072         return array(
00073             new convert_path('workshop', '/MOODLE_BACKUP/COURSE/MODULES/MOD/WORKSHOP'),
00074             new convert_path('workshop_elements', '/MOODLE_BACKUP/COURSE/MODULES/MOD/WORKSHOP/ELEMENTS'),
00075             new convert_path(
00076                 'workshop_element', '/MOODLE_BACKUP/COURSE/MODULES/MOD/WORKSHOP/ELEMENTS/ELEMENT',
00077                 array(
00078                     'dropfields' => array(
00079                         'stddev',
00080                         'totalassessments',
00081                     ),
00082                 )
00083             ),
00084             new convert_path('workshop_element_rubric', '/MOODLE_BACKUP/COURSE/MODULES/MOD/WORKSHOP/ELEMENTS/ELEMENT/RUBRICS/RUBRIC'),
00085         );
00086     }
00087 
00092     public function process_workshop($data, $raw) {
00093 
00094         // re-use the upgrade function to convert workshop record
00095         $fakerecord = (object)$data;
00096         $fakerecord->course = 12345678;
00097         $this->currentworkshop = (array)workshop_upgrade_transform_instance($fakerecord);
00098         unset($this->currentworkshop['course']);
00099 
00100         // add the new fields with the default values
00101         $this->currentworkshop['id']                        = $data['id'];
00102         $this->currentworkshop['evaluation']                = 'best';
00103         $this->currentworkshop['examplesmode']              = workshop::EXAMPLES_VOLUNTARY;
00104         $this->currentworkshop['gradedecimals']             = 0;
00105         $this->currentworkshop['instructauthors']           = '';
00106         $this->currentworkshop['instructauthorsformat']     = FORMAT_HTML;
00107         $this->currentworkshop['instructreviewers']         = '';
00108         $this->currentworkshop['instructreviewersformat']   = FORMAT_HTML;
00109         $this->currentworkshop['latesubmissions']           = 0;
00110 
00111         foreach (array('submissionend', 'submissionstart', 'assessmentend', 'assessmentstart') as $field) {
00112             if (!array_key_exists($field, $this->currentworkshop)) {
00113                 $this->currentworkshop[$field] = null;
00114             }
00115         }
00116 
00117         // get the course module id and context id
00118         $instanceid          = $data['id'];
00119         $this->currentcminfo = $this->get_cminfo($instanceid);
00120         $moduleid            = $this->currentcminfo['id'];
00121         $contextid           = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid);
00122 
00123         // get a fresh new inforef manager for this instance
00124         $this->inforefman = $this->converter->get_inforef_manager('activity', $moduleid);
00125 
00126         // get a fresh new file manager for this instance
00127         $this->fileman = $this->converter->get_file_manager($contextid, 'mod_workshop');
00128 
00129         // convert course files embedded into the intro
00130         $this->fileman->filearea = 'intro';
00131         $this->fileman->itemid   = 0;
00132         $this->currentworkshop['intro'] = moodle1_converter::migrate_referenced_files($this->currentworkshop['intro'], $this->fileman);
00133 
00134         // write workshop.xml
00135         $this->open_xml_writer("activities/workshop_{$moduleid}/workshop.xml");
00136         $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid,
00137             'modulename' => 'workshop', 'contextid' => $contextid));
00138         $this->xmlwriter->begin_tag('workshop', array('id' => $instanceid));
00139 
00140         foreach ($this->currentworkshop as $field => $value) {
00141             if ($field <> 'id') {
00142                 $this->xmlwriter->full_tag($field, $value);
00143             }
00144         }
00145 
00146         return $this->currentworkshop;
00147     }
00148 
00155     public function on_workshop_elements_start() {
00156 
00157         $this->xmlwriter->begin_tag('subplugin_workshopform_'.$this->currentworkshop['strategy'].'_workshop');
00158 
00159         // inform the strategy handler that a new workshop instance is being processed
00160         $handler = $this->get_strategy_handler($this->currentworkshop['strategy']);
00161         $handler->use_xml_writer($this->xmlwriter);
00162         $handler->on_elements_start();
00163     }
00164 
00168     public function process_workshop_element($data, $raw) {
00169 
00170         // generate artificial element id and remember it for later usage
00171         $data['id'] = $this->converter->get_nextid();
00172         $this->currentelementid = $data['id'];
00173         $this->newelementids[$data['elementno']] = $data['id'];
00174 
00175         // let the strategy subplugin do whatever it needs to
00176         $handler = $this->get_strategy_handler($this->currentworkshop['strategy']);
00177         return $handler->process_legacy_element($data, $raw);
00178     }
00179 
00183     public function process_workshop_element_rubric($data, $raw) {
00184         if ($this->currentworkshop['strategy'] == 'rubric') {
00185             $handler = $this->get_strategy_handler('rubric');
00186             $data['elementid'] = $this->currentelementid;
00187             $handler->process_legacy_rubric($data, $raw);
00188         }
00189     }
00190 
00194     public function on_workshop_element_end() {
00195         // give the strategy handlers a chance to write what they need
00196         $handler = $this->get_strategy_handler($this->currentworkshop['strategy']);
00197         $handler->on_legacy_element_end();
00198     }
00199 
00203     public function on_workshop_elements_end() {
00204         // give the strategy hanlders last chance to write what they need
00205         $handler = $this->get_strategy_handler($this->currentworkshop['strategy']);
00206         $handler->on_elements_end();
00207 
00208         // close the dimensions definition
00209         $this->xmlwriter->end_tag('subplugin_workshopform_'.$this->currentworkshop['strategy'].'_workshop');
00210 
00211         // as a temporary hack, we just write empty wrappers for the rest of data
00212         $this->write_xml('examplesubmissions', array());
00213         $this->write_xml('submissions', array());
00214         $this->write_xml('aggregations', array());
00215     }
00216 
00220     public function on_workshop_end() {
00221         // close workshop.xml
00222         $this->xmlwriter->end_tag('workshop');
00223         $this->xmlwriter->end_tag('activity');
00224         $this->close_xml_writer();
00225 
00226         // write inforef.xml
00227         $this->inforefman->add_refs('file', $this->fileman->get_fileids());
00228         $moduleid = $this->currentcminfo['id'];
00229         $this->open_xml_writer("activities/workshop_{$moduleid}/inforef.xml");
00230         $this->inforefman->write_refs($this->xmlwriter);
00231         $this->close_xml_writer();
00232 
00233         // get ready for the next instance
00234         $this->currentworkshop = null;
00235         $this->currentcminfo   = null;
00236         $this->newelementids   = array();
00237     }
00238 
00244     public function get_current_workshop() {
00245         return $this->currentworkshop;
00246     }
00247 
00253     public function get_inforef_manager() {
00254         return $this->inforefman;
00255     }
00256 
00258 
00266     protected function get_strategy_handler($strategy) {
00267         global $CFG; // we include other files here
00268 
00269         if (is_null($this->strategyhandlers)) {
00270             $this->strategyhandlers = array();
00271             $subplugins = get_plugin_list('workshopform');
00272             foreach ($subplugins as $name => $dir) {
00273                 $handlerfile  = $dir.'/backup/moodle1/lib.php';
00274                 $handlerclass = "moodle1_workshopform_{$name}_handler";
00275                 if (!file_exists($handlerfile)) {
00276                     continue;
00277                 }
00278                 require_once($handlerfile);
00279 
00280                 if (!class_exists($handlerclass)) {
00281                     throw new moodle1_convert_exception('missing_handler_class', $handlerclass);
00282                 }
00283                 $this->log('preparing workshop grading strategy handler', backup::LOG_DEBUG, $handlerclass);
00284                 $this->strategyhandlers[$name] = new $handlerclass($this, $name);
00285                 if (!$this->strategyhandlers[$name] instanceof moodle1_workshopform_handler) {
00286                     throw new moodle1_convert_exception('wrong_handler_class', get_class($this->strategyhandlers[$name]));
00287                 }
00288             }
00289         }
00290 
00291         if (!isset($this->strategyhandlers[$strategy])) {
00292             throw new moodle1_convert_exception('usupported_subplugin', 'workshopform_'.$strategy);
00293         }
00294 
00295         return $this->strategyhandlers[$strategy];
00296     }
00297 }
00298 
00299 
00303 abstract class moodle1_workshopform_handler extends moodle1_submod_handler {
00304 
00309     public function __construct(moodle1_mod_handler $workshophandler, $subpluginname) {
00310         parent::__construct($workshophandler, 'workshopform', $subpluginname);
00311     }
00312 
00318     public function use_xml_writer(xml_writer $xmlwriter) {
00319         $this->xmlwriter = $xmlwriter;
00320     }
00321 
00327     public function on_elements_start() {
00328         // do nothing by default
00329     }
00330 
00339     public function process_legacy_element(array $data, array $raw) {
00340         return $data;
00341     }
00342 
00346     public function on_legacy_element_end() {
00347         // do nothing by default
00348     }
00349 
00353     public function on_elements_end() {
00354         // do nothing by default
00355     }
00356 }
 All Data Structures Namespaces Files Functions Variables Enumerations