|
Moodle
2.2.1
http://www.collinsharper.com
|
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 00029 class mock_base_attribute extends base_attribute { 00030 // Nothing to do. Just allow instances to be created 00031 } 00032 00036 class mock_base_final_element extends base_final_element { 00038 protected function get_new_attribute($name) { 00039 return new mock_base_attribute($name); 00040 } 00041 } 00042 00046 class mock_base_nested_element extends base_nested_element { 00048 protected function get_new_attribute($name) { 00049 return new mock_base_attribute($name); 00050 } 00051 00052 protected function get_new_final_element($name) { 00053 return new mock_base_final_element($name); 00054 } 00055 } 00056 00060 class mock_base_optigroup extends base_optigroup { 00062 protected function get_new_attribute($name) { 00063 return new mock_base_attribute($name); 00064 } 00065 00066 protected function get_new_final_element($name) { 00067 return new mock_base_final_element($name); 00068 } 00069 00070 public function is_multiple() { 00071 return parent::is_multiple(); 00072 } 00073 } 00074 00078 class mock_skip_final_element extends backup_final_element { 00079 00080 public function set_value($value) { 00081 $this->clean_value(); 00082 } 00083 } 00084 00088 class mock_modify_final_element extends backup_final_element { 00089 public function set_value($value) { 00090 parent::set_value('original was ' . $value . ', now changed'); 00091 } 00092 } 00093 00097 class mock_final_element_interceptor extends backup_final_element { 00098 public function set_value($value) { 00099 // Get grandparent name 00100 $gpname = $this->get_grandparent()->get_name(); 00101 // Get parent name 00102 $pname = $this->get_parent()->get_name(); 00103 // Get my name 00104 $myname = $this->get_name(); 00105 // Define class and function name 00106 $classname = 'mock_' . $gpname . '_' . $pname . '_interceptor'; 00107 $methodname= 'intercept_' . $pname . '_' . $myname; 00108 // Invoke the interception method 00109 $result = call_user_func(array($classname, $methodname), $value); 00110 // Finally set it 00111 parent::set_value($result); 00112 } 00113 } 00114 00118 abstract class mock_forum_forum_interceptor { 00119 static function intercept_forum_completionposts($element) { 00120 return 'intercepted!'; 00121 } 00122 } 00123