Search moodle.org's
Developer Documentation

   1  <?php
   2  
   3  require_once($CFG->libdir.'/formslib.php');
   4  
   5  
   6  class webservice_test_client_form extends moodleform {
   7      public function definition() {
   8          global $CFG;
   9  
  10          $mform = $this->_form;
  11          list($functions, $protocols) = $this->_customdata;
  12  
  13          $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  14  
  15          $authmethod = array('simple' => 'simple', 'token' => 'token');
  16          $mform->addElement('select', 'authmethod', get_string('authmethod', 'webservice'), $authmethod);
  17          $mform->setType('simple', PARAM_ALPHA);
  18  
  19          $mform->addElement('select', 'protocol', get_string('protocol', 'webservice'), $protocols);
  20          $mform->setType('protocol', PARAM_ALPHA);
  21  
  22          $mform->addElement('select', 'function', get_string('function', 'webservice'), $functions);
  23          $mform->setType('function', PARAM_PLUGIN);
  24  
  25          $this->add_action_buttons(false, get_string('select'));
  26      }
  27  }
  28  
  29  // === Test client forms ===
  30  
  31  class moodle_user_create_users_form extends moodleform {
  32      public function definition() {
  33          global $CFG;
  34  
  35          $mform = $this->_form;
  36  
  37  
  38          $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  39  
  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);
  50          }
  51  
  52          $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  53          $mform->setType('authmethod', PARAM_SAFEDIR);
  54  
  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);
  66  
  67          $mform->addElement('text', 'customfieldtype', 'customfieldtype');
  68          $mform->setType('customfieldtype', PARAM_RAW);
  69          $mform->addElement('text', 'customfieldvalue', 'customfieldvalue');
  70          $mform->setType('customfieldvalue', PARAM_RAW);
  71  
  72          $mform->addElement('hidden', 'function');
  73          $mform->setType('function', PARAM_PLUGIN);
  74  
  75          $mform->addElement('hidden', 'protocol');
  76          $mform->setType('protocol', PARAM_ALPHA);
  77  
  78  
  79  
  80          $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
  81  
  82          $this->add_action_buttons(true, get_string('execute', 'webservice'));
  83      }
  84  
  85      public function get_params() {
  86          if (!$data = $this->get_data()) {
  87              return null;
  88          }
  89  
  90          //set customfields
  91          if (!empty($data->customfieldtype)) {
  92              $data->customfields = array(array('type' => $data->customfieldtype, 'value' => $data->customfieldvalue));
  93          }
  94  
  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);
 101          unset($data->token);
 102          unset($data->authmethod);
 103          unset($data->customfieldtype);
 104          unset($data->customfieldvalue);
 105  
 106          $params = array();
 107          $params['users'] = array();
 108          $params['users'][] = (array)$data;
 109  
 110          return $params;
 111      }
 112  }
 113  
 114  
 115  class moodle_user_update_users_form extends moodleform {
 116      public function definition() {
 117          global $CFG;
 118  
 119          $mform = $this->_form;
 120  
 121  
 122          $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
 123  
 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);
 134          }
 135  
 136          $mform->addElement('hidden', 'authmethod', $data['authmethod']);
 137          $mform->setType('authmethod', PARAM_ALPHA);
 138  
 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);
 153  
 154  
 155          $mform->addElement('text', 'customfieldtype', 'customfieldtype');
 156          $mform->setType('customfieldtype', PARAM_RAW);
 157          $mform->addElement('text', 'customfieldvalue', 'customfieldvalue');
 158          $mform->setType('customfieldvalue', PARAM_RAW);
 159  
 160          $mform->addElement('hidden', 'function');
 161          $mform->setType('function', PARAM_PLUGIN);
 162  
 163          $mform->addElement('hidden', 'protocol');
 164          $mform->setType('protocol', PARAM_ALPHA);
 165  
 166  
 167  
 168          $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
 169  
 170          $this->add_action_buttons(true, get_string('execute', 'webservice'));
 171      }
 172  
 173      public function get_params() {
 174          if (!$data = $this->get_data()) {
 175              return null;
 176          }
 177  
 178          //set customfields
 179          if (!empty($data->customfieldtype)) {
 180              $data->customfields = array(array('type' => $data->customfieldtype, 'value' => $data->customfieldvalue));
 181          }
 182  
 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);
 189          unset($data->token);
 190          unset($data->authmethod);
 191          unset($data->customfieldtype);
 192          unset($data->customfieldvalue);
 193  
 194          foreach($data as $key => $value) {
 195              if (empty($value)) {
 196                   unset($data->{$key});
 197              }
 198          }
 199  
 200          $params = array();
 201          $params['users'] = array();
 202          $params['users'][] = (array)$data;
 203  
 204          return $params;
 205      }
 206  }
 207  
 208  
 209  class moodle_user_delete_users_form extends moodleform {
 210      public function definition() {
 211          global $CFG;
 212  
 213          $mform = $this->_form;
 214  
 215  
 216          $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
 217  
 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);
 228          }
 229  
 230          $mform->addElement('hidden', 'authmethod', $data['authmethod']);
 231          $mform->setType('authmethod', PARAM_ALPHA);
 232  
 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
 240  
 241          $mform->addElement('hidden', 'function');
 242          $mform->setType('function', PARAM_PLUGIN);
 243  
 244          $mform->addElement('hidden', 'protocol');
 245          $mform->setType('protocol', PARAM_ALPHA);
 246  
 247          $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
 248  
 249          $this->add_action_buttons(true, get_string('execute', 'webservice'));
 250      }
 251  
 252      public function get_params() {
 253          if (!$data = $this->get_data()) {
 254              return null;
 255          }
 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);
 262          unset($data->token);
 263          unset($data->authmethod);
 264  
 265          ///  beginning of specific code to the create users form
 266          $params = array();
 267          $params['userids'] = array();
 268          for ($i=0; $i<10; $i++) {
 269              if (empty($data->userids[$i])) {
 270                  continue;
 271              }
 272              $params['userids'][] = $data->userids[$i];
 273          }
 274          /// end of specific code to the create users function
 275  
 276          return $params;
 277      }
 278  }
 279  
 280  
 281  class moodle_user_get_users_by_id_form extends moodleform {
 282      public function definition() {
 283          global $CFG;
 284  
 285          $mform = $this->_form;
 286  
 287  
 288          $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
 289  
 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);
 300          }
 301  
 302          $mform->addElement('hidden', 'authmethod', $data['authmethod']);
 303          $mform->setType('authmethod', PARAM_ALPHA);
 304  
 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
 312  
 313          $mform->addElement('hidden', 'function');
 314          $mform->setType('function', PARAM_PLUGIN);
 315  
 316          $mform->addElement('hidden', 'protocol');
 317          $mform->setType('protocol', PARAM_ALPHA);
 318  
 319  
 320  
 321          $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
 322  
 323          $this->add_action_buttons(true, get_string('execute', 'webservice'));
 324      }
 325  
 326      public function get_params() {
 327          if (!$data = $this->get_data()) {
 328              return null;
 329          }
 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);
 336          unset($data->token);
 337          unset($data->authmethod);
 338  
 339          ///  beginning of specific code to the create users form
 340          $params = array();
 341          $params['userids'] = array();
 342          for ($i=0; $i<10; $i++) {
 343              if (empty($data->userids[$i])) {
 344                  continue;
 345              }
 346              $params['userids'][] = $data->userids[$i];
 347          }
 348          /// end of specific code to the create users function
 349  
 350          return $params;
 351      }
 352  }
 353  
 354  class moodle_group_create_groups_form extends moodleform {
 355      public function definition() {
 356          global $CFG;
 357  
 358          $mform = $this->_form;
 359  
 360  
 361          $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
 362  
 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);
 373          }
 374  
 375          $mform->addElement('hidden', 'authmethod', $data['authmethod']);
 376          $mform->setType('authmethod', PARAM_ALPHA);
 377  
 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);
 386  
 387          $mform->addElement('hidden', 'function');
 388          $mform->setType('function', PARAM_PLUGIN);
 389  
 390          $mform->addElement('hidden', 'protocol');
 391          $mform->setType('protocol', PARAM_ALPHA);
 392  
 393  
 394  
 395          $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
 396  
 397          $this->add_action_buttons(true, get_string('execute', 'webservice'));
 398      }
 399  
 400      public function get_params() {
 401          if (!$data = $this->get_data()) {
 402              return null;
 403          }
 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);
 410          unset($data->token);
 411          unset($data->authmethod);
 412  
 413          $params = array();
 414          $params['groups'] = array();
 415          $params['groups'][] = (array)$data;
 416  
 417          return $params;
 418      }
 419  }
 420  
 421  class moodle_group_get_groups_form extends moodleform {
 422      public function definition() {
 423          global $CFG;
 424  
 425          $mform = $this->_form;
 426  
 427          $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
 428  
 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);
 439          }
 440  
 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);
 448  
 449          $mform->addElement('hidden', 'function');
 450          $mform->setType('function', PARAM_PLUGIN);
 451  
 452          $mform->addElement('hidden', 'protocol');
 453          $mform->setType('protocol', PARAM_ALPHA);
 454  
 455          $this->add_action_buttons(true, get_string('execute', 'webservice'));
 456      }
 457  
 458      public function get_params() {
 459          if (!$data = $this->get_data()) {
 460              return null;
 461          }
 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);
 468          unset($data->token);
 469          unset($data->authmethod);
 470  
 471          $params = array();
 472          $params['groupids'] = array();
 473          for ($i=0; $i<10; $i++) {
 474              if (empty($data->groupids[$i])) {
 475                  continue;
 476              }
 477              $params['groupids'][] = $data->groupids[$i];
 478          }
 479  
 480          return $params;
 481      }
 482  }
 483  
 484  class moodle_group_get_course_groups_form extends moodleform {
 485      public function definition() {
 486          global $CFG;
 487  
 488          $mform = $this->_form;
 489  
 490          $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
 491  
 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);
 502          }
 503  
 504          $mform->addElement('hidden', 'authmethod', $data['authmethod']);
 505          $mform->setType('authmethod', PARAM_ALPHA);
 506          $mform->addElement('text', 'courseid', 'courseid');
 507  
 508          $mform->addElement('hidden', 'function');
 509          $mform->setType('function', PARAM_PLUGIN);
 510  
 511          $mform->addElement('hidden', 'protocol');
 512          $mform->setType('protocol', PARAM_ALPHA);
 513  
 514          $this->add_action_buttons(true, get_string('execute', 'webservice'));
 515      }
 516  
 517      public function get_params() {
 518          if (!$data = $this->get_data()) {
 519              return null;
 520          }
 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);
 527          unset($data->token);
 528          unset($data->authmethod);
 529  
 530          $params = array();
 531          $params['courseid'] = $data->courseid;
 532  
 533          return $params;
 534      }
 535  }
 536  
 537  class moodle_group_delete_groups_form extends moodleform {
 538      public function definition() {
 539          global $CFG;
 540  
 541          $mform = $this->_form;
 542  
 543          $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
 544  
 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);
 555          }
 556  
 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);
 564  
 565          $mform->addElement('hidden', 'function');
 566          $mform->setType('function', PARAM_PLUGIN);
 567  
 568          $mform->addElement('hidden', 'protocol');
 569          $mform->setType('protocol', PARAM_ALPHA);
 570  
 571          $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
 572  
 573          $this->add_action_buttons(true, get_string('execute', 'webservice'));
 574      }
 575  
 576      public function get_params() {
 577          if (!$data = $this->get_data()) {
 578              return null;
 579          }
 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);
 586          unset($data->token);
 587          unset($data->authmethod);
 588  
 589          $params = array();
 590          $params['groupids'] = array();
 591          for ($i=0; $i<10; $i++) {
 592              if (empty($data->groupids[$i])) {
 593                  continue;
 594              }
 595              $params['groupids'][] = $data->groupids[$i];
 596          }
 597  
 598          return $params;
 599      }
 600  }
 601  
 602  class moodle_group_get_groupmembers_form extends moodleform {
 603      public function definition() {
 604          global $CFG;
 605  
 606          $mform = $this->_form;
 607  
 608          $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
 609  
 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);
 620          }
 621  
 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);
 629  
 630          $mform->addElement('hidden', 'function');
 631          $mform->setType('function', PARAM_PLUGIN);
 632  
 633          $mform->addElement('hidden', 'protocol');
 634          $mform->setType('protocol', PARAM_ALPHA);
 635  
 636          $this->add_action_buttons(true, get_string('execute', 'webservice'));
 637      }
 638  
 639      public function get_params() {
 640          if (!$data = $this->get_data()) {
 641              return null;
 642          }
 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);
 649          unset($data->token);
 650          unset($data->authmethod);
 651  
 652          $params = array();
 653          $params['groupids'] = array();
 654          for ($i=0; $i<10; $i++) {
 655              if (empty($data->groupids[$i])) {
 656                  continue;
 657              }
 658              $params['groupids'][] = $data->groupids[$i];
 659          }
 660  
 661          return $params;
 662      }
 663  }
 664  
 665  class moodle_group_add_groupmembers_form extends moodleform {
 666      public function definition() {
 667          global $CFG;
 668  
 669          $mform = $this->_form;
 670  
 671          $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
 672  
 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);
 683          }
 684  
 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);
 693  
 694          $mform->addElement('hidden', 'function');
 695          $mform->setType('function', PARAM_PLUGIN);
 696  
 697          $mform->addElement('hidden', 'protocol');
 698          $mform->setType('protocol', PARAM_ALPHA);
 699  
 700          $this->add_action_buttons(true, get_string('execute', 'webservice'));
 701      }
 702  
 703      public function get_params() {
 704          if (!$data = $this->get_data()) {
 705              return null;
 706          }
 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);
 713          unset($data->token);
 714          unset($data->authmethod);
 715  
 716          $params = array();
 717          $params['members'] = array();
 718          for ($i=0; $i<10; $i++) {
 719              if (empty($data->groupid[$i]) or empty($data->userid[$i])) {
 720                  continue;
 721              }
 722              $params['members'][] = array('userid'=>$data->userid[$i], 'groupid'=>$data->groupid[$i]);
 723          }
 724  
 725          return $params;
 726      }
 727  }
 728  
 729  class moodle_group_delete_groupmembers_form extends moodleform {
 730      public function definition() {
 731          global $CFG;
 732  
 733          $mform = $this->_form;
 734  
 735          $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
 736  
 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);
 747          }
 748  
 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);
 757  
 758          $mform->addElement('hidden', 'function');
 759          $mform->setType('function', PARAM_PLUGIN);
 760  
 761          $mform->addElement('hidden', 'protocol');
 762          $mform->setType('protocol', PARAM_ALPHA);
 763  
 764          $this->add_action_buttons(true, get_string('execute', 'webservice'));
 765      }
 766  
 767      public function get_params() {
 768          if (!$data = $this->get_data()) {
 769              return null;
 770          }
 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);
 777          unset($data->token);
 778          unset($data->authmethod);
 779  
 780          $params = array();
 781          $params['members'] = array();
 782          for ($i=0; $i<10; $i++) {
 783              if (empty($data->groupid[$i]) or empty($data->userid[$i])) {
 784                  continue;
 785              }
 786              $params['members'][] = array('userid'=>$data->userid[$i], 'groupid'=>$data->groupid[$i]);
 787          }
 788  
 789          return $params;
 790      }
 791  }
 792  
 793  /**
 794   * Form class for create_categories() web service function test.
 795   *
 796   * @package   core_webservice
 797   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 798   * @copyright 2012 Fabio Souto
 799   */
 800  class core_course_create_categories_form extends moodleform {
 801      /**
 802       * The form definition.
 803       */
 804      public function definition() {
 805          global $CFG;
 806  
 807          $mform = $this->_form;
 808  
 809          $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
 810  
 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);
 821          }
 822  
 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);
 837  
 838          $mform->addElement('hidden', 'function');
 839          $mform->setType('function', PARAM_PLUGIN);
 840  
 841          $mform->addElement('hidden', 'protocol');
 842          $mform->setType('protocol', PARAM_ALPHA);
 843  
 844          $this->add_action_buttons(true, get_string('execute', 'webservice'));
 845      }
 846  
 847      /**
 848       * Get the parameters that the user submitted using the form.
 849       * @return array|null
 850       */
 851      public function get_params() {
 852          if (!$data = $this->get_data()) {
 853              return null;
 854          }
 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);
 861          unset($data->token);
 862          unset($data->authmethod);
 863  
 864          $params = array();
 865          $params['categories'] = array();
 866          for ($i=0; $i<10; $i++) {
 867              if (empty($data->name[$i]) or empty($data->parent[$i])) {
 868                  continue;
 869              }
 870              $params['categories'][] = array('name'=>$data->name[$i], 'parent'=>$data->parent[$i],
 871                                              'idnumber'=>$data->idnumber[$i], 'description'=>$data->description[$i]);
 872          }
 873          return $params;
 874      }
 875  }
 876  
 877  /**
 878   * Form class for delete_categories() web service function test.
 879   *
 880   * @package   core_webservice
 881   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 882   * @copyright 2012 Fabio Souto
 883   */
 884  class core_course_delete_categories_form extends moodleform {
 885      /**
 886       * The form definition.
 887       */
 888      public function definition() {
 889          global $CFG;
 890  
 891          $mform = $this->_form;
 892  
 893          $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
 894  
 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);
 905          }
 906  
 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);
 918  
 919          $mform->addElement('hidden', 'function');
 920          $mform->setType('function', PARAM_PLUGIN);
 921  
 922          $mform->addElement('hidden', 'protocol');
 923          $mform->setType('protocol', PARAM_ALPHA);
 924  
 925          $this->add_action_buttons(true, get_string('execute', 'webservice'));
 926      }
 927  
 928      /**
 929       * Get the parameters that the user submitted using the form.
 930       * @return array|null
 931       */
 932      public function get_params() {
 933          if (!$data = $this->get_data()) {
 934              return null;
 935          }
 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);
 942          unset($data->token);
 943          unset($data->authmethod);
 944  
 945          $params = array();
 946          $params['categories'] = array();
 947          for ($i=0; $i<10; $i++) {
 948              if (empty($data->id[$i])) {
 949                  continue;
 950              }
 951              $attrs = array();
 952              $attrs['id'] = $data->id[$i];
 953              if (!empty($data->newparent[$i])) {
 954                  $attrs['newparent'] = $data->newparent[$i];
 955              }
 956              if (!empty($data->recursive[$i])) {
 957                  $attrs['recursive'] = $data->recursive[$i];
 958              }
 959              $params['categories'][] = $attrs;
 960          }
 961          return $params;
 962      }
 963  }
 964  
 965  /**
 966   * Form class for create_categories() web service function test.
 967   *
 968   * @package   core_webservice
 969   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 970   * @copyright 2012 Fabio Souto
 971   */
 972  class core_course_update_categories_form extends moodleform {
 973      /**
 974       * The form definition.
 975       */
 976      public function definition() {
 977          global $CFG;
 978  
 979          $mform = $this->_form;
 980  
 981          $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
 982  
 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);
 993          }
 994  
 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);
