Esempio n. 1
0
 /**
  * Creates a new tool proxy
  *
  * @param string $name Tool proxy name
  * @param string $registrationurl Registration url
  * @param string[] $capabilityoffered List of capabilities this tool proxy should be offered
  * @param string[] $serviceoffered List of services this tool proxy should be offered
  * @return object The new tool proxy
  * @since Moodle 3.1
  * @throws moodle_exception
  */
 public static function create_tool_proxy($name, $registrationurl, $capabilityoffered, $serviceoffered)
 {
     $params = self::validate_parameters(self::create_tool_proxy_parameters(), array('name' => $name, 'regurl' => $registrationurl, 'capabilityoffered' => $capabilityoffered, 'serviceoffered' => $serviceoffered));
     $name = $params['name'];
     $regurl = $params['regurl'];
     $capabilityoffered = $params['capabilityoffered'];
     $serviceoffered = $params['serviceoffered'];
     $context = context_system::instance();
     self::validate_context($context);
     require_capability('moodle/site:config', $context);
     // Can't create duplicate proxies with the same URL.
     $duplicates = lti_get_tool_proxies_from_registration_url($registrationurl);
     if (!empty($duplicates)) {
         throw new moodle_exception('duplicateregurl', 'mod_lti');
     }
     $config = new stdClass();
     $config->lti_registrationurl = $registrationurl;
     if (!empty($name)) {
         $config->lti_registrationname = $name;
     }
     if (!empty($capabilityoffered)) {
         $config->lti_capabilities = $capabilityoffered;
     }
     if (!empty($serviceoffered)) {
         $config->lti_services = $serviceoffered;
     }
     $id = lti_add_tool_proxy($config);
     $toolproxy = lti_get_tool_proxy($id);
     // Pending makes more sense than configured as the first state, since
     // the next step is to register, which requires the state be pending.
     $toolproxy->state = LTI_TOOL_PROXY_STATE_PENDING;
     lti_update_tool_proxy($toolproxy);
     return $toolproxy;
 }
Esempio n. 2
0
if ($action == 'delete') {
    lti_delete_tool_proxy($id);
    redirect($redirect);
}

$data = array();
if ($isupdate) {
    $data['isupdate'] = true;
}

$form = new mod_lti_register_types_form($pageurl, (object)$data);

if ($form->is_cancelled()) {
    redirect($redirect);
} else if ($data = $form->get_data()) {
    $id = lti_add_tool_proxy($data);
    redirect($redirect);
} else {
    $PAGE->set_title("{$SITE->shortname}: " . get_string('toolregistration', 'lti'));
    $PAGE->navbar->add(get_string('lti_administration', 'lti'), $redirect);

    echo $OUTPUT->header();
    echo $OUTPUT->heading(get_string('toolregistration', 'lti'));
    echo $OUTPUT->box_start('generalbox');
    if ($action == 'update') {
        $toolproxy = lti_get_tool_proxy_config($id);
        $form->set_data($toolproxy);
        if ($toolproxy->state == LTI_TOOL_PROXY_STATE_ACCEPTED) {
            $form->disable_fields();
        } else {
            $form->required_fields();