2 /***************************************
3 example of a MoodleWS client in PHP5.
4 this demo code is meant to be run as it
5 from the directory $CFG->wwwroot/wspp/clients.
7 To use this code from another machine you
8 MUST run on THAT machine the supplied utility script
9 wsdl2php.php against your Moodle server
10 to generate the MoodleWs class
11 and all support classes for returned datatypes.
12 eg: php wsdl2php.php http://youmoodle/wspp/wsdl_pp.php.
15 Running that utility several times is harmless.
16 If you modify server code and wsdl to add new remote calls
17 you MUST rerun the wsdl2php utilty to keep your clients in sync.
20 Don't forget to adjust the paths to required files
21 **********************************************/
23 ini_set('soap.wsdl_cache_enabled', '0'); // Set to '0' for debugging.
26 require("MoodleWS.php");
28 $moodle= new MoodleWS();
30 heading ("login IN ");
31 $lr= $moodle->login(LOGIN,PASSWORD);
37 print_r_pre($moodle->get_last_changes($lr->client,$lr->sessionkey,2,'id',5));
40 heading ("get courses by category 2");
42 print_r_pre($moodle->get_courses_bycategory($lr->client,$lr->sessionkey,2));
46 heading ("get roles");
48 print_r_pre($moodle->get_roles($lr->client,$lr->sessionkey));
51 heading ("get categories");
53 print_r_pre($moodle->get_categories($lr->client,$lr->sessionkey));
56 heading ("get my courses (as current user)");
58 print_r_pre($moodle->get_my_courses($lr->client,$lr->sessionkey));
60 heading ("get my courses (guest)");
62 print_r_pre($moodle->get_my_courses($lr->client,$lr->sessionkey,1));
65 heading ("get users (ppollet,pguy,toto)");
67 print_r_pre($moodle->get_users($lr->client,$lr->sessionkey,array('ppollet','pguy','toto'),'username'));
71 heading ("get courses ('C2I_101','1PC_PASSINFO','unknown']");
73 //TODO retourne le cours 0 si 'idnumber' est absent
75 print_r_pre($moodle->get_courses($lr->client,$lr->sessionkey,array('C2I_101','1PC_PASSINFO','unknown'),'idnumber'));
77 heading ("get course C2I_101");
79 print_r_pre($moodle->get_course($lr->client,$lr->sessionkey,'C2I_101'));
81 heading ("get course by id 2 ");
83 print_r_pre($moodle->get_course_byid($lr->client,$lr->sessionkey,2));
85 heading ("get course by id -1 unknown ");
87 print_r_pre($moodle->get_course_byid($lr->client,$lr->sessionkey,-1));
91 heading ("get user astrid");
93 print_r_pre($moodle->get_user($lr->client,$lr->sessionkey,'astrid','username'));
97 heading ("get users by course id=2 role =0, any ");
99 $myc=$moodle->get_users_bycourse($lr->client,$lr->sessionkey,2,'id',0);
101 print (count($myc->users));
102 print(" users found <br />\n");
104 heading ("get users by course id=2 role =3, teachers");
106 $myc=$moodle->get_users_bycourse($lr->client,$lr->sessionkey,2,'id',3);
108 print(count($myc->users));
109 print(" users found <br />\n");
112 heading ("get users by course id=2 role =5, students");
114 $myc=$moodle->get_users_bycourse($lr->client,$lr->sessionkey,2,'id',5);
116 print(count($myc->users));
117 print(" users found <br />\n");
119 heading ("get user by name pguy");
122 print_r_pre($moodle->get_user_byusername($lr->client,$lr->sessionkey,'pguy'));
124 heading ("get user by id 77");
126 print_r_pre($moodle->get_user_byid($lr->client,$lr->sessionkey,77));
128 heading ("get user by id -1 (unknown)");
130 print_r_pre($moodle->get_user_byid($lr->client,$lr->sessionkey,-1));
132 heading ("get teachers by course id =38 (unknown)");
134 print_r_pre($moodle->get_teachers($lr->client,$lr->sessionkey,38,'id'));
137 print_r_pre($moodle->get_activities($lr->client,$lr->sessionkey,"ppollet","username",2,"id",10));
140 print_r_pre($moodle->get_activities($lr->client,$lr->sessionkey,"ppollet","username",'','',10));
142 heading ("logout and bye");
145 $moodle->logout($lr->client,$lr->sessionkey);
148 function heading ($msg) {
149 print "<h2>$msg</h2>\n";
152 function print_r_pre($var) {