public function marshall($data, $output = Marshaller::MARSHALL_JSON)
    {
        if (is_null($data) === true) {
            $json = array('base' => $data);
        } elseif ($data instanceof State) {

            $json = array();

            foreach ($data as $variable) {
                $json[$variable->getIdentifier()] = $this->marshallUnit($variable->getValue());
            }
        } elseif ($data instanceof QtiDatatype) {
            $json = $this->marshallUnit($data);
        } else {
            $className = get_class($this);
            $msg = "The '${className}::marshall' method only takes State, QtiDatatype and null values as arguments, '";

            if (is_object($data) === true) {
                $msg .= get_class($data);
            } else {
                $msg .= gettype($data);
            }

            $msg .= "' given.";
            $code = MarshallingException::NOT_SUPPORTED;
            throw new MarshallingException($msg, $code);
        }

        return ($output === self::MARSHALL_JSON) ? json_encode($json) : $json;
    }
public function marshall($data, $output = Marshaller::MARSHALL_JSON)
    {
        if (is_null($data) === true) {
            $json = array('base' => $data);
        } elseif ($data instanceof State) {

            $json = array();

            foreach ($data as $variable) {
                $json[$variable->getIdentifier()] = $this->marshallUnit($variable->getValue());
            }
        } elseif ($data instanceof QtiDatatype) {
            $json = $this->marshallUnit($data);
        } else {
            $className = get_class($this);
            $msg = "The '${className}::marshall' method only takes State, QtiDatatype and null values as arguments, '";

            if (is_object($data) === true) {
                $msg .= get_class($data);
            } else {
                $msg .= gettype($data);
            }

            $msg .= "' given.";
            $code = MarshallingException::NOT_SUPPORTED;
            throw new MarshallingException($msg, $code);
        }

        return ($output === self::MARSHALL_JSON) ? json_encode($json) : $json;
    }
public function marshall ( $ data , $ output = Marshaller :: MARSHALL_JSON ) { if ( is_null ( $ data ) === true ) { $ json = array ( 'base' => $ data ) ; } elseif ( $ data instanceof State ) { $ json = array ( ) ; foreach ( $ data as $ variable ) { $ json [ $ variable -> getIdentifier ( ) ] = $ this -> marshallUnit ( $ variable -> getValue ( ) ) ; } } elseif ( $ data instanceof QtiDatatype ) { $ json = $ this -> marshallUnit ( $ data ) ; } else { $ className = get_class ( $ this ) ; $ msg = "The '${className}::marshall' method only takes State, QtiDatatype and null values as arguments, '" ; if ( is_object ( $ data ) === true ) { $ msg .= get_class ( $ data ) ; } else { $ msg .= gettype ( $ data ) ; } $ msg .= "' given." ; $ code = MarshallingException :: NOT_SUPPORTED ; throw new MarshallingException ( $ msg , $ code ) ; } return ( $ output === self :: MARSHALL_JSON ) ? json_encode ( $ json ) : $ json ; }
Marshall some QTI data into JSON.

@param \qtism\runtime\common\State|\qtism\common\datatypes\QtiDatatype|null $data The data to be marshalled into JSON.
@param integer How the output will be returned (see class constants). Default is plain JSON string.
@return string|array The JSONified data.
@throws \InvalidArgumentException If $data has not a compliant type.
@throws \qtism\runtime\pci\json\MarshallingException If an error occurs while marshalling $data into JSON.
Marshall some QTI data into JSON .