diff --git a/manifest.php b/manifest.php index d8a88512..dd70f221 100755 --- a/manifest.php +++ b/manifest.php @@ -35,7 +35,7 @@ 'label' => 'LTI library', 'description' => 'TAO LTI library and helpers', 'license' => 'GPL-2.0', - 'version' => '3.2.3', + 'version' => '3.2.4', 'author' => 'Open Assessment Technologies SA', 'requires' => array( 'tao' => '>=10.8.0' diff --git a/models/classes/class.LtiUser.php b/models/classes/class.LtiUser.php index c559bdcb..5d3467d4 100755 --- a/models/classes/class.LtiUser.php +++ b/models/classes/class.LtiUser.php @@ -1,5 +1,4 @@ ltiLaunchData = $ltiLaunchData; + $this->userUri = taoLti_models_classes_LtiService::singleton()->findOrSpawnUser($ltiLaunchData)->getUri(); + $this->roles = $this->determinTaoRoles(); + } + + /** + * @return taoLti_models_classes_LtiLaunchData + */ + public function getLaunchData() { + return $this->ltiLaunchData; + } - /** - * Local represenation of user - * @var core_kernel_classes_Resource - */ - private $userUri; - - /** - * Cache of the current user's lti roles - * @var array - */ - protected $roles; - - public function __construct(taoLti_models_classes_LtiLaunchData $ltiLaunchData) { - $this->ltiLaunchData = $ltiLaunchData; - $this->userUri = taoLti_models_classes_LtiService::singleton()->findOrSpawnUser($ltiLaunchData)->getUri(); - $this->roles = $this->determinTaoRoles(); - } - - /** - * - * @return taoLti_models_classes_LtiLaunchData - */ - public function getLaunchData() { - return $this->ltiLaunchData; - } - - /** - * (non-PHPdoc) - * @see common_user_User::getIdentifier() - */ + /** + * (non-PHPdoc) + * @see common_user_User::getIdentifier() + */ public function getIdentifier() { return $this->userUri; } - - public function getPropertyValues($property) { - $returnValue = null; - switch ($property) { - case PROPERTY_USER_DEFLG : - case PROPERTY_USER_UILG : - $returnValue = array($this->getLanguage()); - break; - case PROPERTY_USER_ROLES : - $returnValue = $this->roles; - break; + + /** + * (non-PHPdoc) + * @see common_user_User::getPropertyValues() + */ + public function getPropertyValues($property) { + $returnValue = null; + switch ($property) { + case PROPERTY_USER_DEFLG : + $returnValue = array(DEFAULT_LANG); + break; + case PROPERTY_USER_UILG : + $returnValue = array($this->getUiLanguage()); + break; + case PROPERTY_USER_ROLES : + $returnValue = $this->roles; + break; case PROPERTY_USER_FIRSTNAME : try { $returnValue = [$this->getLaunchData()->getUserGivenName()]; @@ -95,43 +107,54 @@ public function getPropertyValues($property) { $returnValue = ''; } break; - default: - common_Logger::d('Unkown property '.$property.' requested from '.__CLASS__); - $returnValue = array(); - } - return $returnValue; - } - - public function refresh() { - // nothing to do - } - - private function getLanguage() { - $returnValue = DEFAULT_LANG; - if ($this->getLaunchData()->hasLaunchLanguage()) { - // maping not implemented yet - $returnValue = taoLti_models_classes_LtiUtils::mapCode2InterfaceLanguage($this->getLaunchData()->getLaunchLanguage()); - } - return $returnValue; - } - - private function determinTaoRoles() { + default: + common_Logger::d('Unkown property '.$property.' requested from '.__CLASS__); + $returnValue = array(); + } + return $returnValue; + } + + /** + * (non-PHPdoc) + * @see common_user_User::refresh() + */ + public function refresh() { + // nothing to do + } + + /** + * Returns the validated launch interface language. + * + * @return string + */ + private function getUiLanguage() { + if (is_null($this->uiLanguage)) { + if ($this->getLaunchData()->hasLaunchLanguage()) { + $launchLanguage = $this->getLaunchData()->getLaunchLanguage(); + $this->uiLanguage = taoLti_models_classes_LtiUtils::mapCode2InterfaceLanguage($launchLanguage); + } else { + $this->uiLanguage = DEFAULT_LANG; + } + } + return $this->uiLanguage; + } + + private function determinTaoRoles() { $roles = array(); if ($this->getLaunchData()->hasVariable(taoLti_models_classes_LtiLaunchData::ROLES)) { foreach ($this->getLaunchData()->getUserRoles() as $role) { $taoRole = taoLti_models_classes_LtiUtils::mapLTIRole2TaoRole($role); if (!is_null($taoRole)) { $roles[] = $taoRole; - foreach (core_kernel_users_Service::singleton()->getIncludedRoles(new core_kernel_classes_Resource($taoRole)) as $includedRole) { - $roles[] = $includedRole->getUri(); - } + foreach (core_kernel_users_Service::singleton()->getIncludedRoles(new core_kernel_classes_Resource($taoRole)) as $includedRole) { + $roles[] = $includedRole->getUri(); + } } } - $roles = array_unique($roles); + $roles = array_unique($roles); } else { return array(INSTANCE_ROLE_LTI_BASE); } - return $roles; - } - -} \ No newline at end of file + return $roles; + } +} diff --git a/models/classes/class.LtiUtils.php b/models/classes/class.LtiUtils.php index a99baec6..0fd1e144 100755 --- a/models/classes/class.LtiUtils.php +++ b/models/classes/class.LtiUtils.php @@ -95,11 +95,20 @@ public static function mapTaoRole2LTIRoles($roleUri) * not yet implemented, will always use default * * @param string $code + * * @return string */ public static function mapCode2InterfaceLanguage($code) { - $returnValue = DEFAULT_LANG; - return $returnValue; + if (!empty($code)) { + $languageService = tao_models_classes_LanguageService::singleton(); + $usage = new core_kernel_classes_Resource(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; } -} \ No newline at end of file +} diff --git a/models/classes/class.TaoLtiSession.php b/models/classes/class.TaoLtiSession.php index 8b49b9eb..ecd9ef7b 100755 --- a/models/classes/class.TaoLtiSession.php +++ b/models/classes/class.TaoLtiSession.php @@ -106,29 +106,4 @@ public function getLtiLinkResource() } return $this->ltiLink; } - - /** - * Returns the interface language. - * - * Priority: Launcher passed language > Parent language determination - * - * @return string - */ - public function getInterfaceLanguage() - { - - if($this->getLaunchData()->hasLaunchLanguage()){ - $launchLanguage = (string)$this->getLaunchData()->getLaunchLanguage(); - if (!empty($launchLanguage)) { - $languageService = tao_models_classes_LanguageService::singleton(); - $usage = new core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_GUI); - if ($languageService->isLanguageAvailable($launchLanguage, $usage)) { - return $launchLanguage; - } - \common_Logger::d('[Fallback] Language is unavailable: ' . $launchLanguage); - } - } - return parent::getInterfaceLanguage(); - } - -} \ No newline at end of file +} diff --git a/scripts/update/class.Updater.php b/scripts/update/class.Updater.php index 50c675bf..3fbab2b0 100755 --- a/scripts/update/class.Updater.php +++ b/scripts/update/class.Updater.php @@ -74,6 +74,6 @@ public function update($initialVersion) $this->setVersion('2.1.0'); } - $this->skip('2.1.0', '3.2.3'); + $this->skip('2.1.0', '3.2.4'); } }