]> git.mjollnir.org Git - moodle.git/commitdiff
uploading get_group (by id) function
authorpigui <pigui>
Tue, 3 Feb 2009 12:40:44 +0000 (12:40 +0000)
committerpigui <pigui>
Tue, 3 Feb 2009 12:40:44 +0000 (12:40 +0000)
MDL-12886

group/external.php
webservice/rest/testclient/getgroup.php [new file with mode: 0644]

index 58590f1a069db2b488b8150239d546dd28114ebf..992e91b874eb7e31bed8f7806d5ae425ba7012aa 100644 (file)
@@ -10,6 +10,8 @@
 
 require_once(dirname(dirname(__FILE__)) . '/lib/moodleexternal.php');
 require_once(dirname(dirname(__FILE__)) . '/group/lib.php');
+require_once(dirname(dirname(__FILE__)) . '/lib/grouplib.php');
+
 
 /**
  * Group external api class
@@ -29,6 +31,11 @@ final class group_external extends moodle_external {
                                                             'optionalparams' => array( ),
                                                             'return' => array('groupid' => PARAM_INT));
 
+          $this->descriptions['tmp_get_group']     = array( 'params' => array('groupid'=> PARAM_INT),
+                                                            'optionalparams' => array( ),
+                                                            'return' => array('group' => array('id' => PARAM_RAW, 'courseid' => PARAM_RAW,
+                                                                                                                                               'name' => PARAM_RAW, 'enrolmentkey' => PARAM_RAW)));
+
           $this->descriptions['tmp_add_groupmember']   = array( 'params' => array('groupid'=> PARAM_INT, 'userid'=> PARAM_INT),
                                                             'optionalparams' => array( ),
                                                             'return' => array('result' => PARAM_BOOL));
@@ -69,6 +76,21 @@ final class group_external extends moodle_external {
             throw new moodle_exception('wscouldnotaddgroupmember');
         }
        }
+
+       static function tmp_get_group($params){
+
+                       // @TODO: any capability to check?
+                       $group = groups_get_group($params['groupid']);
+
+                       $ret = new StdClass();
+                       $ret->id = $group->id;
+                       $ret->courseid = $group->courseid;
+                       $ret->name = $group->name;
+                       $ret->enrolmentkey = $group->enrolmentkey;
+
+                       return $ret;
+
+       }
 }
 
 ?>
diff --git a/webservice/rest/testclient/getgroup.php b/webservice/rest/testclient/getgroup.php
new file mode 100644 (file)
index 0000000..77819a8
--- /dev/null
@@ -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 a user");
+?>
+
+<form action="getgroup.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="Find 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_get_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->group);
+
+    show_xml ($out);
+} else {
+    echo "<p>Fill the form first</p>";
+}
+
+end_interface();
+
+?>