. /** * Web services admin UI forms * * @package webservice * @copyright 2009 Moodle Pty Ltd (http://moodle.com) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once $CFG->libdir.'/formslib.php'; class external_service_form extends moodleform { function definition() { global $CFG, $USER; $mform = $this->_form; $service = $this->_customdata; $mform->addElement('header', 'extservice', get_string('externalservice', 'webservice')); $mform->addElement('text', 'name', get_string('name')); $mform->addRule('name', get_string('required'), 'required', null, 'client'); $mform->addElement('advcheckbox', 'enabled', get_string('enabled', 'webservice')); // Prepare the list of capabilites to choose from $systemcontext = get_context_instance(CONTEXT_SYSTEM); $allcapabilities = fetch_context_capabilities($systemcontext); $capabilitychoices = array(); $capabilitychoices['norequiredcapability'] = get_string('norequiredcapability', 'webservice'); foreach ($allcapabilities as $cap) { $capabilitychoices[$cap->name] = $cap->name . ': ' . get_capability_string($cap->name); } $mform->addElement('searchableselector', 'requiredcapability', get_string('requiredcapability', 'webservice'),$capabilitychoices, array('size' => 12)); // TODO: change to capability selection or even better if new forms element used, // we also need to indicate if current capability does not exist in system! $mform->addElement('advcheckbox', 'restrictedusers', get_string('restrictedusers', 'webservice')); $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); $this->add_action_buttons(true); ///this three lines are needed to select automatically the 'No required capability" option if (empty($service->requiredcapability)) { $service->requiredcapability = "norequiredcapability"; } $this->set_data($service); } function definition_after_data() { $mform = $this->_form; $service = $this->_customdata; if (!empty($service->component)) { // built-in components must not be modified except the enabled flag!! $mform->hardFreeze('name,requiredcapability,restrictedusers'); } } function validation($data, $files) { $errors = parent::validation($data, $files); //TODO: better make sure the service name is unique return $errors; } }