Permalink
Browse files

commiting delete group function

MDL-12886
  • Loading branch information...
pigui
pigui committed Feb 3, 2009
1 parent 8011f73 commit bec18780213059d6b7b73ec79b6efdfa47ed1353
Showing with 83 additions and 1 deletion.
  1. +17 −0 group/external.php
  2. +65 −0 webservice/rest/testclient/deletegroup.php
  3. +1 −1 webservice/rest/testclient/getgroup.php
View
@@ -35,6 +35,9 @@ function __construct () {
'optionalparams' => array( ),
'return' => array('group' => array('id' => PARAM_RAW, 'courseid' => PARAM_RAW,
'name' => PARAM_RAW, 'enrolmentkey' => PARAM_RAW)));
+ $this->descriptions['tmp_delete_group'] = array( 'params' => array('groupid'=> PARAM_INT),
+ 'optionalparams' => array( ),
+ 'return' => array('result' => PARAM_BOOL));
$this->descriptions['tmp_add_groupmember'] = array( 'params' => array('groupid'=> PARAM_INT, 'userid'=> PARAM_INT),
'optionalparams' => array( ),
@@ -90,6 +93,20 @@ static function tmp_get_group($params){
return $ret;
+ }
+
+ static function tmp_delete_group($params){
+
+ if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_SYSTEM))) {
+
+ // @TODO groups_add_member() does not check userid
+ return groups_delete_group($params['groupid']);
+ }
+ else {
+ throw new moodle_exception('wscouldnotdeletegroup');
+ }
+
+
}
}
@@ -0,0 +1,65 @@
+<?php
+/**
+ * Created on 10/17/2008
+ *
+ * Rest Test Client
+ *
+ * @author David Castro Garcia
+ * @author Ferran Recio Calderó
+ * @author Jordi Piguillem
+ */
+
+require_once ('config_rest.php');
+
+$params = array('groupid');
+
+foreach ($params as $param) {
+ $$param = (isset($_POST[$param]))?$_POST[$param]:'';
+}
+
+start_interface("Delete group");
+?>
+
+<form action="deletegroup.php" method="post">
+<table border="0">
+ <tr><td>Group id: </td><td><input type="text" name="groupid" value="<?php echo $groupid; ?>"/></td></tr>
+ <tr><td></td><td><input type="submit" value="Delete Group"></td></tr>
+</table>
+</form>
+
+<?php
+
+if ($groupid) {
+
+ //we are asking for a token
+ $connectiondata['username'] = 'wsuser';
+ $connectiondata['password'] = 'wspassword';
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $CFG->serverurl.'/user/tmp_get_token');
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, format_postdata($connectiondata));
+ $token = curl_exec($ch);
+ $data['token'] = $token;
+
+ $data['groupid'] = $groupid;
+
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $CFG->serverurl.'/group/tmp_delete_group');
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, format_postdata($data));
+ $out = curl_exec($ch);
+
+ $res = basicxml_xml_to_object($out);
+
+ show_object($res);
+
+ show_xml ($out);
+} else {
+ echo "<p>Fill the form first</p>";
+}
+
+end_interface();
+
+?>
@@ -17,7 +17,7 @@
$$param = (isset($_POST[$param]))?$_POST[$param]:'';
}
-start_interface("Delete a user");
+start_interface("Get Group");
?>
<form action="getgroup.php" method="post">

0 comments on commit bec1878

Please sign in to comment.