/** * Create a new instance of tool_provider to handle all the LTI tool provider interactions. * * @param int $toolid The id of the tool to be provided. */ public function __construct($toolid) { global $CFG, $SITE; $token = helper::generate_proxy_token($toolid); $tool = helper::get_lti_tool($toolid); $this->tool = $tool; $dataconnector = new data_connector(); parent::__construct($dataconnector); // Override debugMode and set to the configured value. $this->debugMode = $CFG->debugdeveloper; $this->baseUrl = $CFG->wwwroot; $toolpath = helper::get_launch_url($toolid); $toolpath = $this->strip_base_url($toolpath); $vendorid = $SITE->shortname; $vendorname = $SITE->fullname; $vendordescription = trim(html_to_text($SITE->summary)); $this->vendor = new Item($vendorid, $vendorname, $vendordescription, $CFG->wwwroot); $name = helper::get_name($tool); $description = helper::get_description($tool); $icon = helper::get_icon($tool)->out(); $icon = $this->strip_base_url($icon); $this->product = new Item($token, $name, $description, helper::get_proxy_url($tool), '1.0'); $requiredmessages = [new Message('basic-lti-launch-request', $toolpath, ['Context.id', 'CourseSection.title', 'CourseSection.label', 'CourseSection.sourcedId', 'CourseSection.longDescription', 'CourseSection.timeFrame.begin', 'ResourceLink.id', 'ResourceLink.title', 'ResourceLink.description', 'User.id', 'User.username', 'Person.name.full', 'Person.name.given', 'Person.name.family', 'Person.email.primary', 'Person.sourcedId', 'Person.name.middle', 'Person.address.street1', 'Person.address.locality', 'Person.address.country', 'Person.address.timezone', 'Person.phone.primary', 'Person.phone.mobile', 'Person.webaddress', 'Membership.role', 'Result.sourcedId', 'Result.autocreate'])]; $optionalmessages = []; $this->resourceHandlers[] = new ResourceHandler(new Item($token, helper::get_name($tool), $description), $icon, $requiredmessages, $optionalmessages); $this->requiredServices[] = new ServiceDefinition(['application/vnd.ims.lti.v2.toolproxy+json'], ['POST']); $this->requiredServices[] = new ServiceDefinition(['application/vnd.ims.lis.v2.membershipcontainer+json'], ['GET']); }
/** * Test getting the cartridge url of a tool. */ public function test_get_proxy_url() { global $CFG; $slasharguments = $CFG->slasharguments; $CFG->slasharguments = false; $course1 = $this->getDataGenerator()->create_course(); $data = new stdClass(); $data->courseid = $course1->id; $tool1 = $this->getDataGenerator()->create_lti_tool($data); $id = $tool1->id; $token = \enrol_lti\helper::generate_proxy_token($id); $launchurl = \enrol_lti\helper::get_proxy_url($tool1); $this->assertEquals('http://www.example.com/moodle/enrol/lti/proxy.php?id=' . $id . '&token=' . $token, $launchurl->out()); $CFG->slasharguments = true; $launchurl = \enrol_lti\helper::get_proxy_url($tool1); $this->assertEquals('http://www.example.com/moodle/enrol/lti/proxy.php/' . $id . '/' . $token . '/', $launchurl->out()); $CFG->slasharguments = $slasharguments; }