Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/backup/util/structure/backup_structure_processor.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 
00035 class backup_structure_processor extends base_processor {
00036 
00037     protected $writer; // xml_writer where the processor is going to output data
00038     protected $vars;   // array of backup::VAR_XXX => helper value pairs to be used by source specifications
00039 
00040     public function __construct(xml_writer $writer) {
00041         $this->writer = $writer;
00042         $this->vars   = array();
00043     }
00044 
00045     public function set_var($key, $value) {
00046         if (isset($this->vars[$key])) {
00047             throw new backup_processor_exception('processorvariablealreadyset', $key);
00048         }
00049         $this->vars[$key] = $value;
00050     }
00051 
00052     public function get_var($key) {
00053         if (!isset($this->vars[$key])) {
00054             throw new backup_processor_exception('processorvariablenotfound', $key);
00055         }
00056         return $this->vars[$key];
00057     }
00058 
00059     public function pre_process_nested_element(base_nested_element $nested) {
00060         // Send open tag to xml_writer
00061         $attrarr = array();
00062         foreach ($nested->get_attributes() as $attribute) {
00063             $attrarr[$attribute->get_name()] = $attribute->get_value();
00064         }
00065         $this->writer->begin_tag($nested->get_name(), $attrarr);
00066     }
00067 
00068     public function process_nested_element(base_nested_element $nested) {
00069         // Proceed with all the file annotations for this element
00070         $fileannotations = $nested->get_file_annotations();
00071         if ($fileannotations) { // If there are areas to search
00072             $backupid  = $this->get_var(backup::VAR_BACKUPID);
00073             foreach ($fileannotations as $component => $area) {
00074                 foreach ($area as $filearea => $info) {
00075                     $contextid = !is_null($info->contextid) ? $info->contextid : $this->get_var(backup::VAR_CONTEXTID);
00076                     $itemid    = !is_null($info->element) ? $info->element->get_value() : null;
00077                     backup_structure_dbops::annotate_files($backupid, $contextid, $component, $filearea, $itemid);
00078                 }
00079             }
00080         }
00081     }
00082 
00083     public function post_process_nested_element(base_nested_element $nested) {
00084         // Send close tag to xml_writer
00085         $this->writer->end_tag($nested->get_name());
00086     }
00087 
00088     public function process_final_element(base_final_element $final) {
00089         // Send full tag to xml_writer and annotations (only if has value)
00090         if ($final->is_set()) {
00091             $attrarr = array();
00092             foreach ($final->get_attributes() as $attribute) {
00093                 $attrarr[$attribute->get_name()] = $attribute->get_value();
00094             }
00095             $this->writer->full_tag($final->get_name(), $final->get_value(), $attrarr);
00096             // Annotate current value if configured to do so
00097             $final->annotate($this->get_var(backup::VAR_BACKUPID));
00098         }
00099     }
00100 
00101     public function process_attribute(base_attribute $attribute) {
00102         // Annotate current value if configured to do so
00103         $attribute->annotate($this->get_var(backup::VAR_BACKUPID));
00104     }
00105 }
00106 
00113 class backup_processor_exception extends base_processor_exception {
00114 
00122     public function __construct($errorcode, $a = null, $debuginfo = null) {
00123         parent::__construct($errorcode, $a, $debuginfo);
00124     }
00125 }
 All Data Structures Namespaces Files Functions Variables Enumerations