Skip to content

Commit

Permalink
Merge pull request #396 from oat-sa/fix/state-as-a-string
Browse files Browse the repository at this point in the history
encode the item state
  • Loading branch information
jsconan committed Mar 24, 2016
2 parents 304e95f + 4227558 commit 21175a7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
'label' => 'QTI test model',
'description' => 'TAO QTI test implementation',
'license' => 'GPL-2.0',
'version' => '2.21.0',
'version' => '2.21.1',
'author' => 'Open Assessment Technologies',
'requires' => array(
'taoTests' => '>=2.13',
Expand Down
18 changes: 15 additions & 3 deletions models/classes/runner/QtiRunnerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,16 @@ public function getItemState(RunnerServiceContext $context, $itemRef)
if ($context instanceof QtiRunnerServiceContext) {
$serviceService = $this->getServiceManager()->get('tao/stateStorage');
$userUri = \common_session_SessionManager::getSession()->getUserUri();
return is_null($userUri) ? null : $serviceService->get($userUri, $itemRef);
$state = is_null($userUri) ? null : $serviceService->get($userUri, $itemRef);

if ($state) {
$state = json_decode($state, true);
if (is_null($state)) {
throw new \common_exception_InconsistentData('Unable to decode the state for the item '.$itemRef);
}
}

return $state;
} else {
throw new \common_exception_InvalidArgumentType('Context must be an instance of QtiRunnerServiceContext');
}
Expand All @@ -446,7 +455,7 @@ public function getItemState(RunnerServiceContext $context, $itemRef)
* Sets the state of a particular item
* @param RunnerServiceContext $context
* @param $itemRef
* @param $state
* @param $state
* @return boolean
* @throws \common_Exception
*/
Expand All @@ -455,7 +464,10 @@ public function setItemState(RunnerServiceContext $context, $itemRef, $state)
if ($context instanceof QtiRunnerServiceContext) {
$serviceService = $this->getServiceManager()->get('tao/stateStorage');
$userUri = \common_session_SessionManager::getSession()->getUserUri();
return is_null($userUri) ? false : $serviceService->set($userUri, $itemRef, $state);
if(!isset($state)){
$state = '';
}
return is_null($userUri) ? false : $serviceService->set($userUri, $itemRef, json_encode($state));
} else {
throw new \common_exception_InvalidArgumentType('Context must be an instance of QtiRunnerServiceContext');
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/update/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,6 @@ public function update($initialVersion) {
$this->setVersion('2.20.0');
}

$this->skip('2.20.0','2.21.0');
$this->skip('2.20.0','2.21.1');
}
}

0 comments on commit 21175a7

Please sign in to comment.