MDL-44151 Amend subplugin packages.
[moodle.git] / mod / assignment / type / offline / backup / moodle2 / backup_assignment_offline_subplugin.class.php
CommitLineData
8bf1e529
EL
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/**
993414fd 19 * @package assignment_offline
8bf1e529
EL
20 * @subpackage backup-moodle2
21 * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25/**
26 * backup subplugin class that provides the necessary information
27 * needed to backup one assignment->offline subplugin.
28 *
29 * Note: Offline assignments really haven't any special subplugin
30 * information to backup/restore, hence code below is skipped (return false)
31 * but it's a good example of sublugins supported at different
32 * elements (assignment and submission) and conditions
33 */
34class backup_assignment_offline_subplugin extends backup_subplugin {
35
36 /**
37 * Returns the subplugin information to attach at assignment element
38 */
332437c5 39 protected function define_assignment_subplugin_structure() {
8bf1e529
EL
40
41 return false; // This subplugin backup is only one example. Skip it.
42
43 /**
44 * Any activity sublugins is always rooted by one backup_subplugin_element()
45 * Those elements have some unique characteristics:
46 * - They are, basically, backup_nested_elements
47 * - They cannot have attributes
48 * - They don't have XML representations (only their final/child elements have
49 * - They are able to specify one condition in order to decide if the subplugin
50 * must be processed or no (usually we'll put the "type" condition here, but some
51 * activities, may prefer not to use any condition, see workshop)
52 */
53
54 /**
55 * Here we are defining the information that will be attached, within the "assignment" element
56 * when assignments of type "offline" are sent to backup, so we define the backup_subplugin_element
57 * as not having any final element (null) and with the condition of the '/assignment/assignmenttype'
58 * being 'offline' (that will be checked on execution)
59 *
60 * Note that, while, we allow direct "injection" of final_elements at the "assignment" level (without
91421f3e 61 * any nesting, we usually pass 'null', and later enclose the real subplugin information into deeper
8bf1e529 62 * levels (get_recommended_name() and 'config' in the example below). That will make things
91421f3e 63 * on restore easier, as far as subplugin information will be clearly separated from module information.
8bf1e529 64 */
332437c5 65 $subplugin = $this->get_subplugin_element(null, '/assignment/assignmenttype', 'offline');
8bf1e529
EL
66
67 /**
68 * Here we define the real structure the subplugin is going to generate - see note above. Obviously the
69 * example below hasn't sense at all, we are exporting the whole config table that is 100% unrelated
91421f3e 70 * with assignments. Take it as just one example. The only important bit is that it's highly recommended to
8bf1e529 71 * use some exclusive name in the main nested element (something that won't conflict with other subplugins/parts).
332437c5 72 * So we are using 'subplugin_assignment_offline_assignment' as name here (the type of the subplugin, the name of the
8bf1e529
EL
73 * subplugin and the name of the connection point). get_recommended_name() will help, in any case ;-)
74 *
75 * All the code below is 100% standard backup structure code, so you define the structure, the sources,
76 * annotations... whatever you need
77 */
332437c5 78 $assassoff = new backup_nested_element($this->get_recommended_name());
8bf1e529
EL
79 $config = new backup_nested_element('config', null, array('name', 'value'));
80
81 $subplugin->add_child($assassoff);
82 $assassoff->add_child($config);
83
f2e34ee5 84 $config->set_source_table('config', array('id' => '/assignment/id'));
8bf1e529
EL
85
86 return $subplugin; // And we return the root subplugin element
87 }
88
89 /**
90 * Returns the subplugin information to attach at submission element
91 */
332437c5 92 protected function define_submission_subplugin_structure() {
8bf1e529
EL
93
94 return false; // This subplugin backup is only one example. Skip it.
95
96 // remember this has not XML representation
332437c5 97 $subplugin = $this->get_subplugin_element(null, '/assignment/assignmenttype', 'offline');
8bf1e529
EL
98
99 // type of the subplugin, name of the subplugin and name of the connection point (recommended)
332437c5 100 $asssuboff = new backup_nested_element($this->get_recommended_name());
91421f3e 101 // Why 'submission_config' name? Because it must be unique in the hierarchy and we
8bf1e529
EL
102 // already are using 'config' above withing the same file
103 $config = new backup_nested_element('submission_config', null, array('name', 'value'));
104
105 $subplugin->add_child($asssuboff);
106 $asssuboff->add_child($config);
107
f2e34ee5 108 $config->set_source_table('config', array('id' => backup::VAR_PARENTID));
8bf1e529
EL
109
110 return $subplugin; // And we return the root subplugin element
111 }
112}