Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'MDL-27960' of git://github.com/nebgor/moodle

  • Loading branch information...
commit ec48e283b04a0e12921c7298834759a68ecc7b17 2 parents 264d81e + b74b347
@stronk7 stronk7 authored
View
103 mod/assignment/backup/moodle1/lib.php
@@ -38,6 +38,12 @@ class moodle1_mod_assignment_handler extends moodle1_mod_handler {
/** @var int cmid */
protected $moduleid = null;
+ /** @var string current subplugin being processed*/
+ private $currentsubpluginname = null;
+
+ /** @var array of a moodle1_assignment_[subplugin_name]_handler instances */
+ private $subpluginhandlers = null;
+
/**
* Declare the paths in moodle.xml we are able to convert
*
@@ -78,6 +84,9 @@ public function process_assignment($data) {
$this->moduleid = $cminfo['id'];
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
+ //store assignment type for possible subplugin conversions.
+ $this->currentsubpluginname = $data['assignmenttype'];
+
// get a fresh new file manager for this instance
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_assignment');
@@ -98,6 +107,9 @@ public function process_assignment($data) {
}
}
+ //after writing the assignment type element, let the subplugin add on whatever it wants.
+ $this->handle_assignment_subplugin($data);
+
$this->xmlwriter->begin_tag('submissions');
return $data;
@@ -113,6 +125,19 @@ public function process_assignment_submission($data) {
}
/**
+ * This handles calls to subplugin conversion classes.
+ * called from <ASSIGNMENTTYPE> within process_assignment()
+ */
+ public function handle_assignment_subplugin($data) {
+ $handler = $this->get_subplugin_handler($this->currentsubpluginname);
+ $this->log('Instantiated assignment subplugin handler for '.$this->currentsubpluginname.'.', backup::LOG_DEBUG);
+ $handler->use_xml_writer($this->xmlwriter);
+
+ $this->log('Processing assignment subplugin handler callback for '.$this->currentsubpluginname.'.', backup::LOG_DEBUG);
+ $handler->append_subplugin_data($data);
+ }
+
+ /**
* This is executed when we reach the closing </MOD> tag of our 'assignment' path
*/
public function on_assignment_end() {
@@ -133,4 +158,82 @@ public function on_assignment_end() {
$this->xmlwriter->end_tag('inforef');
$this->close_xml_writer();
}
+
+ /// internal implementation details follow /////////////////////////////////
+
+ /**
+ * Factory method returning the handler of the given assignment subplugin
+ *
+ * @param string $subplugin the name of the subplugin
+ * @throws moodle1_convert_exception
+ * @return moodle1_assignment_subplugin_handler the instance of the handler
+ */
+ protected function get_subplugin_handler($subplugin) {
+ global $CFG; // we include other files here
+
+ if (is_null($this->subpluginhandlers)) {
+ $this->subpluginhandlers = array();
+ $subplugins = get_plugin_list('assignment');
+ foreach ($subplugins as $name => $dir) {
+ $handlerfile = $dir.'/backup/moodle1/lib.php';
+ $handlerclass = "moodle1_mod_assignment_{$name}_subplugin_handler";
+ if (!file_exists($handlerfile)) {
+ continue;
+ }
+ require_once($handlerfile);
+
+ if (!class_exists($handlerclass)) {
+ throw new moodle1_convert_exception('missing_handler_class', $handlerclass);
+ }
+ $this->log('preparing assignment subplugin handler', backup::LOG_DEBUG, $handlerclass);
+ $this->subpluginhandlers[$name] = new $handlerclass($this, $name);
+ if (!$this->subpluginhandlers[$name] instanceof moodle1_assignment_subplugin_handler) {
+ throw new moodle1_convert_exception('wrong_handler_class', get_class($this->subpluginhandlers[$name]));
+ }
+ }
+ }
+
+ if (!isset($this->subpluginhandlers[$subplugin])) {
+ throw new moodle1_convert_exception('unsupported_subplugin', 'assignment_'.$subplugin);
+ }
+
+ return $this->subpluginhandlers[$subplugin];
+ }
}
+
+
+/**
+ * Base class for the assignment subplugin handler
+ * Extend this for your own subplugin conversion handling purposes.
+ */
+abstract class moodle1_assignment_subplugin_handler extends moodle1_submod_handler {
+
+ /**
+ * @param moodle1_mod_handler $assignmenthandler the handler of a module we are subplugin of
+ * @param string $subpluginname the name of the subplugin
+ */
+ public function __construct(moodle1_mod_handler $assignmenthandler, $subpluginname) {
+ parent::__construct($assignmenthandler, 'assignment', $subpluginname);
+ }
+
+ /**
+ * Provides a xml_writer instance to this assignment subplugin type handler
+ *
+ * @param xml_writer $xmlwriter
+ */
+ public function use_xml_writer(xml_writer $xmlwriter) {
+ $this->xmlwriter = $xmlwriter;
+ }
+
+ /**
+ * a call back (entry point) to the subplugin conversion handler class.
+ * $data are the elements of <assignment>, any (@todo sub paths containing subplugindata isn't handed through).
+ */
+
+ public function append_subplugin_data($data) {
+ // an example that does nothing - you'll do nothing if you don't overide it
+ return false;
+
+ //you will probably want to do stuff with $this->xmlwriter here (within your overridden method) to write plugin specific data.
+ }
+}
View
34 mod/assignment/type/offline/backup/moodle1/lib.php
@@ -0,0 +1,34 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * @package assignment
+ * @subpackage offline subplugin
+ * @copyright 2011 onwards Aparup Banerjee (nebgor)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+/**
+ * A dummy class for offline conversions.
+ * The offline subplugin doesn't really need anything converted.
+ * See the moodle1_assignment_subplugin_handler class.
+ */
+class moodle1_mod_assignment_offline_subplugin_handler extends moodle1_assignment_subplugin_handler {
+ /**
+ * Override the append_subplugin_data($data) method here for plugin specific processing.
+ */
+}
View
34 mod/assignment/type/online/backup/moodle1/lib.php
@@ -0,0 +1,34 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * @package assignment
+ * @subpackage online subplugin
+ * @copyright 2011 onwards Aparup Banerjee (nebgor)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+/**
+ * A dummy class for online conversions.
+ * The online subplugin doesn't really need anything converted.
+ * See the moodle1_assignment_subplugin_handler class.
+ */
+class moodle1_mod_assignment_online_subplugin_handler extends moodle1_assignment_subplugin_handler {
+ /**
+ * Override the append_subplugin_data($data) method here for plugin specific processing.
+ */
+}
View
34 mod/assignment/type/upload/backup/moodle1/lib.php
@@ -0,0 +1,34 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * @package assignment
+ * @subpackage upload subplugin
+ * @copyright 2011 onwards Aparup Banerjee (nebgor)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+/**
+ * A dummy class for upload conversions.
+ * The upload subplugin doesn't really need anything converted.
+ * See the moodle1_assignment_subplugin_handler class.
+ */
+class moodle1_mod_assignment_upload_subplugin_handler extends moodle1_assignment_subplugin_handler {
+ /**
+ * Override the append_subplugin_data($data) method here for plugin specific processing.
+ */
+}
View
34 mod/assignment/type/uploadsingle/backup/moodle1/lib.php
@@ -0,0 +1,34 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * @package assignment
+ * @subpackage uploadsingle subplugin
+ * @copyright 2011 onwards Aparup Banerjee (nebgor)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+/**
+ * A dummy class for uploadsingle conversions.
+ * The uploadsingle subplugin doesn't really need anything converted.
+ * See the moodle1_assignment_subplugin_handler class.
+ */
+class moodle1_mod_assignment_uploadsingle_subplugin_handler extends moodle1_assignment_subplugin_handler {
+ /**
+ * Override the append_subplugin_data($data) method here for plugin specific processing.
+ */
+}
Please sign in to comment.
Something went wrong with that request. Please try again.