Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/backup/moodle2/backup_qtype_plugin.class.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00031 abstract class backup_qtype_plugin extends backup_plugin {
00032 
00039     protected function add_question_question_answers($element) {
00040         // Check $element is one nested_backup_element
00041         if (! $element instanceof backup_nested_element) {
00042             throw new backup_step_exception('question_answers_bad_parent_element', $element);
00043         }
00044 
00045         // Define the elements
00046         $answers = new backup_nested_element('answers');
00047         $answer = new backup_nested_element('answer', array('id'), array(
00048             'answertext', 'answerformat', 'fraction', 'feedback',
00049             'feedbackformat'));
00050 
00051         // Build the tree
00052         $element->add_child($answers);
00053         $answers->add_child($answer);
00054 
00055         // Set the sources
00056         $answer->set_source_sql('
00057                 SELECT *
00058                 FROM {question_answers}
00059                 WHERE question = :question
00060                 ORDER BY id',
00061                 array('question' => backup::VAR_PARENTID));
00062 
00063         // Aliases
00064         $answer->set_source_alias('answer', 'answertext');
00065 
00066         // don't need to annotate ids nor files
00067     }
00068 
00074     protected function add_question_numerical_units($element) {
00075         // Check $element is one nested_backup_element
00076         if (! $element instanceof backup_nested_element) {
00077             throw new backup_step_exception('question_numerical_units_bad_parent_element', $element);
00078         }
00079 
00080         // Define the elements
00081         $units = new backup_nested_element('numerical_units');
00082         $unit = new backup_nested_element('numerical_unit', array('id'), array(
00083             'multiplier', 'unit'));
00084 
00085         // Build the tree
00086         $element->add_child($units);
00087         $units->add_child($unit);
00088 
00089         // Set the sources
00090         $unit->set_source_sql('
00091                 SELECT *
00092                 FROM {question_numerical_units}
00093                 WHERE question = :question
00094                 ORDER BY id',
00095                 array('question' => backup::VAR_PARENTID));
00096 
00097         // don't need to annotate ids nor files
00098     }
00099 
00105     protected function add_question_numerical_options($element) {
00106         // Check $element is one nested_backup_element
00107         if (! $element instanceof backup_nested_element) {
00108             throw new backup_step_exception('question_numerical_options_bad_parent_element', $element);
00109         }
00110 
00111         // Define the elements
00112         $options = new backup_nested_element('numerical_options');
00113         $option = new backup_nested_element('numerical_option', array('id'), array(
00114             'showunits', 'unitsleft', 'unitgradingtype', 'unitpenalty'));
00115 
00116         // Build the tree
00117         $element->add_child($options);
00118         $options->add_child($option);
00119 
00120         // Set the sources
00121         $option->set_source_table('question_numerical_options', array('question' => backup::VAR_PARENTID));
00122 
00123         // don't need to annotate ids nor files
00124     }
00125 
00131     protected function add_question_datasets($element) {
00132         // Check $element is one nested_backup_element
00133         if (! $element instanceof backup_nested_element) {
00134             throw new backup_step_exception('question_datasets_bad_parent_element', $element);
00135         }
00136 
00137         // Define the elements
00138         $definitions = new backup_nested_element('dataset_definitions');
00139         $definition = new backup_nested_element('dataset_definition', array('id'), array(
00140             'category', 'name', 'type', 'options',
00141             'itemcount'));
00142 
00143         $items = new backup_nested_element('dataset_items');
00144         $item = new backup_nested_element('dataset_item', array('id'), array(
00145             'number', 'value'));
00146 
00147         // Build the tree
00148         $element->add_child($definitions);
00149         $definitions->add_child($definition);
00150 
00151         $definition->add_child($items);
00152         $items->add_child($item);
00153 
00154         // Set the sources
00155         $definition->set_source_sql('SELECT qdd.*
00156                                        FROM {question_dataset_definitions} qdd
00157                                        JOIN {question_datasets} qd ON qd.datasetdefinition = qdd.id
00158                                       WHERE qd.question = ?', array(backup::VAR_PARENTID));
00159 
00160         $item->set_source_table('question_dataset_items', array('definition' => backup::VAR_PARENTID));
00161 
00162         // Aliases
00163         $item->set_source_alias('itemnumber', 'number');
00164 
00165         // don't need to annotate ids nor files
00166     }
00167 
00181     public static function get_components_and_fileareas($filter = null) {
00182         $components = array();
00183         // Get all the plugins of this type
00184         $qtypes = get_plugin_list('qtype');
00185         foreach ($qtypes as $name => $path) {
00186             // Apply filter if specified
00187             if (!is_null($filter) && $filter != $name) {
00188                 continue;
00189             }
00190             // Calculate the componentname
00191             $componentname = 'qtype_' . $name;
00192             // Get the plugin fileareas (all them MUST belong to the same component)
00193             $classname = 'backup_qtype_' . $name . '_plugin';
00194             if (class_exists($classname)) {
00195                 $elements = call_user_func(array($classname, 'get_qtype_fileareas'));
00196                 if ($elements) {
00197                     // If there are elements, add them to $components
00198                     $components[$componentname] = $elements;
00199                 }
00200             }
00201         }
00202         return $components;
00203     }
00204 
00211     public static function get_qtype_fileareas() {
00212         // By default, return empty array, only qtypes having own fileareas will override this
00213         return array();
00214     }
00215 }
 All Data Structures Namespaces Files Functions Variables Enumerations