Permalink
Browse files

Merge branch 'MDL-22146_backup_course_format_wip' of git://github.com…

…/stronk7/moodle
  • Loading branch information...
skodak committed Feb 14, 2011
2 parents 995b6ff + a90659d commit 251e5a8b62f1bee1cb020758e46e4ff529eeda2e
@@ -0,0 +1,50 @@
+<?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 moodlecore
+ * @subpackage backup-moodle2
+ * @copyright 2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+/**
+ * Class extending standard backup_plugin in order to implement some
+ * helper methods related with the course formats (format plugin)
+ *
+ * TODO: Finish phpdocs
+ */
+abstract class backup_format_plugin extends backup_plugin {
+
+ protected $courseformat; // To store the format (course->format) of the instance
+
+ public function __construct($plugintype, $pluginname, $optigroup, $step) {
+
+ parent::__construct($plugintype, $pluginname, $optigroup, $step);
+
+ $this->courseformat = backup_plan_dbops::get_courseformat_from_courseid($this->task->get_courseid());
+
+ }
+
+ /**
+ * Return the condition encapsulated into sqlparam format
+ * to get evaluated by value, not by path nor processor setting
+ */
+ protected function get_format_condition() {
+ return array('sqlparam' => $this->courseformat);
+ }
+}
@@ -34,6 +34,7 @@
require_once($CFG->dirroot . '/backup/moodle2/backup_xml_transformer.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_qtype_plugin.class.php');
+require_once($CFG->dirroot . '/backup/moodle2/backup_format_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_subplugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_settingslib.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_stepslib.php');
@@ -33,12 +33,16 @@
protected $pluginname;
protected $connectionpoint;
protected $optigroup; // Optigroup, parent of all optigroup elements
+ protected $step;
+ protected $task;
- public function __construct($plugintype, $pluginname, $optigroup) {
+ public function __construct($plugintype, $pluginname, $optigroup, $step) {
$this->plugintype = $plugintype;
$this->pluginname = $pluginname;
- $this->optigroup = $optigroup;
+ $this->optigroup = $optigroup;
$this->connectionpoint = '';
+ $this->step = $step;
+ $this->task = $step->get_task();
}
public function define_plugin_structure($connectionpoint) {
@@ -52,6 +56,22 @@ public function define_plugin_structure($connectionpoint) {
}
}
+// Protected API starts here
+
+// backup_step/structure_step/task wrappers
+
+ /**
+ * Returns the value of one (task/plan) setting
+ */
+ protected function get_setting_value($name) {
+ if (is_null($this->task)) {
+ throw new backup_step_exception('not_specified_backup_task');
+ }
+ return $this->task->get_setting_value($name);
+ }
+
+// end of backup_step/structure_step/task wrappers
+
/**
* Factory method that will return one backup_plugin_element (backup_optigroup_element)
* with its name automatically calculated, based one the plugin being handled (type, name)
@@ -125,13 +125,21 @@ protected function add_subplugin_structure($subplugintype, $element, $multiple)
$backupfile = $subpluginsdir . '/backup/moodle2/' . $classname . '.class.php';
if (file_exists($backupfile)) {
require_once($backupfile);
- $backupsubplugin = new $classname($subplugintype, $name, $optigroup);
+ $backupsubplugin = new $classname($subplugintype, $name, $optigroup, $this);
// Add subplugin returned structure to optigroup
$backupsubplugin->define_subplugin_structure($element->get_name());
}
}
}
+ /**
+ * As far as activity backup steps are implementing backup_subplugin stuff, they need to
+ * have the parent task available for wrapping purposes (get course/context....)
+ */
+ public function get_task() {
+ return $this->task;
+ }
+
/**
* Wraps any activity backup structure within the common 'activity' element
* that will include common to all activities information like id, context...
@@ -310,6 +318,9 @@ protected function define_structure() {
$availability = new backup_nested_element('availability', array('id'), array(
'sourcecmid', 'requiredcompletion', 'gradeitemid', 'grademin', 'grademax'));
+ // attach format plugin structure to $module element, only one allowed
+ $this->add_plugin_structure('format', $module, false);
+
// Define the tree
$module->add_child($availinfo);
$availinfo->add_child($availability);
@@ -346,6 +357,9 @@ protected function define_structure() {
$section = new backup_nested_element('section', array('id'), array(
'number', 'name', 'summary', 'summaryformat', 'sequence', 'visible'));
+ // attach format plugin structure to $section element, only one allowed
+ $this->add_plugin_structure('format', $section, false);
+
// Define sources
$section->set_source_table('course_sections', array('id' => backup::VAR_SECTIONID));
@@ -395,6 +409,9 @@ protected function define_structure() {
$module = new backup_nested_element('module', array(), array('modulename'));
+ // attach format plugin structure to $course element, only one allowed
+ $this->add_plugin_structure('format', $course, false);
+
// Build the tree
$course->add_child($category);
@@ -34,12 +34,16 @@
protected $subpluginname;
protected $connectionpoint;
protected $optigroup; // Optigroup, parent of all optigroup elements
+ protected $step;
+ protected $task;
- public function __construct($subplugintype, $subpluginname, $optigroup) {
+ public function __construct($subplugintype, $subpluginname, $optigroup, $step) {
$this->subplugintype = $subplugintype;
$this->subpluginname = $subpluginname;
$this->optigroup = $optigroup;
$this->connectionpoint = '';
+ $this->step = $step;
+ $this->task = $step->get_task();
}
public function define_subplugin_structure($connectionpoint) {
@@ -53,6 +57,22 @@ public function define_subplugin_structure($connectionpoint) {
}
}
+// Protected API starts here
+
+// backup_step/structure_step/task wrappers
+
+ /**
+ * Returns the value of one (task/plan) setting
+ */
+ protected function get_setting_value($name) {
+ if (is_null($this->task)) {
+ throw new backup_step_exception('not_specified_backup_task');
+ }
+ return $this->task->get_setting_value($name);
+ }
+
+// end of backup_step/structure_step/task wrappers
+
/**
* Factory method that will return one backup_subplugin_element (backup_optigroup_element)
* with its name automatically calculated, based one the subplugin being handled (type, name)
@@ -0,0 +1,33 @@
+<?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 moodlecore
+ * @subpackage backup-moodle2
+ * @copyright 2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+/**
+ * Class extending standard restore_plugin in order to implement some
+ * helper methods related with the course formats (format plugin)
+ *
+ * TODO: Finish phpdocs
+ */
+abstract class restore_format_plugin extends restore_plugin {
+ // Love these classes. :-) Nothing special to customize here for now
+}
@@ -33,8 +33,10 @@
require_once($CFG->dirroot . '/backup/moodle2/restore_default_block_task.class.php');
require_once($CFG->dirroot . '/backup/moodle2/restore_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/restore_qtype_plugin.class.php');
+require_once($CFG->dirroot . '/backup/moodle2/restore_format_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_qtype_plugin.class.php');
+require_once($CFG->dirroot . '/backup/moodle2/backup_format_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/restore_subplugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/restore_settingslib.php');
require_once($CFG->dirroot . '/backup/moodle2/restore_stepslib.php');
@@ -202,6 +202,18 @@ protected function apply_date_offset($value) {
return $this->step->apply_date_offset($value);
}
+ /**
+ * Returns the value of one (task/plan) setting
+ */
+ protected function get_setting_value($name) {
+ if (is_null($this->task)) {
+ throw new restore_step_exception('not_specified_restore_task');
+ }
+ return $this->task->get_setting_value($name);
+ }
+
+// end of restore_step/structure_step/task wrappers
+
/**
* Simple helper function that returns the name for the restore_path_element
* It's not mandatory to use it but recommended ;-)
@@ -32,12 +32,14 @@ class restore_section_task extends restore_task {
protected $info; // info related to section gathered from backup file
protected $contextid; // course context id
+ protected $sectionid; // new (target) id of the course section
/**
* Constructor - instantiates one object of this class
*/
public function __construct($name, $info, $plan = null) {
$this->info = $info;
+ $this->sectionid = 0;
parent::__construct($name, $plan);
}
@@ -49,10 +51,18 @@ public function get_taskbasepath() {
return $this->get_basepath() . '/sections/section_' . $this->info->sectionid;
}
+ public function set_sectionid($sectionid) {
+ $this->sectionid = $sectionid;
+ }
+
public function get_contextid() {
return $this->contextid;
}
+ public function get_sectionid() {
+ return $this->sectionid;
+ }
+
/**
* Create all the steps that will be part of this task
*/
Oops, something went wrong.

0 comments on commit 251e5a8

Please sign in to comment.