@@ -95,7 +95,7 @@ |
||
95 | 95 | |
96 | 96 | /** |
97 | 97 | * Get the progress of this learnpath. Only the last attempt are taken into account. |
98 | - * @param $stud_id student id (default: all students who have results - then the average is returned) |
|
98 | + * @param integer $stud_id student id (default: all students who have results - then the average is returned) |
|
99 | 99 | * @return array (score, max) if student is given |
100 | 100 | * array (sum of scores, number of scores) otherwise |
101 | 101 | * or null if no scores available |
@@ -9,261 +9,261 @@ |
||
9 | 9 | */ |
10 | 10 | class LearnpathLink extends AbstractLink |
11 | 11 | { |
12 | - private $course_info = null; |
|
13 | - private $learnpath_table = null; |
|
14 | - private $learnpath_data = null; |
|
15 | - |
|
16 | - /** |
|
17 | - * Constructor |
|
18 | - */ |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - parent::__construct(); |
|
22 | - $this->set_type(LINK_LEARNPATH); |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * Generate an array of learnpaths that a teacher hasn't created a link for. |
|
27 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
28 | - */ |
|
29 | - public function get_not_created_links() |
|
30 | - { |
|
31 | - return false; |
|
32 | - if (empty($this->course_code)) |
|
33 | - die('Error in get_not_created_links() : course code not set'); |
|
34 | - |
|
35 | - $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
36 | - |
|
37 | - $sql = 'SELECT id, name from '.$this->get_learnpath_table().' lp |
|
12 | + private $course_info = null; |
|
13 | + private $learnpath_table = null; |
|
14 | + private $learnpath_data = null; |
|
15 | + |
|
16 | + /** |
|
17 | + * Constructor |
|
18 | + */ |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + parent::__construct(); |
|
22 | + $this->set_type(LINK_LEARNPATH); |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * Generate an array of learnpaths that a teacher hasn't created a link for. |
|
27 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
28 | + */ |
|
29 | + public function get_not_created_links() |
|
30 | + { |
|
31 | + return false; |
|
32 | + if (empty($this->course_code)) |
|
33 | + die('Error in get_not_created_links() : course code not set'); |
|
34 | + |
|
35 | + $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
36 | + |
|
37 | + $sql = 'SELECT id, name from '.$this->get_learnpath_table().' lp |
|
38 | 38 | WHERE c_id = '.$this->course_id.' AND id NOT IN ' |
39 | - .' (SELECT ref_id FROM '.$tbl_grade_links |
|
40 | - .' WHERE type = '.LINK_LEARNPATH |
|
41 | - ." AND course_code = '".$this->get_course_code()."'" |
|
42 | - .') AND lp.session_id='.api_get_session_id().''; |
|
43 | - |
|
44 | - $result = Database::query($sql); |
|
45 | - |
|
46 | - $cats=array(); |
|
47 | - while ($data=Database::fetch_array($result)) { |
|
48 | - $cats[] = array ($data['id'], $data['name']); |
|
49 | - } |
|
50 | - |
|
51 | - return $cats; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Generate an array of all learnpaths available. |
|
56 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
57 | - */ |
|
58 | - public function get_all_links() |
|
59 | - { |
|
60 | - if (empty($this->course_code)) |
|
61 | - die('Error in get_not_created_links() : course code not set'); |
|
62 | - |
|
63 | - $session_id = api_get_session_id(); |
|
64 | - if (empty($session_id)) { |
|
65 | - $session_condition = api_get_session_condition(0, true); |
|
66 | - } else { |
|
67 | - $session_condition = api_get_session_condition($session_id, true, true); |
|
68 | - } |
|
69 | - |
|
70 | - $sql = 'SELECT id, name FROM '.$this->get_learnpath_table().' |
|
39 | + .' (SELECT ref_id FROM '.$tbl_grade_links |
|
40 | + .' WHERE type = '.LINK_LEARNPATH |
|
41 | + ." AND course_code = '".$this->get_course_code()."'" |
|
42 | + .') AND lp.session_id='.api_get_session_id().''; |
|
43 | + |
|
44 | + $result = Database::query($sql); |
|
45 | + |
|
46 | + $cats=array(); |
|
47 | + while ($data=Database::fetch_array($result)) { |
|
48 | + $cats[] = array ($data['id'], $data['name']); |
|
49 | + } |
|
50 | + |
|
51 | + return $cats; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Generate an array of all learnpaths available. |
|
56 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
57 | + */ |
|
58 | + public function get_all_links() |
|
59 | + { |
|
60 | + if (empty($this->course_code)) |
|
61 | + die('Error in get_not_created_links() : course code not set'); |
|
62 | + |
|
63 | + $session_id = api_get_session_id(); |
|
64 | + if (empty($session_id)) { |
|
65 | + $session_condition = api_get_session_condition(0, true); |
|
66 | + } else { |
|
67 | + $session_condition = api_get_session_condition($session_id, true, true); |
|
68 | + } |
|
69 | + |
|
70 | + $sql = 'SELECT id, name FROM '.$this->get_learnpath_table().' |
|
71 | 71 | WHERE c_id = '.$this->course_id.' '.$session_condition.' '; |
72 | - $result = Database::query($sql); |
|
72 | + $result = Database::query($sql); |
|
73 | 73 | |
74 | - $cats = array(); |
|
75 | - while ($data=Database::fetch_array($result)) { |
|
76 | - $cats[] = array ($data['id'], $data['name']); |
|
77 | - } |
|
74 | + $cats = array(); |
|
75 | + while ($data=Database::fetch_array($result)) { |
|
76 | + $cats[] = array ($data['id'], $data['name']); |
|
77 | + } |
|
78 | 78 | |
79 | - return $cats; |
|
80 | - } |
|
79 | + return $cats; |
|
80 | + } |
|
81 | 81 | |
82 | 82 | |
83 | - /** |
|
84 | - * Has anyone used this learnpath yet ? |
|
85 | - */ |
|
86 | - public function has_results() |
|
87 | - { |
|
88 | - $tbl_stats = Database::get_course_table(TABLE_LP_VIEW); |
|
89 | - $sql = "SELECT count(id) AS number FROM $tbl_stats |
|
83 | + /** |
|
84 | + * Has anyone used this learnpath yet ? |
|
85 | + */ |
|
86 | + public function has_results() |
|
87 | + { |
|
88 | + $tbl_stats = Database::get_course_table(TABLE_LP_VIEW); |
|
89 | + $sql = "SELECT count(id) AS number FROM $tbl_stats |
|
90 | 90 | WHERE c_id = ".$this->course_id." AND lp_id = ".$this->get_ref_id(); |
91 | - $result = Database::query($sql); |
|
92 | - $number = Database::fetch_array($result,'NUM'); |
|
93 | - return ($number[0] != 0); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Get the progress of this learnpath. Only the last attempt are taken into account. |
|
98 | - * @param $stud_id student id (default: all students who have results - then the average is returned) |
|
99 | - * @return array (score, max) if student is given |
|
100 | - * array (sum of scores, number of scores) otherwise |
|
101 | - * or null if no scores available |
|
102 | - */ |
|
103 | - public function calc_score($stud_id = null, $type = null) |
|
104 | - { |
|
105 | - $tbl_stats = Database::get_course_table(TABLE_LP_VIEW); |
|
106 | - $session_id = api_get_session_id(); |
|
107 | - |
|
108 | - $sql = "SELECT * FROM $tbl_stats |
|
91 | + $result = Database::query($sql); |
|
92 | + $number = Database::fetch_array($result,'NUM'); |
|
93 | + return ($number[0] != 0); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Get the progress of this learnpath. Only the last attempt are taken into account. |
|
98 | + * @param $stud_id student id (default: all students who have results - then the average is returned) |
|
99 | + * @return array (score, max) if student is given |
|
100 | + * array (sum of scores, number of scores) otherwise |
|
101 | + * or null if no scores available |
|
102 | + */ |
|
103 | + public function calc_score($stud_id = null, $type = null) |
|
104 | + { |
|
105 | + $tbl_stats = Database::get_course_table(TABLE_LP_VIEW); |
|
106 | + $session_id = api_get_session_id(); |
|
107 | + |
|
108 | + $sql = "SELECT * FROM $tbl_stats |
|
109 | 109 | WHERE |
110 | 110 | c_id = ".$this->course_id." AND |
111 | 111 | lp_id = ".$this->get_ref_id()." AND |
112 | 112 | session_id = $session_id "; |
113 | 113 | |
114 | - if (isset($stud_id)) |
|
115 | - $sql .= ' AND user_id = '.intval($stud_id); |
|
116 | - |
|
117 | - // order by id, that way the student's first attempt is accessed first |
|
118 | - $sql .= ' ORDER BY view_count DESC'; |
|
119 | - |
|
120 | - $scores = Database::query($sql); |
|
121 | - // for 1 student |
|
122 | - if (isset($stud_id)) { |
|
123 | - if ($data = Database::fetch_assoc($scores)) { |
|
124 | - return array ($data['progress'], 100); |
|
125 | - } else |
|
126 | - return null; |
|
127 | - } else { |
|
128 | - // all students -> get average |
|
129 | - $students = array(); // user list, needed to make sure we only |
|
130 | - // take first attempts into account |
|
131 | - $rescount = 0; |
|
132 | - $sum = 0; |
|
133 | - $bestResult = 0; |
|
134 | - $sumResult = 0; |
|
135 | - while ($data = Database::fetch_array($scores)) { |
|
136 | - if (!(array_key_exists($data['user_id'], $students))) { |
|
137 | - $students[$data['user_id']] = $data['progress']; |
|
138 | - $rescount++; |
|
139 | - $sum += $data['progress'] / 100; |
|
140 | - $sumResult += $data['progress']; |
|
141 | - |
|
142 | - if ($data['progress'] > $bestResult) { |
|
143 | - $bestResult = $data['progress']; |
|
144 | - } |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - if ($rescount == 0) { |
|
149 | - return null; |
|
150 | - } else { |
|
151 | - |
|
152 | - switch ($type) { |
|
153 | - case 'best': |
|
154 | - return array($bestResult, 100); |
|
155 | - break; |
|
156 | - case 'average': |
|
157 | - return array($sumResult/$rescount, 100); |
|
158 | - break; |
|
159 | - case 'ranking': |
|
160 | - return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
161 | - break; |
|
162 | - default: |
|
163 | - return array($sum, $rescount); |
|
164 | - break; |
|
165 | - } |
|
166 | - } |
|
167 | - } |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Get URL where to go to if the user clicks on the link. |
|
172 | - */ |
|
173 | - public function get_link() |
|
174 | - { |
|
175 | - $session_id = api_get_session_id(); |
|
176 | - $url = api_get_path(WEB_CODE_PATH) . 'lp/lp_controller.php?'.api_get_cidreq_params($this->get_course_code(), $session_id).'&gradebook=view'; |
|
177 | - |
|
178 | - if (!api_is_allowed_to_edit() || $this->calc_score(api_get_user_id()) == null) { |
|
179 | - $url .= '&action=view&lp_id='.$this->get_ref_id(); |
|
180 | - } else { |
|
181 | - $url .= '&action=build&lp_id='.$this->get_ref_id(); |
|
182 | - } |
|
183 | - return $url; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Get name to display: same as learnpath title |
|
188 | - */ |
|
189 | - public function get_name() |
|
190 | - { |
|
191 | - $data = $this->get_learnpath_data(); |
|
192 | - return $data['name']; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Get description to display: same as learnpath description |
|
197 | - */ |
|
198 | - public function get_description() |
|
199 | - { |
|
200 | - $data = $this->get_learnpath_data(); |
|
201 | - return $data['description']; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Check if this still links to a learnpath |
|
206 | - */ |
|
207 | - public function is_valid_link() { |
|
208 | - $sql = 'SELECT count(id) FROM '.$this->get_learnpath_table().' |
|
114 | + if (isset($stud_id)) |
|
115 | + $sql .= ' AND user_id = '.intval($stud_id); |
|
116 | + |
|
117 | + // order by id, that way the student's first attempt is accessed first |
|
118 | + $sql .= ' ORDER BY view_count DESC'; |
|
119 | + |
|
120 | + $scores = Database::query($sql); |
|
121 | + // for 1 student |
|
122 | + if (isset($stud_id)) { |
|
123 | + if ($data = Database::fetch_assoc($scores)) { |
|
124 | + return array ($data['progress'], 100); |
|
125 | + } else |
|
126 | + return null; |
|
127 | + } else { |
|
128 | + // all students -> get average |
|
129 | + $students = array(); // user list, needed to make sure we only |
|
130 | + // take first attempts into account |
|
131 | + $rescount = 0; |
|
132 | + $sum = 0; |
|
133 | + $bestResult = 0; |
|
134 | + $sumResult = 0; |
|
135 | + while ($data = Database::fetch_array($scores)) { |
|
136 | + if (!(array_key_exists($data['user_id'], $students))) { |
|
137 | + $students[$data['user_id']] = $data['progress']; |
|
138 | + $rescount++; |
|
139 | + $sum += $data['progress'] / 100; |
|
140 | + $sumResult += $data['progress']; |
|
141 | + |
|
142 | + if ($data['progress'] > $bestResult) { |
|
143 | + $bestResult = $data['progress']; |
|
144 | + } |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + if ($rescount == 0) { |
|
149 | + return null; |
|
150 | + } else { |
|
151 | + |
|
152 | + switch ($type) { |
|
153 | + case 'best': |
|
154 | + return array($bestResult, 100); |
|
155 | + break; |
|
156 | + case 'average': |
|
157 | + return array($sumResult/$rescount, 100); |
|
158 | + break; |
|
159 | + case 'ranking': |
|
160 | + return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
161 | + break; |
|
162 | + default: |
|
163 | + return array($sum, $rescount); |
|
164 | + break; |
|
165 | + } |
|
166 | + } |
|
167 | + } |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Get URL where to go to if the user clicks on the link. |
|
172 | + */ |
|
173 | + public function get_link() |
|
174 | + { |
|
175 | + $session_id = api_get_session_id(); |
|
176 | + $url = api_get_path(WEB_CODE_PATH) . 'lp/lp_controller.php?'.api_get_cidreq_params($this->get_course_code(), $session_id).'&gradebook=view'; |
|
177 | + |
|
178 | + if (!api_is_allowed_to_edit() || $this->calc_score(api_get_user_id()) == null) { |
|
179 | + $url .= '&action=view&lp_id='.$this->get_ref_id(); |
|
180 | + } else { |
|
181 | + $url .= '&action=build&lp_id='.$this->get_ref_id(); |
|
182 | + } |
|
183 | + return $url; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Get name to display: same as learnpath title |
|
188 | + */ |
|
189 | + public function get_name() |
|
190 | + { |
|
191 | + $data = $this->get_learnpath_data(); |
|
192 | + return $data['name']; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Get description to display: same as learnpath description |
|
197 | + */ |
|
198 | + public function get_description() |
|
199 | + { |
|
200 | + $data = $this->get_learnpath_data(); |
|
201 | + return $data['description']; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Check if this still links to a learnpath |
|
206 | + */ |
|
207 | + public function is_valid_link() { |
|
208 | + $sql = 'SELECT count(id) FROM '.$this->get_learnpath_table().' |
|
209 | 209 | WHERE c_id = '.$this->course_id.' AND id = '.$this->get_ref_id().' '; |
210 | - $result = Database::query($sql); |
|
211 | - $number = Database::fetch_row($result,'NUM'); |
|
212 | - return ($number[0] != 0); |
|
213 | - } |
|
214 | - |
|
215 | - public function get_type_name() |
|
216 | - { |
|
217 | - return get_lang('LearningPaths'); |
|
218 | - } |
|
219 | - |
|
220 | - public function needs_name_and_description() |
|
221 | - { |
|
222 | - return false; |
|
223 | - } |
|
224 | - |
|
225 | - public function needs_max() |
|
226 | - { |
|
227 | - return false; |
|
228 | - } |
|
229 | - |
|
230 | - public function needs_results() |
|
231 | - { |
|
232 | - return false; |
|
233 | - } |
|
234 | - |
|
235 | - public function is_allowed_to_change_name() |
|
236 | - { |
|
237 | - return false; |
|
238 | - } |
|
239 | - |
|
240 | - // INTERNAL FUNCTIONS |
|
241 | - |
|
242 | - /** |
|
243 | - * Lazy load function to get the database table of the learnpath |
|
244 | - */ |
|
245 | - private function get_learnpath_table() |
|
246 | - { |
|
247 | - $this->learnpath_table = Database :: get_course_table(TABLE_LP_MAIN); |
|
248 | - return $this->learnpath_table; |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * Lazy load function to get the database contents of this learnpath |
|
253 | - */ |
|
254 | - private function get_learnpath_data() |
|
255 | - { |
|
256 | - if (!isset($this->learnpath_data)) { |
|
257 | - $sql = 'SELECT * FROM '.$this->get_learnpath_table().' |
|
210 | + $result = Database::query($sql); |
|
211 | + $number = Database::fetch_row($result,'NUM'); |
|
212 | + return ($number[0] != 0); |
|
213 | + } |
|
214 | + |
|
215 | + public function get_type_name() |
|
216 | + { |
|
217 | + return get_lang('LearningPaths'); |
|
218 | + } |
|
219 | + |
|
220 | + public function needs_name_and_description() |
|
221 | + { |
|
222 | + return false; |
|
223 | + } |
|
224 | + |
|
225 | + public function needs_max() |
|
226 | + { |
|
227 | + return false; |
|
228 | + } |
|
229 | + |
|
230 | + public function needs_results() |
|
231 | + { |
|
232 | + return false; |
|
233 | + } |
|
234 | + |
|
235 | + public function is_allowed_to_change_name() |
|
236 | + { |
|
237 | + return false; |
|
238 | + } |
|
239 | + |
|
240 | + // INTERNAL FUNCTIONS |
|
241 | + |
|
242 | + /** |
|
243 | + * Lazy load function to get the database table of the learnpath |
|
244 | + */ |
|
245 | + private function get_learnpath_table() |
|
246 | + { |
|
247 | + $this->learnpath_table = Database :: get_course_table(TABLE_LP_MAIN); |
|
248 | + return $this->learnpath_table; |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * Lazy load function to get the database contents of this learnpath |
|
253 | + */ |
|
254 | + private function get_learnpath_data() |
|
255 | + { |
|
256 | + if (!isset($this->learnpath_data)) { |
|
257 | + $sql = 'SELECT * FROM '.$this->get_learnpath_table().' |
|
258 | 258 | WHERE c_id = '.$this->course_id.' AND id = '.$this->get_ref_id().' '; |
259 | - $result = Database::query($sql); |
|
260 | - $this->learnpath_data = Database::fetch_array($result); |
|
261 | - } |
|
262 | - return $this->learnpath_data; |
|
263 | - } |
|
264 | - |
|
265 | - public function get_icon_name() |
|
266 | - { |
|
267 | - return 'learnpath'; |
|
268 | - } |
|
259 | + $result = Database::query($sql); |
|
260 | + $this->learnpath_data = Database::fetch_array($result); |
|
261 | + } |
|
262 | + return $this->learnpath_data; |
|
263 | + } |
|
264 | + |
|
265 | + public function get_icon_name() |
|
266 | + { |
|
267 | + return 'learnpath'; |
|
268 | + } |
|
269 | 269 | } |
@@ -32,6 +32,8 @@ discard block |
||
32 | 32 | * @param array $evals |
33 | 33 | * @param array $links |
34 | 34 | * @param null $addparams |
35 | + * @param boolean $showTeacherView |
|
36 | + * @param integer $userId |
|
35 | 37 | */ |
36 | 38 | public function __construct( |
37 | 39 | $currentcat, |
@@ -895,7 +897,7 @@ discard block |
||
895 | 897 | |
896 | 898 | /** |
897 | 899 | * @param $item |
898 | - * @return mixed |
|
900 | + * @return string|null |
|
899 | 901 | */ |
900 | 902 | private function build_course_code($item) |
901 | 903 | { |
@@ -351,6 +351,12 @@ |
||
351 | 351 | |
352 | 352 | /** |
353 | 353 | * Additional functions needed for fast integration |
354 | + * @param integer $status |
|
355 | + * @param string $section |
|
356 | + * @param string $title |
|
357 | + * @param string $url |
|
358 | + * @param string|null $formatter |
|
359 | + * @param string $comment |
|
354 | 360 | */ |
355 | 361 | public function build_setting($status, $section, $title, $url, $current_value, $expected_value, $formatter, $comment, $img_path = null) { |
356 | 362 | switch ($status) { |
@@ -401,19 +401,19 @@ |
||
401 | 401 | |
402 | 402 | public function format_yes_no_optional($value) |
403 | 403 | { |
404 | - $return = ''; |
|
405 | - switch($value) { |
|
406 | - case 0: |
|
407 | - $return = get_lang('No'); |
|
408 | - break; |
|
409 | - case 1: |
|
410 | - $return = get_lang('Yes'); |
|
411 | - break; |
|
412 | - case 2: |
|
413 | - $return = get_lang('Optional'); |
|
414 | - break; |
|
415 | - } |
|
416 | - return $return; |
|
404 | + $return = ''; |
|
405 | + switch($value) { |
|
406 | + case 0: |
|
407 | + $return = get_lang('No'); |
|
408 | + break; |
|
409 | + case 1: |
|
410 | + $return = get_lang('Yes'); |
|
411 | + break; |
|
412 | + case 2: |
|
413 | + $return = get_lang('Optional'); |
|
414 | + break; |
|
415 | + } |
|
416 | + return $return; |
|
417 | 417 | |
418 | 418 | } |
419 | 419 |
@@ -1255,6 +1255,7 @@ discard block |
||
1255 | 1255 | |
1256 | 1256 | /** |
1257 | 1257 | * Validates the time control key |
1258 | + * @param integer $exercise_id |
|
1258 | 1259 | */ |
1259 | 1260 | public static function exercise_time_control_is_valid( |
1260 | 1261 | $exercise_id, |
@@ -1388,7 +1389,7 @@ discard block |
||
1388 | 1389 | * @param int $in_direction |
1389 | 1390 | * @param string $in_hotpot_path |
1390 | 1391 | * @param bool $in_get_count |
1391 | - * @param null $where_condition |
|
1392 | + * @param string $where_condition |
|
1392 | 1393 | * @return array|int |
1393 | 1394 | */ |
1394 | 1395 | public static function get_exam_results_hotpotatoes_data( |
@@ -2179,7 +2180,7 @@ discard block |
||
2179 | 2180 | /** |
2180 | 2181 | * Return true if pass_pourcentage activated (we use the pass pourcentage feature |
2181 | 2182 | * return false if pass_percentage = 0 (we don't use the pass pourcentage feature |
2182 | - * @param $in_pass_pourcentage |
|
2183 | + * @param string $in_pass_pourcentage |
|
2183 | 2184 | * @return boolean |
2184 | 2185 | * In this version, pass_percentage and show_success_message are disabled if |
2185 | 2186 | * pass_percentage is set to 0 |
@@ -2192,7 +2193,7 @@ discard block |
||
2192 | 2193 | /** |
2193 | 2194 | * Converts a numeric value in a percentage example 0.66666 to 66.67 % |
2194 | 2195 | * @param $value |
2195 | - * @return float Converted number |
|
2196 | + * @return string Converted number |
|
2196 | 2197 | */ |
2197 | 2198 | public static function convert_to_percentage($value) |
2198 | 2199 | { |
@@ -2208,7 +2209,7 @@ discard block |
||
2208 | 2209 | * @param float $score |
2209 | 2210 | * @param float $weight |
2210 | 2211 | * @deprecated seem not to be used |
2211 | - * @return float the score rounded converted to the new range |
|
2212 | + * @return string|null the score rounded converted to the new range |
|
2212 | 2213 | */ |
2213 | 2214 | public static function convert_score($score, $weight) |
2214 | 2215 | { |
@@ -2759,6 +2760,7 @@ discard block |
||
2759 | 2760 | * @param int exercise id |
2760 | 2761 | * @param int $courseId |
2761 | 2762 | * @param int session id |
2763 | + * @param integer $user_count |
|
2762 | 2764 | * @return float Best average score |
2763 | 2765 | */ |
2764 | 2766 | public static function get_best_average_score_by_exercise( |
@@ -3198,8 +3200,9 @@ discard block |
||
3198 | 3200 | } |
3199 | 3201 | |
3200 | 3202 | /** |
3201 | - * @param array $answer |
|
3203 | + * @param string|null $answer |
|
3202 | 3204 | * @param string $user_answer |
3205 | + * @param string|null $current_answer |
|
3203 | 3206 | * @return array |
3204 | 3207 | */ |
3205 | 3208 | public static function check_fill_in_blanks($answer, $user_answer, $current_answer) |
@@ -3805,7 +3808,7 @@ discard block |
||
3805 | 3808 | |
3806 | 3809 | /** |
3807 | 3810 | * @param int $countLetter |
3808 | - * @return mixed |
|
3811 | + * @return string |
|
3809 | 3812 | */ |
3810 | 3813 | public static function detectInputAppropriateClass($countLetter) |
3811 | 3814 | { |
@@ -9,7 +9,6 @@ |
||
9 | 9 | { |
10 | 10 | /** |
11 | 11 | * @param $value array Uploaded file info (from $_FILES) |
12 | - * @param null $options |
|
13 | 12 | * @return bool |
14 | 13 | */ |
15 | 14 | public function validate($elementValue, $maxSize) |
@@ -7,22 +7,22 @@ |
||
7 | 7 | */ |
8 | 8 | class HTML_QuickForm_Rule_MaxFileSize extends HTML_QuickForm_Rule |
9 | 9 | { |
10 | - /** |
|
11 | - * @param $value array Uploaded file info (from $_FILES) |
|
12 | - * @param null $options |
|
13 | - * @return bool |
|
14 | - */ |
|
15 | - public function validate($elementValue, $maxSize) |
|
16 | - { |
|
17 | - if (!empty($elementValue['error']) && |
|
18 | - (UPLOAD_ERR_FORM_SIZE == $elementValue['error'] || UPLOAD_ERR_INI_SIZE == $elementValue['error']) |
|
19 | - ) { |
|
20 | - return false; |
|
21 | - } |
|
22 | - if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) { |
|
23 | - return true; |
|
24 | - } |
|
10 | + /** |
|
11 | + * @param $value array Uploaded file info (from $_FILES) |
|
12 | + * @param null $options |
|
13 | + * @return bool |
|
14 | + */ |
|
15 | + public function validate($elementValue, $maxSize) |
|
16 | + { |
|
17 | + if (!empty($elementValue['error']) && |
|
18 | + (UPLOAD_ERR_FORM_SIZE == $elementValue['error'] || UPLOAD_ERR_INI_SIZE == $elementValue['error']) |
|
19 | + ) { |
|
20 | + return false; |
|
21 | + } |
|
22 | + if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) { |
|
23 | + return true; |
|
24 | + } |
|
25 | 25 | |
26 | - return ($maxSize >= @filesize($elementValue['tmp_name'])); |
|
27 | - } |
|
26 | + return ($maxSize >= @filesize($elementValue['tmp_name'])); |
|
27 | + } |
|
28 | 28 | } |
@@ -16,7 +16,7 @@ |
||
16 | 16 | * |
17 | 17 | * @param string Mobile phone number to be validated |
18 | 18 | * @param string Not using it. Just to respect the declaration |
19 | - * @return boolean Returns true if valid, false otherwise. |
|
19 | + * @return integer Returns true if valid, false otherwise. |
|
20 | 20 | */ |
21 | 21 | function validate($mobilePhoneNumber, $options = null) |
22 | 22 | { |
@@ -138,7 +138,7 @@ |
||
138 | 138 | |
139 | 139 | /** |
140 | 140 | * Return a list an associative array where keys are the active hook observer class name |
141 | - * @param $eventName |
|
141 | + * @param string $eventName |
|
142 | 142 | * |
143 | 143 | * @return array |
144 | 144 | */ |
@@ -25,6 +25,7 @@ |
||
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Useful finder - experimental akelos like only use in notification.lib.php send function |
28 | + * @param string $type |
|
28 | 29 | */ |
29 | 30 | public function find($type, $options = null) |
30 | 31 | { |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | /** |
307 | 307 | * gets the current debug data for this instance |
308 | 308 | * |
309 | - * @return debug data |
|
309 | + * @return string data |
|
310 | 310 | * @access public |
311 | 311 | */ |
312 | 312 | function &getDebug() { |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | * gets the current debug data for this instance as an XML comment |
320 | 320 | * this may change the contents of the debug data |
321 | 321 | * |
322 | - * @return debug data as an XML comment |
|
322 | + * @return string data as an XML comment |
|
323 | 323 | * @access public |
324 | 324 | */ |
325 | 325 | function &getDebugAsXMLComment() { |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | /** |
353 | 353 | * returns error string if present |
354 | 354 | * |
355 | - * @return mixed error string or false |
|
355 | + * @return string|false error string or false |
|
356 | 356 | * @access public |
357 | 357 | */ |
358 | 358 | function getError(){ |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | /** |
366 | 366 | * sets error string |
367 | 367 | * |
368 | - * @return boolean $string error string |
|
368 | + * @return boolean|null $string error string |
|
369 | 369 | * @access private |
370 | 370 | */ |
371 | 371 | function setError($str){ |
@@ -801,7 +801,7 @@ discard block |
||
801 | 801 | * returns false, if not prefixed |
802 | 802 | * |
803 | 803 | * @param string $str The prefixed string |
804 | - * @return mixed The prefix or false if there is no prefix |
|
804 | + * @return string|false The prefix or false if there is no prefix |
|
805 | 805 | * @access public |
806 | 806 | */ |
807 | 807 | function getPrefix($str){ |
@@ -832,7 +832,7 @@ discard block |
||
832 | 832 | * or false if no prefixes registered for the given namespace |
833 | 833 | * |
834 | 834 | * @param string $ns The namespace |
835 | - * @return mixed The prefix, false if the namespace has no prefixes |
|
835 | + * @return string The prefix, false if the namespace has no prefixes |
|
836 | 836 | * @access public |
837 | 837 | */ |
838 | 838 | function getPrefixFromNamespace($ns) { |
@@ -898,7 +898,7 @@ discard block |
||
898 | 898 | * |
899 | 899 | * @param int $timestamp Unix time stamp |
900 | 900 | * @param boolean $utc Whether the time stamp is UTC or local |
901 | -* @return mixed ISO 8601 date string or false |
|
901 | +* @return string|false ISO 8601 date string or false |
|
902 | 902 | * @access public |
903 | 903 | */ |
904 | 904 | function timestamp_to_iso8601($timestamp,$utc=true){ |
@@ -84,810 +84,810 @@ discard block |
||
84 | 84 | */ |
85 | 85 | class nusoap_base |
86 | 86 | { |
87 | - /** |
|
88 | - * Identification for HTTP headers. |
|
89 | - * |
|
90 | - * @var string |
|
91 | - * @access private |
|
92 | - */ |
|
93 | - var $title = 'NuSOAP'; |
|
94 | - /** |
|
95 | - * Version for HTTP headers. |
|
96 | - * |
|
97 | - * @var string |
|
98 | - * @access private |
|
99 | - */ |
|
100 | - var $version = '0.9.5'; |
|
101 | - /** |
|
102 | - * CVS revision for HTTP headers. |
|
103 | - * |
|
104 | - * @var string |
|
105 | - * @access private |
|
106 | - */ |
|
107 | - var $revision = '$Revision: 1.56 $'; |
|
87 | + /** |
|
88 | + * Identification for HTTP headers. |
|
89 | + * |
|
90 | + * @var string |
|
91 | + * @access private |
|
92 | + */ |
|
93 | + var $title = 'NuSOAP'; |
|
94 | + /** |
|
95 | + * Version for HTTP headers. |
|
96 | + * |
|
97 | + * @var string |
|
98 | + * @access private |
|
99 | + */ |
|
100 | + var $version = '0.9.5'; |
|
101 | + /** |
|
102 | + * CVS revision for HTTP headers. |
|
103 | + * |
|
104 | + * @var string |
|
105 | + * @access private |
|
106 | + */ |
|
107 | + var $revision = '$Revision: 1.56 $'; |
|
108 | 108 | /** |
109 | 109 | * Current error string (manipulated by getError/setError) |
110 | - * |
|
111 | - * @var string |
|
112 | - * @access private |
|
113 | - */ |
|
114 | - var $error_str = ''; |
|
110 | + * |
|
111 | + * @var string |
|
112 | + * @access private |
|
113 | + */ |
|
114 | + var $error_str = ''; |
|
115 | 115 | /** |
116 | 116 | * Current debug string (manipulated by debug/appendDebug/clearDebug/getDebug/getDebugAsXMLComment) |
117 | - * |
|
118 | - * @var string |
|
119 | - * @access private |
|
120 | - */ |
|
117 | + * |
|
118 | + * @var string |
|
119 | + * @access private |
|
120 | + */ |
|
121 | 121 | var $debug_str = ''; |
122 | 122 | /** |
123 | - * toggles automatic encoding of special characters as entities |
|
124 | - * (should always be true, I think) |
|
125 | - * |
|
126 | - * @var boolean |
|
127 | - * @access private |
|
128 | - */ |
|
129 | - var $charencoding = true; |
|
130 | - /** |
|
131 | - * the debug level for this instance |
|
132 | - * |
|
133 | - * @var integer |
|
134 | - * @access private |
|
135 | - */ |
|
136 | - var $debugLevel; |
|
137 | - |
|
138 | - /** |
|
139 | - * set schema version |
|
140 | - * |
|
141 | - * @var string |
|
142 | - * @access public |
|
143 | - */ |
|
144 | - var $XMLSchemaVersion = 'http://www.w3.org/2001/XMLSchema'; |
|
145 | - |
|
146 | - /** |
|
147 | - * charset encoding for outgoing messages |
|
148 | - * |
|
149 | - * @var string |
|
150 | - * @access public |
|
151 | - */ |
|
123 | + * toggles automatic encoding of special characters as entities |
|
124 | + * (should always be true, I think) |
|
125 | + * |
|
126 | + * @var boolean |
|
127 | + * @access private |
|
128 | + */ |
|
129 | + var $charencoding = true; |
|
130 | + /** |
|
131 | + * the debug level for this instance |
|
132 | + * |
|
133 | + * @var integer |
|
134 | + * @access private |
|
135 | + */ |
|
136 | + var $debugLevel; |
|
137 | + |
|
138 | + /** |
|
139 | + * set schema version |
|
140 | + * |
|
141 | + * @var string |
|
142 | + * @access public |
|
143 | + */ |
|
144 | + var $XMLSchemaVersion = 'http://www.w3.org/2001/XMLSchema'; |
|
145 | + |
|
146 | + /** |
|
147 | + * charset encoding for outgoing messages |
|
148 | + * |
|
149 | + * @var string |
|
150 | + * @access public |
|
151 | + */ |
|
152 | 152 | var $soap_defencoding = 'ISO-8859-1'; |
153 | - //var $soap_defencoding = 'UTF-8'; |
|
154 | - |
|
155 | - /** |
|
156 | - * namespaces in an array of prefix => uri |
|
157 | - * |
|
158 | - * this is "seeded" by a set of constants, but it may be altered by code |
|
159 | - * |
|
160 | - * @var array |
|
161 | - * @access public |
|
162 | - */ |
|
163 | - var $namespaces = array( |
|
164 | - 'SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/', |
|
165 | - 'xsd' => 'http://www.w3.org/2001/XMLSchema', |
|
166 | - 'xsi' => 'http://www.w3.org/2001/XMLSchema-instance', |
|
167 | - 'SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/' |
|
168 | - ); |
|
169 | - |
|
170 | - /** |
|
171 | - * namespaces used in the current context, e.g. during serialization |
|
172 | - * |
|
173 | - * @var array |
|
174 | - * @access private |
|
175 | - */ |
|
176 | - var $usedNamespaces = array(); |
|
177 | - |
|
178 | - /** |
|
179 | - * XML Schema types in an array of uri => (array of xml type => php type) |
|
180 | - * is this legacy yet? |
|
181 | - * no, this is used by the nusoap_xmlschema class to verify type => namespace mappings. |
|
182 | - * @var array |
|
183 | - * @access public |
|
184 | - */ |
|
185 | - var $typemap = array( |
|
186 | - 'http://www.w3.org/2001/XMLSchema' => array( |
|
187 | - 'string'=>'string','boolean'=>'boolean','float'=>'double','double'=>'double','decimal'=>'double', |
|
188 | - 'duration'=>'','dateTime'=>'string','time'=>'string','date'=>'string','gYearMonth'=>'', |
|
189 | - 'gYear'=>'','gMonthDay'=>'','gDay'=>'','gMonth'=>'','hexBinary'=>'string','base64Binary'=>'string', |
|
190 | - // abstract "any" types |
|
191 | - 'anyType'=>'string','anySimpleType'=>'string', |
|
192 | - // derived datatypes |
|
193 | - 'normalizedString'=>'string','token'=>'string','language'=>'','NMTOKEN'=>'','NMTOKENS'=>'','Name'=>'','NCName'=>'','ID'=>'', |
|
194 | - 'IDREF'=>'','IDREFS'=>'','ENTITY'=>'','ENTITIES'=>'','integer'=>'integer','nonPositiveInteger'=>'integer', |
|
195 | - 'negativeInteger'=>'integer','long'=>'integer','int'=>'integer','short'=>'integer','byte'=>'integer','nonNegativeInteger'=>'integer', |
|
196 | - 'unsignedLong'=>'','unsignedInt'=>'','unsignedShort'=>'','unsignedByte'=>'','positiveInteger'=>''), |
|
197 | - 'http://www.w3.org/2000/10/XMLSchema' => array( |
|
198 | - 'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double', |
|
199 | - 'float'=>'double','dateTime'=>'string', |
|
200 | - 'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'), |
|
201 | - 'http://www.w3.org/1999/XMLSchema' => array( |
|
202 | - 'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double', |
|
203 | - 'float'=>'double','dateTime'=>'string', |
|
204 | - 'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'), |
|
205 | - 'http://soapinterop.org/xsd' => array('SOAPStruct'=>'struct'), |
|
206 | - 'http://schemas.xmlsoap.org/soap/encoding/' => array('base64'=>'string','array'=>'array','Array'=>'array'), |
|
153 | + //var $soap_defencoding = 'UTF-8'; |
|
154 | + |
|
155 | + /** |
|
156 | + * namespaces in an array of prefix => uri |
|
157 | + * |
|
158 | + * this is "seeded" by a set of constants, but it may be altered by code |
|
159 | + * |
|
160 | + * @var array |
|
161 | + * @access public |
|
162 | + */ |
|
163 | + var $namespaces = array( |
|
164 | + 'SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/', |
|
165 | + 'xsd' => 'http://www.w3.org/2001/XMLSchema', |
|
166 | + 'xsi' => 'http://www.w3.org/2001/XMLSchema-instance', |
|
167 | + 'SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/' |
|
168 | + ); |
|
169 | + |
|
170 | + /** |
|
171 | + * namespaces used in the current context, e.g. during serialization |
|
172 | + * |
|
173 | + * @var array |
|
174 | + * @access private |
|
175 | + */ |
|
176 | + var $usedNamespaces = array(); |
|
177 | + |
|
178 | + /** |
|
179 | + * XML Schema types in an array of uri => (array of xml type => php type) |
|
180 | + * is this legacy yet? |
|
181 | + * no, this is used by the nusoap_xmlschema class to verify type => namespace mappings. |
|
182 | + * @var array |
|
183 | + * @access public |
|
184 | + */ |
|
185 | + var $typemap = array( |
|
186 | + 'http://www.w3.org/2001/XMLSchema' => array( |
|
187 | + 'string'=>'string','boolean'=>'boolean','float'=>'double','double'=>'double','decimal'=>'double', |
|
188 | + 'duration'=>'','dateTime'=>'string','time'=>'string','date'=>'string','gYearMonth'=>'', |
|
189 | + 'gYear'=>'','gMonthDay'=>'','gDay'=>'','gMonth'=>'','hexBinary'=>'string','base64Binary'=>'string', |
|
190 | + // abstract "any" types |
|
191 | + 'anyType'=>'string','anySimpleType'=>'string', |
|
192 | + // derived datatypes |
|
193 | + 'normalizedString'=>'string','token'=>'string','language'=>'','NMTOKEN'=>'','NMTOKENS'=>'','Name'=>'','NCName'=>'','ID'=>'', |
|
194 | + 'IDREF'=>'','IDREFS'=>'','ENTITY'=>'','ENTITIES'=>'','integer'=>'integer','nonPositiveInteger'=>'integer', |
|
195 | + 'negativeInteger'=>'integer','long'=>'integer','int'=>'integer','short'=>'integer','byte'=>'integer','nonNegativeInteger'=>'integer', |
|
196 | + 'unsignedLong'=>'','unsignedInt'=>'','unsignedShort'=>'','unsignedByte'=>'','positiveInteger'=>''), |
|
197 | + 'http://www.w3.org/2000/10/XMLSchema' => array( |
|
198 | + 'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double', |
|
199 | + 'float'=>'double','dateTime'=>'string', |
|
200 | + 'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'), |
|
201 | + 'http://www.w3.org/1999/XMLSchema' => array( |
|
202 | + 'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double', |
|
203 | + 'float'=>'double','dateTime'=>'string', |
|
204 | + 'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'), |
|
205 | + 'http://soapinterop.org/xsd' => array('SOAPStruct'=>'struct'), |
|
206 | + 'http://schemas.xmlsoap.org/soap/encoding/' => array('base64'=>'string','array'=>'array','Array'=>'array'), |
|
207 | 207 | 'http://xml.apache.org/xml-soap' => array('Map') |
208 | - ); |
|
209 | - |
|
210 | - /** |
|
211 | - * XML entities to convert |
|
212 | - * |
|
213 | - * @var array |
|
214 | - * @access public |
|
215 | - * @deprecated |
|
216 | - * @see expandEntities |
|
217 | - */ |
|
218 | - var $xmlEntities = array('quot' => '"','amp' => '&', |
|
219 | - 'lt' => '<','gt' => '>','apos' => "'"); |
|
220 | - |
|
221 | - /** |
|
222 | - * constructor |
|
223 | - * |
|
224 | - * @access public |
|
225 | - */ |
|
226 | - public function __construct() |
|
208 | + ); |
|
209 | + |
|
210 | + /** |
|
211 | + * XML entities to convert |
|
212 | + * |
|
213 | + * @var array |
|
214 | + * @access public |
|
215 | + * @deprecated |
|
216 | + * @see expandEntities |
|
217 | + */ |
|
218 | + var $xmlEntities = array('quot' => '"','amp' => '&', |
|
219 | + 'lt' => '<','gt' => '>','apos' => "'"); |
|
220 | + |
|
221 | + /** |
|
222 | + * constructor |
|
223 | + * |
|
224 | + * @access public |
|
225 | + */ |
|
226 | + public function __construct() |
|
227 | 227 | { |
228 | - $this->debugLevel = $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel']; |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * gets the global debug level, which applies to future instances |
|
233 | - * |
|
234 | - * @return integer Debug level 0-9, where 0 turns off |
|
235 | - * @access public |
|
236 | - */ |
|
237 | - function getGlobalDebugLevel() { |
|
238 | - return $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel']; |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * sets the global debug level, which applies to future instances |
|
243 | - * |
|
244 | - * @param int $level Debug level 0-9, where 0 turns off |
|
245 | - * @access public |
|
246 | - */ |
|
247 | - function setGlobalDebugLevel($level) { |
|
248 | - $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = $level; |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * gets the debug level for this instance |
|
253 | - * |
|
254 | - * @return int Debug level 0-9, where 0 turns off |
|
255 | - * @access public |
|
256 | - */ |
|
257 | - function getDebugLevel() { |
|
258 | - return $this->debugLevel; |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * sets the debug level for this instance |
|
263 | - * |
|
264 | - * @param int $level Debug level 0-9, where 0 turns off |
|
265 | - * @access public |
|
266 | - */ |
|
267 | - function setDebugLevel($level) { |
|
268 | - $this->debugLevel = $level; |
|
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * adds debug data to the instance debug string with formatting |
|
273 | - * |
|
274 | - * @param string $string debug data |
|
275 | - * @access private |
|
276 | - */ |
|
277 | - function debug($string){ |
|
278 | - if ($this->debugLevel > 0) { |
|
279 | - $this->appendDebug($this->getmicrotime().' '.get_class($this).": $string\n"); |
|
280 | - } |
|
281 | - } |
|
282 | - |
|
283 | - /** |
|
284 | - * adds debug data to the instance debug string without formatting |
|
285 | - * |
|
286 | - * @param string $string debug data |
|
287 | - * @access public |
|
288 | - */ |
|
289 | - function appendDebug($string){ |
|
290 | - if ($this->debugLevel > 0) { |
|
291 | - // it would be nice to use a memory stream here to use |
|
292 | - // memory more efficiently |
|
293 | - $this->debug_str .= $string; |
|
294 | - } |
|
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * clears the current debug data for this instance |
|
299 | - * |
|
300 | - * @access public |
|
301 | - */ |
|
302 | - function clearDebug() { |
|
303 | - // it would be nice to use a memory stream here to use |
|
304 | - // memory more efficiently |
|
305 | - $this->debug_str = ''; |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * gets the current debug data for this instance |
|
310 | - * |
|
311 | - * @return debug data |
|
312 | - * @access public |
|
313 | - */ |
|
314 | - function &getDebug() { |
|
315 | - // it would be nice to use a memory stream here to use |
|
316 | - // memory more efficiently |
|
317 | - return $this->debug_str; |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * gets the current debug data for this instance as an XML comment |
|
322 | - * this may change the contents of the debug data |
|
323 | - * |
|
324 | - * @return debug data as an XML comment |
|
325 | - * @access public |
|
326 | - */ |
|
327 | - function &getDebugAsXMLComment() { |
|
328 | - // it would be nice to use a memory stream here to use |
|
329 | - // memory more efficiently |
|
330 | - while (strpos($this->debug_str, '--')) { |
|
331 | - $this->debug_str = str_replace('--', '- -', $this->debug_str); |
|
332 | - } |
|
333 | - $ret = "<!--\n" . $this->debug_str . "\n-->"; |
|
334 | - return $ret; |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * expands entities, e.g. changes '<' to '<'. |
|
339 | - * |
|
340 | - * @param string $val The string in which to expand entities. |
|
341 | - * @access private |
|
342 | - */ |
|
343 | - function expandEntities($val) { |
|
344 | - if ($this->charencoding) { |
|
345 | - $val = str_replace('&', '&', $val); |
|
346 | - $val = str_replace("'", ''', $val); |
|
347 | - $val = str_replace('"', '"', $val); |
|
348 | - $val = str_replace('<', '<', $val); |
|
349 | - $val = str_replace('>', '>', $val); |
|
350 | - } |
|
351 | - return $val; |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * returns error string if present |
|
356 | - * |
|
357 | - * @return mixed error string or false |
|
358 | - * @access public |
|
359 | - */ |
|
360 | - function getError(){ |
|
361 | - if($this->error_str != ''){ |
|
362 | - return $this->error_str; |
|
363 | - } |
|
364 | - return false; |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * sets error string |
|
369 | - * |
|
370 | - * @return boolean $string error string |
|
371 | - * @access private |
|
372 | - */ |
|
373 | - function setError($str){ |
|
374 | - $this->error_str = $str; |
|
375 | - } |
|
376 | - |
|
377 | - /** |
|
378 | - * detect if array is a simple array or a struct (associative array) |
|
379 | - * |
|
380 | - * @param mixed $val The PHP array |
|
381 | - * @return string (arraySimple|arrayStruct) |
|
382 | - * @access private |
|
383 | - */ |
|
384 | - function isArraySimpleOrStruct($val) { |
|
228 | + $this->debugLevel = $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel']; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * gets the global debug level, which applies to future instances |
|
233 | + * |
|
234 | + * @return integer Debug level 0-9, where 0 turns off |
|
235 | + * @access public |
|
236 | + */ |
|
237 | + function getGlobalDebugLevel() { |
|
238 | + return $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel']; |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * sets the global debug level, which applies to future instances |
|
243 | + * |
|
244 | + * @param int $level Debug level 0-9, where 0 turns off |
|
245 | + * @access public |
|
246 | + */ |
|
247 | + function setGlobalDebugLevel($level) { |
|
248 | + $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = $level; |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * gets the debug level for this instance |
|
253 | + * |
|
254 | + * @return int Debug level 0-9, where 0 turns off |
|
255 | + * @access public |
|
256 | + */ |
|
257 | + function getDebugLevel() { |
|
258 | + return $this->debugLevel; |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * sets the debug level for this instance |
|
263 | + * |
|
264 | + * @param int $level Debug level 0-9, where 0 turns off |
|
265 | + * @access public |
|
266 | + */ |
|
267 | + function setDebugLevel($level) { |
|
268 | + $this->debugLevel = $level; |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * adds debug data to the instance debug string with formatting |
|
273 | + * |
|
274 | + * @param string $string debug data |
|
275 | + * @access private |
|
276 | + */ |
|
277 | + function debug($string){ |
|
278 | + if ($this->debugLevel > 0) { |
|
279 | + $this->appendDebug($this->getmicrotime().' '.get_class($this).": $string\n"); |
|
280 | + } |
|
281 | + } |
|
282 | + |
|
283 | + /** |
|
284 | + * adds debug data to the instance debug string without formatting |
|
285 | + * |
|
286 | + * @param string $string debug data |
|
287 | + * @access public |
|
288 | + */ |
|
289 | + function appendDebug($string){ |
|
290 | + if ($this->debugLevel > 0) { |
|
291 | + // it would be nice to use a memory stream here to use |
|
292 | + // memory more efficiently |
|
293 | + $this->debug_str .= $string; |
|
294 | + } |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * clears the current debug data for this instance |
|
299 | + * |
|
300 | + * @access public |
|
301 | + */ |
|
302 | + function clearDebug() { |
|
303 | + // it would be nice to use a memory stream here to use |
|
304 | + // memory more efficiently |
|
305 | + $this->debug_str = ''; |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * gets the current debug data for this instance |
|
310 | + * |
|
311 | + * @return debug data |
|
312 | + * @access public |
|
313 | + */ |
|
314 | + function &getDebug() { |
|
315 | + // it would be nice to use a memory stream here to use |
|
316 | + // memory more efficiently |
|
317 | + return $this->debug_str; |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * gets the current debug data for this instance as an XML comment |
|
322 | + * this may change the contents of the debug data |
|
323 | + * |
|
324 | + * @return debug data as an XML comment |
|
325 | + * @access public |
|
326 | + */ |
|
327 | + function &getDebugAsXMLComment() { |
|
328 | + // it would be nice to use a memory stream here to use |
|
329 | + // memory more efficiently |
|
330 | + while (strpos($this->debug_str, '--')) { |
|
331 | + $this->debug_str = str_replace('--', '- -', $this->debug_str); |
|
332 | + } |
|
333 | + $ret = "<!--\n" . $this->debug_str . "\n-->"; |
|
334 | + return $ret; |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * expands entities, e.g. changes '<' to '<'. |
|
339 | + * |
|
340 | + * @param string $val The string in which to expand entities. |
|
341 | + * @access private |
|
342 | + */ |
|
343 | + function expandEntities($val) { |
|
344 | + if ($this->charencoding) { |
|
345 | + $val = str_replace('&', '&', $val); |
|
346 | + $val = str_replace("'", ''', $val); |
|
347 | + $val = str_replace('"', '"', $val); |
|
348 | + $val = str_replace('<', '<', $val); |
|
349 | + $val = str_replace('>', '>', $val); |
|
350 | + } |
|
351 | + return $val; |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * returns error string if present |
|
356 | + * |
|
357 | + * @return mixed error string or false |
|
358 | + * @access public |
|
359 | + */ |
|
360 | + function getError(){ |
|
361 | + if($this->error_str != ''){ |
|
362 | + return $this->error_str; |
|
363 | + } |
|
364 | + return false; |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * sets error string |
|
369 | + * |
|
370 | + * @return boolean $string error string |
|
371 | + * @access private |
|
372 | + */ |
|
373 | + function setError($str){ |
|
374 | + $this->error_str = $str; |
|
375 | + } |
|
376 | + |
|
377 | + /** |
|
378 | + * detect if array is a simple array or a struct (associative array) |
|
379 | + * |
|
380 | + * @param mixed $val The PHP array |
|
381 | + * @return string (arraySimple|arrayStruct) |
|
382 | + * @access private |
|
383 | + */ |
|
384 | + function isArraySimpleOrStruct($val) { |
|
385 | 385 | $keyList = array_keys($val); |
386 | - foreach ($keyList as $keyListValue) { |
|
387 | - if (!is_int($keyListValue)) { |
|
388 | - return 'arrayStruct'; |
|
389 | - } |
|
390 | - } |
|
391 | - return 'arraySimple'; |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * serializes PHP values in accordance w/ section 5. Type information is |
|
396 | - * not serialized if $use == 'literal'. |
|
397 | - * |
|
398 | - * @param mixed $val The value to serialize |
|
399 | - * @param string $name The name (local part) of the XML element |
|
400 | - * @param string $type The XML schema type (local part) for the element |
|
401 | - * @param string $name_ns The namespace for the name of the XML element |
|
402 | - * @param string $type_ns The namespace for the type of the element |
|
403 | - * @param array $attributes The attributes to serialize as name=>value pairs |
|
404 | - * @param string $use The WSDL "use" (encoded|literal) |
|
405 | - * @param boolean $soapval Whether this is called from soapval. |
|
406 | - * @return string The serialized element, possibly with child elements |
|
407 | - * @access public |
|
408 | - */ |
|
409 | - function serialize_val($val,$name=false,$type=false,$name_ns=false,$type_ns=false,$attributes=false,$use='encoded',$soapval=false) { |
|
410 | - $this->debug("in serialize_val: name=$name, type=$type, name_ns=$name_ns, type_ns=$type_ns, use=$use, soapval=$soapval"); |
|
411 | - $this->appendDebug('value=' . $this->varDump($val)); |
|
412 | - $this->appendDebug('attributes=' . $this->varDump($attributes)); |
|
413 | - |
|
414 | - if (is_object($val) && get_class($val) == 'soapval' && (! $soapval)) { |
|
415 | - $this->debug("serialize_val: serialize soapval"); |
|
416 | - $xml = $val->serialize($use); |
|
417 | - $this->appendDebug($val->getDebug()); |
|
418 | - $val->clearDebug(); |
|
419 | - $this->debug("serialize_val of soapval returning $xml"); |
|
420 | - return $xml; |
|
386 | + foreach ($keyList as $keyListValue) { |
|
387 | + if (!is_int($keyListValue)) { |
|
388 | + return 'arrayStruct'; |
|
389 | + } |
|
390 | + } |
|
391 | + return 'arraySimple'; |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * serializes PHP values in accordance w/ section 5. Type information is |
|
396 | + * not serialized if $use == 'literal'. |
|
397 | + * |
|
398 | + * @param mixed $val The value to serialize |
|
399 | + * @param string $name The name (local part) of the XML element |
|
400 | + * @param string $type The XML schema type (local part) for the element |
|
401 | + * @param string $name_ns The namespace for the name of the XML element |
|
402 | + * @param string $type_ns The namespace for the type of the element |
|
403 | + * @param array $attributes The attributes to serialize as name=>value pairs |
|
404 | + * @param string $use The WSDL "use" (encoded|literal) |
|
405 | + * @param boolean $soapval Whether this is called from soapval. |
|
406 | + * @return string The serialized element, possibly with child elements |
|
407 | + * @access public |
|
408 | + */ |
|
409 | + function serialize_val($val,$name=false,$type=false,$name_ns=false,$type_ns=false,$attributes=false,$use='encoded',$soapval=false) { |
|
410 | + $this->debug("in serialize_val: name=$name, type=$type, name_ns=$name_ns, type_ns=$type_ns, use=$use, soapval=$soapval"); |
|
411 | + $this->appendDebug('value=' . $this->varDump($val)); |
|
412 | + $this->appendDebug('attributes=' . $this->varDump($attributes)); |
|
413 | + |
|
414 | + if (is_object($val) && get_class($val) == 'soapval' && (! $soapval)) { |
|
415 | + $this->debug("serialize_val: serialize soapval"); |
|
416 | + $xml = $val->serialize($use); |
|
417 | + $this->appendDebug($val->getDebug()); |
|
418 | + $val->clearDebug(); |
|
419 | + $this->debug("serialize_val of soapval returning $xml"); |
|
420 | + return $xml; |
|
421 | 421 | } |
422 | - // force valid name if necessary |
|
423 | - if (is_numeric($name)) { |
|
424 | - $name = '__numeric_' . $name; |
|
425 | - } elseif (! $name) { |
|
426 | - $name = 'noname'; |
|
427 | - } |
|
428 | - // if name has ns, add ns prefix to name |
|
429 | - $xmlns = ''; |
|
422 | + // force valid name if necessary |
|
423 | + if (is_numeric($name)) { |
|
424 | + $name = '__numeric_' . $name; |
|
425 | + } elseif (! $name) { |
|
426 | + $name = 'noname'; |
|
427 | + } |
|
428 | + // if name has ns, add ns prefix to name |
|
429 | + $xmlns = ''; |
|
430 | 430 | if($name_ns){ |
431 | - $prefix = 'nu'.rand(1000,9999); |
|
432 | - $name = $prefix.':'.$name; |
|
433 | - $xmlns .= " xmlns:$prefix=\"$name_ns\""; |
|
434 | - } |
|
435 | - // if type is prefixed, create type prefix |
|
436 | - if($type_ns != '' && $type_ns == $this->namespaces['xsd']){ |
|
437 | - // need to fix this. shouldn't default to xsd if no ns specified |
|
438 | - // w/o checking against typemap |
|
439 | - $type_prefix = 'xsd'; |
|
440 | - } elseif($type_ns){ |
|
441 | - $type_prefix = 'ns'.rand(1000,9999); |
|
442 | - $xmlns .= " xmlns:$type_prefix=\"$type_ns\""; |
|
443 | - } |
|
444 | - // serialize attributes if present |
|
445 | - $atts = ''; |
|
446 | - if($attributes){ |
|
447 | - foreach($attributes as $k => $v){ |
|
448 | - $atts .= " $k=\"".$this->expandEntities($v).'"'; |
|
449 | - } |
|
450 | - } |
|
451 | - // serialize null value |
|
452 | - if (is_null($val)) { |
|
453 | - $this->debug("serialize_val: serialize null"); |
|
454 | - if ($use == 'literal') { |
|
455 | - // TODO: depends on minOccurs |
|
456 | - $xml = "<$name$xmlns$atts/>"; |
|
457 | - $this->debug("serialize_val returning $xml"); |
|
458 | - return $xml; |
|
459 | - } else { |
|
460 | - if (isset($type) && isset($type_prefix)) { |
|
461 | - $type_str = " xsi:type=\"$type_prefix:$type\""; |
|
462 | - } else { |
|
463 | - $type_str = ''; |
|
464 | - } |
|
465 | - $xml = "<$name$xmlns$type_str$atts xsi:nil=\"true\"/>"; |
|
466 | - $this->debug("serialize_val returning $xml"); |
|
467 | - return $xml; |
|
468 | - } |
|
469 | - } |
|
431 | + $prefix = 'nu'.rand(1000,9999); |
|
432 | + $name = $prefix.':'.$name; |
|
433 | + $xmlns .= " xmlns:$prefix=\"$name_ns\""; |
|
434 | + } |
|
435 | + // if type is prefixed, create type prefix |
|
436 | + if($type_ns != '' && $type_ns == $this->namespaces['xsd']){ |
|
437 | + // need to fix this. shouldn't default to xsd if no ns specified |
|
438 | + // w/o checking against typemap |
|
439 | + $type_prefix = 'xsd'; |
|
440 | + } elseif($type_ns){ |
|
441 | + $type_prefix = 'ns'.rand(1000,9999); |
|
442 | + $xmlns .= " xmlns:$type_prefix=\"$type_ns\""; |
|
443 | + } |
|
444 | + // serialize attributes if present |
|
445 | + $atts = ''; |
|
446 | + if($attributes){ |
|
447 | + foreach($attributes as $k => $v){ |
|
448 | + $atts .= " $k=\"".$this->expandEntities($v).'"'; |
|
449 | + } |
|
450 | + } |
|
451 | + // serialize null value |
|
452 | + if (is_null($val)) { |
|
453 | + $this->debug("serialize_val: serialize null"); |
|
454 | + if ($use == 'literal') { |
|
455 | + // TODO: depends on minOccurs |
|
456 | + $xml = "<$name$xmlns$atts/>"; |
|
457 | + $this->debug("serialize_val returning $xml"); |
|
458 | + return $xml; |
|
459 | + } else { |
|
460 | + if (isset($type) && isset($type_prefix)) { |
|
461 | + $type_str = " xsi:type=\"$type_prefix:$type\""; |
|
462 | + } else { |
|
463 | + $type_str = ''; |
|
464 | + } |
|
465 | + $xml = "<$name$xmlns$type_str$atts xsi:nil=\"true\"/>"; |
|
466 | + $this->debug("serialize_val returning $xml"); |
|
467 | + return $xml; |
|
468 | + } |
|
469 | + } |
|
470 | 470 | // serialize if an xsd built-in primitive type |
471 | 471 | if($type != '' && isset($this->typemap[$this->XMLSchemaVersion][$type])){ |
472 | - $this->debug("serialize_val: serialize xsd built-in primitive type"); |
|
473 | - if (is_bool($val)) { |
|
474 | - if ($type == 'boolean') { |
|
475 | - $val = $val ? 'true' : 'false'; |
|
476 | - } elseif (! $val) { |
|
477 | - $val = 0; |
|
478 | - } |
|
479 | - } else if (is_string($val)) { |
|
480 | - $val = $this->expandEntities($val); |
|
481 | - } |
|
482 | - if ($use == 'literal') { |
|
483 | - $xml = "<$name$xmlns$atts>$val</$name>"; |
|
484 | - $this->debug("serialize_val returning $xml"); |
|
485 | - return $xml; |
|
486 | - } else { |
|
487 | - $xml = "<$name$xmlns xsi:type=\"xsd:$type\"$atts>$val</$name>"; |
|
488 | - $this->debug("serialize_val returning $xml"); |
|
489 | - return $xml; |
|
490 | - } |
|
472 | + $this->debug("serialize_val: serialize xsd built-in primitive type"); |
|
473 | + if (is_bool($val)) { |
|
474 | + if ($type == 'boolean') { |
|
475 | + $val = $val ? 'true' : 'false'; |
|
476 | + } elseif (! $val) { |
|
477 | + $val = 0; |
|
478 | + } |
|
479 | + } else if (is_string($val)) { |
|
480 | + $val = $this->expandEntities($val); |
|
481 | + } |
|
482 | + if ($use == 'literal') { |
|
483 | + $xml = "<$name$xmlns$atts>$val</$name>"; |
|
484 | + $this->debug("serialize_val returning $xml"); |
|
485 | + return $xml; |
|
486 | + } else { |
|
487 | + $xml = "<$name$xmlns xsi:type=\"xsd:$type\"$atts>$val</$name>"; |
|
488 | + $this->debug("serialize_val returning $xml"); |
|
489 | + return $xml; |
|
490 | + } |
|
491 | 491 | } |
492 | - // detect type and serialize |
|
493 | - $xml = ''; |
|
494 | - switch(true) { |
|
495 | - case (is_bool($val) || $type == 'boolean'): |
|
496 | - $this->debug("serialize_val: serialize boolean"); |
|
497 | - if ($type == 'boolean') { |
|
498 | - $val = $val ? 'true' : 'false'; |
|
499 | - } elseif (! $val) { |
|
500 | - $val = 0; |
|
501 | - } |
|
502 | - if ($use == 'literal') { |
|
503 | - $xml .= "<$name$xmlns$atts>$val</$name>"; |
|
504 | - } else { |
|
505 | - $xml .= "<$name$xmlns xsi:type=\"xsd:boolean\"$atts>$val</$name>"; |
|
506 | - } |
|
507 | - break; |
|
508 | - case (is_int($val) || is_long($val) || $type == 'int'): |
|
509 | - $this->debug("serialize_val: serialize int"); |
|
510 | - if ($use == 'literal') { |
|
511 | - $xml .= "<$name$xmlns$atts>$val</$name>"; |
|
512 | - } else { |
|
513 | - $xml .= "<$name$xmlns xsi:type=\"xsd:int\"$atts>$val</$name>"; |
|
514 | - } |
|
515 | - break; |
|
516 | - case (is_float($val)|| is_double($val) || $type == 'float'): |
|
517 | - $this->debug("serialize_val: serialize float"); |
|
518 | - if ($use == 'literal') { |
|
519 | - $xml .= "<$name$xmlns$atts>$val</$name>"; |
|
520 | - } else { |
|
521 | - $xml .= "<$name$xmlns xsi:type=\"xsd:float\"$atts>$val</$name>"; |
|
522 | - } |
|
523 | - break; |
|
524 | - case (is_string($val) || $type == 'string'): |
|
525 | - $this->debug("serialize_val: serialize string"); |
|
526 | - $val = $this->expandEntities($val); |
|
527 | - if ($use == 'literal') { |
|
528 | - $xml .= "<$name$xmlns$atts>$val</$name>"; |
|
529 | - } else { |
|
530 | - $xml .= "<$name$xmlns xsi:type=\"xsd:string\"$atts>$val</$name>"; |
|
531 | - } |
|
532 | - break; |
|
533 | - case is_object($val): |
|
534 | - $this->debug("serialize_val: serialize object"); |
|
535 | - if (get_class($val) == 'soapval') { |
|
536 | - $this->debug("serialize_val: serialize soapval object"); |
|
537 | - $pXml = $val->serialize($use); |
|
538 | - $this->appendDebug($val->getDebug()); |
|
539 | - $val->clearDebug(); |
|
540 | - } else { |
|
541 | - if (! $name) { |
|
542 | - $name = get_class($val); |
|
543 | - $this->debug("In serialize_val, used class name $name as element name"); |
|
544 | - } else { |
|
545 | - $this->debug("In serialize_val, do not override name $name for element name for class " . get_class($val)); |
|
546 | - } |
|
547 | - foreach(get_object_vars($val) as $k => $v){ |
|
548 | - $pXml = isset($pXml) ? $pXml.$this->serialize_val($v,$k,false,false,false,false,$use) : $this->serialize_val($v,$k,false,false,false,false,$use); |
|
549 | - } |
|
550 | - } |
|
551 | - if(isset($type) && isset($type_prefix)){ |
|
552 | - $type_str = " xsi:type=\"$type_prefix:$type\""; |
|
553 | - } else { |
|
554 | - $type_str = ''; |
|
555 | - } |
|
556 | - if ($use == 'literal') { |
|
557 | - $xml .= "<$name$xmlns$atts>$pXml</$name>"; |
|
558 | - } else { |
|
559 | - $xml .= "<$name$xmlns$type_str$atts>$pXml</$name>"; |
|
560 | - } |
|
561 | - break; |
|
562 | - case (is_array($val) || $type): |
|
563 | - // detect if struct or array |
|
564 | - $valueType = $this->isArraySimpleOrStruct($val); |
|
492 | + // detect type and serialize |
|
493 | + $xml = ''; |
|
494 | + switch(true) { |
|
495 | + case (is_bool($val) || $type == 'boolean'): |
|
496 | + $this->debug("serialize_val: serialize boolean"); |
|
497 | + if ($type == 'boolean') { |
|
498 | + $val = $val ? 'true' : 'false'; |
|
499 | + } elseif (! $val) { |
|
500 | + $val = 0; |
|
501 | + } |
|
502 | + if ($use == 'literal') { |
|
503 | + $xml .= "<$name$xmlns$atts>$val</$name>"; |
|
504 | + } else { |
|
505 | + $xml .= "<$name$xmlns xsi:type=\"xsd:boolean\"$atts>$val</$name>"; |
|
506 | + } |
|
507 | + break; |
|
508 | + case (is_int($val) || is_long($val) || $type == 'int'): |
|
509 | + $this->debug("serialize_val: serialize int"); |
|
510 | + if ($use == 'literal') { |
|
511 | + $xml .= "<$name$xmlns$atts>$val</$name>"; |
|
512 | + } else { |
|
513 | + $xml .= "<$name$xmlns xsi:type=\"xsd:int\"$atts>$val</$name>"; |
|
514 | + } |
|
515 | + break; |
|
516 | + case (is_float($val)|| is_double($val) || $type == 'float'): |
|
517 | + $this->debug("serialize_val: serialize float"); |
|
518 | + if ($use == 'literal') { |
|
519 | + $xml .= "<$name$xmlns$atts>$val</$name>"; |
|
520 | + } else { |
|
521 | + $xml .= "<$name$xmlns xsi:type=\"xsd:float\"$atts>$val</$name>"; |
|
522 | + } |
|
523 | + break; |
|
524 | + case (is_string($val) || $type == 'string'): |
|
525 | + $this->debug("serialize_val: serialize string"); |
|
526 | + $val = $this->expandEntities($val); |
|
527 | + if ($use == 'literal') { |
|
528 | + $xml .= "<$name$xmlns$atts>$val</$name>"; |
|
529 | + } else { |
|
530 | + $xml .= "<$name$xmlns xsi:type=\"xsd:string\"$atts>$val</$name>"; |
|
531 | + } |
|
532 | + break; |
|
533 | + case is_object($val): |
|
534 | + $this->debug("serialize_val: serialize object"); |
|
535 | + if (get_class($val) == 'soapval') { |
|
536 | + $this->debug("serialize_val: serialize soapval object"); |
|
537 | + $pXml = $val->serialize($use); |
|
538 | + $this->appendDebug($val->getDebug()); |
|
539 | + $val->clearDebug(); |
|
540 | + } else { |
|
541 | + if (! $name) { |
|
542 | + $name = get_class($val); |
|
543 | + $this->debug("In serialize_val, used class name $name as element name"); |
|
544 | + } else { |
|
545 | + $this->debug("In serialize_val, do not override name $name for element name for class " . get_class($val)); |
|
546 | + } |
|
547 | + foreach(get_object_vars($val) as $k => $v){ |
|
548 | + $pXml = isset($pXml) ? $pXml.$this->serialize_val($v,$k,false,false,false,false,$use) : $this->serialize_val($v,$k,false,false,false,false,$use); |
|
549 | + } |
|
550 | + } |
|
551 | + if(isset($type) && isset($type_prefix)){ |
|
552 | + $type_str = " xsi:type=\"$type_prefix:$type\""; |
|
553 | + } else { |
|
554 | + $type_str = ''; |
|
555 | + } |
|
556 | + if ($use == 'literal') { |
|
557 | + $xml .= "<$name$xmlns$atts>$pXml</$name>"; |
|
558 | + } else { |
|
559 | + $xml .= "<$name$xmlns$type_str$atts>$pXml</$name>"; |
|
560 | + } |
|
561 | + break; |
|
562 | + case (is_array($val) || $type): |
|
563 | + // detect if struct or array |
|
564 | + $valueType = $this->isArraySimpleOrStruct($val); |
|
565 | 565 | if($valueType=='arraySimple' || preg_match('/^ArrayOf/',$type)){ |
566 | - $this->debug("serialize_val: serialize array"); |
|
567 | - $i = 0; |
|
568 | - if(is_array($val) && count($val)> 0){ |
|
569 | - foreach($val as $v){ |
|
570 | - if(is_object($v) && get_class($v) == 'soapval'){ |
|
571 | - $tt_ns = $v->type_ns; |
|
572 | - $tt = $v->type; |
|
573 | - } elseif (is_array($v)) { |
|
574 | - $tt = $this->isArraySimpleOrStruct($v); |
|
575 | - } else { |
|
576 | - $tt = gettype($v); |
|
577 | - } |
|
578 | - $array_types[$tt] = 1; |
|
579 | - // TODO: for literal, the name should be $name |
|
580 | - $xml .= $this->serialize_val($v,'item',false,false,false,false,$use); |
|
581 | - ++$i; |
|
582 | - } |
|
583 | - if(count($array_types) > 1){ |
|
584 | - $array_typename = 'xsd:anyType'; |
|
585 | - } elseif(isset($tt) && isset($this->typemap[$this->XMLSchemaVersion][$tt])) { |
|
586 | - if ($tt == 'integer') { |
|
587 | - $tt = 'int'; |
|
588 | - } |
|
589 | - $array_typename = 'xsd:'.$tt; |
|
590 | - } elseif(isset($tt) && $tt == 'arraySimple'){ |
|
591 | - $array_typename = 'SOAP-ENC:Array'; |
|
592 | - } elseif(isset($tt) && $tt == 'arrayStruct'){ |
|
593 | - $array_typename = 'unnamed_struct_use_soapval'; |
|
594 | - } else { |
|
595 | - // if type is prefixed, create type prefix |
|
596 | - if ($tt_ns != '' && $tt_ns == $this->namespaces['xsd']){ |
|
597 | - $array_typename = 'xsd:' . $tt; |
|
598 | - } elseif ($tt_ns) { |
|
599 | - $tt_prefix = 'ns' . rand(1000, 9999); |
|
600 | - $array_typename = "$tt_prefix:$tt"; |
|
601 | - $xmlns .= " xmlns:$tt_prefix=\"$tt_ns\""; |
|
602 | - } else { |
|
603 | - $array_typename = $tt; |
|
604 | - } |
|
605 | - } |
|
606 | - $array_type = $i; |
|
607 | - if ($use == 'literal') { |
|
608 | - $type_str = ''; |
|
609 | - } else if (isset($type) && isset($type_prefix)) { |
|
610 | - $type_str = " xsi:type=\"$type_prefix:$type\""; |
|
611 | - } else { |
|
612 | - $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"".$array_typename."[$array_type]\""; |
|
613 | - } |
|
614 | - // empty array |
|
615 | - } else { |
|
616 | - if ($use == 'literal') { |
|
617 | - $type_str = ''; |
|
618 | - } else if (isset($type) && isset($type_prefix)) { |
|
619 | - $type_str = " xsi:type=\"$type_prefix:$type\""; |
|
620 | - } else { |
|
621 | - $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"xsd:anyType[0]\""; |
|
622 | - } |
|
623 | - } |
|
624 | - // TODO: for array in literal, there is no wrapper here |
|
625 | - $xml = "<$name$xmlns$type_str$atts>".$xml."</$name>"; |
|
626 | - } else { |
|
627 | - // got a struct |
|
628 | - $this->debug("serialize_val: serialize struct"); |
|
629 | - if(isset($type) && isset($type_prefix)){ |
|
630 | - $type_str = " xsi:type=\"$type_prefix:$type\""; |
|
631 | - } else { |
|
632 | - $type_str = ''; |
|
633 | - } |
|
634 | - if ($use == 'literal') { |
|
635 | - $xml .= "<$name$xmlns$atts>"; |
|
636 | - } else { |
|
637 | - $xml .= "<$name$xmlns$type_str$atts>"; |
|
638 | - } |
|
639 | - foreach($val as $k => $v){ |
|
640 | - // Apache Map |
|
641 | - if ($type == 'Map' && $type_ns == 'http://xml.apache.org/xml-soap') { |
|
642 | - $xml .= '<item>'; |
|
643 | - $xml .= $this->serialize_val($k,'key',false,false,false,false,$use); |
|
644 | - $xml .= $this->serialize_val($v,'value',false,false,false,false,$use); |
|
645 | - $xml .= '</item>'; |
|
646 | - } else { |
|
647 | - $xml .= $this->serialize_val($v,$k,false,false,false,false,$use); |
|
648 | - } |
|
649 | - } |
|
650 | - $xml .= "</$name>"; |
|
651 | - } |
|
652 | - break; |
|
653 | - default: |
|
654 | - $this->debug("serialize_val: serialize unknown"); |
|
655 | - $xml .= 'not detected, got '.gettype($val).' for '.$val; |
|
656 | - break; |
|
657 | - } |
|
658 | - $this->debug("serialize_val returning $xml"); |
|
659 | - return $xml; |
|
660 | - } |
|
661 | - |
|
662 | - /** |
|
663 | - * serializes a message |
|
664 | - * |
|
665 | - * @param string $body the XML of the SOAP body |
|
666 | - * @param mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array |
|
667 | - * @param array $namespaces optional the namespaces used in generating the body and headers |
|
668 | - * @param string $style optional (rpc|document) |
|
669 | - * @param string $use optional (encoded|literal) |
|
670 | - * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded) |
|
671 | - * @return string the message |
|
672 | - * @access public |
|
673 | - */ |
|
566 | + $this->debug("serialize_val: serialize array"); |
|
567 | + $i = 0; |
|
568 | + if(is_array($val) && count($val)> 0){ |
|
569 | + foreach($val as $v){ |
|
570 | + if(is_object($v) && get_class($v) == 'soapval'){ |
|
571 | + $tt_ns = $v->type_ns; |
|
572 | + $tt = $v->type; |
|
573 | + } elseif (is_array($v)) { |
|
574 | + $tt = $this->isArraySimpleOrStruct($v); |
|
575 | + } else { |
|
576 | + $tt = gettype($v); |
|
577 | + } |
|
578 | + $array_types[$tt] = 1; |
|
579 | + // TODO: for literal, the name should be $name |
|
580 | + $xml .= $this->serialize_val($v,'item',false,false,false,false,$use); |
|
581 | + ++$i; |
|
582 | + } |
|
583 | + if(count($array_types) > 1){ |
|
584 | + $array_typename = 'xsd:anyType'; |
|
585 | + } elseif(isset($tt) && isset($this->typemap[$this->XMLSchemaVersion][$tt])) { |
|
586 | + if ($tt == 'integer') { |
|
587 | + $tt = 'int'; |
|
588 | + } |
|
589 | + $array_typename = 'xsd:'.$tt; |
|
590 | + } elseif(isset($tt) && $tt == 'arraySimple'){ |
|
591 | + $array_typename = 'SOAP-ENC:Array'; |
|
592 | + } elseif(isset($tt) && $tt == 'arrayStruct'){ |
|
593 | + $array_typename = 'unnamed_struct_use_soapval'; |
|
594 | + } else { |
|
595 | + // if type is prefixed, create type prefix |
|
596 | + if ($tt_ns != '' && $tt_ns == $this->namespaces['xsd']){ |
|
597 | + $array_typename = 'xsd:' . $tt; |
|
598 | + } elseif ($tt_ns) { |
|
599 | + $tt_prefix = 'ns' . rand(1000, 9999); |
|
600 | + $array_typename = "$tt_prefix:$tt"; |
|
601 | + $xmlns .= " xmlns:$tt_prefix=\"$tt_ns\""; |
|
602 | + } else { |
|
603 | + $array_typename = $tt; |
|
604 | + } |
|
605 | + } |
|
606 | + $array_type = $i; |
|
607 | + if ($use == 'literal') { |
|
608 | + $type_str = ''; |
|
609 | + } else if (isset($type) && isset($type_prefix)) { |
|
610 | + $type_str = " xsi:type=\"$type_prefix:$type\""; |
|
611 | + } else { |
|
612 | + $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"".$array_typename."[$array_type]\""; |
|
613 | + } |
|
614 | + // empty array |
|
615 | + } else { |
|
616 | + if ($use == 'literal') { |
|
617 | + $type_str = ''; |
|
618 | + } else if (isset($type) && isset($type_prefix)) { |
|
619 | + $type_str = " xsi:type=\"$type_prefix:$type\""; |
|
620 | + } else { |
|
621 | + $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"xsd:anyType[0]\""; |
|
622 | + } |
|
623 | + } |
|
624 | + // TODO: for array in literal, there is no wrapper here |
|
625 | + $xml = "<$name$xmlns$type_str$atts>".$xml."</$name>"; |
|
626 | + } else { |
|
627 | + // got a struct |
|
628 | + $this->debug("serialize_val: serialize struct"); |
|
629 | + if(isset($type) && isset($type_prefix)){ |
|
630 | + $type_str = " xsi:type=\"$type_prefix:$type\""; |
|
631 | + } else { |
|
632 | + $type_str = ''; |
|
633 | + } |
|
634 | + if ($use == 'literal') { |
|
635 | + $xml .= "<$name$xmlns$atts>"; |
|
636 | + } else { |
|
637 | + $xml .= "<$name$xmlns$type_str$atts>"; |
|
638 | + } |
|
639 | + foreach($val as $k => $v){ |
|
640 | + // Apache Map |
|
641 | + if ($type == 'Map' && $type_ns == 'http://xml.apache.org/xml-soap') { |
|
642 | + $xml .= '<item>'; |
|
643 | + $xml .= $this->serialize_val($k,'key',false,false,false,false,$use); |
|
644 | + $xml .= $this->serialize_val($v,'value',false,false,false,false,$use); |
|
645 | + $xml .= '</item>'; |
|
646 | + } else { |
|
647 | + $xml .= $this->serialize_val($v,$k,false,false,false,false,$use); |
|
648 | + } |
|
649 | + } |
|
650 | + $xml .= "</$name>"; |
|
651 | + } |
|
652 | + break; |
|
653 | + default: |
|
654 | + $this->debug("serialize_val: serialize unknown"); |
|
655 | + $xml .= 'not detected, got '.gettype($val).' for '.$val; |
|
656 | + break; |
|
657 | + } |
|
658 | + $this->debug("serialize_val returning $xml"); |
|
659 | + return $xml; |
|
660 | + } |
|
661 | + |
|
662 | + /** |
|
663 | + * serializes a message |
|
664 | + * |
|
665 | + * @param string $body the XML of the SOAP body |
|
666 | + * @param mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array |
|
667 | + * @param array $namespaces optional the namespaces used in generating the body and headers |
|
668 | + * @param string $style optional (rpc|document) |
|
669 | + * @param string $use optional (encoded|literal) |
|
670 | + * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded) |
|
671 | + * @return string the message |
|
672 | + * @access public |
|
673 | + */ |
|
674 | 674 | function serializeEnvelope($body,$headers=false,$namespaces=array(),$style='rpc',$use='encoded',$encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'){ |
675 | 675 | // TODO: add an option to automatically run utf8_encode on $body and $headers |
676 | 676 | // if $this->soap_defencoding is UTF-8. Not doing this automatically allows |
677 | 677 | // one to send arbitrary UTF-8 characters, not just characters that map to ISO-8859-1 |
678 | 678 | |
679 | - $this->debug("In serializeEnvelope length=" . strlen($body) . " body (max 1000 characters)=" . substr($body, 0, 1000) . " style=$style use=$use encodingStyle=$encodingStyle"); |
|
680 | - $this->debug("headers:"); |
|
681 | - $this->appendDebug($this->varDump($headers)); |
|
682 | - $this->debug("namespaces:"); |
|
683 | - $this->appendDebug($this->varDump($namespaces)); |
|
679 | + $this->debug("In serializeEnvelope length=" . strlen($body) . " body (max 1000 characters)=" . substr($body, 0, 1000) . " style=$style use=$use encodingStyle=$encodingStyle"); |
|
680 | + $this->debug("headers:"); |
|
681 | + $this->appendDebug($this->varDump($headers)); |
|
682 | + $this->debug("namespaces:"); |
|
683 | + $this->appendDebug($this->varDump($namespaces)); |
|
684 | 684 | |
685 | - // serialize namespaces |
|
685 | + // serialize namespaces |
|
686 | 686 | $ns_string = ''; |
687 | - foreach(array_merge($this->namespaces,$namespaces) as $k => $v){ |
|
688 | - $ns_string .= " xmlns:$k=\"$v\""; |
|
689 | - } |
|
690 | - if($encodingStyle) { |
|
691 | - $ns_string = " SOAP-ENV:encodingStyle=\"$encodingStyle\"$ns_string"; |
|
692 | - } |
|
693 | - |
|
694 | - // serialize headers |
|
695 | - if($headers){ |
|
696 | - if (is_array($headers)) { |
|
697 | - $xml = ''; |
|
698 | - foreach ($headers as $k => $v) { |
|
699 | - if (is_object($v) && get_class($v) == 'soapval') { |
|
700 | - $xml .= $this->serialize_val($v, false, false, false, false, false, $use); |
|
701 | - } else { |
|
702 | - $xml .= $this->serialize_val($v, $k, false, false, false, false, $use); |
|
703 | - } |
|
704 | - } |
|
705 | - $headers = $xml; |
|
706 | - $this->debug("In serializeEnvelope, serialized array of headers to $headers"); |
|
707 | - } |
|
708 | - $headers = "<SOAP-ENV:Header>".$headers."</SOAP-ENV:Header>"; |
|
709 | - } |
|
710 | - // serialize envelope |
|
711 | - return |
|
712 | - '<?xml version="1.0" encoding="'.$this->soap_defencoding .'"?'.">". |
|
713 | - '<SOAP-ENV:Envelope'.$ns_string.">". |
|
714 | - $headers. |
|
715 | - "<SOAP-ENV:Body>". |
|
716 | - $body. |
|
717 | - "</SOAP-ENV:Body>". |
|
718 | - "</SOAP-ENV:Envelope>"; |
|
719 | - } |
|
720 | - |
|
721 | - /** |
|
722 | - * formats a string to be inserted into an HTML stream |
|
723 | - * |
|
724 | - * @param string $str The string to format |
|
725 | - * @return string The formatted string |
|
726 | - * @access public |
|
727 | - * @deprecated |
|
728 | - */ |
|
687 | + foreach(array_merge($this->namespaces,$namespaces) as $k => $v){ |
|
688 | + $ns_string .= " xmlns:$k=\"$v\""; |
|
689 | + } |
|
690 | + if($encodingStyle) { |
|
691 | + $ns_string = " SOAP-ENV:encodingStyle=\"$encodingStyle\"$ns_string"; |
|
692 | + } |
|
693 | + |
|
694 | + // serialize headers |
|
695 | + if($headers){ |
|
696 | + if (is_array($headers)) { |
|
697 | + $xml = ''; |
|
698 | + foreach ($headers as $k => $v) { |
|
699 | + if (is_object($v) && get_class($v) == 'soapval') { |
|
700 | + $xml .= $this->serialize_val($v, false, false, false, false, false, $use); |
|
701 | + } else { |
|
702 | + $xml .= $this->serialize_val($v, $k, false, false, false, false, $use); |
|
703 | + } |
|
704 | + } |
|
705 | + $headers = $xml; |
|
706 | + $this->debug("In serializeEnvelope, serialized array of headers to $headers"); |
|
707 | + } |
|
708 | + $headers = "<SOAP-ENV:Header>".$headers."</SOAP-ENV:Header>"; |
|
709 | + } |
|
710 | + // serialize envelope |
|
711 | + return |
|
712 | + '<?xml version="1.0" encoding="'.$this->soap_defencoding .'"?'.">". |
|
713 | + '<SOAP-ENV:Envelope'.$ns_string.">". |
|
714 | + $headers. |
|
715 | + "<SOAP-ENV:Body>". |
|
716 | + $body. |
|
717 | + "</SOAP-ENV:Body>". |
|
718 | + "</SOAP-ENV:Envelope>"; |
|
719 | + } |
|
720 | + |
|
721 | + /** |
|
722 | + * formats a string to be inserted into an HTML stream |
|
723 | + * |
|
724 | + * @param string $str The string to format |
|
725 | + * @return string The formatted string |
|
726 | + * @access public |
|
727 | + * @deprecated |
|
728 | + */ |
|
729 | 729 | function formatDump($str){ |
730 | - $str = htmlspecialchars($str); |
|
731 | - return nl2br($str); |
|
732 | - } |
|
733 | - |
|
734 | - /** |
|
735 | - * contracts (changes namespace to prefix) a qualified name |
|
736 | - * |
|
737 | - * @param string $qname qname |
|
738 | - * @return string contracted qname |
|
739 | - * @access private |
|
740 | - */ |
|
741 | - function contractQname($qname){ |
|
742 | - // get element namespace |
|
743 | - //$this->xdebug("Contract $qname"); |
|
744 | - if (strrpos($qname, ':')) { |
|
745 | - // get unqualified name |
|
746 | - $name = substr($qname, strrpos($qname, ':') + 1); |
|
747 | - // get ns |
|
748 | - $ns = substr($qname, 0, strrpos($qname, ':')); |
|
749 | - $p = $this->getPrefixFromNamespace($ns); |
|
750 | - if ($p) { |
|
751 | - return $p . ':' . $name; |
|
752 | - } |
|
753 | - return $qname; |
|
754 | - } else { |
|
755 | - return $qname; |
|
756 | - } |
|
757 | - } |
|
758 | - |
|
759 | - /** |
|
760 | - * expands (changes prefix to namespace) a qualified name |
|
761 | - * |
|
762 | - * @param string $qname qname |
|
763 | - * @return string expanded qname |
|
764 | - * @access private |
|
765 | - */ |
|
766 | - function expandQname($qname){ |
|
767 | - // get element prefix |
|
768 | - if(strpos($qname,':') && !preg_match('/^http:\/\//',$qname)){ |
|
769 | - // get unqualified name |
|
770 | - $name = substr(strstr($qname,':'),1); |
|
771 | - // get ns prefix |
|
772 | - $prefix = substr($qname,0,strpos($qname,':')); |
|
773 | - if(isset($this->namespaces[$prefix])){ |
|
774 | - return $this->namespaces[$prefix].':'.$name; |
|
775 | - } else { |
|
776 | - return $qname; |
|
777 | - } |
|
778 | - } else { |
|
779 | - return $qname; |
|
780 | - } |
|
781 | - } |
|
782 | - |
|
783 | - /** |
|
784 | - * returns the local part of a prefixed string |
|
785 | - * returns the original string, if not prefixed |
|
786 | - * |
|
787 | - * @param string $str The prefixed string |
|
788 | - * @return string The local part |
|
789 | - * @access public |
|
790 | - */ |
|
791 | - function getLocalPart($str){ |
|
792 | - if($sstr = strrchr($str,':')){ |
|
793 | - // get unqualified name |
|
794 | - return substr( $sstr, 1 ); |
|
795 | - } else { |
|
796 | - return $str; |
|
797 | - } |
|
798 | - } |
|
799 | - |
|
800 | - /** |
|
801 | - * returns the prefix part of a prefixed string |
|
802 | - * returns false, if not prefixed |
|
803 | - * |
|
804 | - * @param string $str The prefixed string |
|
805 | - * @return mixed The prefix or false if there is no prefix |
|
806 | - * @access public |
|
807 | - */ |
|
808 | - function getPrefix($str){ |
|
809 | - if($pos = strrpos($str,':')){ |
|
810 | - // get prefix |
|
811 | - return substr($str,0,$pos); |
|
812 | - } |
|
813 | - return false; |
|
814 | - } |
|
815 | - |
|
816 | - /** |
|
817 | - * pass it a prefix, it returns a namespace |
|
818 | - * |
|
819 | - * @param string $prefix The prefix |
|
820 | - * @return mixed The namespace, false if no namespace has the specified prefix |
|
821 | - * @access public |
|
822 | - */ |
|
823 | - function getNamespaceFromPrefix($prefix){ |
|
824 | - if (isset($this->namespaces[$prefix])) { |
|
825 | - return $this->namespaces[$prefix]; |
|
826 | - } |
|
827 | - //$this->setError("No namespace registered for prefix '$prefix'"); |
|
828 | - return false; |
|
829 | - } |
|
830 | - |
|
831 | - /** |
|
832 | - * returns the prefix for a given namespace (or prefix) |
|
833 | - * or false if no prefixes registered for the given namespace |
|
834 | - * |
|
835 | - * @param string $ns The namespace |
|
836 | - * @return mixed The prefix, false if the namespace has no prefixes |
|
837 | - * @access public |
|
838 | - */ |
|
839 | - function getPrefixFromNamespace($ns) { |
|
840 | - foreach ($this->namespaces as $p => $n) { |
|
841 | - if ($ns == $n || $ns == $p) { |
|
842 | - $this->usedNamespaces[$p] = $n; |
|
843 | - return $p; |
|
844 | - } |
|
845 | - } |
|
846 | - return false; |
|
847 | - } |
|
848 | - |
|
849 | - /** |
|
850 | - * returns the time in ODBC canonical form with microseconds |
|
851 | - * |
|
852 | - * @return string The time in ODBC canonical form with microseconds |
|
853 | - * @access public |
|
854 | - */ |
|
855 | - function getmicrotime() { |
|
856 | - if (function_exists('gettimeofday')) { |
|
857 | - $tod = gettimeofday(); |
|
858 | - $sec = $tod['sec']; |
|
859 | - $usec = $tod['usec']; |
|
860 | - } else { |
|
861 | - $sec = time(); |
|
862 | - $usec = 0; |
|
863 | - } |
|
864 | - return strftime('%Y-%m-%d %H:%M:%S', $sec) . '.' . sprintf('%06d', $usec); |
|
865 | - } |
|
866 | - |
|
867 | - /** |
|
868 | - * Returns a string with the output of var_dump |
|
869 | - * |
|
870 | - * @param mixed $data The variable to var_dump |
|
871 | - * @return string The output of var_dump |
|
872 | - * @access public |
|
873 | - */ |
|
730 | + $str = htmlspecialchars($str); |
|
731 | + return nl2br($str); |
|
732 | + } |
|
733 | + |
|
734 | + /** |
|
735 | + * contracts (changes namespace to prefix) a qualified name |
|
736 | + * |
|
737 | + * @param string $qname qname |
|
738 | + * @return string contracted qname |
|
739 | + * @access private |
|
740 | + */ |
|
741 | + function contractQname($qname){ |
|
742 | + // get element namespace |
|
743 | + //$this->xdebug("Contract $qname"); |
|
744 | + if (strrpos($qname, ':')) { |
|
745 | + // get unqualified name |
|
746 | + $name = substr($qname, strrpos($qname, ':') + 1); |
|
747 | + // get ns |
|
748 | + $ns = substr($qname, 0, strrpos($qname, ':')); |
|
749 | + $p = $this->getPrefixFromNamespace($ns); |
|
750 | + if ($p) { |
|
751 | + return $p . ':' . $name; |
|
752 | + } |
|
753 | + return $qname; |
|
754 | + } else { |
|
755 | + return $qname; |
|
756 | + } |
|
757 | + } |
|
758 | + |
|
759 | + /** |
|
760 | + * expands (changes prefix to namespace) a qualified name |
|
761 | + * |
|
762 | + * @param string $qname qname |
|
763 | + * @return string expanded qname |
|
764 | + * @access private |
|
765 | + */ |
|
766 | + function expandQname($qname){ |
|
767 | + // get element prefix |
|
768 | + if(strpos($qname,':') && !preg_match('/^http:\/\//',$qname)){ |
|
769 | + // get unqualified name |
|
770 | + $name = substr(strstr($qname,':'),1); |
|
771 | + // get ns prefix |
|
772 | + $prefix = substr($qname,0,strpos($qname,':')); |
|
773 | + if(isset($this->namespaces[$prefix])){ |
|
774 | + return $this->namespaces[$prefix].':'.$name; |
|
775 | + } else { |
|
776 | + return $qname; |
|
777 | + } |
|
778 | + } else { |
|
779 | + return $qname; |
|
780 | + } |
|
781 | + } |
|
782 | + |
|
783 | + /** |
|
784 | + * returns the local part of a prefixed string |
|
785 | + * returns the original string, if not prefixed |
|
786 | + * |
|
787 | + * @param string $str The prefixed string |
|
788 | + * @return string The local part |
|
789 | + * @access public |
|
790 | + */ |
|
791 | + function getLocalPart($str){ |
|
792 | + if($sstr = strrchr($str,':')){ |
|
793 | + // get unqualified name |
|
794 | + return substr( $sstr, 1 ); |
|
795 | + } else { |
|
796 | + return $str; |
|
797 | + } |
|
798 | + } |
|
799 | + |
|
800 | + /** |
|
801 | + * returns the prefix part of a prefixed string |
|
802 | + * returns false, if not prefixed |
|
803 | + * |
|
804 | + * @param string $str The prefixed string |
|
805 | + * @return mixed The prefix or false if there is no prefix |
|
806 | + * @access public |
|
807 | + */ |
|
808 | + function getPrefix($str){ |
|
809 | + if($pos = strrpos($str,':')){ |
|
810 | + // get prefix |
|
811 | + return substr($str,0,$pos); |
|
812 | + } |
|
813 | + return false; |
|
814 | + } |
|
815 | + |
|
816 | + /** |
|
817 | + * pass it a prefix, it returns a namespace |
|
818 | + * |
|
819 | + * @param string $prefix The prefix |
|
820 | + * @return mixed The namespace, false if no namespace has the specified prefix |
|
821 | + * @access public |
|
822 | + */ |
|
823 | + function getNamespaceFromPrefix($prefix){ |
|
824 | + if (isset($this->namespaces[$prefix])) { |
|
825 | + return $this->namespaces[$prefix]; |
|
826 | + } |
|
827 | + //$this->setError("No namespace registered for prefix '$prefix'"); |
|
828 | + return false; |
|
829 | + } |
|
830 | + |
|
831 | + /** |
|
832 | + * returns the prefix for a given namespace (or prefix) |
|
833 | + * or false if no prefixes registered for the given namespace |
|
834 | + * |
|
835 | + * @param string $ns The namespace |
|
836 | + * @return mixed The prefix, false if the namespace has no prefixes |
|
837 | + * @access public |
|
838 | + */ |
|
839 | + function getPrefixFromNamespace($ns) { |
|
840 | + foreach ($this->namespaces as $p => $n) { |
|
841 | + if ($ns == $n || $ns == $p) { |
|
842 | + $this->usedNamespaces[$p] = $n; |
|
843 | + return $p; |
|
844 | + } |
|
845 | + } |
|
846 | + return false; |
|
847 | + } |
|
848 | + |
|
849 | + /** |
|
850 | + * returns the time in ODBC canonical form with microseconds |
|
851 | + * |
|
852 | + * @return string The time in ODBC canonical form with microseconds |
|
853 | + * @access public |
|
854 | + */ |
|
855 | + function getmicrotime() { |
|
856 | + if (function_exists('gettimeofday')) { |
|
857 | + $tod = gettimeofday(); |
|
858 | + $sec = $tod['sec']; |
|
859 | + $usec = $tod['usec']; |
|
860 | + } else { |
|
861 | + $sec = time(); |
|
862 | + $usec = 0; |
|
863 | + } |
|
864 | + return strftime('%Y-%m-%d %H:%M:%S', $sec) . '.' . sprintf('%06d', $usec); |
|
865 | + } |
|
866 | + |
|
867 | + /** |
|
868 | + * Returns a string with the output of var_dump |
|
869 | + * |
|
870 | + * @param mixed $data The variable to var_dump |
|
871 | + * @return string The output of var_dump |
|
872 | + * @access public |
|
873 | + */ |
|
874 | 874 | function varDump($data) { |
875 | - ob_start(); |
|
876 | - var_dump($data); |
|
877 | - $ret_val = ob_get_contents(); |
|
878 | - ob_end_clean(); |
|
879 | - return $ret_val; |
|
880 | - } |
|
881 | - |
|
882 | - /** |
|
883 | - * represents the object as a string |
|
884 | - * |
|
885 | - * @return string |
|
886 | - * @access public |
|
887 | - */ |
|
888 | - function __toString() { |
|
889 | - return $this->varDump($this); |
|
890 | - } |
|
875 | + ob_start(); |
|
876 | + var_dump($data); |
|
877 | + $ret_val = ob_get_contents(); |
|
878 | + ob_end_clean(); |
|
879 | + return $ret_val; |
|
880 | + } |
|
881 | + |
|
882 | + /** |
|
883 | + * represents the object as a string |
|
884 | + * |
|
885 | + * @return string |
|
886 | + * @access public |
|
887 | + */ |
|
888 | + function __toString() { |
|
889 | + return $this->varDump($this); |
|
890 | + } |
|
891 | 891 | } |
892 | 892 | |
893 | 893 | // XML Schema Datatype Helper Functions |
@@ -903,35 +903,35 @@ discard block |
||
903 | 903 | * @access public |
904 | 904 | */ |
905 | 905 | function timestamp_to_iso8601($timestamp,$utc=true){ |
906 | - $datestr = date('Y-m-d\TH:i:sO',$timestamp); |
|
907 | - $pos = strrpos($datestr, "+"); |
|
908 | - if ($pos === FALSE) { |
|
909 | - $pos = strrpos($datestr, "-"); |
|
910 | - } |
|
911 | - if ($pos !== FALSE) { |
|
912 | - if (strlen($datestr) == $pos + 5) { |
|
913 | - $datestr = substr($datestr, 0, $pos + 3) . ':' . substr($datestr, -2); |
|
914 | - } |
|
915 | - } |
|
916 | - if($utc){ |
|
917 | - $pattern = '/'. |
|
918 | - '([0-9]{4})-'. // centuries & years CCYY- |
|
919 | - '([0-9]{2})-'. // months MM- |
|
920 | - '([0-9]{2})'. // days DD |
|
921 | - 'T'. // separator T |
|
922 | - '([0-9]{2}):'. // hours hh: |
|
923 | - '([0-9]{2}):'. // minutes mm: |
|
924 | - '([0-9]{2})(\.[0-9]*)?'. // seconds ss.ss... |
|
925 | - '(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's |
|
926 | - '/'; |
|
927 | - |
|
928 | - if(preg_match($pattern,$datestr,$regs)){ |
|
929 | - return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ',$regs[1],$regs[2],$regs[3],$regs[4],$regs[5],$regs[6]); |
|
930 | - } |
|
931 | - return false; |
|
932 | - } else { |
|
933 | - return $datestr; |
|
934 | - } |
|
906 | + $datestr = date('Y-m-d\TH:i:sO',$timestamp); |
|
907 | + $pos = strrpos($datestr, "+"); |
|
908 | + if ($pos === FALSE) { |
|
909 | + $pos = strrpos($datestr, "-"); |
|
910 | + } |
|
911 | + if ($pos !== FALSE) { |
|
912 | + if (strlen($datestr) == $pos + 5) { |
|
913 | + $datestr = substr($datestr, 0, $pos + 3) . ':' . substr($datestr, -2); |
|
914 | + } |
|
915 | + } |
|
916 | + if($utc){ |
|
917 | + $pattern = '/'. |
|
918 | + '([0-9]{4})-'. // centuries & years CCYY- |
|
919 | + '([0-9]{2})-'. // months MM- |
|
920 | + '([0-9]{2})'. // days DD |
|
921 | + 'T'. // separator T |
|
922 | + '([0-9]{2}):'. // hours hh: |
|
923 | + '([0-9]{2}):'. // minutes mm: |
|
924 | + '([0-9]{2})(\.[0-9]*)?'. // seconds ss.ss... |
|
925 | + '(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's |
|
926 | + '/'; |
|
927 | + |
|
928 | + if(preg_match($pattern,$datestr,$regs)){ |
|
929 | + return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ',$regs[1],$regs[2],$regs[3],$regs[4],$regs[5],$regs[6]); |
|
930 | + } |
|
931 | + return false; |
|
932 | + } else { |
|
933 | + return $datestr; |
|
934 | + } |
|
935 | 935 | } |
936 | 936 | |
937 | 937 | /** |
@@ -942,35 +942,35 @@ discard block |
||
942 | 942 | * @access public |
943 | 943 | */ |
944 | 944 | function iso8601_to_timestamp($datestr){ |
945 | - $pattern = '/'. |
|
946 | - '([0-9]{4})-'. // centuries & years CCYY- |
|
947 | - '([0-9]{2})-'. // months MM- |
|
948 | - '([0-9]{2})'. // days DD |
|
949 | - 'T'. // separator T |
|
950 | - '([0-9]{2}):'. // hours hh: |
|
951 | - '([0-9]{2}):'. // minutes mm: |
|
952 | - '([0-9]{2})(\.[0-9]+)?'. // seconds ss.ss... |
|
953 | - '(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's |
|
954 | - '/'; |
|
955 | - if(preg_match($pattern,$datestr,$regs)){ |
|
956 | - // not utc |
|
957 | - if($regs[8] != 'Z'){ |
|
958 | - $op = substr($regs[8],0,1); |
|
959 | - $h = substr($regs[8],1,2); |
|
960 | - $m = substr($regs[8],strlen($regs[8])-2,2); |
|
961 | - if($op == '-'){ |
|
962 | - $regs[4] = $regs[4] + $h; |
|
963 | - $regs[5] = $regs[5] + $m; |
|
964 | - } elseif($op == '+'){ |
|
965 | - $regs[4] = $regs[4] - $h; |
|
966 | - $regs[5] = $regs[5] - $m; |
|
967 | - } |
|
968 | - } |
|
969 | - return gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); |
|
945 | + $pattern = '/'. |
|
946 | + '([0-9]{4})-'. // centuries & years CCYY- |
|
947 | + '([0-9]{2})-'. // months MM- |
|
948 | + '([0-9]{2})'. // days DD |
|
949 | + 'T'. // separator T |
|
950 | + '([0-9]{2}):'. // hours hh: |
|
951 | + '([0-9]{2}):'. // minutes mm: |
|
952 | + '([0-9]{2})(\.[0-9]+)?'. // seconds ss.ss... |
|
953 | + '(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's |
|
954 | + '/'; |
|
955 | + if(preg_match($pattern,$datestr,$regs)){ |
|
956 | + // not utc |
|
957 | + if($regs[8] != 'Z'){ |
|
958 | + $op = substr($regs[8],0,1); |
|
959 | + $h = substr($regs[8],1,2); |
|
960 | + $m = substr($regs[8],strlen($regs[8])-2,2); |
|
961 | + if($op == '-'){ |
|
962 | + $regs[4] = $regs[4] + $h; |
|
963 | + $regs[5] = $regs[5] + $m; |
|
964 | + } elseif($op == '+'){ |
|
965 | + $regs[4] = $regs[4] - $h; |
|
966 | + $regs[5] = $regs[5] - $m; |
|
967 | + } |
|
968 | + } |
|
969 | + return gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); |
|
970 | 970 | // return strtotime("$regs[1]-$regs[2]-$regs[3] $regs[4]:$regs[5]:$regs[6]Z"); |
971 | - } else { |
|
972 | - return false; |
|
973 | - } |
|
971 | + } else { |
|
972 | + return false; |
|
973 | + } |
|
974 | 974 | } |
975 | 975 | |
976 | 976 | /** |
@@ -982,13 +982,13 @@ discard block |
||
982 | 982 | */ |
983 | 983 | function usleepWindows($usec) |
984 | 984 | { |
985 | - $start = gettimeofday(); |
|
986 | - |
|
987 | - do |
|
988 | - { |
|
989 | - $stop = gettimeofday(); |
|
990 | - $timePassed = 1000000 * ($stop['sec'] - $start['sec']) |
|
991 | - + $stop['usec'] - $start['usec']; |
|
992 | - } |
|
993 | - while ($timePassed < $usec); |
|
985 | + $start = gettimeofday(); |
|
986 | + |
|
987 | + do |
|
988 | + { |
|
989 | + $stop = gettimeofday(); |
|
990 | + $timePassed = 1000000 * ($stop['sec'] - $start['sec']) |
|
991 | + + $stop['usec'] - $start['usec']; |
|
992 | + } |
|
993 | + while ($timePassed < $usec); |
|
994 | 994 | } |