[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 /** 32 * Form class for create_categories() web service function test. 33 * 34 * @package core_webservice 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 * @copyright 2012 Fabio Souto 37 */ 38 class core_course_create_categories_form extends moodleform { 39 /** 40 * The form definition. 41 */ 42 public function definition() { 43 global $CFG; 44 45 $mform = $this->_form; 46 47 $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice')); 48 49 // Note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters. 50 $data = $this->_customdata; 51 if ($data['authmethod'] == 'simple') { 52 $mform->addElement('text', 'wsusername', 'wsusername'); 53 $mform->setType('wsusername', core_user::get_property_type('username')); 54 $mform->addElement('text', 'wspassword', 'wspassword'); 55 $mform->setType('wspassword', core_user::get_property_type('password')); 56 } else if ($data['authmethod'] == 'token') { 57 $mform->addElement('text', 'token', 'token'); 58 $mform->setType('token', PARAM_RAW_TRIMMED); 59 } 60 61 $mform->addElement('hidden', 'authmethod', $data['authmethod']); 62 $mform->setType('authmethod', core_user::get_property_type('auth')); 63 $mform->addElement('text', 'name[0]', 'name[0]'); 64 $mform->addElement('text', 'parent[0]', 'parent[0]'); 65 $mform->addElement('text', 'idnumber[0]', 'idnumber[0]'); 66 $mform->addElement('text', 'description[0]', 'description[0]'); 67 $mform->addElement('text', 'name[1]', 'name[1]'); 68 $mform->addElement('text', 'parent[1]', 'parent[1]'); 69 $mform->addElement('text', 'idnumber[1]', 'idnumber[1]'); 70 $mform->addElement('text', 'description[1]', 'description[1]'); 71 $mform->setType('name', core_user::get_property_type('firstname')); 72 $mform->setType('parent', core_user::get_property_type('id')); 73 $mform->setType('idnumber', core_user::get_property_type('idnumber')); 74 $mform->setType('description', core_user::get_property_type('description')); 75 76 $mform->addElement('hidden', 'function'); 77 $mform->setType('function', PARAM_PLUGIN); 78 79 $mform->addElement('hidden', 'protocol'); 80 $mform->setType('protocol', PARAM_ALPHA); 81 82 $this->add_action_buttons(true, get_string('execute', 'webservice')); 83 } 84 85 /** 86 * Get the parameters that the user submitted using the form. 87 * @return array|null 88 */ 89 public function get_params() { 90 if (!$data = $this->get_data()) { 91 return null; 92 } 93 // Remove unused from form data. 94 unset($data->submitbutton); 95 unset($data->protocol); 96 unset($data->function); 97 unset($data->wsusername); 98 unset($data->wspassword); 99 unset($data->token); 100 unset($data->authmethod); 101 102 $params = array(); 103 $params['categories'] = array(); 104 for ($i=0; $i<10; $i++) { 105 if (empty($data->name[$i]) or empty($data->parent[$i])) { 106 continue; 107 } 108 $params['categories'][] = array('name'=>$data->name[$i], 'parent'=>$data->parent[$i], 109 'idnumber'=>$data->idnumber[$i], 'description'=>$data->description[$i]); 110 } 111 return $params; 112 } 113 } 114 115 /** 116 * Form class for delete_categories() web service function test. 117 * 118 * @package core_webservice 119 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 120 * @copyright 2012 Fabio Souto 121 */ 122 class core_course_delete_categories_form extends moodleform { 123 /** 124 * The form definition. 125 */ 126 public function definition() { 127 global $CFG; 128 129 $mform = $this->_form; 130 131 $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice')); 132 133 // Note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters. 134 $data = $this->_customdata; 135 if ($data['authmethod'] == 'simple') { 136 $mform->addElement('text', 'wsusername', 'wsusername'); 137 $mform->setType('wsusername', core_user::get_property_type('username')); 138 $mform->addElement('text', 'wspassword', 'wspassword'); 139 $mform->setType('wspassword', core_user::get_property_type('password')); 140 } else if ($data['authmethod'] == 'token') { 141 $mform->addElement('text', 'token', 'token'); 142 $mform->setType('token', PARAM_RAW_TRIMMED); 143 } 144 145 $mform->addElement('hidden', 'authmethod', $data['authmethod']); 146 $mform->setType('authmethod', core_user::get_property_type('auth')); 147 $mform->addElement('text', 'id[0]', 'id[0]'); 148 $mform->addElement('text', 'newparent[0]', 'newparent[0]'); 149 $mform->addElement('text', 'recursive[0]', 'recursive[0]'); 150 $mform->addElement('text', 'id[1]', 'id[1]'); 151 $mform->addElement('text', 'newparent[1]', 'newparent[1]'); 152 $mform->addElement('text', 'recursive[1]', 'recursive[1]'); 153 $mform->setType('id', core_user::get_property_type('id')); 154 $mform->setType('newparent', PARAM_INT); 155 $mform->setType('recursive', PARAM_BOOL); 156 157 $mform->addElement('hidden', 'function'); 158 $mform->setType('function', PARAM_PLUGIN); 159 160 $mform->addElement('hidden', 'protocol'); 161 $mform->setType('protocol', PARAM_ALPHA); 162 163 $this->add_action_buttons(true, get_string('execute', 'webservice')); 164 } 165 166 /** 167 * Get the parameters that the user submitted using the form. 168 * @return array|null 169 */ 170 public function get_params() { 171 if (!$data = $this->get_data()) { 172 return null; 173 } 174 // Remove unused from form data. 175 unset($data->submitbutton); 176 unset($data->protocol); 177 unset($data->function); 178 unset($data->wsusername); 179 unset($data->wspassword); 180 unset($data->token); 181 unset($data->authmethod); 182 183 $params = array(); 184 $params['categories'] = array(); 185 for ($i=0; $i<10; $i++) { 186 if (empty($data->id[$i])) { 187 continue; 188 } 189 $attrs = array(); 190 $attrs['id'] = $data->id[$i]; 191 if (!empty($data->newparent[$i])) { 192 $attrs['newparent'] = $data->newparent[$i]; 193 } 194 if (!empty($data->recursive[$i])) { 195 $attrs['recursive'] = $data->recursive[$i]; 196 } 197 $params['categories'][] = $attrs; 198 } 199 return $params; 200 } 201 } 202 203 /** 204 * Form class for create_categories() web service function test. 205 * 206 * @package core_webservice 207 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 208 * @copyright 2012 Fabio Souto 209 */ 210 class core_course_update_categories_form extends moodleform { 211 /** 212 * The form definition. 213 */ 214 public function definition() { 215 global $CFG; 216 217 $mform = $this->_form; 218 219 $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice')); 220 221 // Note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters. 222 $data = $this->_customdata; 223 if ($data['authmethod'] == 'simple') { 224 $mform->addElement('text', 'wsusername', 'wsusername'); 225 $mform->setType('wsusername', core_user::get_property_type('username')); 226 $mform->addElement('text', 'wspassword', 'wspassword'); 227 $mform->setType('wspassword', core_user::get_property_type('password')); 228 } else if ($data['authmethod'] == 'token') { 229 $mform->addElement('text', 'token', 'token'); 230 $mform->setType('token', PARAM_RAW_TRIMMED); 231 } 232 233 $mform->addElement('hidden', 'authmethod', $data['authmethod']); 234 $mform->setType('authmethod', core_user::get_property_type('auth')); 235 $mform->addElement('text', 'id[0]', 'id[0]'); 236 $mform->addElement('text', 'name[0]', 'name[0]'); 237 $mform->addElement('text', 'parent[0]', 'parent[0]'); 238 $mform->addElement('text', 'idnumber[0]', 'idnumber[0]'); 239 $mform->addElement('text', 'description[0]', 'description[0]'); 240 $mform->addElement('text', 'id[1]', 'id[1]'); 241 $mform->addElement('text', 'name[1]', 'name[1]'); 242 $mform->addElement('text', 'parent[1]', 'parent[1]'); 243 $mform->addElement('text', 'idnumber[1]', 'idnumber[1]'); 244 $mform->addElement('text', 'description[1]', 'description[1]'); 245 $mform->setType('id', core_user::get_property_type('id')); 246 $mform->setType('name', core_user::get_property_type('firstname')); 247 $mform->setType('parent', PARAM_INT); 248 $mform->setType('idnumber', core_user::get_property_type('idnumber')); 249 $mform->setType('description', core_user::get_property_type('description')); 250 251 $mform->addElement('hidden', 'function'); 252 $mform->setType('function', PARAM_PLUGIN); 253 254 $mform->addElement('hidden', 'protocol'); 255 $mform->setType('protocol', PARAM_ALPHA); 256 257 $this->add_action_buttons(true, get_string('execute', 'webservice')); 258 } 259 260 /** 261 * Get the parameters that the user submitted using the form. 262 * @return array|null 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 277 $params = array(); 278 $params['categories'] = array(); 279 for ($i=0; $i<10; $i++) { 280 281 if (empty($data->id[$i])) { 282 continue; 283 } 284 $attrs = array(); 285 $attrs['id'] = $data->id[$i]; 286 if (!empty($data->name[$i])) { 287 $attrs['name'] = $data->name[$i]; 288 } 289 if (!empty($data->parent[$i])) { 290 $attrs['parent'] = $data->parent[$i]; 291 } 292 if (!empty($data->idnumber[$i])) { 293 $attrs['idnumber'] = $data->idnumber[$i]; 294 } 295 if (!empty($data->description[$i])) { 296 $attrs['description'] = $data->description[$i]; 297 } 298 $params['categories'][] = $attrs; 299 } 300 return $params; 301 } 302 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |