diff --git a/src/qtism/data/storage/php/marshalling/PhpQtiDatatypeMarshaller.php b/src/qtism/data/storage/php/marshalling/PhpQtiDatatypeMarshaller.php index 6e6202ae2..eeaaa4c70 100644 --- a/src/qtism/data/storage/php/marshalling/PhpQtiDatatypeMarshaller.php +++ b/src/qtism/data/storage/php/marshalling/PhpQtiDatatypeMarshaller.php @@ -30,6 +30,7 @@ use qtism\common\datatypes\Duration; use qtism\common\datatypes\Pair; use qtism\common\datatypes\Coords; +use qtism\common\datatypes\Identifier; use qtism\common\datatypes\QtiDatatype; /** @@ -65,6 +66,10 @@ public function marshall() } elseif ($toMarshall instanceof Point) { $this->marshallPoint(); + return; + } else if ($toMarshall instanceof Identifier) { + $this->marshallIdentifier(); + return; } } catch (PhpMarshallingException $e) { @@ -184,6 +189,32 @@ protected function marshallDuration() throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e); } } + + /** + * Marshall an Identifier QTI datatype object. + * + * @throws \qtism\data\storage\php\marshalling\PhpMarshallingException + */ + protected function marshallIdentifier() + { + $identifier = $this->getToMarshall(); + $ctx = $this->getContext(); + $access = $ctx->getStreamAccess(); + + try { + $varName = $ctx->generateVariableName($identifier); + $access->writeVariable($varName); + $access->writeEquals($ctx->mustFormatOutput()); + $args = new PhpArgumentCollection(array(new PhpArgument($identifier->getValue()))); + $access->writeInstantiation(get_class($identifier), $args); + $access->writeSemicolon($ctx->mustFormatOutput()); + + $ctx->pushOnVariableStack($varName); + } catch (StreamAccessException $e) { + $msg = "An error occured while marshalling an Identifier object into the PHP source code stream."; + throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e); + } + } /** * Marshall a Point QTI datatype object.