function definition() { global $CFG; $mform = $this->_form; $data = $this->_customdata; $mform->addElement('header', 'addfunction', get_string('addfunctions', 'webservice')); require_once $CFG->dirroot . "/webservice/lib.php"; $webservicemanager = new webservice(); $functions = $webservicemanager->get_not_associated_external_functions($data['id']); //we add the descriptions to the functions foreach ($functions as $functionid => $functionname) { //retrieve full function information (including the description) $function = external_function_info($functionname); $functions[$functionid] = $function->name . ':' . $function->description; } $mform->addElement('searchableselector', 'fids', get_string('name'), $functions, array('multiple')); $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'action'); $mform->setType('action', PARAM_ACTION); $this->add_action_buttons(true, get_string('addfunctions', 'webservice')); $this->set_data($data); }
} foreach ($capabilities as $capability) { assign_capability($capability->name, CAP_ALLOW, $roleid, $context->id, true); } $context->mark_dirty(); // Create a new service with all functions for the user. $webservicemanager = new webservice(); if (!($service = $DB->get_record('external_services', array('shortname' => 'mdk_all')))) { $service = new stdClass(); $service->name = 'MDK: All functions'; $service->shortname = 'mdk_all'; $service->enabled = 1; $service->restrictedusers = 1; $service->downloadfiles = 1; $service->id = $webservicemanager->add_external_service($service); } $functions = $webservicemanager->get_not_associated_external_functions($service->id); foreach ($functions as $function) { $webservicemanager->add_external_function_to_service($function->name, $service->id); } if (!$webservicemanager->get_ws_authorised_user($service->id, $user->id)) { $adduser = new stdClass(); $adduser->externalserviceid = $service->id; $adduser->userid = $user->id; $webservicemanager->add_ws_authorised_user($adduser); } // Generate a token for the user. if (!($token = $DB->get_field('external_tokens', 'token', array('userid' => $user->id, 'externalserviceid' => $service->id)))) { $token = external_generate_token(EXTERNAL_TOKEN_PERMANENT, $service->id, $user->id, $context, 0, ''); } mtrace('User \'webservice\' token: ' . $token);