PageRenderTime 56ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/webservice/testclient_forms.php

https://bitbucket.org/ngmares/moodle
PHP | 981 lines | 699 code | 199 blank | 83 comment | 113 complexity | 0605bc348b951966d26f9755d0792913 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0, MPL-2.0-no-copyleft-exception, GPL-3.0, Apache-2.0, BSD-3-Clause
  1. <?php
  2. require_once($CFG->libdir.'/formslib.php');
  3. class webservice_test_client_form extends moodleform {
  4. public function definition() {
  5. global $CFG;
  6. $mform = $this->_form;
  7. list($functions, $protocols) = $this->_customdata;
  8. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  9. $authmethod = array('simple' => 'simple', 'token' => 'token');
  10. $mform->addElement('select', 'authmethod', get_string('authmethod', 'webservice'), $authmethod);
  11. $mform->addElement('select', 'protocol', get_string('protocol', 'webservice'), $protocols);
  12. $mform->addElement('select', 'function', get_string('function', 'webservice'), $functions);
  13. $this->add_action_buttons(false, get_string('select'));
  14. }
  15. }
  16. // === Test client forms ===
  17. class moodle_user_create_users_form extends moodleform {
  18. public function definition() {
  19. global $CFG;
  20. $mform = $this->_form;
  21. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  22. //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
  23. $data = $this->_customdata;
  24. if ($data['authmethod'] == 'simple') {
  25. $mform->addElement('text', 'wsusername', 'wsusername');
  26. $mform->addElement('text', 'wspassword', 'wspassword');
  27. } else if ($data['authmethod'] == 'token') {
  28. $mform->addElement('text', 'token', 'token');
  29. }
  30. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  31. $mform->setType('authmethod', PARAM_SAFEDIR);
  32. /// specific to the create users function
  33. $mform->addElement('text', 'username', 'username');
  34. $mform->addElement('text', 'password', 'password');
  35. $mform->addElement('text', 'firstname', 'firstname');
  36. $mform->addElement('text', 'lastname', 'lastname');
  37. $mform->addElement('text', 'email', 'email');
  38. $mform->addElement('text', 'customfieldtype', 'customfieldtype');
  39. $mform->addElement('text', 'customfieldvalue', 'customfieldvalue');
  40. $mform->addElement('hidden', 'function');
  41. $mform->setType('function', PARAM_SAFEDIR);
  42. $mform->addElement('hidden', 'protocol');
  43. $mform->setType('protocol', PARAM_SAFEDIR);
  44. $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
  45. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  46. }
  47. public function get_params() {
  48. if (!$data = $this->get_data()) {
  49. return null;
  50. }
  51. //set customfields
  52. if (!empty($data->customfieldtype)) {
  53. $data->customfields = array(array('type' => $data->customfieldtype, 'value' => $data->customfieldvalue));
  54. }
  55. // remove unused from form data
  56. unset($data->submitbutton);
  57. unset($data->protocol);
  58. unset($data->function);
  59. unset($data->wsusername);
  60. unset($data->wspassword);
  61. unset($data->token);
  62. unset($data->authmethod);
  63. unset($data->customfieldtype);
  64. unset($data->customfieldvalue);
  65. $params = array();
  66. $params['users'] = array();
  67. $params['users'][] = (array)$data;
  68. return $params;
  69. }
  70. }
  71. class moodle_user_update_users_form extends moodleform {
  72. public function definition() {
  73. global $CFG;
  74. $mform = $this->_form;
  75. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  76. //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
  77. $data = $this->_customdata;
  78. if ($data['authmethod'] == 'simple') {
  79. $mform->addElement('text', 'wsusername', 'wsusername');
  80. $mform->addElement('text', 'wspassword', 'wspassword');
  81. } else if ($data['authmethod'] == 'token') {
  82. $mform->addElement('text', 'token', 'token');
  83. }
  84. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  85. $mform->setType('authmethod', PARAM_SAFEDIR);
  86. /// specific to the create users function
  87. $mform->addElement('text', 'id', 'id');
  88. $mform->addRule('id', get_string('required'), 'required', null, 'client');
  89. $mform->addElement('text', 'username', 'username');
  90. $mform->addElement('text', 'password', 'password');
  91. $mform->addElement('text', 'firstname', 'firstname');
  92. $mform->addElement('text', 'lastname', 'lastname');
  93. $mform->addElement('text', 'email', 'email');
  94. $mform->addElement('text', 'customfieldtype', 'customfieldtype');
  95. $mform->addElement('text', 'customfieldvalue', 'customfieldvalue');
  96. $mform->addElement('hidden', 'function');
  97. $mform->setType('function', PARAM_SAFEDIR);
  98. $mform->addElement('hidden', 'protocol');
  99. $mform->setType('protocol', PARAM_SAFEDIR);
  100. $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
  101. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  102. }
  103. public function get_params() {
  104. if (!$data = $this->get_data()) {
  105. return null;
  106. }
  107. //set customfields
  108. if (!empty($data->customfieldtype)) {
  109. $data->customfields = array(array('type' => $data->customfieldtype, 'value' => $data->customfieldvalue));
  110. }
  111. // remove unused from form data
  112. unset($data->submitbutton);
  113. unset($data->protocol);
  114. unset($data->function);
  115. unset($data->wsusername);
  116. unset($data->wspassword);
  117. unset($data->token);
  118. unset($data->authmethod);
  119. unset($data->customfieldtype);
  120. unset($data->customfieldvalue);
  121. foreach($data as $key => $value) {
  122. if (empty($value)) {
  123. unset($data->{$key});
  124. }
  125. }
  126. $params = array();
  127. $params['users'] = array();
  128. $params['users'][] = (array)$data;
  129. return $params;
  130. }
  131. }
  132. class moodle_user_delete_users_form extends moodleform {
  133. public function definition() {
  134. global $CFG;
  135. $mform = $this->_form;
  136. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  137. //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
  138. $data = $this->_customdata;
  139. if ($data['authmethod'] == 'simple') {
  140. $mform->addElement('text', 'wsusername', 'wsusername');
  141. $mform->addElement('text', 'wspassword', 'wspassword');
  142. } else if ($data['authmethod'] == 'token') {
  143. $mform->addElement('text', 'token', 'token');
  144. }
  145. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  146. $mform->setType('authmethod', PARAM_SAFEDIR);
  147. /// beginning of specific code to the create users function
  148. $mform->addElement('text', 'userids[0]', 'userids[0]');
  149. $mform->addElement('text', 'userids[1]', 'userids[1]');
  150. $mform->addElement('text', 'userids[2]', 'userids[2]');
  151. $mform->addElement('text', 'userids[3]', 'userids[3]');
  152. /// end of specific code to the create users function
  153. $mform->addElement('hidden', 'function');
  154. $mform->setType('function', PARAM_SAFEDIR);
  155. $mform->addElement('hidden', 'protocol');
  156. $mform->setType('protocol', PARAM_SAFEDIR);
  157. $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
  158. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  159. }
  160. public function get_params() {
  161. if (!$data = $this->get_data()) {
  162. return null;
  163. }
  164. // remove unused from form data
  165. unset($data->submitbutton);
  166. unset($data->protocol);
  167. unset($data->function);
  168. unset($data->wsusername);
  169. unset($data->wspassword);
  170. unset($data->token);
  171. unset($data->authmethod);
  172. /// beginning of specific code to the create users form
  173. $params = array();
  174. $params['userids'] = array();
  175. for ($i=0; $i<10; $i++) {
  176. if (empty($data->userids[$i])) {
  177. continue;
  178. }
  179. $params['userids'][] = $data->userids[$i];
  180. }
  181. /// end of specific code to the create users function
  182. return $params;
  183. }
  184. }
  185. class moodle_user_get_users_by_id_form extends moodleform {
  186. public function definition() {
  187. global $CFG;
  188. $mform = $this->_form;
  189. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  190. //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
  191. $data = $this->_customdata;
  192. if ($data['authmethod'] == 'simple') {
  193. $mform->addElement('text', 'wsusername', 'wsusername');
  194. $mform->addElement('text', 'wspassword', 'wspassword');
  195. } else if ($data['authmethod'] == 'token') {
  196. $mform->addElement('text', 'token', 'token');
  197. }
  198. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  199. $mform->setType('authmethod', PARAM_SAFEDIR);
  200. /// beginning of specific code to the create users function
  201. $mform->addElement('text', 'userids[0]', 'userids[0]');
  202. $mform->addElement('text', 'userids[1]', 'userids[1]');
  203. $mform->addElement('text', 'userids[2]', 'userids[2]');
  204. $mform->addElement('text', 'userids[3]', 'userids[3]');
  205. /// end of specific code to the create users function
  206. $mform->addElement('hidden', 'function');
  207. $mform->setType('function', PARAM_SAFEDIR);
  208. $mform->addElement('hidden', 'protocol');
  209. $mform->setType('protocol', PARAM_SAFEDIR);
  210. $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
  211. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  212. }
  213. public function get_params() {
  214. if (!$data = $this->get_data()) {
  215. return null;
  216. }
  217. // remove unused from form data
  218. unset($data->submitbutton);
  219. unset($data->protocol);
  220. unset($data->function);
  221. unset($data->wsusername);
  222. unset($data->wspassword);
  223. unset($data->token);
  224. unset($data->authmethod);
  225. /// beginning of specific code to the create users form
  226. $params = array();
  227. $params['userids'] = array();
  228. for ($i=0; $i<10; $i++) {
  229. if (empty($data->userids[$i])) {
  230. continue;
  231. }
  232. $params['userids'][] = $data->userids[$i];
  233. }
  234. /// end of specific code to the create users function
  235. return $params;
  236. }
  237. }
  238. class moodle_group_create_groups_form extends moodleform {
  239. public function definition() {
  240. global $CFG;
  241. $mform = $this->_form;
  242. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  243. //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
  244. $data = $this->_customdata;
  245. if ($data['authmethod'] == 'simple') {
  246. $mform->addElement('text', 'wsusername', 'wsusername');
  247. $mform->addElement('text', 'wspassword', 'wspassword');
  248. } else if ($data['authmethod'] == 'token') {
  249. $mform->addElement('text', 'token', 'token');
  250. }
  251. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  252. $mform->setType('authmethod', PARAM_SAFEDIR);
  253. $mform->addElement('text', 'courseid', 'courseid');
  254. $mform->addElement('text', 'name', 'name');
  255. $mform->addElement('text', 'description', 'description');
  256. $mform->addElement('text', 'enrolmentkey', 'enrolmentkey');
  257. $mform->addElement('hidden', 'function');
  258. $mform->setType('function', PARAM_SAFEDIR);
  259. $mform->addElement('hidden', 'protocol');
  260. $mform->setType('protocol', PARAM_SAFEDIR);
  261. $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
  262. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  263. }
  264. public function get_params() {
  265. if (!$data = $this->get_data()) {
  266. return null;
  267. }
  268. // remove unused from form data
  269. unset($data->submitbutton);
  270. unset($data->protocol);
  271. unset($data->function);
  272. unset($data->wsusername);
  273. unset($data->wspassword);
  274. unset($data->token);
  275. unset($data->authmethod);
  276. $params = array();
  277. $params['groups'] = array();
  278. $params['groups'][] = (array)$data;
  279. return $params;
  280. }
  281. }
  282. class moodle_group_get_groups_form extends moodleform {
  283. public function definition() {
  284. global $CFG;
  285. $mform = $this->_form;
  286. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  287. //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
  288. $data = $this->_customdata;
  289. if ($data['authmethod'] == 'simple') {
  290. $mform->addElement('text', 'wsusername', 'wsusername');
  291. $mform->addElement('text', 'wspassword', 'wspassword');
  292. } else if ($data['authmethod'] == 'token') {
  293. $mform->addElement('text', 'token', 'token');
  294. }
  295. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  296. $mform->setType('authmethod', PARAM_SAFEDIR);
  297. $mform->addElement('text', 'groupids[0]', 'groupids[0]');
  298. $mform->addElement('text', 'groupids[1]', 'groupids[1]');
  299. $mform->addElement('text', 'groupids[2]', 'groupids[2]');
  300. $mform->addElement('text', 'groupids[3]', 'groupids[3]');
  301. $mform->addElement('hidden', 'function');
  302. $mform->setType('function', PARAM_SAFEDIR);
  303. $mform->addElement('hidden', 'protocol');
  304. $mform->setType('protocol', PARAM_SAFEDIR);
  305. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  306. }
  307. public function get_params() {
  308. if (!$data = $this->get_data()) {
  309. return null;
  310. }
  311. // remove unused from form data
  312. unset($data->submitbutton);
  313. unset($data->protocol);
  314. unset($data->function);
  315. unset($data->wsusername);
  316. unset($data->wspassword);
  317. unset($data->token);
  318. unset($data->authmethod);
  319. $params = array();
  320. $params['groupids'] = array();
  321. for ($i=0; $i<10; $i++) {
  322. if (empty($data->groupids[$i])) {
  323. continue;
  324. }
  325. $params['groupids'][] = $data->groupids[$i];
  326. }
  327. return $params;
  328. }
  329. }
  330. class moodle_group_get_course_groups_form extends moodleform {
  331. public function definition() {
  332. global $CFG;
  333. $mform = $this->_form;
  334. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  335. //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
  336. $data = $this->_customdata;
  337. if ($data['authmethod'] == 'simple') {
  338. $mform->addElement('text', 'wsusername', 'wsusername');
  339. $mform->addElement('text', 'wspassword', 'wspassword');
  340. } else if ($data['authmethod'] == 'token') {
  341. $mform->addElement('text', 'token', 'token');
  342. }
  343. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  344. $mform->setType('authmethod', PARAM_SAFEDIR);
  345. $mform->addElement('text', 'courseid', 'courseid');
  346. $mform->addElement('hidden', 'function');
  347. $mform->setType('function', PARAM_SAFEDIR);
  348. $mform->addElement('hidden', 'protocol');
  349. $mform->setType('protocol', PARAM_SAFEDIR);
  350. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  351. }
  352. public function get_params() {
  353. if (!$data = $this->get_data()) {
  354. return null;
  355. }
  356. // remove unused from form data
  357. unset($data->submitbutton);
  358. unset($data->protocol);
  359. unset($data->function);
  360. unset($data->wsusername);
  361. unset($data->wspassword);
  362. unset($data->token);
  363. unset($data->authmethod);
  364. $params = array();
  365. $params['courseid'] = $data->courseid;
  366. return $params;
  367. }
  368. }
  369. class moodle_group_delete_groups_form extends moodleform {
  370. public function definition() {
  371. global $CFG;
  372. $mform = $this->_form;
  373. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  374. //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
  375. $data = $this->_customdata;
  376. if ($data['authmethod'] == 'simple') {
  377. $mform->addElement('text', 'wsusername', 'wsusername');
  378. $mform->addElement('text', 'wspassword', 'wspassword');
  379. } else if ($data['authmethod'] == 'token') {
  380. $mform->addElement('text', 'token', 'token');
  381. }
  382. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  383. $mform->setType('authmethod', PARAM_SAFEDIR);
  384. $mform->addElement('text', 'groupids[0]', 'groupids[0]');
  385. $mform->addElement('text', 'groupids[1]', 'groupids[1]');
  386. $mform->addElement('text', 'groupids[2]', 'groupids[2]');
  387. $mform->addElement('text', 'groupids[3]', 'groupids[3]');
  388. $mform->addElement('hidden', 'function');
  389. $mform->setType('function', PARAM_SAFEDIR);
  390. $mform->addElement('hidden', 'protocol');
  391. $mform->setType('protocol', PARAM_SAFEDIR);
  392. $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
  393. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  394. }
  395. public function get_params() {
  396. if (!$data = $this->get_data()) {
  397. return null;
  398. }
  399. // remove unused from form data
  400. unset($data->submitbutton);
  401. unset($data->protocol);
  402. unset($data->function);
  403. unset($data->wsusername);
  404. unset($data->wspassword);
  405. unset($data->token);
  406. unset($data->authmethod);
  407. $params = array();
  408. $params['groupids'] = array();
  409. for ($i=0; $i<10; $i++) {
  410. if (empty($data->groupids[$i])) {
  411. continue;
  412. }
  413. $params['groupids'][] = $data->groupids[$i];
  414. }
  415. return $params;
  416. }
  417. }
  418. class moodle_group_get_groupmembers_form extends moodleform {
  419. public function definition() {
  420. global $CFG;
  421. $mform = $this->_form;
  422. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  423. //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
  424. $data = $this->_customdata;
  425. if ($data['authmethod'] == 'simple') {
  426. $mform->addElement('text', 'wsusername', 'wsusername');
  427. $mform->addElement('text', 'wspassword', 'wspassword');
  428. } else if ($data['authmethod'] == 'token') {
  429. $mform->addElement('text', 'token', 'token');
  430. }
  431. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  432. $mform->setType('authmethod', PARAM_SAFEDIR);
  433. $mform->addElement('text', 'groupids[0]', 'groupids[0]');
  434. $mform->addElement('text', 'groupids[1]', 'groupids[1]');
  435. $mform->addElement('text', 'groupids[2]', 'groupids[2]');
  436. $mform->addElement('text', 'groupids[3]', 'groupids[3]');
  437. $mform->addElement('hidden', 'function');
  438. $mform->setType('function', PARAM_SAFEDIR);
  439. $mform->addElement('hidden', 'protocol');
  440. $mform->setType('protocol', PARAM_SAFEDIR);
  441. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  442. }
  443. public function get_params() {
  444. if (!$data = $this->get_data()) {
  445. return null;
  446. }
  447. // remove unused from form data
  448. unset($data->submitbutton);
  449. unset($data->protocol);
  450. unset($data->function);
  451. unset($data->wsusername);
  452. unset($data->wspassword);
  453. unset($data->token);
  454. unset($data->authmethod);
  455. $params = array();
  456. $params['groupids'] = array();
  457. for ($i=0; $i<10; $i++) {
  458. if (empty($data->groupids[$i])) {
  459. continue;
  460. }
  461. $params['groupids'][] = $data->groupids[$i];
  462. }
  463. return $params;
  464. }
  465. }
  466. class moodle_group_add_groupmembers_form extends moodleform {
  467. public function definition() {
  468. global $CFG;
  469. $mform = $this->_form;
  470. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  471. //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
  472. $data = $this->_customdata;
  473. if ($data['authmethod'] == 'simple') {
  474. $mform->addElement('text', 'wsusername', 'wsusername');
  475. $mform->addElement('text', 'wspassword', 'wspassword');
  476. } else if ($data['authmethod'] == 'token') {
  477. $mform->addElement('text', 'token', 'token');
  478. }
  479. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  480. $mform->setType('authmethod', PARAM_SAFEDIR);
  481. $mform->addElement('text', 'userid[0]', 'userid[0]');
  482. $mform->addElement('text', 'groupid[0]', 'groupid[0]');
  483. $mform->addElement('text', 'userid[1]', 'userid[1]');
  484. $mform->addElement('text', 'groupid[1]', 'groupid[1]');
  485. $mform->addElement('hidden', 'function');
  486. $mform->setType('function', PARAM_SAFEDIR);
  487. $mform->addElement('hidden', 'protocol');
  488. $mform->setType('protocol', PARAM_SAFEDIR);
  489. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  490. }
  491. public function get_params() {
  492. if (!$data = $this->get_data()) {
  493. return null;
  494. }
  495. // remove unused from form data
  496. unset($data->submitbutton);
  497. unset($data->protocol);
  498. unset($data->function);
  499. unset($data->wsusername);
  500. unset($data->wspassword);
  501. unset($data->token);
  502. unset($data->authmethod);
  503. $params = array();
  504. $params['members'] = array();
  505. for ($i=0; $i<10; $i++) {
  506. if (empty($data->groupid[$i]) or empty($data->userid[$i])) {
  507. continue;
  508. }
  509. $params['members'][] = array('userid'=>$data->userid[$i], 'groupid'=>$data->groupid[$i]);
  510. }
  511. return $params;
  512. }
  513. }
  514. class moodle_group_delete_groupmembers_form extends moodleform {
  515. public function definition() {
  516. global $CFG;
  517. $mform = $this->_form;
  518. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  519. //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
  520. $data = $this->_customdata;
  521. if ($data['authmethod'] == 'simple') {
  522. $mform->addElement('text', 'wsusername', 'wsusername');
  523. $mform->addElement('text', 'wspassword', 'wspassword');
  524. } else if ($data['authmethod'] == 'token') {
  525. $mform->addElement('text', 'token', 'token');
  526. }
  527. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  528. $mform->setType('authmethod', PARAM_SAFEDIR);
  529. $mform->addElement('text', 'userid[0]', 'userid[0]');
  530. $mform->addElement('text', 'groupid[0]', 'groupid[0]');
  531. $mform->addElement('text', 'userid[1]', 'userid[1]');
  532. $mform->addElement('text', 'groupid[1]', 'groupid[1]');
  533. $mform->addElement('hidden', 'function');
  534. $mform->setType('function', PARAM_SAFEDIR);
  535. $mform->addElement('hidden', 'protocol');
  536. $mform->setType('protocol', PARAM_SAFEDIR);
  537. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  538. }
  539. public function get_params() {
  540. if (!$data = $this->get_data()) {
  541. return null;
  542. }
  543. // remove unused from form data
  544. unset($data->submitbutton);
  545. unset($data->protocol);
  546. unset($data->function);
  547. unset($data->wsusername);
  548. unset($data->wspassword);
  549. unset($data->token);
  550. unset($data->authmethod);
  551. $params = array();
  552. $params['members'] = array();
  553. for ($i=0; $i<10; $i++) {
  554. if (empty($data->groupid[$i]) or empty($data->userid[$i])) {
  555. continue;
  556. }
  557. $params['members'][] = array('userid'=>$data->userid[$i], 'groupid'=>$data->groupid[$i]);
  558. }
  559. return $params;
  560. }
  561. }
  562. /**
  563. * Form class for create_categories() web service function test.
  564. *
  565. * @package core_webservice
  566. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  567. * @copyright 2012 Fabio Souto
  568. */
  569. class core_course_create_categories_form extends moodleform {
  570. /**
  571. * The form definition.
  572. */
  573. public function definition() {
  574. global $CFG;
  575. $mform = $this->_form;
  576. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  577. // Note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters.
  578. $data = $this->_customdata;
  579. if ($data['authmethod'] == 'simple') {
  580. $mform->addElement('text', 'wsusername', 'wsusername');
  581. $mform->addElement('text', 'wspassword', 'wspassword');
  582. } else if ($data['authmethod'] == 'token') {
  583. $mform->addElement('text', 'token', 'token');
  584. }
  585. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  586. $mform->setType('authmethod', PARAM_SAFEDIR);
  587. $mform->addElement('text', 'name[0]', 'name[0]');
  588. $mform->addElement('text', 'parent[0]', 'parent[0]');
  589. $mform->addElement('text', 'idnumber[0]', 'idnumber[0]');
  590. $mform->addElement('text', 'description[0]', 'description[0]');
  591. $mform->addElement('text', 'name[1]', 'name[1]');
  592. $mform->addElement('text', 'parent[1]', 'parent[1]');
  593. $mform->addElement('text', 'idnumber[1]', 'idnumber[1]');
  594. $mform->addElement('text', 'description[1]', 'description[1]');
  595. $mform->addElement('hidden', 'function');
  596. $mform->setType('function', PARAM_SAFEDIR);
  597. $mform->addElement('hidden', 'protocol');
  598. $mform->setType('protocol', PARAM_SAFEDIR);
  599. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  600. }
  601. /**
  602. * Get the parameters that the user submitted using the form.
  603. * @return array|null
  604. */
  605. public function get_params() {
  606. if (!$data = $this->get_data()) {
  607. return null;
  608. }
  609. // Remove unused from form data.
  610. unset($data->submitbutton);
  611. unset($data->protocol);
  612. unset($data->function);
  613. unset($data->wsusername);
  614. unset($data->wspassword);
  615. unset($data->token);
  616. unset($data->authmethod);
  617. $params = array();
  618. $params['categories'] = array();
  619. for ($i=0; $i<10; $i++) {
  620. if (empty($data->name[$i]) or empty($data->parent[$i])) {
  621. continue;
  622. }
  623. $params['categories'][] = array('name'=>$data->name[$i], 'parent'=>$data->parent[$i],
  624. 'idnumber'=>$data->idnumber[$i], 'description'=>$data->description[$i]);
  625. }
  626. return $params;
  627. }
  628. }
  629. /**
  630. * Form class for delete_categories() web service function test.
  631. *
  632. * @package core_webservice
  633. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  634. * @copyright 2012 Fabio Souto
  635. */
  636. class core_course_delete_categories_form extends moodleform {
  637. /**
  638. * The form definition.
  639. */
  640. public function definition() {
  641. global $CFG;
  642. $mform = $this->_form;
  643. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  644. // Note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters.
  645. $data = $this->_customdata;
  646. if ($data['authmethod'] == 'simple') {
  647. $mform->addElement('text', 'wsusername', 'wsusername');
  648. $mform->addElement('text', 'wspassword', 'wspassword');
  649. } else if ($data['authmethod'] == 'token') {
  650. $mform->addElement('text', 'token', 'token');
  651. }
  652. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  653. $mform->setType('authmethod', PARAM_SAFEDIR);
  654. $mform->addElement('text', 'id[0]', 'id[0]');
  655. $mform->addElement('text', 'newparent[0]', 'newparent[0]');
  656. $mform->addElement('text', 'recursive[0]', 'recursive[0]');
  657. $mform->addElement('text', 'id[1]', 'id[1]');
  658. $mform->addElement('text', 'newparent[1]', 'newparent[1]');
  659. $mform->addElement('text', 'recursive[1]', 'recursive[1]');
  660. $mform->addElement('hidden', 'function');
  661. $mform->setType('function', PARAM_SAFEDIR);
  662. $mform->addElement('hidden', 'protocol');
  663. $mform->setType('protocol', PARAM_SAFEDIR);
  664. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  665. }
  666. /**
  667. * Get the parameters that the user submitted using the form.
  668. * @return array|null
  669. */
  670. public function get_params() {
  671. if (!$data = $this->get_data()) {
  672. return null;
  673. }
  674. // Remove unused from form data.
  675. unset($data->submitbutton);
  676. unset($data->protocol);
  677. unset($data->function);
  678. unset($data->wsusername);
  679. unset($data->wspassword);
  680. unset($data->token);
  681. unset($data->authmethod);
  682. $params = array();
  683. $params['categories'] = array();
  684. for ($i=0; $i<10; $i++) {
  685. if (empty($data->id[$i])) {
  686. continue;
  687. }
  688. $attrs = array();
  689. $attrs['id'] = $data->id[$i];
  690. if (!empty($data->newparent[$i])) {
  691. $attrs['newparent'] = $data->newparent[$i];
  692. }
  693. if (!empty($data->recursive[$i])) {
  694. $attrs['recursive'] = $data->recursive[$i];
  695. }
  696. $params['categories'][] = $attrs;
  697. }
  698. return $params;
  699. }
  700. }
  701. /**
  702. * Form class for create_categories() web service function test.
  703. *
  704. * @package core_webservice
  705. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  706. * @copyright 2012 Fabio Souto
  707. */
  708. class core_course_update_categories_form extends moodleform {
  709. /**
  710. * The form definition.
  711. */
  712. public function definition() {
  713. global $CFG;
  714. $mform = $this->_form;
  715. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  716. // Note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters.
  717. $data = $this->_customdata;
  718. if ($data['authmethod'] == 'simple') {
  719. $mform->addElement('text', 'wsusername', 'wsusername');
  720. $mform->addElement('text', 'wspassword', 'wspassword');
  721. } else if ($data['authmethod'] == 'token') {
  722. $mform->addElement('text', 'token', 'token');
  723. }
  724. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  725. $mform->setType('authmethod', PARAM_SAFEDIR);
  726. $mform->addElement('text', 'id[0]', 'id[0]');
  727. $mform->addElement('text', 'name[0]', 'name[0]');
  728. $mform->addElement('text', 'parent[0]', 'parent[0]');
  729. $mform->addElement('text', 'idnumber[0]', 'idnumber[0]');
  730. $mform->addElement('text', 'description[0]', 'description[0]');
  731. $mform->addElement('text', 'id[1]', 'id[1]');
  732. $mform->addElement('text', 'name[1]', 'name[1]');
  733. $mform->addElement('text', 'parent[1]', 'parent[1]');
  734. $mform->addElement('text', 'idnumber[1]', 'idnumber[1]');
  735. $mform->addElement('text', 'description[1]', 'description[1]');
  736. $mform->addElement('hidden', 'function');
  737. $mform->setType('function', PARAM_SAFEDIR);
  738. $mform->addElement('hidden', 'protocol');
  739. $mform->setType('protocol', PARAM_SAFEDIR);
  740. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  741. }
  742. /**
  743. * Get the parameters that the user submitted using the form.
  744. * @return array|null
  745. */
  746. public function get_params() {
  747. if (!$data = $this->get_data()) {
  748. return null;
  749. }
  750. // Remove unused from form data.
  751. unset($data->submitbutton);
  752. unset($data->protocol);
  753. unset($data->function);
  754. unset($data->wsusername);
  755. unset($data->wspassword);
  756. unset($data->token);
  757. unset($data->authmethod);
  758. $params = array();
  759. $params['categories'] = array();
  760. for ($i=0; $i<10; $i++) {
  761. if (empty($data->id[$i])) {
  762. continue;
  763. }
  764. $attrs = array();
  765. $attrs['id'] = $data->id[$i];
  766. if (!empty($data->name[$i])) {
  767. $attrs['name'] = $data->name[$i];
  768. }
  769. if (!empty($data->parent[$i])) {
  770. $attrs['parent'] = $data->parent[$i];
  771. }
  772. if (!empty($data->idnumber[$i])) {
  773. $attrs['idnumber'] = $data->idnumber[$i];
  774. }
  775. if (!empty($data->description[$i])) {
  776. $attrs['description'] = $data->description[$i];
  777. }
  778. $params['categories'][] = $attrs;
  779. }
  780. return $params;
  781. }
  782. }