Skip to content

Commit

Permalink
Merge pull request #64 from oat-sa/feature/missing-varibale-exception
Browse files Browse the repository at this point in the history
Custom exception on missing data
  • Loading branch information
antoinerobin authored May 12, 2017
2 parents 367923d + db1bc0a commit 91a5f3e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 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.0.0',
'version' => '3.1.0',
'author' => 'Open Assessment Technologies SA',
'requires' => array(
'tao' => '>=9.0.0'
Expand Down
35 changes: 35 additions & 0 deletions models/classes/LtiVariableMissingException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2017 (original work) Open Assessment Technologies SA
*
*/
namespace oat\taoLti\models\classes;

use oat\taoLti\models\classes\LtiMessages\LtiErrorMessage;

class LtiVariableMissingException extends \taoLti_models_classes_LtiException
implements \common_log_SeverityLevel
{
public function __construct($variableName)
{
parent::__construct('Undefined LTI variable '.$variableName, LtiErrorMessage::ERROR_MISSING_PARAMETER);
}

public function getSeverity() {
return \common_Logger::DEBUG_LEVEL;
}
}
4 changes: 2 additions & 2 deletions models/classes/class.LtiLaunchData.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
*/

use oat\taoLti\models\classes\LtiMessages\LtiErrorMessage;
use oat\taoLti\models\classes\LtiVariableMissingException;

class taoLti_models_classes_LtiLaunchData
{
Expand Down Expand Up @@ -114,7 +114,7 @@ public function getVariable($key) {
if (isset($this->variables[$key])) {
return $this->variables[$key];
} else {
throw new taoLti_models_classes_LtiException('Undefined LTI variable '.$key, LtiErrorMessage::ERROR_MISSING_PARAMETER);
throw new LtiVariableMissingException($key);
}
}

Expand Down
13 changes: 11 additions & 2 deletions models/classes/class.LtiUser.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?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 Down Expand Up @@ -81,10 +82,18 @@ public function getPropertyValues($property) {
$returnValue = $this->roles;
break;
case PROPERTY_USER_FIRSTNAME :
$returnValue = [$this->getLaunchData()->getUserGivenName()];
try {
$returnValue = [$this->getLaunchData()->getUserGivenName()];
} catch (LtiVariableMissingException $e) {
$returnValue = '';
}
break;
case PROPERTY_USER_LASTNAME :
$returnValue = [$this->getLaunchData()->getUserFamilyName()];
try {
$returnValue = [$this->getLaunchData()->getUserFamilyName()];
} catch (LtiVariableMissingException $e) {
$returnValue = '';
}
break;
default:
common_Logger::d('Unkown property '.$property.' requested from '.__CLASS__);
Expand Down
2 changes: 1 addition & 1 deletion scripts/update/class.Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ public function update($initialVersion)

$this->setVersion('2.1.0');
}
$this->skip('2.1.0', '3.0.0');
$this->skip('2.1.0', '3.1.0');
}
}

0 comments on commit 91a5f3e

Please sign in to comment.