MDL-42588 mod_scorm: display activity name
[moodle.git] / backup / moodle2 / backup_plugin.class.php
blob6a060abf8fbc5002bb0f4b9ed86a65018482da85
1 <?php
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.
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/>.
18 /**
19 * Defines backup_plugin class
21 * @package core_backup
22 * @subpackage moodle2
23 * @category backup
24 * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') || die();
30 /**
31 * Class implementing the plugins support for moodle2 backups
33 * TODO: Finish phpdocs
35 abstract class backup_plugin {
37 protected $plugintype;
38 protected $pluginname;
39 protected $connectionpoint;
40 protected $optigroup; // Optigroup, parent of all optigroup elements
41 protected $step;
42 protected $task;
44 public function __construct($plugintype, $pluginname, $optigroup, $step) {
45 $this->plugintype = $plugintype;
46 $this->pluginname = $pluginname;
47 $this->optigroup = $optigroup;
48 $this->connectionpoint = '';
49 $this->step = $step;
50 $this->task = $step->get_task();
53 public function define_plugin_structure($connectionpoint) {
55 $this->connectionpoint = $connectionpoint;
57 $methodname = 'define_' . $connectionpoint . '_plugin_structure';
59 if (method_exists($this, $methodname)) {
60 $this->$methodname();
64 // Protected API starts here
66 // backup_step/structure_step/task wrappers
68 /**
69 * Returns the value of one (task/plan) setting
71 protected function get_setting_value($name) {
72 if (is_null($this->task)) {
73 throw new backup_step_exception('not_specified_backup_task');
75 return $this->task->get_setting_value($name);
78 // end of backup_step/structure_step/task wrappers
80 /**
81 * Factory method that will return one backup_plugin_element (backup_optigroup_element)
82 * with its name automatically calculated, based one the plugin being handled (type, name)
84 protected function get_plugin_element($final_elements = null, $conditionparam = null, $conditionvalue = null) {
85 // Something exclusive for this backup_plugin_element (backup_optigroup_element)
86 // because it hasn't XML representation
87 $name = 'optigroup_' . $this->plugintype . '_' . $this->pluginname . '_' . $this->connectionpoint;
88 $optigroup_element = new backup_plugin_element($name, $final_elements, $conditionparam, $conditionvalue);
89 $this->optigroup->add_child($optigroup_element); // Add optigroup_element to stay connected since beginning
90 return $optigroup_element;
93 /**
94 * Simple helper function that suggests one name for the main nested element in plugins
95 * It's not mandatory to use it but recommended ;-)
97 protected function get_recommended_name() {
98 return 'plugin_' . $this->plugintype . '_' . $this->pluginname . '_' . $this->connectionpoint;