* @package taoQTI */ class BaseValue extends CommonExpression { // --- ASSOCIATIONS --- // --- ATTRIBUTES --- // --- OPERATIONS --- /** * Short description of method getRule * * @access public * @author Joel Bout, * @return string */ public function getRule() { $returnValue = (string) ''; // JSON ENCODE the value to get quote when quote are required function of the variable base type // not so easy ;) //$returnValue = json_encode($this->value); // @todo make usable for complex variable such as pair, directed pair .. // @todo centralize the management of the options (attributes) $options = []; $value = null; switch ($this->attributes['baseType']) { case "boolean": $options['type'] = "boolean"; $value = json_encode($this->value); break; case "integer": $options['type'] = "integer"; $value = json_encode($this->value); break; case "float": $options['type'] = "float"; $value = json_encode($this->value); break; case "identifier": case "string": $options['type'] = "string"; $value = json_encode($this->value); break; case "pair": $options['type'] = "list"; $value = '"' . implode('","', $this->value) . '"'; break; case "directedPair": $options['type'] = "tuple"; $value = '"' . implode('","', (array)$this->value) . '"'; // Méchant casting, won't work with a dictionnary, but with a tuple it is okay break; default: throw new common_Exception("taoQTI_models_classes_QTI_response_BaseValue::getRule an error occured : the type " . $this->attributes['baseType'] . " is unknown"); } $returnValue = 'createVariable(' . (count($options) ? '"' . addslashes(json_encode($options)) . '"' : 'null') . ', ' . $value . ')'; return (string) $returnValue; } }