/** * Parse a custom parameter to replace any substitution variables * * @param object $toolproxy Tool proxy instance object * @param object $tool Tool instance object * @param array $params LTI launch parameters * @param string $value Custom parameter value * @param boolean $islti2 True if an LTI 2 tool is being launched * * @return Parsed value of custom parameter */ function lti_parse_custom_parameter($toolproxy, $tool, $params, $value, $islti2) { global $USER, $COURSE; if ($value) { if (substr($value, 0, 1) == '\\') { $value = substr($value, 1); } else { if (substr($value, 0, 1) == '$') { $value1 = substr($value, 1); $enabledcapabilities = lti_get_enabled_capabilities($tool); if (!$islti2 || in_array($value1, $enabledcapabilities)) { $capabilities = lti_get_capabilities(); if (array_key_exists($value1, $capabilities)) { $val = $capabilities[$value1]; if ($val) { if (substr($val, 0, 1) != '$') { $value = $params[$val]; } else { $valarr = explode('->', substr($val, 1), 2); $value = "{${$valarr[0]}->{$valarr[1]}}"; $value = str_replace('<br />', ' ', $value); $value = str_replace('<br>', ' ', $value); $value = format_string($value); } } } else { if ($islti2) { $val = $value; $services = lti_get_services(); foreach ($services as $service) { $service->set_tool_proxy($toolproxy); $value = $service->parse_value($val); if ($val != $value) { break; } } } } } } } } return $value; }
/** * Returns a summary of each LTI capability this tool type requires in plain language * * @param stdClass $type The tool type * * @return array An array of text descriptions of each of the capabilities this tool type requires */ function get_tool_type_capability_groups($type) { $capabilities = lti_get_enabled_capabilities($type); $groups = array(); $hascourse = false; $hasactivities = false; $hasuseraccount = false; $hasuserpersonal = false; foreach ($capabilities as $capability) { // Bail out early if we've already found all groups. if (count($groups) >= 4) { continue; } if (!$hascourse && preg_match('/^CourseSection/', $capability)) { $hascourse = true; $groups[] = get_string('courseinformation', 'mod_lti'); } else { if (!$hasactivities && preg_match('/^ResourceLink/', $capability)) { $hasactivities = true; $groups[] = get_string('courseactivitiesorresources', 'mod_lti'); } else { if (!$hasuseraccount && preg_match('/^User/', $capability) || preg_match('/^Membership/', $capability)) { $hasuseraccount = true; $groups[] = get_string('useraccountinformation', 'mod_lti'); } else { if (!$hasuserpersonal && preg_match('/^Person/', $capability)) { $hasuserpersonal = true; $groups[] = get_string('userpersonalinformation', 'mod_lti'); } } } } } return $groups; }
/** * 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; }