forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-22151 & MDL-22138 - Quiz activity backup & questions banks too!
CV S: ----------------------------------------------------------------------
- Loading branch information
Showing
18 changed files
with
804 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?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 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
/** | ||
* Class implementing the plugins support for moodle2 backups | ||
* | ||
* TODO: Finish phpdocs | ||
*/ | ||
abstract class backup_plugin { | ||
|
||
protected $plugintype; | ||
protected $pluginname; | ||
protected $connectionpoint; | ||
protected $optigroup; // Optigroup, parent of all optigroup elements | ||
|
||
public function __construct($plugintype, $pluginname, $optigroup) { | ||
$this->plugintype = $plugintype; | ||
$this->pluginname = $pluginname; | ||
$this->optigroup = $optigroup; | ||
$this->connectionpoint = ''; | ||
} | ||
|
||
public function define_plugin_structure($connectionpoint) { | ||
|
||
$this->connectionpoint = $connectionpoint; | ||
|
||
$methodname = 'define_' . $connectionpoint . '_plugin_structure'; | ||
|
||
if (method_exists($this, $methodname)) { | ||
$this->$methodname(); | ||
} | ||
} | ||
|
||
/** | ||
* 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) | ||
*/ | ||
protected function get_plugin_element($final_elements = null, $conditionparam = null, $conditionvalue = null) { | ||
// Something exclusive for this backup_plugin_element (backup_optigroup_element) | ||
// because it hasn't XML representation | ||
$name = 'optigroup_' . $this->plugintype . '_' . $this->pluginname . '_' . $this->connectionpoint; | ||
$optigroup_element = new backup_plugin_element($name, $final_elements, $conditionparam, $conditionvalue); | ||
$this->optigroup->add_child($optigroup_element); // Add optigroup_element to stay connected since beginning | ||
return $optigroup_element; | ||
} | ||
|
||
/** | ||
* Simple helper function that suggests one name for the main nested element in plugins | ||
* It's not mandatory to use it but recommended ;-) | ||
*/ | ||
protected function get_recommended_name() { | ||
return 'plugin_' . $this->plugintype . '_' . $this->pluginname . '_' . $this->connectionpoint; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
<?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 2010 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 questions (qtype plugin) | ||
* | ||
* TODO: Finish phpdocs | ||
*/ | ||
abstract class backup_qtype_plugin extends backup_plugin { | ||
|
||
/** | ||
* Attach to $element (usually questions) the needed backup structures | ||
* for question_answers for a given question | ||
* Used by various qtypes (calculated, essay, multianswer, | ||
* multichoice, numerical, shortanswer, truefalse) | ||
*/ | ||
protected function add_question_question_answers($element) { | ||
// Check $element is one nested_backup_element | ||
if (! $element instanceof backup_nested_element) { | ||
throw new backup_step_exception('question_answers_bad_parent_element', $element); | ||
} | ||
|
||
// Define the elements | ||
$answers = new backup_nested_element('answers'); | ||
$answer = new backup_nested_element('answer', array('id'), array( | ||
'answertext', 'answerformat', 'fraction', 'feedback', | ||
'feedbackformat')); | ||
|
||
// Build the tree | ||
$element->add_child($answers); | ||
$answers->add_child($answer); | ||
|
||
// Set the sources | ||
$answer->set_source_table('question_answers', array('question' => backup::VAR_PARENTID)); | ||
|
||
// Aliases | ||
$answer->set_source_alias('answer', 'answertext'); | ||
|
||
// don't need to annotate ids nor files | ||
} | ||
|
||
/** | ||
* Attach to $element (usually questions) the needed backup structures | ||
* for question_numerical_units for a given question | ||
* Used both by calculated and numerical qtypes | ||
*/ | ||
protected function add_question_numerical_units($element) { | ||
// Check $element is one nested_backup_element | ||
if (! $element instanceof backup_nested_element) { | ||
throw new backup_step_exception('question_numerical_units_bad_parent_element', $element); | ||
} | ||
|
||
// Define the elements | ||
$units = new backup_nested_element('numerical_units'); | ||
$unit = new backup_nested_element('numerical_unit', array('id'), array( | ||
'multiplier', 'unit')); | ||
|
||
// Build the tree | ||
$element->add_child($units); | ||
$units->add_child($unit); | ||
|
||
// Set the sources | ||
$unit->set_source_table('question_numerical_units', array('question' => backup::VAR_PARENTID)); | ||
|
||
// don't need to annotate ids nor files | ||
} | ||
|
||
/** | ||
* Attach to $element (usually questions) the needed backup structures | ||
* for question_numerical_options for a given question | ||
* Used both by calculated and numerical qtypes | ||
*/ | ||
protected function add_question_numerical_options($element) { | ||
// Check $element is one nested_backup_element | ||
if (! $element instanceof backup_nested_element) { | ||
throw new backup_step_exception('question_numerical_options_bad_parent_element', $element); | ||
} | ||
|
||
// Define the elements | ||
$options = new backup_nested_element('numerical_options'); | ||
$option = new backup_nested_element('numerical_option', array('id'), array( | ||
'instructions', 'instructionsformat', 'showunits', 'unitsleft', | ||
'unitgradingtype', 'unitpenalty')); | ||
|
||
// Build the tree | ||
$element->add_child($options); | ||
$options->add_child($option); | ||
|
||
// Set the sources | ||
$option->set_source_table('question_numerical_options', array('question' => backup::VAR_PARENTID)); | ||
|
||
// don't need to annotate ids nor files | ||
} | ||
|
||
/** | ||
* Attach to $element (usually questions) the needed backup structures | ||
* for question_datasets for a given question | ||
* Used by calculated qtypes | ||
*/ | ||
protected function add_question_datasets($element) { | ||
// Check $element is one nested_backup_element | ||
if (! $element instanceof backup_nested_element) { | ||
throw new backup_step_exception('question_datasets_bad_parent_element', $element); | ||
} | ||
|
||
// Define the elements | ||
$definitions = new backup_nested_element('dataset_definitions'); | ||
$definition = new backup_nested_element('dataset_definition', array('id'), array( | ||
'category', 'name', 'type', 'options', | ||
'itemcount')); | ||
|
||
$items = new backup_nested_element('dataset_items'); | ||
$item = new backup_nested_element('dataset_item', array('id'), array( | ||
'number', 'value')); | ||
|
||
// Build the tree | ||
$element->add_child($definitions); | ||
$definitions->add_child($definition); | ||
|
||
$definition->add_child($items); | ||
$items->add_child($item); | ||
|
||
// Set the sources | ||
$definition->set_source_sql('SELECT * | ||
FROM {question_dataset_definitions} qdd | ||
JOIN {question_datasets} qd ON qd.datasetdefinition = qdd.id | ||
WHERE qd.question = ?', array(backup::VAR_PARENTID)); | ||
|
||
$item->set_source_table('question_dataset_items', array('definition' => backup::VAR_PARENTID)); | ||
|
||
// Aliases | ||
$item->set_source_alias('itemnumber', 'number'); | ||
|
||
// don't need to annotate ids nor files | ||
} | ||
} |
Oops, something went wrong.