Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/backup/util/structure/backup_optigroup.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 
00045 class backup_optigroup extends base_optigroup implements processable {
00046 
00047     public function add_child($element) {
00048         if (!($element instanceof backup_optigroup_element)) { // parameter must be backup_optigroup_element
00049             if (is_object($element)) {
00050                 $found = get_class($element);
00051             } else {
00052                 $found = 'non object';
00053             }
00054             throw new base_optigroup_exception('optigroup_element_incorrect', $found);
00055         }
00056         parent::add_child($element);
00057     }
00058 
00059     public function process($processor) {
00060         if (!$processor instanceof base_processor) { // No correct processor, throw exception
00061             throw new base_element_struct_exception('incorrect_processor');
00062         }
00063         // Iterate over all the children backup_optigroup_elements, delegating the process
00064         // an knowing it only handles final elements, so we'll delegate process of nested
00065         // elements below. Tricky but we need to priorize finals BEFORE nested always.
00066         foreach ($this->get_children() as $child) {
00067             if ($child->condition_matches()) { // Only if the optigroup_element condition matches
00068                 $child->process($processor);
00069                 if (!$this->is_multiple()) {
00070                     break; // one match found and this optigroup is not multiple => break loop
00071                 }
00072             }
00073         }
00074         // Now iterate again, but looking for nested elements what will go AFTER all the finals
00075         // that have been processed above
00076         foreach ($this->get_children() as $child) {
00077             if ($child->condition_matches()) { // Only if the optigroup_element condition matches
00078                 foreach ($child->get_children() as $nested_element) {
00079                      $nested_element->process($processor);
00080                 }
00081                 if (!$this->is_multiple()) {
00082                     break; // one match found and this optigroup is not multiple => break loop
00083                 }
00084             }
00085         }
00086     }
00087 }
 All Data Structures Namespaces Files Functions Variables Enumerations