|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00004 // // 00005 // This file is part of Moodle - http://moodle.org/ // 00006 // Moodle - Modular Object-Oriented Dynamic Learning Environment // 00007 // // 00008 // Moodle is free software: you can redistribute it and/or modify // 00009 // it under the terms of the GNU General Public License as published by // 00010 // the Free Software Foundation, either version 3 of the License, or // 00011 // (at your option) any later version. // 00012 // // 00013 // Moodle is distributed in the hope that it will be useful, // 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 00016 // GNU General Public License for more details. // 00017 // // 00018 // You should have received a copy of the GNU General Public License // 00019 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. // 00020 // // 00022 00030 class core_webservice_renderer extends plugin_renderer_base { 00031 00037 public function admin_authorised_user_selector(&$options) { 00038 global $CFG; 00039 $formcontent = html_writer::empty_tag('input', 00040 array('name' => 'sesskey', 'value' => sesskey(), 'type' => 'hidden')); 00041 00042 $table = new html_table(); 00043 $table->size = array('45%', '10%', '45%'); 00044 $table->attributes['class'] = 'roleassigntable generaltable generalbox boxaligncenter'; 00045 $table->summary = ''; 00046 $table->cellspacing = 0; 00047 $table->cellpadding = 0; 00048 00049 // LTR/RTL support, for drawing button arrows in the right direction 00050 if (right_to_left()) { 00051 $addarrow = '▶'; 00052 $removearrow = '◀'; 00053 } else { 00054 $addarrow = '◀'; 00055 $removearrow = '▶'; 00056 } 00057 00058 //create the add and remove button 00059 $addinput = html_writer::empty_tag('input', 00060 array('name' => 'add', 'id' => 'add', 'type' => 'submit', 00061 'value' => $addarrow . ' ' . get_string('add'), 00062 'title' => get_string('add'))); 00063 $addbutton = html_writer::tag('div', $addinput, array('id' => 'addcontrols')); 00064 $removeinput = html_writer::empty_tag('input', 00065 array('name' => 'remove', 'id' => 'remove', 'type' => 'submit', 00066 'value' => $removearrow . ' ' . get_string('remove'), 00067 'title' => get_string('remove'))); 00068 $removebutton = html_writer::tag('div', $removeinput, array('id' => 'removecontrols')); 00069 00070 00071 //create the three cells 00072 $label = html_writer::tag('label', get_string('serviceusers', 'webservice'), 00073 array('for' => 'removeselect')); 00074 $label = html_writer::tag('p', $label); 00075 $authoriseduserscell = new html_table_cell($label . 00076 $options->alloweduserselector->display(true)); 00077 $authoriseduserscell->id = 'existingcell'; 00078 $buttonscell = new html_table_cell($addbutton . html_writer::empty_tag('br') . $removebutton); 00079 $buttonscell->id = 'buttonscell'; 00080 $label = html_writer::tag('label', get_string('potusers', 'webservice'), 00081 array('for' => 'addselect')); 00082 $label = html_writer::tag('p', $label); 00083 $otheruserscell = new html_table_cell($label . 00084 $options->potentialuserselector->display(true)); 00085 $otheruserscell->id = 'potentialcell'; 00086 00087 $cells = array($authoriseduserscell, $buttonscell, $otheruserscell); 00088 $row = new html_table_row($cells); 00089 $table->data[] = $row; 00090 $formcontent .= html_writer::table($table); 00091 00092 $formcontent = html_writer::tag('div', $formcontent); 00093 00094 $actionurl = new moodle_url('/' . $CFG->admin . '/webservice/service_users.php', 00095 array('id' => $options->serviceid)); 00096 $html = html_writer::tag('form', $formcontent, 00097 array('id' => 'assignform', 'action' => $actionurl, 'method' => 'post')); 00098 return $html; 00099 } 00100 00106 public function admin_authorised_user_list($users, $serviceid) { 00107 global $CFG; 00108 $html = $this->output->box_start('generalbox', 'alloweduserlist'); 00109 foreach ($users as $user) { 00110 $modifiedauthoriseduserurl = new moodle_url('/' . $CFG->admin . '/webservice/service_user_settings.php', 00111 array('userid' => $user->id, 'serviceid' => $serviceid)); 00112 $html .= html_writer::tag('a', $user->firstname . " " 00113 . $user->lastname . ", " . $user->email, 00114 array('href' => $modifiedauthoriseduserurl)); 00115 //add missing capabilities 00116 if (!empty($user->missingcapabilities)) { 00117 $html .= html_writer::tag('div', 00118 get_string('usermissingcaps', 'webservice', $user->missingcapabilities) 00119 . ' ' . $this->output->help_icon('missingcaps', 'webservice'), 00120 array('class' => 'missingcaps', 'id' => 'usermissingcaps')); 00121 $html .= html_writer::empty_tag('br'); 00122 } else { 00123 $html .= html_writer::empty_tag('br') . html_writer::empty_tag('br'); 00124 } 00125 } 00126 $html .= $this->output->box_end(); 00127 return $html; 00128 } 00129 00136 public function admin_remove_service_function_confirmation($function, $service) { 00137 $optionsyes = array('id' => $service->id, 'action' => 'delete', 00138 'confirm' => 1, 'sesskey' => sesskey(), 'fid' => $function->id); 00139 $optionsno = array('id' => $service->id); 00140 $formcontinue = new single_button(new moodle_url('service_functions.php', 00141 $optionsyes), get_string('remove')); 00142 $formcancel = new single_button(new moodle_url('service_functions.php', 00143 $optionsno), get_string('cancel'), 'get'); 00144 return $this->output->confirm(get_string('removefunctionconfirm', 'webservice', 00145 (object) array('service' => $service->name, 'function' => $function->name)), 00146 $formcontinue, $formcancel); 00147 } 00148 00154 public function admin_remove_service_confirmation($service) { 00155 global $CFG; 00156 $optionsyes = array('id' => $service->id, 'action' => 'delete', 00157 'confirm' => 1, 'sesskey' => sesskey()); 00158 $optionsno = array('section' => 'externalservices'); 00159 $formcontinue = new single_button(new moodle_url('service.php', $optionsyes), 00160 get_string('delete'), 'post'); 00161 $formcancel = new single_button( 00162 new moodle_url($CFG->wwwroot . "/" . $CFG->admin . "/settings.php", $optionsno), 00163 get_string('cancel'), 'get'); 00164 return $this->output->confirm(get_string('deleteserviceconfirm', 'webservice', $service->name), 00165 $formcontinue, $formcancel); 00166 } 00167 00173 public function admin_delete_token_confirmation($token) { 00174 global $CFG; 00175 $optionsyes = array('tokenid' => $token->id, 'action' => 'delete', 00176 'confirm' => 1, 'sesskey' => sesskey()); 00177 $optionsno = array('section' => 'webservicetokens', 'sesskey' => sesskey()); 00178 $formcontinue = new single_button( 00179 new moodle_url('/' . $CFG->admin . '/webservice/tokens.php', $optionsyes), 00180 get_string('delete')); 00181 $formcancel = new single_button( 00182 new moodle_url('/' . $CFG->admin . '/settings.php', $optionsno), 00183 get_string('cancel'), 'get'); 00184 return $this->output->confirm(get_string('deletetokenconfirm', 'webservice', 00185 (object) array('user' => $token->firstname . " " 00186 . $token->lastname, 'service' => $token->name)), 00187 $formcontinue, $formcancel); 00188 } 00189 00197 public function admin_service_function_list($functions, $service) { 00198 global $CFG; 00199 if (!empty($functions)) { 00200 $table = new html_table(); 00201 $table->head = array(get_string('function', 'webservice'), 00202 get_string('description'), get_string('requiredcaps', 'webservice')); 00203 $table->align = array('left', 'left', 'left'); 00204 $table->size = array('15%', '40%', '40%'); 00205 $table->width = '100%'; 00206 $table->align[] = 'left'; 00207 00208 //display remove function operation (except for build-in service) 00209 if (empty($service->component)) { 00210 $table->head[] = get_string('edit'); 00211 $table->align[] = 'center'; 00212 } 00213 00214 foreach ($functions as $function) { 00215 $function = external_function_info($function); 00216 $requiredcaps = html_writer::tag('div', 00217 empty($function->capabilities) ? '' : $function->capabilities, 00218 array('class' => 'functiondesc')); 00219 ; 00220 $description = html_writer::tag('div', $function->description, 00221 array('class' => 'functiondesc')); 00222 //display remove function operation (except for build-in service) 00223 if (empty($service->component)) { 00224 $removeurl = new moodle_url('/' . $CFG->admin . '/webservice/service_functions.php', 00225 array('sesskey' => sesskey(), 'fid' => $function->id, 00226 'id' => $service->id, 00227 'action' => 'delete')); 00228 $removelink = html_writer::tag('a', 00229 get_string('removefunction', 'webservice'), 00230 array('href' => $removeurl)); 00231 $table->data[] = array($function->name, $description, $requiredcaps, $removelink); 00232 } else { 00233 $table->data[] = array($function->name, $description, $requiredcaps); 00234 } 00235 } 00236 00237 $html = html_writer::table($table); 00238 } else { 00239 $html = get_string('nofunctions', 'webservice') . html_writer::empty_tag('br'); 00240 } 00241 00242 //display add function operation (except for build-in service) 00243 if (empty($service->component)) { 00244 $addurl = new moodle_url('/' . $CFG->admin . '/webservice/service_functions.php', 00245 array('sesskey' => sesskey(), 'id' => $service->id, 'action' => 'add')); 00246 $html .= html_writer::tag('a', get_string('addfunctions', 'webservice'), array('href' => $addurl)); 00247 } 00248 00249 return $html; 00250 } 00251 00257 public function user_reset_token_confirmation($token) { 00258 global $CFG; 00259 $managetokenurl = $CFG->wwwroot . "/user/managetoken.php?sesskey=" . sesskey(); 00260 $optionsyes = array('tokenid' => $token->id, 'action' => 'resetwstoken', 'confirm' => 1, 00261 'sesskey' => sesskey()); 00262 $optionsno = array('section' => 'webservicetokens', 'sesskey' => sesskey()); 00263 $formcontinue = new single_button(new moodle_url($managetokenurl, $optionsyes), 00264 get_string('reset')); 00265 $formcancel = new single_button(new moodle_url($managetokenurl, $optionsno), 00266 get_string('cancel'), 'get'); 00267 $html = $this->output->confirm(get_string('resettokenconfirm', 'webservice', 00268 (object) array('user' => $token->firstname . " " . 00269 $token->lastname, 'service' => $token->name)), 00270 $formcontinue, $formcancel); 00271 return $html; 00272 } 00273 00280 public function user_webservice_tokens_box($tokens, $userid, $documentation = false) { 00281 global $CFG, $DB; 00282 00283 // display strings 00284 $stroperation = get_string('operation', 'webservice'); 00285 $strtoken = get_string('key', 'webservice'); 00286 $strservice = get_string('service', 'webservice'); 00287 $strcreator = get_string('tokencreator', 'webservice'); 00288 $strcontext = get_string('context', 'webservice'); 00289 $strvaliduntil = get_string('validuntil', 'webservice'); 00290 00291 $return = $this->output->heading(get_string('securitykeys', 'webservice'), 3, 'main', true); 00292 $return .= $this->output->box_start('generalbox webservicestokenui'); 00293 00294 $return .= get_string('keyshelp', 'webservice'); 00295 00296 $table = new html_table(); 00297 $table->head = array($strtoken, $strservice, $strvaliduntil, $strcreator, $stroperation); 00298 $table->align = array('left', 'left', 'left', 'center', 'left', 'center'); 00299 $table->width = '100%'; 00300 $table->data = array(); 00301 00302 if ($documentation) { 00303 $table->head[] = get_string('doc', 'webservice'); 00304 $table->align[] = 'center'; 00305 } 00306 00307 if (!empty($tokens)) { 00308 foreach ($tokens as $token) { 00309 00310 if ($token->creatorid == $userid) { 00311 $reset = "<a href=\"" . $CFG->wwwroot . "/user/managetoken.php?sesskey=" 00312 . sesskey() . "&action=resetwstoken&tokenid=" . $token->id . "\">"; 00313 $reset .= get_string('reset') . "</a>"; 00314 $creator = $token->firstname . " " . $token->lastname; 00315 } else { 00316 //retrieve administrator name 00317 $admincreator = $DB->get_record('user', array('id'=>$token->creatorid)); 00318 $creator = $admincreator->firstname . " " . $admincreator->lastname; 00319 $reset = ''; 00320 } 00321 00322 $userprofilurl = new moodle_url('/user/view.php?id=' . $token->creatorid); 00323 $creatoratag = html_writer::start_tag('a', array('href' => $userprofilurl)); 00324 $creatoratag .= $creator; 00325 $creatoratag .= html_writer::end_tag('a'); 00326 00327 $validuntil = ''; 00328 if (!empty($token->validuntil)) { 00329 $validuntil = date("F j, Y"); //TODO: language support (look for moodle function) 00330 } 00331 00332 $tokenname = $token->name; 00333 if (!$token->enabled) { //that is the (1 token-1ws) related ws is not enabled. 00334 $tokenname = '<span class="dimmed_text">'.$token->name.'</span>'; 00335 } 00336 $row = array($token->token, $tokenname, $validuntil, $creatoratag, $reset); 00337 00338 if ($documentation) { 00339 $doclink = new moodle_url('/webservice/wsdoc.php', 00340 array('id' => $token->id, 'sesskey' => sesskey())); 00341 $row[] = html_writer::tag('a', get_string('doc', 'webservice'), 00342 array('href' => $doclink)); 00343 } 00344 00345 $table->data[] = $row; 00346 } 00347 $return .= html_writer::table($table); 00348 } else { 00349 $return .= get_string('notoken', 'webservice'); 00350 } 00351 00352 $return .= $this->output->box_end(); 00353 return $return; 00354 } 00355 00372 public function detailed_description_html($params) { 00374 $paramdesc = ""; 00375 if (!empty($params->desc)) { 00376 $paramdesc .= html_writer::start_tag('span', array('style' => "color:#2A33A6")); 00377 if ($params->required == VALUE_REQUIRED) { 00378 $required = ''; 00379 } 00380 if ($params->required == VALUE_DEFAULT) { 00381 if ($params->default === null) { 00382 $params->default = "null"; 00383 } 00384 $required = html_writer::start_tag('b', array()) . 00385 get_string('default', 'webservice', print_r($params->default, true)) 00386 . html_writer::end_tag('b'); 00387 } 00388 if ($params->required == VALUE_OPTIONAL) { 00389 $required = html_writer::start_tag('b', array()) . 00390 get_string('optional', 'webservice') . html_writer::end_tag('b'); 00391 } 00392 $paramdesc .= " " . $required . " "; 00393 $paramdesc .= html_writer::start_tag('i', array()); 00394 $paramdesc .= "//"; 00395 00396 $paramdesc .= $params->desc; 00397 00398 $paramdesc .= html_writer::end_tag('i'); 00399 00400 $paramdesc .= html_writer::end_tag('span'); 00401 $paramdesc .= html_writer::empty_tag('br', array()); 00402 } 00403 00405 if ($params instanceof external_multiple_structure) { 00406 return $paramdesc . "list of ( " . html_writer::empty_tag('br', array()) 00407 . $this->detailed_description_html($params->content) . ")"; 00408 } else if ($params instanceof external_single_structure) { 00410 $singlestructuredesc = $paramdesc . "object {" . html_writer::empty_tag('br', array()); 00411 foreach ($params->keys as $attributname => $attribut) { 00412 $singlestructuredesc .= html_writer::start_tag('b', array()); 00413 $singlestructuredesc .= $attributname; 00414 $singlestructuredesc .= html_writer::end_tag('b'); 00415 $singlestructuredesc .= " " . 00416 $this->detailed_description_html($params->keys[$attributname]); 00417 } 00418 $singlestructuredesc .= "} "; 00419 $singlestructuredesc .= html_writer::empty_tag('br', array()); 00420 return $singlestructuredesc; 00421 } else { 00423 switch ($params->type) { 00424 case PARAM_BOOL: // 0 or 1 only for now 00425 case PARAM_INT: 00426 $type = 'int'; 00427 break; 00428 case PARAM_FLOAT; 00429 $type = 'double'; 00430 break; 00431 default: 00432 $type = 'string'; 00433 } 00434 return $type . " " . $paramdesc; 00435 } 00436 } 00437 00445 public function description_in_indented_xml_format($returndescription, $indentation = "") { 00446 $indentation = $indentation . " "; 00447 $brakeline = <<<EOF 00448 00449 00450 EOF; 00452 if ($returndescription instanceof external_multiple_structure) { 00453 $return = $indentation . "<MULTIPLE>" . $brakeline; 00454 $return .= $this->description_in_indented_xml_format($returndescription->content, 00455 $indentation); 00456 $return .= $indentation . "</MULTIPLE>" . $brakeline; 00457 return $return; 00458 } else if ($returndescription instanceof external_single_structure) { 00460 $singlestructuredesc = $indentation . "<SINGLE>" . $brakeline; 00461 $keyindentation = $indentation . " "; 00462 foreach ($returndescription->keys as $attributname => $attribut) { 00463 $singlestructuredesc .= $keyindentation . "<KEY name=\"" . $attributname . "\">" 00464 . $brakeline . 00465 $this->description_in_indented_xml_format( 00466 $returndescription->keys[$attributname], $keyindentation) . 00467 $keyindentation . "</KEY>" . $brakeline; 00468 } 00469 $singlestructuredesc .= $indentation . "</SINGLE>" . $brakeline; 00470 return $singlestructuredesc; 00471 } else { 00473 switch ($returndescription->type) { 00474 case PARAM_BOOL: // 0 or 1 only for now 00475 case PARAM_INT: 00476 $type = 'int'; 00477 break; 00478 case PARAM_FLOAT; 00479 $type = 'double'; 00480 break; 00481 default: 00482 $type = 'string'; 00483 } 00484 return $indentation . "<VALUE>" . $type . "</VALUE>" . $brakeline; 00485 } 00486 } 00487 00494 public function xmlrpc_param_description_html($paramdescription, $indentation = "") { 00495 $indentation = $indentation . " "; 00496 $brakeline = <<<EOF 00497 00498 00499 EOF; 00501 if ($paramdescription instanceof external_multiple_structure) { 00502 $return = $brakeline . $indentation . "Array "; 00503 $indentation = $indentation . " "; 00504 $return .= $brakeline . $indentation . "("; 00505 $return .= $brakeline . $indentation . "[0] =>"; 00506 $return .= $this->xmlrpc_param_description_html($paramdescription->content, $indentation); 00507 $return .= $brakeline . $indentation . ")"; 00508 return $return; 00509 } else if ($paramdescription instanceof external_single_structure) { 00511 $singlestructuredesc = $brakeline . $indentation . "Array "; 00512 $keyindentation = $indentation . " "; 00513 $singlestructuredesc .= $brakeline . $keyindentation . "("; 00514 foreach ($paramdescription->keys as $attributname => $attribut) { 00515 $singlestructuredesc .= $brakeline . $keyindentation . "[" . $attributname . "] =>" . 00516 $this->xmlrpc_param_description_html( 00517 $paramdescription->keys[$attributname], $keyindentation) . 00518 $keyindentation; 00519 } 00520 $singlestructuredesc .= $brakeline . $keyindentation . ")"; 00521 return $singlestructuredesc; 00522 } else { 00524 switch ($paramdescription->type) { 00525 case PARAM_BOOL: // 0 or 1 only for now 00526 case PARAM_INT: 00527 $type = 'int'; 00528 break; 00529 case PARAM_FLOAT; 00530 $type = 'double'; 00531 break; 00532 default: 00533 $type = 'string'; 00534 } 00535 return " " . $type; 00536 } 00537 } 00538 00546 public function colored_box_with_pre_tag($title, $content, $rgb = 'FEEBE5') { 00547 //TODO: this tag removes xhtml strict error but cause warning 00548 $coloredbox = html_writer::start_tag('div', array()); 00549 $coloredbox .= html_writer::start_tag('div', 00550 array('style' => "border:solid 1px #DEDEDE;background:#" . $rgb 00551 . ";color:#222222;padding:4px;")); 00552 $coloredbox .= html_writer::start_tag('pre', array()); 00553 $coloredbox .= html_writer::start_tag('b', array()); 00554 $coloredbox .= $title; 00555 $coloredbox .= html_writer::end_tag('b', array()); 00556 $coloredbox .= html_writer::empty_tag('br', array()); 00557 $coloredbox .= "\n" . $content . "\n"; 00558 $coloredbox .= html_writer::end_tag('pre', array()); 00559 $coloredbox .= html_writer::end_tag('div', array()); 00560 $coloredbox .= html_writer::end_tag('div', array()); 00561 return $coloredbox; 00562 } 00563 00570 public function rest_param_description_html($paramdescription, $paramstring) { 00571 $brakeline = <<<EOF 00572 00573 00574 EOF; 00576 if ($paramdescription instanceof external_multiple_structure) { 00577 $paramstring = $paramstring . '[0]'; 00578 $return = $this->rest_param_description_html($paramdescription->content, $paramstring); 00579 return $return; 00580 } else if ($paramdescription instanceof external_single_structure) { 00582 $singlestructuredesc = ""; 00583 $initialparamstring = $paramstring; 00584 foreach ($paramdescription->keys as $attributname => $attribut) { 00585 $paramstring = $initialparamstring . '[' . $attributname . ']'; 00586 $singlestructuredesc .= $this->rest_param_description_html( 00587 $paramdescription->keys[$attributname], $paramstring); 00588 } 00589 return $singlestructuredesc; 00590 } else { 00592 $paramstring = $paramstring . '='; 00593 switch ($paramdescription->type) { 00594 case PARAM_BOOL: // 0 or 1 only for now 00595 case PARAM_INT: 00596 $type = 'int'; 00597 break; 00598 case PARAM_FLOAT; 00599 $type = 'double'; 00600 break; 00601 default: 00602 $type = 'string'; 00603 } 00604 return $paramstring . " " . $type . $brakeline; 00605 } 00606 } 00607 00618 public function documentation_html($functions, $printableformat, $activatedprotocol, 00619 $authparams, $parenturl = '/webservice/wsdoc.php') { 00620 00621 $documentationhtml = $this->output->heading(get_string('wsdocapi', 'webservice')); 00622 00623 $br = html_writer::empty_tag('br', array()); 00624 $brakeline = <<<EOF 00625 00626 00627 EOF; 00629 $docinfo = new stdClass(); 00630 $docurl = new moodle_url('http://docs.moodle.org/dev/Creating_a_web_service_client'); 00631 $docinfo->doclink = html_writer::tag('a', 00632 get_string('wsclientdoc', 'webservice'), array('href' => $docurl)); 00633 $documentationhtml .= html_writer::start_tag('table', 00634 array('style' => "margin-left:auto; margin-right:auto;")); 00635 $documentationhtml .= html_writer::start_tag('tr', array()); 00636 $documentationhtml .= html_writer::start_tag('td', array()); 00637 $documentationhtml .= get_string('wsdocumentationintro', 'webservice', $docinfo); 00638 $documentationhtml .= $br . $br; 00639 00640 00642 $authparams['print'] = true; 00643 //$parameters = array ('token' => $token, 'wsusername' => $username, 'wspassword' => $password, 'print' => true); 00644 $url = new moodle_url($parenturl, $authparams); // Required 00645 $documentationhtml .= $this->output->single_button($url, get_string('print', 'webservice')); 00646 $documentationhtml .= $br; 00647 00648 00650 //(opened if printableformat = true) 00651 foreach ($functions as $functionname => $description) { 00652 00653 if (empty($printableformat)) { 00654 $documentationhtml .= print_collapsible_region_start('', 00655 'aera_' . $functionname, 00656 html_writer::start_tag('strong', array()) 00657 . $functionname . html_writer::end_tag('strong'), 00658 false, 00659 !$printableformat, 00660 true); 00661 } else { 00662 $documentationhtml .= html_writer::tag('strong', $functionname); 00663 $documentationhtml .= $br; 00664 } 00665 00667 $documentationhtml .= $br; 00668 $documentationhtml .= html_writer::start_tag('div', 00669 array('style' => 'border:solid 1px #DEDEDE;background:#E2E0E0; 00670 color:#222222;padding:4px;')); 00671 $documentationhtml .= $description->description; 00672 $documentationhtml .= html_writer::end_tag('div'); 00673 $documentationhtml .= $br . $br; 00674 00676 $documentationhtml .= html_writer::start_tag('span', array('style' => 'color:#EA33A6')); 00677 $documentationhtml .= get_string('arguments', 'webservice'); 00678 $documentationhtml .= html_writer::end_tag('span'); 00679 $documentationhtml .= $br; 00680 foreach ($description->parameters_desc->keys as $paramname => $paramdesc) { 00682 $documentationhtml .= html_writer::start_tag('span', array('style' => 'font-size:80%')); 00683 00684 if ($paramdesc->required == VALUE_REQUIRED) { 00685 $required = get_string('required', 'webservice'); 00686 } 00687 if ($paramdesc->required == VALUE_DEFAULT) { 00688 if ($paramdesc->default === null) { 00689 $default = "null"; 00690 } else { 00691 $default = print_r($paramdesc->default, true); 00692 } 00693 $required = get_string('default', 'webservice', $default); 00694 } 00695 if ($paramdesc->required == VALUE_OPTIONAL) { 00696 $required = get_string('optional', 'webservice'); 00697 } 00698 00699 $documentationhtml .= html_writer::start_tag('b', array()); 00700 $documentationhtml .= $paramname; 00701 $documentationhtml .= html_writer::end_tag('b'); 00702 $documentationhtml .= " (" . $required . ")"; // argument is required or optional ? 00703 $documentationhtml .= $br; 00704 $documentationhtml .= " " 00705 . $paramdesc->desc; // argument description 00706 $documentationhtml .= $br . $br; 00708 $documentationhtml .= $this->colored_box_with_pre_tag( 00709 get_string('generalstructure', 'webservice'), 00710 $this->detailed_description_html($paramdesc), 00711 'FFF1BC'); 00713 if (!empty($activatedprotocol['xmlrpc'])) { 00714 $documentationhtml .= $this->colored_box_with_pre_tag( 00715 get_string('phpparam', 'webservice'), 00716 htmlentities('[' . $paramname . '] =>' 00717 . $this->xmlrpc_param_description_html($paramdesc)), 00718 'DFEEE7'); 00719 } 00721 if (!empty($activatedprotocol['rest'])) { 00722 $documentationhtml .= $this->colored_box_with_pre_tag( 00723 get_string('restparam', 'webservice'), 00724 htmlentities($this->rest_param_description_html( 00725 $paramdesc, $paramname)), 00726 'FEEBE5'); 00727 } 00728 $documentationhtml .= html_writer::end_tag('span'); 00729 } 00730 $documentationhtml .= $br . $br; 00731 00732 00734 $documentationhtml .= html_writer::start_tag('span', array('style' => 'color:#EA33A6')); 00735 $documentationhtml .= get_string('response', 'webservice'); 00736 $documentationhtml .= html_writer::end_tag('span'); 00737 $documentationhtml .= $br; 00739 $documentationhtml .= html_writer::start_tag('span', array('style' => 'font-size:80%')); 00740 if (!empty($description->returns_desc->desc)) { 00741 $documentationhtml .= $description->returns_desc->desc; 00742 $documentationhtml .= $br . $br; 00743 } 00744 if (!empty($description->returns_desc)) { 00746 $documentationhtml .= $this->colored_box_with_pre_tag( 00747 get_string('generalstructure', 'webservice'), 00748 $this->detailed_description_html($description->returns_desc), 00749 'FFF1BC'); 00751 if (!empty($activatedprotocol['xmlrpc'])) { 00752 $documentationhtml .= $this->colored_box_with_pre_tag( 00753 get_string('phpresponse', 'webservice'), 00754 htmlentities($this->xmlrpc_param_description_html( 00755 $description->returns_desc)), 00756 'DFEEE7'); 00757 } 00759 if (!empty($activatedprotocol['rest'])) { 00760 $restresponse = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" 00761 . $brakeline . "<RESPONSE>" . $brakeline; 00762 $restresponse .= $this->description_in_indented_xml_format( 00763 $description->returns_desc); 00764 $restresponse .="</RESPONSE>" . $brakeline; 00765 $documentationhtml .= $this->colored_box_with_pre_tag( 00766 get_string('restcode', 'webservice'), 00767 htmlentities($restresponse), 00768 'FEEBE5'); 00769 } 00770 } 00771 $documentationhtml .= html_writer::end_tag('span'); 00772 $documentationhtml .= $br . $br; 00773 00775 if (!empty($activatedprotocol['rest'])) { 00776 $documentationhtml .= html_writer::start_tag('span', array('style' => 'color:#EA33A6')); 00777 $documentationhtml .= get_string('errorcodes', 'webservice'); 00778 $documentationhtml .= html_writer::end_tag('span'); 00779 $documentationhtml .= $br . $br; 00780 $documentationhtml .= html_writer::start_tag('span', array('style' => 'font-size:80%')); 00781 $errormessage = get_string('invalidparameter', 'debug'); 00782 $restexceptiontext = <<<EOF 00783 <?xml version="1.0" encoding="UTF-8"?> 00784 <EXCEPTION class="invalid_parameter_exception"> 00785 <MESSAGE>{$errormessage}</MESSAGE> 00786 <DEBUGINFO></DEBUGINFO> 00787 </EXCEPTION> 00788 EOF; 00789 $documentationhtml .= $this->colored_box_with_pre_tag( 00790 get_string('restexception', 'webservice'), 00791 htmlentities($restexceptiontext), 00792 'FEEBE5'); 00793 00794 $documentationhtml .= html_writer::end_tag('span'); 00795 } 00796 $documentationhtml .= $br . $br; 00797 if (empty($printableformat)) { 00798 $documentationhtml .= print_collapsible_region_end(true); 00799 } 00800 } 00801 00803 $documentationhtml .= html_writer::end_tag('td'); 00804 $documentationhtml .= html_writer::end_tag('tr'); 00805 $documentationhtml .= html_writer::end_tag('table'); 00806 00807 return $documentationhtml; 00808 } 00809 00810 }