protected static function dataModelValuesToRuntime(ValueCollection $valueCollection, $baseType, $cardinality)
    {
        // Cardinality?
        // -> Single? Multiple? Ordered? Record?
        if ($cardinality === Cardinality::SINGLE) {
            // We should find a single value in the DefaultValue's values.
            if (count($valueCollection) == 1) {
                $dataModelValue = RuntimeUtils::valueToRuntime($valueCollection[0]->getValue(), $baseType);

                return $dataModelValue;
            } else {
                // The Data Model is in an inconsistent state.
                // This should be handled by the Data Model but
                // I prefer to be defensive.
                $msg = "A Data Model VariableDeclaration with 'single' cardinality must contain a single value, ";
                $msg .= count($valueCollection) . " value(s) found.";
                throw new UnexpectedValueException($msg);
            }
        } else {
            // Multiple|Ordered|Record, use a container.
            $container = null;

            try {
                // Create the appropriate Container object.
                $className = ucfirst(Cardinality::getNameByConstant($cardinality)) . 'Container';
                $nsClassName = 'qtism\\runtime\\common\\' . $className;
                $callback = array($nsClassName , 'createFromDataModel');
                $container = call_user_func_array($callback, array($valueCollection, $baseType));

                return $container; // return container.
            } catch (InvalidArgumentException $e) {
                $msg = "The default value found in the Data Model Variable Declaration is not consistent. ";
                $msg.= "The values must have a baseType compliant with the baseType of the VariableDeclaration.";
                $msg.= "If the VariableDeclaration's cardinality is 'record', make sure the values it contains have ";
                $msg.= "fieldIdentifiers.";

                throw new UnexpectedValueException($msg, 0, $e);
            }
        }
    }
protected static function dataModelValuesToRuntime(ValueCollection $valueCollection, $baseType, $cardinality)
    {
        // Cardinality?
        // -> Single? Multiple? Ordered? Record?
        if ($cardinality === Cardinality::SINGLE) {
            // We should find a single value in the DefaultValue's values.
            if (count($valueCollection) == 1) {
                $dataModelValue = RuntimeUtils::valueToRuntime($valueCollection[0]->getValue(), $baseType);

                return $dataModelValue;
            } else {
                // The Data Model is in an inconsistent state.
                // This should be handled by the Data Model but
                // I prefer to be defensive.
                $msg = "A Data Model VariableDeclaration with 'single' cardinality must contain a single value, ";
                $msg .= count($valueCollection) . " value(s) found.";
                throw new UnexpectedValueException($msg);
            }
        } else {
            // Multiple|Ordered|Record, use a container.
            $container = null;

            try {
                // Create the appropriate Container object.
                $className = ucfirst(Cardinality::getNameByConstant($cardinality)) . 'Container';
                $nsClassName = 'qtism\\runtime\\common\\' . $className;
                $callback = array($nsClassName , 'createFromDataModel');
                $container = call_user_func_array($callback, array($valueCollection, $baseType));

                return $container; // return container.
            } catch (InvalidArgumentException $e) {
                $msg = "The default value found in the Data Model Variable Declaration is not consistent. ";
                $msg.= "The values must have a baseType compliant with the baseType of the VariableDeclaration.";
                $msg.= "If the VariableDeclaration's cardinality is 'record', make sure the values it contains have ";
                $msg.= "fieldIdentifiers.";

                throw new UnexpectedValueException($msg, 0, $e);
            }
        }
    }
protected static function dataModelValuesToRuntime ( ValueCollection $ valueCollection , $ baseType , $ cardinality ) { // Cardinality? // -> Single? Multiple? Ordered? Record? if ( $ cardinality === Cardinality :: SINGLE ) { // We should find a single value in the DefaultValue's values. if ( count ( $ valueCollection ) == 1 ) { $ dataModelValue = RuntimeUtils :: valueToRuntime ( $ valueCollection [ 0 ] -> getValue ( ) , $ baseType ) ; return $ dataModelValue ; } else { // The Data Model is in an inconsistent state. // This should be handled by the Data Model but // I prefer to be defensive. $ msg = "A Data Model VariableDeclaration with 'single' cardinality must contain a single value, " ; $ msg .= count ( $ valueCollection ) . " value(s) found." ; throw new UnexpectedValueException ( $ msg ) ; } } else { // Multiple|Ordered|Record, use a container. $ container = null ; try { // Create the appropriate Container object. $ className = ucfirst ( Cardinality :: getNameByConstant ( $ cardinality ) ) . 'Container' ; $ nsClassName = 'qtism\\runtime\\common\\' . $ className ; $ callback = array ( $ nsClassName , 'createFromDataModel' ) ; $ container = call_user_func_array ( $ callback , array ( $ valueCollection , $ baseType ) ) ; return $ container ; // return container. } catch ( InvalidArgumentException $ e ) { $ msg = "The default value found in the Data Model Variable Declaration is not consistent. " ; $ msg .= "The values must have a baseType compliant with the baseType of the VariableDeclaration." ; $ msg .= "If the VariableDeclaration's cardinality is 'record', make sure the values it contains have " ; $ msg .= "fieldIdentifiers." ; throw new UnexpectedValueException ( $ msg , 0 , $ e ) ; } } }
Create a QTI Runtime value from Data Model ValueCollection

@param \qtism\data\state\ValueCollection $valueCollection A collection of qtism\data\state\Value objects.
@param integer $baseType The baseType the Value objects in the ValueCollection must respect.
@param integer $cardinality The cardinality the Value objects in the ValueCollection must respect.
@throws \UnexpectedValueException If $baseType or/and $cardinality are not respected by the Value objects in the ValueCollection.
@return mixed The resulting QTI Runtime value (primitive or container depending on baseType/cardinality).
Create a QTI Runtime value from Data Model ValueCollection