3 require_once($CFG->libdir
.'/formslib.php');
6 class webservice_test_client_form
extends moodleform
{
7 public function definition() {
10 $mform = $this->_form
;
11 list($functions, $protocols) = $this->_customdata
;
13 $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
15 $authmethod = array('simple' => 'simple', 'token' => 'token');
16 $mform->addElement('select', 'authmethod', get_string('authmethod', 'webservice'), $authmethod);
17 $mform->setType('simple', PARAM_ALPHA
);
19 $mform->addElement('select', 'protocol', get_string('protocol', 'webservice'), $protocols);
20 $mform->setType('protocol', PARAM_ALPHA
);
22 $mform->addElement('select', 'function', get_string('function', 'webservice'), $functions);
23 $mform->setType('function', PARAM_PLUGIN
);
25 $this->add_action_buttons(false, get_string('select'));
29 // === Test client forms ===
31 class moodle_user_create_users_form
extends moodleform
{
32 public function definition() {
35 $mform = $this->_form
;
38 $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
40 //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
41 $data = $this->_customdata
;
42 if ($data['authmethod'] == 'simple') {
43 $mform->addElement('text', 'wsusername', 'wsusername');
44 $mform->setType('wsusername', PARAM_USERNAME
);
45 $mform->addElement('text', 'wspassword', 'wspassword');
46 $mform->setType('wspassword', PARAM_RAW
);
47 } else if ($data['authmethod'] == 'token') {
48 $mform->addElement('text', 'token', 'token');
49 $mform->setType('token', PARAM_RAW_TRIMMED
);
52 $mform->addElement('hidden', 'authmethod', $data['authmethod']);
53 $mform->setType('authmethod', PARAM_SAFEDIR
);
55 /// specific to the create users function
56 $mform->addElement('text', 'username', 'username');
57 $mform->setType('username', PARAM_USERNAME
);
58 $mform->addElement('text', 'password', 'password');
59 $mform->setType('password', PARAM_RAW
);
60 $mform->addElement('text', 'firstname', 'firstname');
61 $mform->setType('firstname', PARAM_RAW
);
62 $mform->addElement('text', 'lastname', 'lastname');
63 $mform->setType('lastname', PARAM_RAW
);
64 $mform->addElement('text', 'email', 'email');
65 $mform->setType('email', PARAM_EMAIL
);
67 $mform->addElement('text', 'customfieldtype', 'customfieldtype');
68 $mform->setType('customfieldtype', PARAM_RAW
);
69 $mform->addElement('text', 'customfieldvalue', 'customfieldvalue');
70 $mform->setType('customfieldvalue', PARAM_RAW
);
72 $mform->addElement('hidden', 'function');
73 $mform->setType('function', PARAM_PLUGIN
);
75 $mform->addElement('hidden', 'protocol');
76 $mform->setType('protocol', PARAM_ALPHA
);
80 $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
82 $this->add_action_buttons(true, get_string('execute', 'webservice'));
85 public function get_params() {
86 if (!$data = $this->get_data()) {
91 if (!empty($data->customfieldtype
)) {
92 $data->customfields
= array(array('type' => $data->customfieldtype
, 'value' => $data->customfieldvalue
));
95 // remove unused from form data
96 unset($data->submitbutton
);
97 unset($data->protocol
);
98 unset($data->function);
99 unset($data->wsusername
);
100 unset($data->wspassword
);
102 unset($data->authmethod
);
103 unset($data->customfieldtype
);
104 unset($data->customfieldvalue
);
107 $params['users'] = array();
108 $params['users'][] = (array)$data;
115 class moodle_user_update_users_form
extends moodleform
{
116 public function definition() {
119 $mform = $this->_form
;
122 $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
124 //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
125 $data = $this->_customdata
;
126 if ($data['authmethod'] == 'simple') {
127 $mform->addElement('text', 'wsusername', 'wsusername');
128 $mform->setType('wsusername', PARAM_USERNAME
);
129 $mform->addElement('text', 'wspassword', 'wspassword');
130 $mform->setType('wspassword', PARAM_RAW
);
131 } else if ($data['authmethod'] == 'token') {
132 $mform->addElement('text', 'token', 'token');
133 $mform->setType('token', PARAM_RAW_TRIMMED
);
136 $mform->addElement('hidden', 'authmethod', $data['authmethod']);
137 $mform->setType('authmethod', PARAM_ALPHA
);
139 /// specific to the create users function
140 $mform->addElement('text', 'id', 'id');
141 $mform->addRule('id', get_string('required'), 'required', null, 'client');
142 $mform->setType('id', PARAM_INT
);
143 $mform->addElement('text', 'username', 'username');
144 $mform->setType('username', PARAM_USERNAME
);
145 $mform->addElement('text', 'password', 'password');
146 $mform->setType('password', PARAM_RAW
);
147 $mform->addElement('text', 'firstname', 'firstname');
148 $mform->setType('firstname', PARAM_RAW
);
149 $mform->addElement('text', 'lastname', 'lastname');
150 $mform->setType('lastname', PARAM_RAW
);
151 $mform->addElement('text', 'email', 'email');
152 $mform->setType('email', PARAM_EMAIL
);
155 $mform->addElement('text', 'customfieldtype', 'customfieldtype');
156 $mform->setType('customfieldtype', PARAM_RAW
);
157 $mform->addElement('text', 'customfieldvalue', 'customfieldvalue');
158 $mform->setType('customfieldvalue', PARAM_RAW
);
160 $mform->addElement('hidden', 'function');
161 $mform->setType('function', PARAM_PLUGIN
);
163 $mform->addElement('hidden', 'protocol');
164 $mform->setType('protocol', PARAM_ALPHA
);
168 $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
170 $this->add_action_buttons(true, get_string('execute', 'webservice'));
173 public function get_params() {
174 if (!$data = $this->get_data()) {
179 if (!empty($data->customfieldtype
)) {
180 $data->customfields
= array(array('type' => $data->customfieldtype
, 'value' => $data->customfieldvalue
));
183 // remove unused from form data
184 unset($data->submitbutton
);
185 unset($data->protocol
);
186 unset($data->function);
187 unset($data->wsusername
);
188 unset($data->wspassword
);
190 unset($data->authmethod
);
191 unset($data->customfieldtype
);
192 unset($data->customfieldvalue
);
194 foreach($data as $key => $value) {
196 unset($data->{$key});
201 $params['users'] = array();
202 $params['users'][] = (array)$data;
209 class moodle_user_delete_users_form
extends moodleform
{
210 public function definition() {
213 $mform = $this->_form
;
216 $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
218 //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
219 $data = $this->_customdata
;
220 if ($data['authmethod'] == 'simple') {
221 $mform->addElement('text', 'wsusername', 'wsusername');
222 $mform->setType('wsusername', PARAM_USERNAME
);
223 $mform->addElement('text', 'wspassword', 'wspassword');
224 $mform->setType('wspassword', PARAM_RAW
);
225 } else if ($data['authmethod'] == 'token') {
226 $mform->addElement('text', 'token', 'token');
227 $mform->setType('token', PARAM_RAW_TRIMMED
);
230 $mform->addElement('hidden', 'authmethod', $data['authmethod']);
231 $mform->setType('authmethod', PARAM_ALPHA
);
233 /// beginning of specific code to the create users function
234 $mform->addElement('text', 'userids[0]', 'userids[0]');
235 $mform->addElement('text', 'userids[1]', 'userids[1]');
236 $mform->addElement('text', 'userids[2]', 'userids[2]');
237 $mform->addElement('text', 'userids[3]', 'userids[3]');
238 $mform->setType('userids', PARAM_INT
);
239 /// end of specific code to the create users function
241 $mform->addElement('hidden', 'function');
242 $mform->setType('function', PARAM_PLUGIN
);
244 $mform->addElement('hidden', 'protocol');
245 $mform->setType('protocol', PARAM_ALPHA
);
247 $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
249 $this->add_action_buttons(true, get_string('execute', 'webservice'));
252 public function get_params() {
253 if (!$data = $this->get_data()) {
256 // remove unused from form data
257 unset($data->submitbutton
);
258 unset($data->protocol
);
259 unset($data->function);
260 unset($data->wsusername
);
261 unset($data->wspassword
);
263 unset($data->authmethod
);
265 /// beginning of specific code to the create users form
267 $params['userids'] = array();
268 for ($i=0; $i<10; $i++
) {
269 if (empty($data->userids
[$i])) {
272 $params['userids'][] = $data->userids
[$i];
274 /// end of specific code to the create users function
281 class moodle_user_get_users_by_id_form
extends moodleform
{
282 public function definition() {
285 $mform = $this->_form
;
288 $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
290 //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
291 $data = $this->_customdata
;
292 if ($data['authmethod'] == 'simple') {
293 $mform->addElement('text', 'wsusername', 'wsusername');
294 $mform->setType('wsusername', PARAM_USERNAME
);
295 $mform->addElement('text', 'wspassword', 'wspassword');
296 $mform->setType('wspassword', PARAM_RAW
);
297 } else if ($data['authmethod'] == 'token') {
298 $mform->addElement('text', 'token', 'token');
299 $mform->setType('token', PARAM_RAW_TRIMMED
);
302 $mform->addElement('hidden', 'authmethod', $data['authmethod']);
303 $mform->setType('authmethod', PARAM_ALPHA
);
305 /// beginning of specific code to the create users function
306 $mform->addElement('text', 'userids[0]', 'userids[0]');
307 $mform->addElement('text', 'userids[1]', 'userids[1]');
308 $mform->addElement('text', 'userids[2]', 'userids[2]');
309 $mform->addElement('text', 'userids[3]', 'userids[3]');
310 $mform->setType('userids', PARAM_INT
);
311 /// end of specific code to the create users function
313 $mform->addElement('hidden', 'function');
314 $mform->setType('function', PARAM_PLUGIN
);
316 $mform->addElement('hidden', 'protocol');
317 $mform->setType('protocol', PARAM_ALPHA
);
321 $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
323 $this->add_action_buttons(true, get_string('execute', 'webservice'));
326 public function get_params() {
327 if (!$data = $this->get_data()) {
330 // remove unused from form data
331 unset($data->submitbutton
);
332 unset($data->protocol
);
333 unset($data->function);
334 unset($data->wsusername
);
335 unset($data->wspassword
);
337 unset($data->authmethod
);
339 /// beginning of specific code to the create users form
341 $params['userids'] = array();
342 for ($i=0; $i<10; $i++
) {
343 if (empty($data->userids
[$i])) {
346 $params['userids'][] = $data->userids
[$i];
348 /// end of specific code to the create users function
354 class moodle_group_create_groups_form
extends moodleform
{
355 public function definition() {
358 $mform = $this->_form
;
361 $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
363 //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
364 $data = $this->_customdata
;
365 if ($data['authmethod'] == 'simple') {
366 $mform->addElement('text', 'wsusername', 'wsusername');
367 $mform->setType('wsusername', PARAM_USERNAME
);
368 $mform->addElement('text', 'wspassword', 'wspassword');
369 $mform->setType('wspassword', PARAM_RAW
);
370 } else if ($data['authmethod'] == 'token') {
371 $mform->addElement('text', 'token', 'token');
372 $mform->setType('token', PARAM_RAW_TRIMMED
);
375 $mform->addElement('hidden', 'authmethod', $data['authmethod']);
376 $mform->setType('authmethod', PARAM_ALPHA
);
378 $mform->addElement('text', 'courseid', 'courseid');
379 $mform->setType('courseid', PARAM_INT
);
380 $mform->addElement('text', 'name', 'name');
381 $mform->setType('name', PARAM_TEXT
);
382 $mform->addElement('text', 'description', 'description');
383 $mform->setType('description', PARAM_TEXT
);
384 $mform->addElement('text', 'enrolmentkey', 'enrolmentkey');
385 $mform->setType('enrolmentkey', PARAM_RAW
);
387 $mform->addElement('hidden', 'function');
388 $mform->setType('function', PARAM_PLUGIN
);
390 $mform->addElement('hidden', 'protocol');
391 $mform->setType('protocol', PARAM_ALPHA
);
395 $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
397 $this->add_action_buttons(true, get_string('execute', 'webservice'));
400 public function get_params() {
401 if (!$data = $this->get_data()) {
404 // remove unused from form data
405 unset($data->submitbutton
);
406 unset($data->protocol
);
407 unset($data->function);
408 unset($data->wsusername
);
409 unset($data->wspassword
);
411 unset($data->authmethod
);
414 $params['groups'] = array();
415 $params['groups'][] = (array)$data;
421 class moodle_group_get_groups_form
extends moodleform
{
422 public function definition() {
425 $mform = $this->_form
;
427 $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
429 //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
430 $data = $this->_customdata
;
431 if ($data['authmethod'] == 'simple') {
432 $mform->addElement('text', 'wsusername', 'wsusername');
433 $mform->setType('wsusername', PARAM_USERNAME
);
434 $mform->addElement('text', 'wspassword', 'wspassword');
435 $mform->setType('wspassword', PARAM_RAW
);
436 } else if ($data['authmethod'] == 'token') {
437 $mform->addElement('text', 'token', 'token');
438 $mform->setType('token', PARAM_RAW_TRIMMED
);
441 $mform->addElement('hidden', 'authmethod', $data['authmethod']);
442 $mform->setType('authmethod', PARAM_ALPHA
);
443 $mform->addElement('text', 'groupids[0]', 'groupids[0]');
444 $mform->addElement('text', 'groupids[1]', 'groupids[1]');
445 $mform->addElement('text', 'groupids[2]', 'groupids[2]');
446 $mform->addElement('text', 'groupids[3]', 'groupids[3]');
447 $mform->setType('groupids', PARAM_INT
);
449 $mform->addElement('hidden', 'function');
450 $mform->setType('function', PARAM_PLUGIN
);
452 $mform->addElement('hidden', 'protocol');
453 $mform->setType('protocol', PARAM_ALPHA
);
455 $this->add_action_buttons(true, get_string('execute', 'webservice'));
458 public function get_params() {
459 if (!$data = $this->get_data()) {
462 // remove unused from form data
463 unset($data->submitbutton
);
464 unset($data->protocol
);
465 unset($data->function);
466 unset($data->wsusername
);
467 unset($data->wspassword
);
469 unset($data->authmethod
);
472 $params['groupids'] = array();
473 for ($i=0; $i<10; $i++
) {
474 if (empty($data->groupids
[$i])) {
477 $params['groupids'][] = $data->groupids
[$i];
484 class moodle_group_get_course_groups_form
extends moodleform
{
485 public function definition() {
488 $mform = $this->_form
;
490 $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
492 //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
493 $data = $this->_customdata
;
494 if ($data['authmethod'] == 'simple') {
495 $mform->addElement('text', 'wsusername', 'wsusername');
496 $mform->setType('wsusername', PARAM_USERNAME
);
497 $mform->addElement('text', 'wspassword', 'wspassword');
498 $mform->setType('wspassword', PARAM_RAW
);
499 } else if ($data['authmethod'] == 'token') {
500 $mform->addElement('text', 'token', 'token');
501 $mform->setType('token', PARAM_RAW_TRIMMED
);
504 $mform->addElement('hidden', 'authmethod', $data['authmethod']);
505 $mform->setType('authmethod', PARAM_ALPHA
);
506 $mform->addElement('text', 'courseid', 'courseid');
508 $mform->addElement('hidden', 'function');
509 $mform->setType('function', PARAM_PLUGIN
);
511 $mform->addElement('hidden', 'protocol');
512 $mform->setType('protocol', PARAM_ALPHA
);
514 $this->add_action_buttons(true, get_string('execute', 'webservice'));
517 public function get_params() {
518 if (!$data = $this->get_data()) {
521 // remove unused from form data
522 unset($data->submitbutton
);
523 unset($data->protocol
);
524 unset($data->function);
525 unset($data->wsusername
);
526 unset($data->wspassword
);
528 unset($data->authmethod
);
531 $params['courseid'] = $data->courseid
;
537 class moodle_group_delete_groups_form
extends moodleform
{
538 public function definition() {
541 $mform = $this->_form
;
543 $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
545 //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
546 $data = $this->_customdata
;
547 if ($data['authmethod'] == 'simple') {
548 $mform->addElement('text', 'wsusername', 'wsusername');
549 $mform->setType('wsusername', PARAM_USERNAME
);
550 $mform->addElement('text', 'wspassword', 'wspassword');
551 $mform->setType('wspassword', PARAM_RAW
);
552 } else if ($data['authmethod'] == 'token') {
553 $mform->addElement('text', 'token', 'token');
554 $mform->setType('token', PARAM_RAW_TRIMMED
);
557 $mform->addElement('hidden', 'authmethod', $data['authmethod']);
558 $mform->setType('authmethod', PARAM_ALPHA
);
559 $mform->addElement('text', 'groupids[0]', 'groupids[0]');
560 $mform->addElement('text', 'groupids[1]', 'groupids[1]');
561 $mform->addElement('text', 'groupids[2]', 'groupids[2]');
562 $mform->addElement('text', 'groupids[3]', 'groupids[3]');
563 $mform->setType('groupids', PARAM_INT
);
565 $mform->addElement('hidden', 'function');
566 $mform->setType('function', PARAM_PLUGIN
);
568 $mform->addElement('hidden', 'protocol');
569 $mform->setType('protocol', PARAM_ALPHA
);
571 $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
573 $this->add_action_buttons(true, get_string('execute', 'webservice'));
576 public function get_params() {
577 if (!$data = $this->get_data()) {
580 // remove unused from form data
581 unset($data->submitbutton
);
582 unset($data->protocol
);
583 unset($data->function);
584 unset($data->wsusername
);
585 unset($data->wspassword
);
587 unset($data->authmethod
);
590 $params['groupids'] = array();
591 for ($i=0; $i<10; $i++
) {
592 if (empty($data->groupids
[$i])) {
595 $params['groupids'][] = $data->groupids
[$i];
602 class moodle_group_get_groupmembers_form
extends moodleform
{
603 public function definition() {
606 $mform = $this->_form
;
608 $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
610 //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
611 $data = $this->_customdata
;
612 if ($data['authmethod'] == 'simple') {
613 $mform->addElement('text', 'wsusername', 'wsusername');
614 $mform->setType('wsusername', PARAM_USERNAME
);
615 $mform->addElement('text', 'wspassword', 'wspassword');
616 $mform->setType('wspassword', PARAM_RAW
);
617 } else if ($data['authmethod'] == 'token') {
618 $mform->addElement('text', 'token', 'token');
619 $mform->setType('token', PARAM_RAW_TRIMMED
);
622 $mform->addElement('hidden', 'authmethod', $data['authmethod']);
623 $mform->setType('authmethod', PARAM_ALPHA
);
624 $mform->addElement('text', 'groupids[0]', 'groupids[0]');
625 $mform->addElement('text', 'groupids[1]', 'groupids[1]');
626 $mform->addElement('text', 'groupids[2]', 'groupids[2]');
627 $mform->addElement('text', 'groupids[3]', 'groupids[3]');
628 $mform->setType('groupids', PARAM_INT
);
630 $mform->addElement('hidden', 'function');
631 $mform->setType('function', PARAM_PLUGIN
);
633 $mform->addElement('hidden', 'protocol');
634 $mform->setType('protocol', PARAM_ALPHA
);
636 $this->add_action_buttons(true, get_string('execute', 'webservice'));
639 public function get_params() {
640 if (!$data = $this->get_data()) {
643 // remove unused from form data
644 unset($data->submitbutton
);
645 unset($data->protocol
);
646 unset($data->function);
647 unset($data->wsusername
);
648 unset($data->wspassword
);
650 unset($data->authmethod
);
653 $params['groupids'] = array();
654 for ($i=0; $i<10; $i++
) {
655 if (empty($data->groupids
[$i])) {
658 $params['groupids'][] = $data->groupids
[$i];
665 class moodle_group_add_groupmembers_form
extends moodleform
{
666 public function definition() {
669 $mform = $this->_form
;
671 $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
673 //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
674 $data = $this->_customdata
;
675 if ($data['authmethod'] == 'simple') {
676 $mform->addElement('text', 'wsusername', 'wsusername');
677 $mform->setType('wsusername', PARAM_USERNAME
);
678 $mform->addElement('text', 'wspassword', 'wspassword');
679 $mform->setType('wspassword', PARAM_RAW
);
680 } else if ($data['authmethod'] == 'token') {
681 $mform->addElement('text', 'token', 'token');
682 $mform->setType('token', PARAM_RAW_TRIMMED
);
685 $mform->addElement('hidden', 'authmethod', $data['authmethod']);
686 $mform->setType('authmethod', PARAM_SAFEDIR
);
687 $mform->addElement('text', 'userid[0]', 'userid[0]');
688 $mform->addElement('text', 'groupid[0]', 'groupid[0]');
689 $mform->addElement('text', 'userid[1]', 'userid[1]');
690 $mform->addElement('text', 'groupid[1]', 'groupid[1]');
691 $mform->setType('userid', PARAM_INT
);
692 $mform->setType('groupids', PARAM_INT
);
694 $mform->addElement('hidden', 'function');
695 $mform->setType('function', PARAM_PLUGIN
);
697 $mform->addElement('hidden', 'protocol');
698 $mform->setType('protocol', PARAM_ALPHA
);
700 $this->add_action_buttons(true, get_string('execute', 'webservice'));
703 public function get_params() {
704 if (!$data = $this->get_data()) {
707 // remove unused from form data
708 unset($data->submitbutton
);
709 unset($data->protocol
);
710 unset($data->function);
711 unset($data->wsusername
);
712 unset($data->wspassword
);
714 unset($data->authmethod
);
717 $params['members'] = array();
718 for ($i=0; $i<10; $i++
) {
719 if (empty($data->groupid
[$i]) or empty($data->userid
[$i])) {
722 $params['members'][] = array('userid'=>$data->userid
[$i], 'groupid'=>$data->groupid
[$i]);
729 class moodle_group_delete_groupmembers_form
extends moodleform
{
730 public function definition() {
733 $mform = $this->_form
;
735 $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
737 //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
738 $data = $this->_customdata
;
739 if ($data['authmethod'] == 'simple') {
740 $mform->addElement('text', 'wsusername', 'wsusername');
741 $mform->setType('wsusername', PARAM_USERNAME
);
742 $mform->addElement('text', 'wspassword', 'wspassword');
743 $mform->setType('wspassword', PARAM_RAW
);
744 } else if ($data['authmethod'] == 'token') {
745 $mform->addElement('text', 'token', 'token');
746 $mform->setType('token', PARAM_RAW_TRIMMED
);
749 $mform->addElement('hidden', 'authmethod', $data['authmethod']);
750 $mform->setType('authmethod', PARAM_ALPHA
);
751 $mform->addElement('text', 'userid[0]', 'userid[0]');
752 $mform->addElement('text', 'groupid[0]', 'groupid[0]');
753 $mform->addElement('text', 'userid[1]', 'userid[1]');
754 $mform->addElement('text', 'groupid[1]', 'groupid[1]');
755 $mform->setType('userid', PARAM_INT
);
756 $mform->setType('groupids', PARAM_INT
);
758 $mform->addElement('hidden', 'function');
759 $mform->setType('function', PARAM_PLUGIN
);
761 $mform->addElement('hidden', 'protocol');
762 $mform->setType('protocol', PARAM_ALPHA
);
764 $this->add_action_buttons(true, get_string('execute', 'webservice'));
767 public function get_params() {
768 if (!$data = $this->get_data()) {
771 // remove unused from form data
772 unset($data->submitbutton
);
773 unset($data->protocol
);
774 unset($data->function);
775 unset($data->wsusername
);
776 unset($data->wspassword
);
778 unset($data->authmethod
);
781 $params['members'] = array();
782 for ($i=0; $i<10; $i++
) {
783 if (empty($data->groupid
[$i]) or empty($data->userid
[$i])) {
786 $params['members'][] = array('userid'=>$data->userid
[$i], 'groupid'=>$data->groupid
[$i]);
794 * Form class for create_categories() web service function test.
796 * @package core_webservice
797 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
798 * @copyright 2012 Fabio Souto
800 class core_course_create_categories_form
extends moodleform
{
802 * The form definition.
804 public function definition() {
807 $mform = $this->_form
;
809 $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
811 // Note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters.
812 $data = $this->_customdata
;
813 if ($data['authmethod'] == 'simple') {
814 $mform->addElement('text', 'wsusername', 'wsusername');
815 $mform->setType('wsusername', PARAM_USERNAME
);
816 $mform->addElement('text', 'wspassword', 'wspassword');
817 $mform->setType('wspassword', PARAM_RAW
);
818 } else if ($data['authmethod'] == 'token') {
819 $mform->addElement('text', 'token', 'token');
820 $mform->setType('token', PARAM_RAW_TRIMMED
);
823 $mform->addElement('hidden', 'authmethod', $data['authmethod']);
824 $mform->setType('authmethod', PARAM_ALPHA
);
825 $mform->addElement('text', 'name[0]', 'name[0]');
826 $mform->addElement('text', 'parent[0]', 'parent[0]');
827 $mform->addElement('text', 'idnumber[0]', 'idnumber[0]');
828 $mform->addElement('text', 'description[0]', 'description[0]');
829 $mform->addElement('text', 'name[1]', 'name[1]');
830 $mform->addElement('text', 'parent[1]', 'parent[1]');
831 $mform->addElement('text', 'idnumber[1]', 'idnumber[1]');
832 $mform->addElement('text', 'description[1]', 'description[1]');
833 $mform->setType('name', PARAM_TEXT
);
834 $mform->setType('parent', PARAM_INT
);
835 $mform->setType('idnumber', PARAM_RAW
);
836 $mform->setType('description', PARAM_TEXT
);
838 $mform->addElement('hidden', 'function');
839 $mform->setType('function', PARAM_PLUGIN
);
841 $mform->addElement('hidden', 'protocol');
842 $mform->setType('protocol', PARAM_ALPHA
);
844 $this->add_action_buttons(true, get_string('execute', 'webservice'));
848 * Get the parameters that the user submitted using the form.
851 public function get_params() {
852 if (!$data = $this->get_data()) {
855 // Remove unused from form data.
856 unset($data->submitbutton
);
857 unset($data->protocol
);
858 unset($data->function);
859 unset($data->wsusername
);
860 unset($data->wspassword
);
862 unset($data->authmethod
);
865 $params['categories'] = array();
866 for ($i=0; $i<10; $i++
) {
867 if (empty($data->name
[$i]) or empty($data->parent
[$i])) {
870 $params['categories'][] = array('name'=>$data->name
[$i], 'parent'=>$data->parent
[$i],
871 'idnumber'=>$data->idnumber
[$i], 'description'=>$data->description
[$i]);
878 * Form class for delete_categories() web service function test.
880 * @package core_webservice
881 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
882 * @copyright 2012 Fabio Souto
884 class core_course_delete_categories_form
extends moodleform
{
886 * The form definition.
888 public function definition() {
891 $mform = $this->_form
;
893 $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
895 // Note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters.
896 $data = $this->_customdata
;
897 if ($data['authmethod'] == 'simple') {
898 $mform->addElement('text', 'wsusername', 'wsusername');
899 $mform->setType('wsusername', PARAM_USERNAME
);
900 $mform->addElement('text', 'wspassword', 'wspassword');
901 $mform->setType('wspassword', PARAM_RAW
);
902 } else if ($data['authmethod'] == 'token') {
903 $mform->addElement('text', 'token', 'token');
904 $mform->setType('token', PARAM_RAW_TRIMMED
);
907 $mform->addElement('hidden', 'authmethod', $data['authmethod']);
908 $mform->setType('authmethod', PARAM_ALPHA
);
909 $mform->addElement('text', 'id[0]', 'id[0]');
910 $mform->addElement('text', 'newparent[0]', 'newparent[0]');
911 $mform->addElement('text', 'recursive[0]', 'recursive[0]');
912 $mform->addElement('text', 'id[1]', 'id[1]');
913 $mform->addElement('text', 'newparent[1]', 'newparent[1]');
914 $mform->addElement('text', 'recursive[1]', 'recursive[1]');
915 $mform->setType('id', PARAM_INT
);
916 $mform->setType('newparent', PARAM_INT
);
917 $mform->setType('recursive', PARAM_BOOL
);
919 $mform->addElement('hidden', 'function');
920 $mform->setType('function', PARAM_PLUGIN
);
922 $mform->addElement('hidden', 'protocol');
923 $mform->setType('protocol', PARAM_ALPHA
);
925 $this->add_action_buttons(true, get_string('execute', 'webservice'));
929 * Get the parameters that the user submitted using the form.
932 public function get_params() {
933 if (!$data = $this->get_data()) {
936 // Remove unused from form data.
937 unset($data->submitbutton
);
938 unset($data->protocol
);
939 unset($data->function);
940 unset($data->wsusername
);
941 unset($data->wspassword
);
943 unset($data->authmethod
);
946 $params['categories'] = array();
947 for ($i=0; $i<10; $i++
) {
948 if (empty($data->id
[$i])) {
952 $attrs['id'] = $data->id
[$i];
953 if (!empty($data->newparent
[$i])) {
954 $attrs['newparent'] = $data->newparent
[$i];
956 if (!empty($data->recursive
[$i])) {
957 $attrs['recursive'] = $data->recursive
[$i];
959 $params['categories'][] = $attrs;
966 * Form class for create_categories() web service function test.
968 * @package core_webservice
969 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
970 * @copyright 2012 Fabio Souto
972 class core_course_update_categories_form
extends moodleform
{
974 * The form definition.
976 public function definition() {
979 $mform = $this->_form
;
981 $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
983 // Note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters.
984 $data = $this->_customdata
;
985 if ($data['authmethod'] == 'simple') {
986 $mform->addElement('text', 'wsusername', 'wsusername');
987 $mform->setType('wsusername', PARAM_USERNAME
);
988 $mform->addElement('text', 'wspassword', 'wspassword');
989 $mform->setType('wspassword', PARAM_RAW
);
990 } else if ($data['authmethod'] == 'token') {
991 $mform->addElement('text', 'token', 'token');
992 $mform->setType('token', PARAM_RAW_TRIMMED
);
995 $mform->addElement('hidden', 'authmethod', $data['authmethod']);
996 $mform->setType('authmethod', PARAM_ALPHA
);
997 $mform->addElement('text', 'id[0]', 'id[0]');
998 $mform->addElement('text', 'name[0]', 'name[0]');
999 $mform->addElement('text', 'parent[0]', 'parent[0]');
1000 $mform->addElement('text', 'idnumber[0]', 'idnumber[0]');
1001 $mform->addElement('text', 'description[0]', 'description[0]');
1002 $mform->addElement('text', 'id[1]', 'id[1]');
1003 $mform->addElement('text', 'name[1]', 'name[1]');
1004 $mform->addElement('text', 'parent[1]', 'parent[1]');
1005 $mform->addElement('text', 'idnumber[1]', 'idnumber[1]');
1006 $mform->addElement('text', 'description[1]', 'description[1]');
1007 $mform->setType('id', PARAM_INT
);
1008 $mform->setType('name', PARAM_TEXT
);
1009 $mform->setType('parent', PARAM_INT
);
1010 $mform->setType('idnumber', PARAM_RAW
);
1011 $mform->setType('description', PARAM_TEXT
);
1013 $mform->addElement('hidden', 'function');
1014 $mform->setType('function', PARAM_PLUGIN
);
1016 $mform->addElement('hidden', 'protocol');
1017 $mform->setType('protocol', PARAM_ALPHA
);
1019 $this->add_action_buttons(true, get_string('execute', 'webservice'));
1023 * Get the parameters that the user submitted using the form.
1024 * @return array|null
1026 public function get_params() {
1027 if (!$data = $this->get_data()) {
1030 // Remove unused from form data.
1031 unset($data->submitbutton
);
1032 unset($data->protocol
);
1033 unset($data->function);
1034 unset($data->wsusername
);
1035 unset($data->wspassword
);
1036 unset($data->token
);
1037 unset($data->authmethod
);
1040 $params['categories'] = array();
1041 for ($i=0; $i<10; $i++
) {
1043 if (empty($data->id
[$i])) {
1047 $attrs['id'] = $data->id
[$i];
1048 if (!empty($data->name
[$i])) {
1049 $attrs['name'] = $data->name
[$i];
1051 if (!empty($data->parent
[$i])) {
1052 $attrs['parent'] = $data->parent
[$i];
1054 if (!empty($data->idnumber
[$i])) {
1055 $attrs['idnumber'] = $data->idnumber
[$i];
1057 if (!empty($data->description
[$i])) {
1058 $attrs['description'] = $data->description
[$i];
1060 $params['categories'][] = $attrs;