// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
- * Web services function UI
+ * Web services services UI
*
* @package webservice
* @copyright 2009 Moodle Pty Ltd (http://moodle.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
require_once('../../config.php');
-require_once($CFG->libdir.'/adminlib.php');
-require_once($CFG->dirroot.'/admin/webservice/lib.php');
+require_once($CFG->libdir . '/adminlib.php');
+require_once($CFG->dirroot . '/admin/webservice/lib.php');
+require_once($CFG->dirroot . '/webservice/lib.php');
$id = required_param('id', PARAM_INT);
-$PAGE->set_url('/admin/webservice/service_users.php', array('id'=>$id));
+$PAGE->set_url('/admin/webservice/service_users.php', array('id' => $id));
$PAGE->navbar->ignore_active(true);
$PAGE->navbar->add(get_string('administrationsite'));
$PAGE->navbar->add(get_string('plugins', 'admin'));
$PAGE->navbar->add(get_string('webservices', 'webservice'));
-$PAGE->navbar->add(get_string('externalservices', 'webservice'), new moodle_url('/admin/settings.php?section=externalservices'));
+$PAGE->navbar->add(get_string('externalservices', 'webservice'),
+ new moodle_url('/admin/settings.php?section=externalservices'));
$PAGE->navbar->add(get_string('serviceusers', 'webservice'));
-$PAGE->requires->js('/admin/webservice/script.js');
-
admin_externalpage_setup('externalserviceusers');
-echo $OUTPUT->header();
+$webservicemanager = new webservice();
/// Get the user_selector we will need.
-$potentialuserselector = new service_user_selector('addselect', array('serviceid' => $id, 'displayallowedusers' => 0));
-$alloweduserselector = new service_user_selector('removeselect', array('serviceid' => $id, 'displayallowedusers' => 1));
+$potentialuserselector = new service_user_selector('addselect',
+ array('serviceid' => $id, 'displayallowedusers' => 0));
+$alloweduserselector = new service_user_selector('removeselect',
+ array('serviceid' => $id, 'displayallowedusers' => 1));
/// Process incoming user assignments to the service
- if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
- $userstoassign = $potentialuserselector->get_selected_users();
- if (!empty($userstoassign)) {
-
- foreach ($userstoassign as $adduser) {
- $serviceuser = new object();
- $serviceuser->externalserviceid = $id;
- $serviceuser->userid = $adduser->id;
- $serviceuser->timecreated = mktime();
- $DB->insert_record('external_services_users', $serviceuser);
- add_to_log(1, 'core', 'assign', $CFG->admin.'/webservice/service_users.php?id='.$id, 'add', '', $adduser->id);
- }
-
- $potentialuserselector->invalidate_selected_users();
- $alloweduserselector->invalidate_selected_users();
- }
+if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
+ $userstoassign = $potentialuserselector->get_selected_users();
+ if (!empty($userstoassign)) {
+ foreach ($userstoassign as $adduser) {
+ $serviceuser = new object();
+ $serviceuser->externalserviceid = $id;
+ $serviceuser->userid = $adduser->id;
+ $webservicemanager->add_ws_authorised_user($serviceuser);
+ add_to_log(1, 'core', 'assign', $CFG->admin . '/webservice/service_users.php?id='
+ . $id, 'add', '', $adduser->id);
}
+ $potentialuserselector->invalidate_selected_users();
+ $alloweduserselector->invalidate_selected_users();
+ }
+}
/// Process removing user assignments to the service
- if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
- $userstoremove = $alloweduserselector->get_selected_users();
- if (!empty($userstoremove)) {
-
- foreach ($userstoremove as $removeuser) {
- $DB->delete_records('external_services_users', array('externalserviceid' => $id, 'userid' => $removeuser->id));
- add_to_log(1, 'core', 'assign', $CFG->admin.'/webservice/service_users.php?id='.$id, 'remove', '', $removeuser->id);
- }
-
- $potentialuserselector->invalidate_selected_users();
- $alloweduserselector->invalidate_selected_users();
- }
+if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
+ $userstoremove = $alloweduserselector->get_selected_users();
+ if (!empty($userstoremove)) {
+ foreach ($userstoremove as $removeuser) {
+ $webservicemanager->remove_ws_authorised_user($removeuser, $id);
+ add_to_log(1, 'core', 'assign', $CFG->admin . '/webservice/service_users.php?id='
+ . $id, 'remove', '', $removeuser->id);
}
+ $potentialuserselector->invalidate_selected_users();
+ $alloweduserselector->invalidate_selected_users();
+ }
+}
/// Print the form.
/// display the UI
-?>
-<form id="assignform" method="post" action="service_users.php?id=<?php echo $id ?>"><div>
- <input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" />
-
- <table summary="" class="roleassigntable generaltable generalbox boxaligncenter" cellspacing="0">
- <tr>
- <td id="existingcell">
- <p><label for="removeselect"><?php print_string('serviceusers', 'webservice'); ?></label></p>
- <?php $alloweduserselector->display() ?>
- </td>
- <td id="buttonscell">
- <div id="addcontrols">
- <input name="add" id="add" type="submit" value="<?php echo $OUTPUT->larrow().' '.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
- </div>
+$renderer = $PAGE->get_renderer('core', 'webservice');
- <div id="removecontrols">
- <input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').' '.$OUTPUT->rarrow(); ?>" title="<?php print_string('remove'); ?>" />
- </div>
- </td>
- <td id="potentialcell">
- <p><label for="addselect"><?php print_string('potusers', 'webservice'); ?></label></p>
- <?php $potentialuserselector->display() ?>
- </td>
- </tr>
- </table>
-</div></form>
-
-<?php
-
-/// save user settings (administrator clicked on update button)
-if (optional_param('updateuser', false, PARAM_BOOL) && confirm_sesskey()) {
- $useridtoupdate = optional_param('userid', false, PARAM_INT);
- $iprestriction = optional_param('iprestriction', '', PARAM_TEXT);
- $serviceuserid = optional_param('serviceuserid', '', PARAM_INT);
- $fromday = optional_param('fromday'.$useridtoupdate, '', PARAM_INT);
- $frommonth = optional_param('frommonth'.$useridtoupdate, '', PARAM_INT);
- $fromyear = optional_param('fromyear'.$useridtoupdate, '', PARAM_INT);
- $addcap = optional_param('addcap', false, PARAM_INT);
- $enablevaliduntil = optional_param('enablevaliduntil', false, PARAM_INT);
- if (!empty($fromday) && !empty($frommonth) && !empty($fromyear)) {
- $validuntil = mktime(23, 59, 59, $frommonth, $fromday, $fromyear);
- } else {
- $validuntil = "";
- }
-
- $serviceuser = new object();
- $serviceuser->id = $serviceuserid;
- if ($enablevaliduntil) {
- $serviceuser->validuntil = $validuntil;
- } else {
- $serviceuser->validuntil = null; //the valid until field is disabled, we reset the value
- }
- $serviceuser->iprestriction = $iprestriction;
- $DB->update_record('external_services_users', $serviceuser);
+echo $OUTPUT->header();
- //TODO: assign capability
-}
+echo $OUTPUT->heading(get_string('selectauthorisedusers', 'webservice'), 3, 'main');
+$selectoroptions = new stdClass();
+$selectoroptions->serviceid = $id;
+$selectoroptions->alloweduserselector = $alloweduserselector;
+$selectoroptions->potentialuserselector = $potentialuserselector;
+echo $renderer->admin_authorised_user_selector($selectoroptions);
//display the list of allowed users with their options (ip/timecreated / validuntil...)
//check that the user has the service required capability (if needed)
-$sql = " SELECT u.id as id, esu.id as serviceuserid, u.email as email, u.firstname as firstname, u.lastname as lastname,
- esu.iprestriction as iprestriction, esu.validuntil as validuntil,
- esu.timecreated as timecreated
- FROM {user} u, {external_services_users} esu
- WHERE username <> 'guest' AND deleted = 0 AND confirmed = 1
- AND esu.userid = u.id
- AND esu.externalserviceid = ?";
-$allowedusers = $DB->get_records_sql($sql, array($id));
+$allowedusers = $webservicemanager->get_ws_authorised_users($id);
if (!empty($allowedusers)) {
- echo $OUTPUT->box_start('generalbox', 'alloweduserlist');
-
- echo "<label><strong>".get_string('serviceuserssettings', 'webservice').":</strong></label>";
- echo "<br/><br/><span style=\"font-size:85%\">"; //reduce font of the user settings
- foreach($allowedusers as $user) {
-
- echo print_collapsible_region_start('', 'usersettings'.$user->id,$user->firstname." ".$user->lastname.", ".$user->email,false,true,true);
-
- //user settings form
- $contents = "<div class=\"fcontainer clearfix\">";
-
- //ip restriction textfield
- $iprestid = 'iprest'.$user->id;
- $contents .= "<div class=\"fitem\"><div class=\"fitemtitle\"><label for=\"$iprestid\">".get_string('iprestriction','webservice')." </label></div><div class=\"felement\">";
- $contents .= '<input type="text" id="'.$iprestid.'" name="iprestriction" style="width: 30em;" value="'.s($user->iprestriction).'" />';
- $contents .= "</div></div>";
- //valid until date selector
- $contents .= "<div class=\"fitem\"><div class=\"fitemtitle\"><label>".get_string('validuntil','webservice')." </label></div><div class=\"felement\">";
- // the following date selector needs to have specific day/month/year field ids because we use javascript (enable/disable).
- $contents .= html_writer::select_time('days', 'fromday'.$user->id, $user->validuntil);
- $contents .= html_writer::select_time('months', 'frommonth'.$user->id, $user->validuntil);
- $contents .= html_writer::select_time('years', 'fromyear'.$user->id, $user->validuntil);;
- $contents .= html_writer::checkbox('enablevaliduntil', 1, !empty($user->validuntil), get_string('enabled', 'webservice'), array('id'=>'enablevaliduntil'.$user->id));
- // TODO: init date selector using standard $PAGE->requires->js_init_call();
-
- $contents .= "</div></div>";
- //TO IMPLEMENT : assign the required capability (if needed)
- $contents .= "<div class=\"fitem\"><div class=\"fitemtitle\"><label>".get_string('addrequiredcapability','webservice')." </label></div><div class=\"felement fcheckbox\">";
- $contents .= html_writer::checkbox('addcap', 1, 'TODO:'.get_string('addrequiredcapability', 'webservice'));
- $contents .= '<div><input type="submit" name="submit" value="'.s(get_string('update')).'" /></div>';
- $contents .= '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
- $contents .= '<input type="hidden" name="id" value="'.$id.'" />';
- $contents .= '<input type="hidden" name="userid" value="'.$user->id.'" />';
- $contents .= '<input type="hidden" name="serviceuserid" value="'.$user->serviceuserid.'" />';
- $contents .= '<input type="hidden" name="updateuser" value="1" />';
- $contents .= "</div>";
-
- echo html_writer::tag('form', array('target'=>'service_users.php', 'method'=>'post', 'id'=>'usersetting'.$user->id), $contents);
-
- echo print_collapsible_region_end(true);
-
-
- }
- echo "</span>";
- echo $OUTPUT->box_end();
+ $renderer = $PAGE->get_renderer('core', 'webservice');
+ echo $OUTPUT->heading(get_string('serviceuserssettings', 'webservice'), 3, 'main');
+ echo $renderer->admin_authorised_user_list($allowedusers, $id);
}
-
echo $OUTPUT->footer();
<?php
+
///////////////////////////////////////////////////////////////////////////
// //
// This file is part of Moodle - http://moodle.org/ //
* @author Jerome Mouneyrac
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
class core_webservice_renderer extends plugin_renderer_base {
+ /**
+ * Display the authorised user selector
+ * @param object $options
+ * @return string html
+ */
+ public function admin_authorised_user_selector(&$options) {
+ global $OUTPUT;
+
+ $formcontent = html_writer::empty_tag('input',
+ array('name' => 'sesskey', 'value' => sesskey(), 'type' => 'hidden'));
+
+ $table = new html_table();
+ $table->size = array('45%', '10%', '45%');
+ $table->attributes['class'] = 'roleassigntable generaltable generalbox boxaligncenter';
+ $table->summary = '';
+ $table->cellspacing = 0;
+ $table->cellpadding = 0;
+
+ //create the add and remove button
+ $addinput = html_writer::empty_tag('input',
+ array('name' => 'add', 'id' => 'add', 'type' => 'submit',
+ 'value' => 'â—€' . ' ' . get_string('add'),
+ 'title' => get_string('add')));
+ $addbutton = html_writer::tag('div', $addinput, array('id' => 'addcontrols'));
+ $removeinput = html_writer::empty_tag('input',
+ array('name' => 'remove', 'id' => 'remove', 'type' => 'submit',
+ 'value' => 'â–¶' . ' ' . get_string('remove'),
+ 'title' => get_string('remove')));
+ $removebutton = html_writer::tag('div', $removeinput, array('id' => 'removecontrols'));
+
+
+ //create the three cells
+ $label = html_writer::tag('label', get_string('serviceusers', 'webservice'),
+ array('for' => 'removeselect'));
+ $label = html_writer::tag('p', $label);
+ $authoriseduserscell = new html_table_cell($label . $options->alloweduserselector->display(true));
+ $authoriseduserscell->id = 'existingcell';
+ $buttonscell = new html_table_cell($addbutton . html_writer::empty_tag('br') . $removebutton);
+ $buttonscell->id = 'buttonscell';
+ $label = html_writer::tag('label', get_string('potusers', 'webservice'),
+ array('for' => 'addselect'));
+ $label = html_writer::tag('p', $label);
+ $otheruserscell = new html_table_cell($label . $options->potentialuserselector->display(true));
+ $otheruserscell->id = 'potentialcell';
+
+ $cells = array($authoriseduserscell, $buttonscell, $otheruserscell);
+ $row = new html_table_row($cells);
+ $table->data[] = $row;
+ $formcontent .= html_writer::table($table);
+
+ $formcontent = html_writer::tag('div', $formcontent);
+
+ $actionurl = new moodle_url('/admin/webservice/service_users.php',
+ array('id' => $options->serviceid));
+ $html = html_writer::tag('form', $formcontent,
+ array('id' => 'assignform', 'action' => $actionurl, 'method' => 'post'));
+ return $html;
+ }
+
+ /**
+ * Display list of authorised user
+ * @param array $users
+ * @return string $html
+ */
+ public function admin_authorised_user_list($users, $serviceid) {
+ global $OUTPUT;
+ $html = $OUTPUT->box_start('generalbox', 'alloweduserlist');
+ foreach ($users as $user) {
+ $modifiedauthoriseduserurl = new moodle_url('/admin/webservice/service_user_settings.php',
+ array('userid' => $user->id, 'serviceid' => $serviceid));
+ $html .= html_writer::tag('a', $user->firstname . " " . $user->lastname . ", " . $user->email,
+ array('href' => $modifiedauthoriseduserurl));
+ $html .= html_writer::empty_tag('br');
+ }
+ $html .= $OUTPUT->box_end();
+ return $html;
+ }
+
/**
* Display Reset token confirmation box
* @param object $token to reset
*/
public function user_reset_token_confirmation($token) {
global $OUTPUT, $CFG;
- $managetokenurl = $CFG->wwwroot."/user/managetoken.php?sesskey=" . sesskey();
- $optionsyes = array('tokenid'=>$token->id, 'action'=>'resetwstoken', 'confirm'=>1, 'sesskey'=>sesskey());
- $optionsno = array('section'=>'webservicetokens', 'sesskey'=>sesskey());
+ $managetokenurl = $CFG->wwwroot . "/user/managetoken.php?sesskey=" . sesskey();
+ $optionsyes = array('tokenid' => $token->id, 'action' => 'resetwstoken', 'confirm' => 1, 'sesskey' => sesskey());
+ $optionsno = array('section' => 'webservicetokens', 'sesskey' => sesskey());
$formcontinue = new single_button(new moodle_url($managetokenurl, $optionsyes), get_string('reset'));
$formcancel = new single_button(new moodle_url($managetokenurl, $optionsno), get_string('cancel'), 'get');
- $html = $OUTPUT->confirm(get_string('resettokenconfirm', 'webservice',
- (object)array('user'=>$token->firstname." ".$token->lastname, 'service'=>$token->name)),
- $formcontinue, $formcancel);
+ $html = $OUTPUT->confirm(get_string('resettokenconfirm', 'webservice',
+ (object) array('user' => $token->firstname . " " . $token->lastname, 'service' => $token->name)),
+ $formcontinue, $formcancel);
return $html;
}
-
-
/**
* Display user tokens with buttons to reset them
* @param object $tokens
$return .= get_string('keyshelp', 'webservice');
$table = new html_table();
- $table->head = array($strtoken, $strservice, $strvaliduntil, $strcreator, $stroperation);
+ $table->head = array($strtoken, $strservice, $strvaliduntil, $strcreator, $stroperation);
$table->align = array('left', 'left', 'left', 'center', 'left', 'center');
$table->width = '100%';
- $table->data = array();
+ $table->data = array();
if (!empty($tokens)) {
foreach ($tokens as $token) {
//TODO: retrieve context
if ($token->creatorid == $userid) {
- $reset = "<a href=\"".$CFG->wwwroot."/user/managetoken.php?sesskey=".sesskey().
- "&action=resetwstoken&tokenid=".$token->id."\">";
- $reset .= get_string('reset')."</a>";
- $creator = $token->firstname." ".$token->lastname;
+ $reset = "<a href=\"" . $CFG->wwwroot . "/user/managetoken.php?sesskey=" . sesskey() .
+ "&action=resetwstoken&tokenid=" . $token->id . "\">";
+ $reset .= get_string('reset') . "</a>";
+ $creator = $token->firstname . " " . $token->lastname;
} else {
//retrive administrator name
- require_once($CFG->dirroot.'/user/lib.php');
+ require_once($CFG->dirroot . '/user/lib.php');
$creators = user_get_users_by_id(array($token->creatorid));
$admincreator = $creators[$token->creatorid];
- $creator = $admincreator->firstname." ".$admincreator->lastname;
+ $creator = $admincreator->firstname . " " . $admincreator->lastname;
$reset = '';
}
- $userprofilurl = new moodle_url('/user/view.php?id='.$token->creatorid);
+ $userprofilurl = new moodle_url('/user/view.php?id=' . $token->creatorid);
$creatoratag = html_writer::start_tag('a', array('href' => $userprofilurl));
$creatoratag .= $creator;
$creatoratag .= html_writer::end_tag('a');
$table->data[] = array($token->token, $token->name, $validuntil, $creatoratag, $reset);
}
$return .= html_writer::table($table);
-
} else {
$return .= get_string('notoken', 'webservice');
}
return $return;
}
-
-
- /**
+ /**
* Return documentation for a ws description object
* ws description object can be 'external_multiple_structure', 'external_single_structure' or 'external_value'
* Example of documentation for moodle_group_create_groups function:
- list of (
- object {
- courseid int //id of course
- name string //multilang compatible name, course unique
- description string //group description text
- enrolmentkey string //group enrol secret phrase
- }
- )
+ list of (
+ object {
+ courseid int //id of course
+ name string //multilang compatible name, course unique
+ description string //group description text
+ enrolmentkey string //group enrol secret phrase
+ }
+ )
* @param object $params a part of parameter/return description
* @return string the html to display
*/
public function detailed_description_html($params) {
- /// retrieve the description of the description object
+ /// retrieve the description of the description object
$paramdesc = "";
if (!empty($params->desc)) {
$paramdesc .= html_writer::start_tag('span', array('style' => "color:#2A33A6"));
if ($params->default === null) {
$params->default = "null";
}
- $required = html_writer::start_tag('b', array()).get_string('default', 'webservice', $params->default).html_writer::end_tag('b');
+ $required = html_writer::start_tag('b', array()) . get_string('default', 'webservice', $params->default) . html_writer::end_tag('b');
}
if ($params->required == VALUE_OPTIONAL) {
- $required = html_writer::start_tag('b', array()).get_string('optional', 'webservice').html_writer::end_tag('b');
+ $required = html_writer::start_tag('b', array()) . get_string('optional', 'webservice') . html_writer::end_tag('b');
}
- $paramdesc .= " ".$required." ";
+ $paramdesc .= " " . $required . " ";
$paramdesc .= html_writer::start_tag('i', array());
$paramdesc .= "//";
$paramdesc .= $params->desc;
$paramdesc .= html_writer::end_tag('i');
-
+
$paramdesc .= html_writer::end_tag('span');
$paramdesc .= html_writer::empty_tag('br', array());
}
- /// description object is a list
+ /// description object is a list
if ($params instanceof external_multiple_structure) {
return $paramdesc . "list of ( " . html_writer::empty_tag('br', array()) . $this->detailed_description_html($params->content) . ")";
} else if ($params instanceof external_single_structure) {
- /// description object is an object
- $singlestructuredesc = $paramdesc."object {". html_writer::empty_tag('br', array());
+ /// description object is an object
+ $singlestructuredesc = $paramdesc . "object {" . html_writer::empty_tag('br', array());
foreach ($params->keys as $attributname => $attribut) {
$singlestructuredesc .= html_writer::start_tag('b', array());
$singlestructuredesc .= $attributname;
$singlestructuredesc .= html_writer::end_tag('b');
- $singlestructuredesc .= " ".$this->detailed_description_html($params->keys[$attributname]);
+ $singlestructuredesc .= " " . $this->detailed_description_html($params->keys[$attributname]);
}
$singlestructuredesc .= "} ";
$singlestructuredesc .= html_writer::empty_tag('br', array());
return $singlestructuredesc;
} else {
- /// description object is a primary type (string, integer)
- switch($params->type) {
+ /// description object is a primary type (string, integer)
+ switch ($params->type) {
case PARAM_BOOL: // 0 or 1 only for now
case PARAM_INT:
$type = 'int';
default:
$type = 'string';
}
- return $type." ".$paramdesc;
+ return $type . " " . $paramdesc;
}
}
EOF;
- /// description object is a list
+ /// description object is a list
if ($returndescription instanceof external_multiple_structure) {
- $return = $indentation."<MULTIPLE>".$brakeline;
+ $return = $indentation . "<MULTIPLE>" . $brakeline;
$return .= $this->description_in_indented_xml_format($returndescription->content, $indentation);
- $return .= $indentation."</MULTIPLE>".$brakeline;
+ $return .= $indentation . "</MULTIPLE>" . $brakeline;
return $return;
} else if ($returndescription instanceof external_single_structure) {
- /// description object is an object
- $singlestructuredesc = $indentation."<SINGLE>".$brakeline;
- $keyindentation = $indentation." ";
+ /// description object is an object
+ $singlestructuredesc = $indentation . "<SINGLE>" . $brakeline;
+ $keyindentation = $indentation . " ";
foreach ($returndescription->keys as $attributname => $attribut) {
- $singlestructuredesc .= $keyindentation."<KEY name=\"".$attributname."\">".$brakeline.
- $this->description_in_indented_xml_format($returndescription->keys[$attributname], $keyindentation).
- $keyindentation."</KEY>".$brakeline;
+ $singlestructuredesc .= $keyindentation . "<KEY name=\"" . $attributname . "\">" . $brakeline .
+ $this->description_in_indented_xml_format($returndescription->keys[$attributname], $keyindentation) .
+ $keyindentation . "</KEY>" . $brakeline;
}
- $singlestructuredesc .= $indentation."</SINGLE>".$brakeline;
+ $singlestructuredesc .= $indentation . "</SINGLE>" . $brakeline;
return $singlestructuredesc;
} else {
- /// description object is a primary type (string, integer)
- switch($returndescription->type) {
+ /// description object is a primary type (string, integer)
+ switch ($returndescription->type) {
case PARAM_BOOL: // 0 or 1 only for now
case PARAM_INT:
$type = 'int';
default:
$type = 'string';
}
- return $indentation."<VALUE>".$type."</VALUE>".$brakeline;
+ return $indentation . "<VALUE>" . $type . "</VALUE>" . $brakeline;
}
}
- /**
+ /**
* Create indented XML-RPC param description
* @param object $paramdescription
* @param string $indentation composed by space only
EOF;
- /// description object is a list
+ /// description object is a list
if ($paramdescription instanceof external_multiple_structure) {
- $return = $brakeline.$indentation."Array ";
+ $return = $brakeline . $indentation . "Array ";
$indentation = $indentation . " ";
- $return .= $brakeline.$indentation."(";
- $return .= $brakeline.$indentation."[0] =>";
+ $return .= $brakeline . $indentation . "(";
+ $return .= $brakeline . $indentation . "[0] =>";
$return .= $this->xmlrpc_param_description_html($paramdescription->content, $indentation);
- $return .= $brakeline.$indentation.")";
+ $return .= $brakeline . $indentation . ")";
return $return;
} else if ($paramdescription instanceof external_single_structure) {
- /// description object is an object
- $singlestructuredesc = $brakeline.$indentation."Array ";
- $keyindentation = $indentation." ";
- $singlestructuredesc .= $brakeline.$keyindentation."(";
+ /// description object is an object
+ $singlestructuredesc = $brakeline . $indentation . "Array ";
+ $keyindentation = $indentation . " ";
+ $singlestructuredesc .= $brakeline . $keyindentation . "(";
foreach ($paramdescription->keys as $attributname => $attribut) {
- $singlestructuredesc .= $brakeline.$keyindentation."[".$attributname."] =>".
- $this->xmlrpc_param_description_html($paramdescription->keys[$attributname], $keyindentation).
+ $singlestructuredesc .= $brakeline . $keyindentation . "[" . $attributname . "] =>" .
+ $this->xmlrpc_param_description_html($paramdescription->keys[$attributname], $keyindentation) .
$keyindentation;
}
- $singlestructuredesc .= $brakeline.$keyindentation.")";
+ $singlestructuredesc .= $brakeline . $keyindentation . ")";
return $singlestructuredesc;
} else {
- /// description object is a primary type (string, integer)
- switch($paramdescription->type) {
+ /// description object is a primary type (string, integer)
+ switch ($paramdescription->type) {
case PARAM_BOOL: // 0 or 1 only for now
case PARAM_INT:
$type = 'int';
default:
$type = 'string';
}
- return " ".$type;
+ return " " . $type;
}
}
*/
public function colored_box_with_pre_tag($title, $content, $rgb = 'FEEBE5') {
$coloredbox = html_writer::start_tag('ins', array()); //TODO: this tag removes xhtml strict error but cause warning
- $coloredbox .= html_writer::start_tag('div', array('style' => "border:solid 1px #DEDEDE;background:#".$rgb.";color:#222222;padding:4px;"));
+ $coloredbox .= html_writer::start_tag('div', array('style' => "border:solid 1px #DEDEDE;background:#" . $rgb . ";color:#222222;padding:4px;"));
$coloredbox .= html_writer::start_tag('pre', array());
$coloredbox .= html_writer::start_tag('b', array());
$coloredbox .= $title;
$coloredbox .= html_writer::end_tag('b', array());
$coloredbox .= html_writer::empty_tag('br', array());
- $coloredbox .= "\n".$content."\n";
+ $coloredbox .= "\n" . $content . "\n";
$coloredbox .= html_writer::end_tag('pre', array());
$coloredbox .= html_writer::end_tag('div', array());
$coloredbox .= html_writer::end_tag('ins', array());
return $coloredbox;
}
-
- /**
+ /**
* Return indented REST param description
* @param object $paramdescription
* @param string $indentation composed by space only
EOF;
- /// description object is a list
+ /// description object is a list
if ($paramdescription instanceof external_multiple_structure) {
- $paramstring = $paramstring.'[0]';
+ $paramstring = $paramstring . '[0]';
$return = $this->rest_param_description_html($paramdescription->content, $paramstring);
return $return;
} else if ($paramdescription instanceof external_single_structure) {
- /// description object is an object
+ /// description object is an object
$singlestructuredesc = "";
$initialparamstring = $paramstring;
foreach ($paramdescription->keys as $attributname => $attribut) {
- $paramstring = $initialparamstring.'['.$attributname.']';
+ $paramstring = $initialparamstring . '[' . $attributname . ']';
$singlestructuredesc .= $this->rest_param_description_html($paramdescription->keys[$attributname], $paramstring);
}
return $singlestructuredesc;
} else {
- /// description object is a primary type (string, integer)
- $paramstring = $paramstring.'=';
- switch($paramdescription->type) {
+ /// description object is a primary type (string, integer)
+ $paramstring = $paramstring . '=';
+ switch ($paramdescription->type) {
case PARAM_BOOL: // 0 or 1 only for now
case PARAM_INT:
$type = 'int';
default:
$type = 'string';
}
- return $paramstring." ".$type.$brakeline;
+ return $paramstring . " " . $type . $brakeline;
}
}
-
/**
* This display all the documentation
* @param array $functions contains all decription objects
EOF;
- /// Some general information
+ /// Some general information
$documentationhtml = html_writer::start_tag('table', array('style' => "margin-left:auto; margin-right:auto;"));
$documentationhtml .= html_writer::start_tag('tr', array());
$documentationhtml .= html_writer::start_tag('td', array());
$documentationhtml .= get_string('wsdocumentationintro', 'webservice', $authparams['wsusername']);
- $documentationhtml .= $br.$br;
-
+ $documentationhtml .= $br . $br;
+
- /// Print button
+ /// Print button
$authparams['print'] = true;
//$parameters = array ('token' => $token, 'wsusername' => $username, 'wspassword' => $password, 'print' => true);
$url = new moodle_url('/webservice/wsdoc.php', $authparams); // Required
- $documentationhtml .= $OUTPUT->single_button($url, get_string('print','webservice'));
+ $documentationhtml .= $OUTPUT->single_button($url, get_string('print', 'webservice'));
$documentationhtml .= $br;
-
-
- /// each functions will be displayed into a collapsible region (opened if printableformat = true)
+
+
+ /// each functions will be displayed into a collapsible region (opened if printableformat = true)
foreach ($functions as $functionname => $description) {
if (empty($printableformat)) {
$documentationhtml .= print_collapsible_region_start('',
- 'aera_'.$functionname,
- html_writer::start_tag('strong', array()).$functionname.html_writer::end_tag('strong'),
- false,
- !$printableformat,
- true);
+ 'aera_' . $functionname,
+ html_writer::start_tag('strong', array()) . $functionname . html_writer::end_tag('strong'),
+ false,
+ !$printableformat,
+ true);
} else {
$documentationhtml .= html_writer::tag('strong', $functionname);
$documentationhtml .= $br;
}
- /// function global description
+ /// function global description
$documentationhtml .= $br;
$documentationhtml .= html_writer::start_tag('div', array('style' => 'border:solid 1px #DEDEDE;background:#E2E0E0;color:#222222;padding:4px;'));
$documentationhtml .= $description->description;
$documentationhtml .= html_writer::end_tag('div');
- $documentationhtml .= $br.$br;
+ $documentationhtml .= $br . $br;
- /// function arguments documentation
+ /// function arguments documentation
$documentationhtml .= html_writer::start_tag('span', array('style' => 'color:#EA33A6'));
$documentationhtml .= get_string('arguments', 'webservice');
$documentationhtml .= html_writer::end_tag('span');
$documentationhtml .= $br;
foreach ($description->parameters_desc->keys as $paramname => $paramdesc) {
- /// a argument documentation
+ /// a argument documentation
$documentationhtml .= html_writer::start_tag('span', array('style' => 'font-size:80%'));
-
+
if ($paramdesc->required == VALUE_REQUIRED) {
- $required = get_string('required', 'webservice');
+ $required = get_string('required', 'webservice');
}
if ($paramdesc->required == VALUE_DEFAULT) {
if ($paramdesc->default === null) {
$required = get_string('default', 'webservice', $default);
}
if ($paramdesc->required == VALUE_OPTIONAL) {
- $required = get_string('optional', 'webservice');
+ $required = get_string('optional', 'webservice');
}
-
+
$documentationhtml .= html_writer::start_tag('b', array());
$documentationhtml .= $paramname;
$documentationhtml .= html_writer::end_tag('b');
- $documentationhtml .= " (" .$required. ")"; // argument is required or optional ?
+ $documentationhtml .= " (" . $required . ")"; // argument is required or optional ?
$documentationhtml .= $br;
- $documentationhtml .= " ".$paramdesc->desc; // argument description
- $documentationhtml .= $br.$br;
+ $documentationhtml .= " " . $paramdesc->desc; // argument description
+ $documentationhtml .= $br . $br;
///general structure of the argument
- $documentationhtml .= $this->colored_box_with_pre_tag(get_string('generalstructure', 'webservice'),
- $this->detailed_description_html($paramdesc),
- 'FFF1BC');
+ $documentationhtml .= $this->colored_box_with_pre_tag(get_string('generalstructure', 'webservice'),
+ $this->detailed_description_html($paramdesc),
+ 'FFF1BC');
///xml-rpc structure of the argument in PHP format
if (!empty($activatedprotocol['xmlrpc'])) {
- $documentationhtml .= $this->colored_box_with_pre_tag(get_string('phpparam', 'webservice'),
- htmlentities('['.$paramname.'] =>'.$this->xmlrpc_param_description_html($paramdesc)),
- 'DFEEE7');
+ $documentationhtml .= $this->colored_box_with_pre_tag(get_string('phpparam', 'webservice'),
+ htmlentities('[' . $paramname . '] =>' . $this->xmlrpc_param_description_html($paramdesc)),
+ 'DFEEE7');
}
///POST format for the REST protocol for the argument
if (!empty($activatedprotocol['rest'])) {
- $documentationhtml .= $this->colored_box_with_pre_tag(get_string('restparam', 'webservice'),
- htmlentities($this->rest_param_description_html($paramdesc,$paramname)),
- 'FEEBE5');
+ $documentationhtml .= $this->colored_box_with_pre_tag(get_string('restparam', 'webservice'),
+ htmlentities($this->rest_param_description_html($paramdesc, $paramname)),
+ 'FEEBE5');
}
$documentationhtml .= html_writer::end_tag('span');
}
- $documentationhtml .= $br.$br;
+ $documentationhtml .= $br . $br;
- /// function response documentation
+ /// function response documentation
$documentationhtml .= html_writer::start_tag('span', array('style' => 'color:#EA33A6'));
$documentationhtml .= get_string('response', 'webservice');
$documentationhtml .= html_writer::end_tag('span');
$documentationhtml .= html_writer::start_tag('span', array('style' => 'font-size:80%'));
if (!empty($description->returns_desc->desc)) {
$documentationhtml .= $description->returns_desc->desc;
- $documentationhtml .= $br.$br;
+ $documentationhtml .= $br . $br;
}
if (!empty($description->returns_desc)) {
///general structure of the response
- $documentationhtml .= $this->colored_box_with_pre_tag(get_string('generalstructure', 'webservice'),
- $this->detailed_description_html($description->returns_desc),
- 'FFF1BC');
+ $documentationhtml .= $this->colored_box_with_pre_tag(get_string('generalstructure', 'webservice'),
+ $this->detailed_description_html($description->returns_desc),
+ 'FFF1BC');
///xml-rpc structure of the response in PHP format
if (!empty($activatedprotocol['xmlrpc'])) {
- $documentationhtml .= $this->colored_box_with_pre_tag(get_string('phpresponse', 'webservice'),
- htmlentities($this->xmlrpc_param_description_html($description->returns_desc)),
- 'DFEEE7');
+ $documentationhtml .= $this->colored_box_with_pre_tag(get_string('phpresponse', 'webservice'),
+ htmlentities($this->xmlrpc_param_description_html($description->returns_desc)),
+ 'DFEEE7');
}
///XML response for the REST protocol
if (!empty($activatedprotocol['rest'])) {
- $restresponse = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>".$brakeline."<RESPONSE>".$brakeline;
+ $restresponse = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" . $brakeline . "<RESPONSE>" . $brakeline;
$restresponse .= $this->description_in_indented_xml_format($description->returns_desc);
- $restresponse .="</RESPONSE>".$brakeline;
- $documentationhtml .= $this->colored_box_with_pre_tag(get_string('restcode', 'webservice'),
- htmlentities($restresponse),
- 'FEEBE5');
+ $restresponse .="</RESPONSE>" . $brakeline;
+ $documentationhtml .= $this->colored_box_with_pre_tag(get_string('restcode', 'webservice'),
+ htmlentities($restresponse),
+ 'FEEBE5');
}
}
$documentationhtml .= html_writer::end_tag('span');
- $documentationhtml .= $br.$br;
+ $documentationhtml .= $br . $br;
- /// function errors documentation for REST protocol
+ /// function errors documentation for REST protocol
if (!empty($activatedprotocol['rest'])) {
$documentationhtml .= html_writer::start_tag('span', array('style' => 'color:#EA33A6'));
$documentationhtml .= get_string('errorcodes', 'webservice');
$documentationhtml .= html_writer::end_tag('span');
- $documentationhtml .= $br.$br;
+ $documentationhtml .= $br . $br;
$documentationhtml .= html_writer::start_tag('span', array('style' => 'font-size:80%'));
$errormessage = get_string('invalidparameter', 'debug');
- $restexceptiontext =<<<EOF
+ $restexceptiontext = <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<EXCEPTION class="invalid_parameter_exception">
<MESSAGE>{$errormessage}</MESSAGE>
<DEBUGINFO></DEBUGINFO>
</EXCEPTION>
EOF;
- $documentationhtml .= $this->colored_box_with_pre_tag(get_string('restexception', 'webservice'),
- htmlentities($restexceptiontext),
- 'FEEBE5');
+ $documentationhtml .= $this->colored_box_with_pre_tag(get_string('restexception', 'webservice'),
+ htmlentities($restexceptiontext),
+ 'FEEBE5');
- $documentationhtml .= html_writer::end_tag('span');
+ $documentationhtml .= html_writer::end_tag('span');
}
- $documentationhtml .= $br.$br;
+ $documentationhtml .= $br . $br;
if (empty($printableformat)) {
$documentationhtml .= print_collapsible_region_end(true);
}
}
- /// close the table and return the documentation
+ /// close the table and return the documentation
$documentationhtml .= html_writer::end_tag('td');
$documentationhtml .= html_writer::end_tag('tr');
$documentationhtml .= html_writer::end_tag('table');
return $documentationhtml;
-
}
/**
// $htmlloginpage .= get_string('error','webservice',$errormessage);
// $htmlloginpage .= html_writer::empty_tag('br', array());
// $htmlloginpage .= html_writer::empty_tag('br', array());
-
//login form - we cannot use moodle form as we don't have sessionkey
$target = new moodle_url('/webservice/wsdoc.php', array()); // Required
$contents = get_string('entertoken', 'webservice');
- $contents .= $br.$br;
- $contents .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>'token', 'style'=>'width: 30em;'));
-
- $contents .= $br.$br;
+ $contents .= $br . $br;
+ $contents .= html_writer::empty_tag('input', array('type' => 'text', 'name' => 'token', 'style' => 'width: 30em;'));
+
+ $contents .= $br . $br;
$contents .= get_string('wsdocumentationlogin', 'webservice');
- $contents .= $br.$br;
- $contents .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>'wsusername', 'style'=>'width: 30em;', 'value'=>get_string('wsusername', 'webservice')));
- $contents .= $br.$br;
- $contents .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>'wspassword', 'style'=>'width: 30em;', 'value'=>get_string('wspassword', 'webservice')));
- $contents .= $br.$br;
- $contents .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'submit', 'value'=>get_string('wsdocumentation', 'webservice')));
-
- $htmlloginpage .= html_writer::tag('form', "<div>$contents</div>", array('method'=>'post', 'target'=>$target));
+ $contents .= $br . $br;
+ $contents .= html_writer::empty_tag('input', array('type' => 'text', 'name' => 'wsusername', 'style' => 'width: 30em;', 'value' => get_string('wsusername', 'webservice')));
+ $contents .= $br . $br;
+ $contents .= html_writer::empty_tag('input', array('type' => 'text', 'name' => 'wspassword', 'style' => 'width: 30em;', 'value' => get_string('wspassword', 'webservice')));
+ $contents .= $br . $br;
+ $contents .= html_writer::empty_tag('input', array('type' => 'submit', 'name' => 'submit', 'value' => get_string('wsdocumentation', 'webservice')));
+
+ $htmlloginpage .= html_writer::tag('form', "<div>$contents</div>", array('method' => 'post', 'target' => $target));
$htmlloginpage .= html_writer::end_tag('td');
$htmlloginpage .= html_writer::end_tag('tr');
$htmlloginpage .= html_writer::end_tag('table');
return $htmlloginpage;
-
}
+
}