Skip to content

Commit

Permalink
Merge pull request #79 from oat-sa/release-3.2.4
Browse files Browse the repository at this point in the history
Release 3.2.4
  • Loading branch information
Jérôme Bogaerts authored Jul 21, 2017
2 parents 229184f + 917a5c0 commit 0d31fcc
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 104 deletions.
2 changes: 1 addition & 1 deletion manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
169 changes: 96 additions & 73 deletions models/classes/class.LtiUser.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
use oat\taoLti\models\classes\LtiVariableMissingException;
/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand All @@ -19,6 +18,7 @@
*
*
*/
use oat\taoLti\models\classes\LtiVariableMissingException;

/**
* Authentication adapter interface to be implemented by authentication methodes
Expand All @@ -29,58 +29,70 @@
*/
class taoLti_models_classes_LtiUser
extends common_user_User
extends common_user_User
{
/**
* Data with which this session was launched
* @var taoLti_models_classes_LtiLaunchData
*/
private $ltiLaunchData;
private $ltiLaunchData;

/**
* Local represenation of user
* @var core_kernel_classes_Resource
*/
private $userUri;

/**
* Cache of the current user's lti roles
* @var array
*/
protected $roles;

/**
* Currently used UI languages.
*
* @var array
*/
protected $uiLanguage;

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;
}

/**
* 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()];
Expand All @@ -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;
}

}
return $roles;
}
}
15 changes: 12 additions & 3 deletions models/classes/class.LtiUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
27 changes: 1 addition & 26 deletions models/classes/class.TaoLtiSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
}
2 changes: 1 addition & 1 deletion scripts/update/class.Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

0 comments on commit 0d31fcc

Please sign in to comment.