helpers/class.LegacyStateOutput.php
public function addVariable(Variable $variable) {
        $output = &$this->getOutput();
        $baseType = $variable->getBaseType();
        $cardinality = $variable->getCardinality();
        $varName = $variable->getIdentifier();
        
        if ($cardinality === Cardinality::SINGLE) {
            $singleValue = $variable->getValue();
            if (is_null($singleValue) === true) {
                $output[$varName] = array('');
                return;
            }
            
            $values = array($variable->getValue());
        }
        else {
            $containerValue = $variable->getValue();
            if (is_null($containerValue) === true || $containerValue->isNull() === true) {
                $output[$varName] = array();
                return;
            }
            
            $values = $containerValue->getArrayCopy(true);
        }
        
        $output[$varName] = array();
        
        foreach ($values as $val) {
            if (is_null($val) === true) {
                $output[$varName][] = '';   
            }
            else if (gettype($val) === 'boolean') {
                $output[$varName][] = ($val === true) ? 'true' : 'false';
            }
            else if ($val instanceof QtiPoint) {
                $output[$varName][] = array('' . $val->getX(), '' . $val->getY());
            }
            else if ($val instanceof QtiPair) {
                $output[$varName][] = array($val->getFirst(), $val->getSecond());
            }
            else if (gettype($val) === 'object') {
                $output[$varName][] = $val->__toString();
            }
            else {
                $output[$varName][] = '' . $val;
            }
        }
    }
public function addVariable(Variable $variable) {
        $output = &$this->getOutput();
        $baseType = $variable->getBaseType();
        $cardinality = $variable->getCardinality();
        $varName = $variable->getIdentifier();
        
        if ($cardinality === Cardinality::SINGLE) {
            $singleValue = $variable->getValue();
            if (is_null($singleValue) === true) {
                $output[$varName] = array('');
                return;
            }
            
            $values = array($variable->getValue());
        }
        else {
            $containerValue = $variable->getValue();
            if (is_null($containerValue) === true || $containerValue->isNull() === true) {
                $output[$varName] = array();
                return;
            }
            
            $values = $containerValue->getArrayCopy(true);
        }
        
        $output[$varName] = array();
        
        foreach ($values as $val) {
            if (is_null($val) === true) {
                $output[$varName][] = '';   
            }
            else if (gettype($val) === 'boolean') {
                $output[$varName][] = ($val === true) ? 'true' : 'false';
            }
            else if ($val instanceof QtiPoint) {
                $output[$varName][] = array('' . $val->getX(), '' . $val->getY());
            }
            else if ($val instanceof QtiPair) {
                $output[$varName][] = array($val->getFirst(), $val->getSecond());
            }
            else if (gettype($val) === 'object') {
                $output[$varName][] = $val->__toString();
            }
            else {
                $output[$varName][] = '' . $val;
            }
        }
    }
Add a variable to the State that has to be built for the client-side. The final output
array is available through the tao_helpers_StateOutput::getOutput() method.

@param Variable $variable A QTI Runtime Variable