/** * get the mapping in JSON format. If no mapping defined return null. * * @deprecated now use the new qtism lib for response evaluation * @access public * @author Joel Bout, <*****@*****.**> */ public function mapToJSON() { $returnValue = null; $mapping = $this->getMapping(); if (count($mapping)) { $returnValue = array(); $returnValue['identifier'] = $this->getIdentifier(); $returnValue['defaultValue'] = $this->mappingDefaultValue; if ($this->hasAttribute('areaMapping')) { $returnValue = array_merge($returnValue, $this->getAttributeValue('areaMapping')); } $mappingValue = array(); // If a mapping has been defined if (!empty($mapping)) { foreach ($mapping as $mapKey => $mappedValue) { $mapEntryJSON = array(); $mapEntryJSON['value'] = (double) $mappedValue; $mapEntryJSON['key'] = taoQTI_models_classes_Matching_VariableFactory::createJSONValueFromQTIData($mapKey, $this->getAttributeValue('baseType')); array_push($mappingValue, (object) $mapEntryJSON); } $returnValue['value'] = $mappingValue; } $returnValue = (object) $returnValue; } return $returnValue; }
/** * Short description of method setValue * * @access public * @author Joel Bout, <*****@*****.**> * @param value * @return mixed */ public function setValue($value) { // Set the value of the expression and cast it function of the (defined) base type of the variable if ($this->attributes['baseType']) { switch ($this->attributes['baseType']) { case 'boolean': if (is_string($value)) { $this->value = (bool) ($value == 'true' || $value == '1' ? 1 : 0); } else { if (is_bool($value)) { $this->value = $value; } else { if ($value == null) { $this->value = null; } else { throw new Exception('taoQTI_models_classes_QTI_response_ExpressionOperator::setValue : an error occured, the value [' . $value . '] is not a well formed boolean'); } } } break; case 'float': $this->value = (double) $value; break; case 'integer': $this->value = (int) $value; break; case 'identifier': case 'string': $this->value = (string) $value; break; case 'pair': $this->value = taoQTI_models_classes_Matching_VariableFactory::createJSONValueFromQTIData($value, 'pair'); break; case 'directedPair': $this->value = taoQTI_models_classes_Matching_VariableFactory::createJSONValueFromQTIData($value, 'directedPair'); break; } } }