Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'MDL-27439' of git://github.com/nebgor/moodle into backu…

…p-convert
  • Loading branch information...
commit 8b866ce4b1e0d9f4e4e6146c1584fdece841cb3c 2 parents 8312ab6 + be53cf4
David Mudrák authored May 24, 2011

Showing 1 changed file with 107 additions and 0 deletions. Show diff stats Hide diff stats

  1. 107  mod/assignment/backup/moodle1/lib.php
107  mod/assignment/backup/moodle1/lib.php
... ...
@@ -0,0 +1,107 @@
  1
+<?php
  2
+
  3
+// This file is part of Moodle - http://moodle.org/
  4
+//
  5
+// Moodle is free software: you can redistribute it and/or modify
  6
+// it under the terms of the GNU General Public License as published by
  7
+// the Free Software Foundation, either version 3 of the License, or
  8
+// (at your option) any later version.
  9
+//
  10
+// Moodle is distributed in the hope that it will be useful,
  11
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
  12
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13
+// GNU General Public License for more details.
  14
+//
  15
+// You should have received a copy of the GNU General Public License
  16
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17
+
  18
+/**
  19
+ * Provides support for the conversion of moodle1 backup to the moodle2 format
  20
+ * Based off of a template @ http://docs.moodle.org/en/Development:Backup_1.9_conversion_for_developers
  21
+ *
  22
+ * @package    mod
  23
+ * @subpackage assignment
  24
+ * @copyright  2011 Aparup Banerjee <aparup@moodle.com>
  25
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  26
+ */
  27
+
  28
+defined('MOODLE_INTERNAL') || die();
  29
+
  30
+/**
  31
+ * Assignment conversion handler
  32
+ */
  33
+class moodle1_mod_assignment_handler extends moodle1_mod_handler {
  34
+
  35
+    /**
  36
+     * Declare the paths in moodle.xml we are able to convert
  37
+     *
  38
+     * The method returns list of {@link convert_path} instances.
  39
+     * For each path returned, the corresponding conversion method must be
  40
+     * defined.
  41
+     *
  42
+     * Note that the path /MOODLE_BACKUP/COURSE/MODULES/MOD/ASSIGNMENT does not
  43
+     * actually exist in the file. The last element with the module name was
  44
+     * appended by the moodle1_converter class.
  45
+     *
  46
+     * @return array of {@link convert_path} instances
  47
+     */
  48
+    public function get_paths() {
  49
+        return array(
  50
+            new convert_path(
  51
+                'assignment', '/MOODLE_BACKUP/COURSE/MODULES/MOD/ASSIGNMENT',
  52
+                array(
  53
+                    'renamefields' => array(
  54
+                        'description' => 'intro',
  55
+                        'format' => 'introformat',
  56
+                    )
  57
+                )
  58
+            )
  59
+            //@todo process user data
  60
+            //new convert_path('assignment_submission', '/MOODLE_BACKUP/COURSE/MODULES/MOD/ASSIGNMENT/SUBMISSIONS/SUBMISSION')
  61
+        );
  62
+    }
  63
+
  64
+    /**
  65
+     * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/ASSIGNMENT
  66
+     * data available
  67
+     */
  68
+    public function process_assignment($data) {
  69
+        // get the course module id and context id
  70
+        $instanceid = $data['id'];
  71
+        $moduleid   = $this->get_moduleid($instanceid);
  72
+        $contextid  = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid);
  73
+
  74
+        // we now have all information needed to start writing into the file
  75
+        $this->open_xml_writer("activities/assignment_{$moduleid}/assignment.xml");
  76
+        $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid,
  77
+            'modulename' => 'assignment', 'contextid' => $contextid));
  78
+        $this->xmlwriter->begin_tag('assignment', array('id' => $instanceid));
  79
+
  80
+        unset($data['id']); // we already write it as attribute, do not repeat it as child element
  81
+        foreach ($data as $field => $value) {
  82
+            $this->xmlwriter->full_tag($field, $value);
  83
+        }
  84
+
  85
+        $this->xmlwriter->begin_tag('submissions');
  86
+    }
  87
+
  88
+    /**
  89
+     * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/ASSIGNMENT/SUBMISSIONS/SUBMISSION
  90
+     * data available
  91
+     */
  92
+    public function process_assignment_submission($data) {
  93
+        //@todo process user data
  94
+        //$this->write_xml('submission', $data, array('/submission/id'));
  95
+    }
  96
+
  97
+    /**
  98
+     * This is executed when we reach the closing </MOD> tag of our 'assignment' path
  99
+     */
  100
+    public function on_assignment_end() {
  101
+
  102
+        $this->xmlwriter->end_tag('submissions');
  103
+        $this->xmlwriter->end_tag('assignment');
  104
+        $this->xmlwriter->end_tag('activity');
  105
+        $this->close_xml_writer();
  106
+    }
  107
+}

0 notes on commit 8b866ce

Please sign in to comment.
Something went wrong with that request. Please try again.