From b74b347aba5e12c850c2ceb97c65e48ece9cd438 Mon Sep 17 00:00:00 2001 From: Aparup Banerjee Date: Wed, 22 Jun 2011 17:20:19 +0800 Subject: [PATCH] MDL-27960 assignment subplugin moodle1 conversion handling and handlers added --- mod/assignment/backup/moodle1/lib.php | 103 ++++++++++++++++++ .../type/offline/backup/moodle1/lib.php | 34 ++++++ .../type/online/backup/moodle1/lib.php | 34 ++++++ .../type/upload/backup/moodle1/lib.php | 34 ++++++ .../type/uploadsingle/backup/moodle1/lib.php | 34 ++++++ 5 files changed, 239 insertions(+) create mode 100644 mod/assignment/type/offline/backup/moodle1/lib.php create mode 100644 mod/assignment/type/online/backup/moodle1/lib.php create mode 100644 mod/assignment/type/upload/backup/moodle1/lib.php create mode 100644 mod/assignment/type/uploadsingle/backup/moodle1/lib.php diff --git a/mod/assignment/backup/moodle1/lib.php b/mod/assignment/backup/moodle1/lib.php index 5930e1938d3..bf2cfb8f45f 100644 --- a/mod/assignment/backup/moodle1/lib.php +++ b/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 @@ class moodle1_mod_assignment_handler extends moodle1_mod_handler { $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 @@ class moodle1_mod_assignment_handler extends moodle1_mod_handler { } } + //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; @@ -112,6 +124,19 @@ class moodle1_mod_assignment_handler extends moodle1_mod_handler { //$this->write_xml('submission', $data, array('/submission/id')); } + /** + * This handles calls to subplugin conversion classes. + * called from 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 tag of our 'assignment' path */ @@ -133,4 +158,82 @@ class moodle1_mod_assignment_handler extends moodle1_mod_handler { $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 , 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. + } +} \ No newline at end of file diff --git a/mod/assignment/type/offline/backup/moodle1/lib.php b/mod/assignment/type/offline/backup/moodle1/lib.php new file mode 100644 index 00000000000..939eb2df0e8 --- /dev/null +++ b/mod/assignment/type/offline/backup/moodle1/lib.php @@ -0,0 +1,34 @@ +. + +/** + * @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. + */ +} diff --git a/mod/assignment/type/online/backup/moodle1/lib.php b/mod/assignment/type/online/backup/moodle1/lib.php new file mode 100644 index 00000000000..c1516d377c7 --- /dev/null +++ b/mod/assignment/type/online/backup/moodle1/lib.php @@ -0,0 +1,34 @@ +. + +/** + * @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. + */ +} diff --git a/mod/assignment/type/upload/backup/moodle1/lib.php b/mod/assignment/type/upload/backup/moodle1/lib.php new file mode 100644 index 00000000000..5537f3efa6b --- /dev/null +++ b/mod/assignment/type/upload/backup/moodle1/lib.php @@ -0,0 +1,34 @@ +. + +/** + * @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. + */ +} diff --git a/mod/assignment/type/uploadsingle/backup/moodle1/lib.php b/mod/assignment/type/uploadsingle/backup/moodle1/lib.php new file mode 100644 index 00000000000..70a3592a4af --- /dev/null +++ b/mod/assignment/type/uploadsingle/backup/moodle1/lib.php @@ -0,0 +1,34 @@ +. + +/** + * @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. + */ +} -- 2.43.0