* */ class LtiUtils { const LIS_CONTEXT_ROLE_NAMESPACE = 'urn:lti:role:ims/lis/'; /** * Maps a fuly qualified or abbreviated lti role * to an existing tao role * * @param string $role * @throws common_Exception * @throws common_exception_Error * @return core_kernel_classes_Resource the tao role or null */ public static function mapLTIRole2TaoRole($role) { $taoRole = null; if (filter_var($role, FILTER_VALIDATE_URL)) { // url found $taoRole = new core_kernel_classes_Resource($role); } else { // if not fully qualified prepend LIS context role NS if (strtolower(substr($role, 0, 4)) !== 'urn:') { $role = self::LIS_CONTEXT_ROLE_NAMESPACE . $role; } list ($prefix, $nid, $nss) = explode(':', $role, 3); if ($nid != 'lti') { common_Logger::w('Non LTI URN ' . $role . ' passed via LTI'); } $urn = 'urn:' . strtolower($nid) . ':' . $nss; // search for fitting role $class = new core_kernel_classes_Class(LtiRoles::CLASS_URI); $cand = $class->searchInstances([ LtiRoles::PROPERTY_URN => $urn ]); if (count($cand) > 1) { throw new common_exception_Error('Multiple instances share the URN ' . $urn); } if (count($cand) == 1) { $taoRole = current($cand); } else { common_Logger::w('Unknown LTI role with urn: ' . $urn); } } if (!is_null($taoRole) && $taoRole->exists()) { return $taoRole->getUri(); } else { return null; } } /** * Adds the LTI roles to the tao roles * * @param string $roleUri * @return array */ public static function mapTaoRole2LTIRoles($roleUri) { $roles = [$roleUri]; if ($roleUri == 'http://www.tao.lu/Ontologies/TAO.rdf#DeliveryRole') { $roles[] = 'http://www.imsglobal.org/imspurl/lis/v1/vocab/membership#Learner'; } return $roles; } /** * Returns the tao language code that corresponds to the code provided * not yet implemented, will always use default * * @param string $code * * @return string * @throws common_exception_Error */ public static function mapCode2InterfaceLanguage($code) { if (!empty($code)) { $languageService = tao_models_classes_LanguageService::singleton(); $usage = new core_kernel_classes_Resource(tao_models_classes_LanguageService::INSTANCE_LANGUAGE_USAGE_GUI); if ($languageService->isLanguageAvailable($code, $usage)) { return $code; } \common_Logger::d('[Fallback] The provided launch language is unavailable: ' . $code); } return DEFAULT_LANG; } }