1012  
1013          $mform->addElement('hidden', 'function');
1014          $mform->setType('function', PARAM_PLUGIN);
1015  
1016          $mform->addElement('hidden', 'protocol');
1017          $mform->setType('protocol', PARAM_ALPHA);
1018  
1019          $this->add_action_buttons(true, get_string('execute', 'webservice'));
1020      }
1021  
1022      /**
1023       * Get the parameters that the user submitted using the form.
1024       * @return array|null
1025       */
1026      public function get_params() {
1027          if (!$data = $this->get_data()) {
1028              return null;
1029          }
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);
1038  
1039          $params = array();
1040          $params['categories'] = array();
1041          for ($i=0; $i<10; $i++) {
1042  
1043              if (empty($data->id[$i])) {
1044                  continue;
1045              }
1046              $attrs = array();
1047              $attrs['id'] = $data->id[$i];
1048              if (!empty($data->name[$i])) {
1049                  $attrs['name'] = $data->name[$i];
1050              }
1051              if (!empty($data->parent[$i])) {
1052                  $attrs['parent'] = $data->parent[$i];
1053              }
1054              if (!empty($data->idnumber[$i])) {
1055                  $attrs['idnumber'] = $data->idnumber[$i];
1056              }
1057              if (!empty($data->description[$i])) {
1058                  $attrs['description'] = $data->description[$i];
1059              }
1060              $params['categories'][] = $attrs;
1061          }
1062          return $params;
1063      }
1064  }

Search This Site: