/** * Class constructor. * * @param ltiservice_toolproxy\local\resource\toolproxy $service Service instance */ public function __construct($service) { parent::__construct($service); $this->id = 'ToolProxy.collection'; $this->template = '/toolproxy'; $this->formats[] = 'application/vnd.ims.lti.v2.toolproxy+json'; $this->methods[] = 'POST'; }
/** * Parse a value for custom parameter substitution variables. * * @param string $value String to be parsed * * @return string */ public function parse_value($value) { global $COURSE, $DB; if ($COURSE->id === SITEID) { $this->params['context_type'] = 'Group'; } else { $this->params['context_type'] = 'CourseSection'; } $this->params['context_id'] = $COURSE->id; $this->params['vendor_code'] = $this->get_service()->get_tool_proxy()->vendorcode; $this->params['product_code'] = $this->get_service()->get_tool_proxy()->guid; $id = optional_param('id', 0, PARAM_INT); // Course Module ID. if (!empty($id)) { $cm = get_coursemodule_from_id('lti', $id, 0, false, IGNORE_MISSING); $lti = $DB->get_record('lti', array('id' => $cm->instance), 'typeid', IGNORE_MISSING); if ($lti && !empty($lti->typeid)) { $this->params['tool_code'] = $lti->typeid; } } $value = str_replace('$ToolProxyBinding.memberships.url', parent::get_endpoint(), $value); return $value; }
/** * Parse a value for custom parameter substitution variables. * * @param string $value String to be parsed * * @return string */ public function parse_value($value) { global $COURSE; if ($COURSE->format == 'site') { $this->params['context_type'] = 'Group'; } else { $this->params['context_type'] = 'CourseSection'; } $this->params['context_id'] = $COURSE->id; $this->params['vendor_code'] = $this->get_service()->get_tool_proxy()->vendorcode; $this->params['product_code'] = $this->get_service()->get_tool_proxy()->guid; $value = str_replace('$ToolProxyBinding.custom.url', parent::get_endpoint(), $value); return $value; }
/** * Parse a value for custom parameter substitution variables. * * @param string $value String to be parsed * * @return string */ public function parse_value($value) { $id = optional_param('id', 0, PARAM_INT); // Course Module ID. if (!empty($id)) { $cm = get_coursemodule_from_id('lti', $id, 0, false, MUST_EXIST); $this->params['link_id'] = $cm->instance; } $value = str_replace('$LtiLink.custom.url', parent::get_endpoint(), $value); return $value; }
/** * Parse a value for custom parameter substitution variables. * * @param string $value String to be parsed * * @return string */ public function parse_value($value) { $value = str_replace('$ToolProxy.custom.url', parent::get_endpoint(), $value); return $value; }
/** * Get the resource fully qualified endpoint. * * @return string */ public function get_endpoint() { return parent::get_endpoint() . '?lti_version=' . service_base::LTI_VERSION2P0; }
/** * Get the JSON representation of the users. * * Note that when a limit is set and the exclude array is not empty, then the number of memberships * returned may be less than the limit. * * @param \mod_lti\local\ltiservice\resource_base $resource Resource handling the request * @param array $users Array of user records * @param string $id Course ID * @param object $tool Tool instance object * @param array $exclude Array of user records to be excluded from the response * @param int $limitfrom Position of first record to be returned * @param int $limitnum Maximum number of records to be returned * @param object $lti LTI instance record * @param \core_availability\info_module $info Conditional availability information for LTI instance * * @return string */ private static function users_to_json($resource, $users, $id, $tool, $exclude, $limitfrom, $limitnum, $lti, $info) { $nextpage = 'null'; if ($limitnum > 0) { $limitfrom += $limitnum; $nextpage = "\"{$resource->get_endpoint()}?limit={$limitnum}&from={$limitfrom}\""; } $json = <<<EOD { "@context" : "http://purl.imsglobal.org/ctx/lis/v2/MembershipContainer", "@type" : "Page", "@id" : "{$resource->get_endpoint()}", "nextPage" : {$nextpage}, "pageOf" : { "@type" : "LISMembershipContainer", "membershipSubject" : { "@type" : "Context", "contextId" : "{$id}", "membership" : [ EOD; $enabledcapabilities = lti_get_enabled_capabilities($tool); $sep = ' '; foreach ($users as $user) { $include = !in_array($user->id, $exclude); if ($include && !empty($info)) { $include = $info->is_user_visible($info->get_course_module(), $user->id); } if ($include) { $member = new \stdClass(); if (in_array('User.id', $enabledcapabilities)) { $member->userId = $user->id; } if (in_array('Person.sourcedId', $enabledcapabilities)) { $member->sourcedId = format_string($user->idnumber); } if (in_array('Person.name.full', $enabledcapabilities)) { $member->name = format_string("{$user->firstname} {$user->lastname}"); } if (in_array('Person.name.given', $enabledcapabilities)) { $member->givenName = format_string($user->firstname); } if (in_array('Person.name.family', $enabledcapabilities)) { $member->familyName = format_string($user->lastname); } if (in_array('Person.email.primary', $enabledcapabilities)) { $member->email = format_string($user->email); } if (in_array('Result.sourcedId', $enabledcapabilities) && !empty($lti) && !empty($lti->servicesalt)) { $member->resultSourcedId = json_encode(lti_build_sourcedid($lti->id, $user->id, $lti->servicesalt, $lti->typeid)); } $roles = explode(',', lti_get_ims_role($user->id, null, $id, true)); $membership = new \stdClass(); $membership->status = 'Active'; $membership->member = $member; $membership->role = $roles; $json .= $sep . json_encode($membership); $sep = ",\n "; } } $json .= <<<EOD ] } } } EOD; return $json; }
/** * Get the JSON representation of the settings. * * @param array $settings Settings * @param boolean $simpleformat <code>true</code> if simple JSON is to be returned * @param string $type JSON-LD type * @param \mod_lti\local\ltiservice\resource_base $resource Resource handling the request * * @return string */ public static function settings_to_json($settings, $simpleformat, $type, $resource) { $json = ''; if (!empty($resource)) { $indent = ''; if (!$simpleformat) { $json .= " {\n \"@type\":\"{$type}\",\n"; $json .= " \"@id\":\"{$resource->get_endpoint()}\",\n"; $json .= ' "custom":'; $json .= "{"; $indent = ' '; } $isfirst = true; if (!empty($settings)) { foreach ($settings as $key => $value) { if (!$isfirst) { $json .= ","; } else { $isfirst = false; } $json .= "\n{$indent} \"{$key}\":\"{$value}\""; } } if (!$simpleformat) { $json .= "\n{$indent}}\n }"; } } return $json; }