/** * Creates a tool type. * * @param string $cartridgeurl Url of the xml cartridge representing the LTI tool * @param string $key The consumer key to identify this consumer * @param string $secret The secret * @return array created tool type * @since Moodle 3.1 * @throws moodle_exception If the tool type could not be created */ public static function create_tool_type($cartridgeurl, $key, $secret) { $params = self::validate_parameters(self::create_tool_type_parameters(), array('cartridgeurl' => $cartridgeurl, 'key' => $key, 'secret' => $secret)); $cartridgeurl = $params['cartridgeurl']; $key = $params['key']; $secret = $params['secret']; $context = context_system::instance(); self::validate_context($context); require_capability('moodle/site:config', $context); $id = null; if (!empty($cartridgeurl)) { $type = new stdClass(); $data = new stdClass(); $type->state = LTI_TOOL_STATE_CONFIGURED; $data->lti_coursevisible = 1; $data->lti_sendname = LTI_SETTING_DELEGATE; $data->lti_sendemailaddr = LTI_SETTING_DELEGATE; $data->lti_acceptgrades = LTI_SETTING_DELEGATE; $data->lti_forcessl = 0; if (!empty($key)) { $data->lti_resourcekey = $key; } if (!empty($secret)) { $data->lti_password = $secret; } lti_load_type_from_cartridge($cartridgeurl, $data); if (empty($data->lti_toolurl)) { throw new moodle_exception('unabletocreatetooltype', 'mod_lti'); } else { $id = lti_add_type($type, $data); } } if (!empty($id)) { $type = lti_get_type($id); return serialise_tool_type($type); } else { throw new moodle_exception('unabletocreatetooltype', 'mod_lti'); } }
/** * Loads the cartridge information into the tool type, if the launch url is for a cartridge file * * @param stdClass $type The tool type object to be filled in * @since Moodle 3.1 */ function lti_load_type_if_cartridge($type) { if (!empty($type->lti_toolurl) && lti_is_cartridge($type->lti_toolurl)) { lti_load_type_from_cartridge($type->lti_toolurl, $type); } }
* @author Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once '../../config.php'; require_once $CFG->libdir . '/adminlib.php'; require_once $CFG->dirroot . '/mod/lti/lib.php'; require_once $CFG->dirroot . '/mod/lti/locallib.php'; $cartridgeurl = optional_param('cartridgeurl', '', PARAM_URL); // No guest autologin. require_login(0, false); admin_externalpage_setup('ltitoolconfigure'); if ($cartridgeurl) { $type = new stdClass(); $data = new stdClass(); $type->state = LTI_TOOL_STATE_CONFIGURED; $data->lti_coursevisible = 1; lti_load_type_from_cartridge($cartridgeurl, $data); lti_add_type($type, $data); } $pageurl = new moodle_url('/mod/lti/toolconfigure.php'); $PAGE->set_url($pageurl); $PAGE->set_title("{$SITE->shortname}: " . get_string('toolregistration', 'mod_lti')); $PAGE->requires->string_for_js('success', 'moodle'); $PAGE->requires->string_for_js('error', 'moodle'); $PAGE->requires->string_for_js('successfullycreatedtooltype', 'mod_lti'); $PAGE->requires->string_for_js('failedtocreatetooltype', 'mod_lti'); $output = $PAGE->get_renderer('mod_lti'); echo $output->header(); $page = new \mod_lti\output\tool_configure_page(); echo $output->render($page); echo $output->footer();