Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/backup/util/dbops/backup_question_dbops.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 
00033 abstract class backup_question_dbops extends backup_dbops {
00034 
00040     public static function calculate_question_categories($backupid, $contextid) {
00041         global $DB;
00042 
00043         // First step, annotate all the categories for the given context (course/module)
00044         // i.e. the whole context questions bank
00045         $DB->execute("INSERT INTO {backup_ids_temp} (backupid, itemname, itemid)
00046                       SELECT ?, 'question_category', id
00047                         FROM {question_categories}
00048                        WHERE contextid = ?", array($backupid, $contextid));
00049 
00050         // Now, based in the annotated questions, annotate all the categories they
00051         // belong to (whole context question banks too)
00052         // First, get all the contexts we are going to save their question bank (no matter
00053         // where they are in the contexts hierarchy, transversals... whatever)
00054         $contexts = $DB->get_fieldset_sql("SELECT DISTINCT qc2.contextid
00055                                              FROM {question_categories} qc2
00056                                              JOIN {question} q ON q.category = qc2.id
00057                                              JOIN {backup_ids_temp} bi ON bi.itemid = q.id
00058                                             WHERE bi.backupid = ?
00059                                               AND bi.itemname = 'question'
00060                                               AND qc2.contextid != ?", array($backupid, $contextid));
00061         // And now, simply insert all the question categories (complete question bank)
00062         // for those contexts if we have found any
00063         if ($contexts) {
00064             list($contextssql, $contextparams) = $DB->get_in_or_equal($contexts);
00065             $params = array_merge(array($backupid), $contextparams);
00066             $DB->execute("INSERT INTO {backup_ids_temp} (backupid, itemname, itemid)
00067                           SELECT ?, 'question_category', id
00068                             FROM {question_categories}
00069                            WHERE contextid $contextssql", $params);
00070         }
00071     }
00072 
00076     public static function delete_temp_questions($backupid) {
00077         global $DB;
00078         $DB->delete_records('backup_ids_temp', array('backupid' => $backupid, 'itemname' => 'question'));
00079     }
00080 }
 All Data Structures Namespaces Files Functions Variables Enumerations