コード例 #1
0
 /**
  * Add a variable to be transformed into its IMS PCI JSON Representation
  * for a later output.
  * 
  * @param Variable $variable
  */
 public function addVariable(Variable $variable)
 {
     $output =& $this->getOutput();
     $varName = $variable->getIdentifier();
     $marshaller = new taoQtiCommon_helpers_PciJsonMarshaller();
     $output[$varName] = $marshaller->marshall($variable->getValue(), taoQtiCommon_helpers_PciJsonMarshaller::MARSHALL_ARRAY);
 }
コード例 #2
0
 /**
  * Get the intrinsic values of a given QTI $variable.
  * 
  * @param Variable $variable
  * @return array
  */
 public static function getVariableValues(Variable $variable)
 {
     $returnValue = array();
     $baseType = $variable->getBaseType();
     $cardinalityType = $variable->getCardinality();
     $value = $variable->getValue();
     // This only works if the variable has a value ;)
     if ($value !== null) {
         if ($baseType === BaseType::IDENTIFIER) {
             if ($cardinalityType === Cardinality::SINGLE) {
                 $returnValue[] = $value->getValue();
             } else {
                 if ($cardinalityType === Cardinality::MULTIPLE) {
                     foreach ($variable->getValue() as $value) {
                         $returnValue[] = $value->getValue();
                     }
                 }
             }
         }
     }
     return $returnValue;
 }
コード例 #3
0
 /**
  * @dataProvider fillVariableProvider
  * 
  * @param IAssessmentItem $itemRef The reference item.
  * @param string $variableIdentifier The identifier of the variable.
  * @param array $data Client-side data.
  * @param Variable $expectedVariable
  */
 public function testFillVariable(array $data, Variable $expectedVariable)
 {
     // Non-time dependent basic item in 'Yoda English'.
     $itemRef = new AssessmentItem('Q01', 'Question 01', false, 'en-YO');
     $outcomeDeclarations = new OutcomeDeclarationCollection();
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME1', BaseType::FLOAT, Cardinality::SINGLE);
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME2', BaseType::INTEGER, Cardinality::SINGLE);
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME3', BaseType::BOOLEAN, Cardinality::SINGLE);
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME4', BaseType::STRING, Cardinality::SINGLE);
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME5', BaseType::POINT, Cardinality::SINGLE);
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME6', BaseType::PAIR, Cardinality::SINGLE);
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME7', BaseType::DIRECTED_PAIR, Cardinality::SINGLE);
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME8', BaseType::DURATION, Cardinality::SINGLE);
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME9', BaseType::URI, Cardinality::SINGLE);
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME10', BaseType::IDENTIFIER, Cardinality::SINGLE);
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME11', BaseType::INT_OR_IDENTIFIER, Cardinality::SINGLE);
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME12', BaseType::INTEGER, Cardinality::SINGLE);
     $responseDeclarations = new ResponseDeclarationCollection();
     $responseDeclarations[] = new ResponseDeclaration('RESPONSE1', BaseType::IDENTIFIER, Cardinality::SINGLE);
     $responseDeclarations[] = new ResponseDeclaration('RESPONSE2', BaseType::IDENTIFIER, Cardinality::MULTIPLE);
     $responseDeclarations[] = new ResponseDeclaration('RESPONSE3', BaseType::DIRECTED_PAIR, Cardinality::ORDERED);
     $responseDeclarations[] = new ResponseDeclaration('RESPONSE4', -1, Cardinality::RECORD);
     $responseDeclarations[] = new ResponseDeclaration('RESPONSE5', -1, Cardinality::RECORD);
     $responseDeclarations[] = new ResponseDeclaration('RESPONSE6', -1, Cardinality::RECORD);
     $responseDeclarations[] = new ResponseDeclaration('RESPONSE7', -1, Cardinality::RECORD);
     $responseDeclarations[] = new ResponseDeclaration('RESPONSE8', BaseType::BOOLEAN, Cardinality::MULTIPLE);
     $itemRef->setOutcomeDeclarations($outcomeDeclarations);
     $itemRef->setResponseDeclarations($responseDeclarations);
     $filler = new taoQtiCommon_helpers_PciVariableFiller($itemRef);
     $variable = $filler->fill($expectedVariable->getIdentifier(), $data);
     $this->assertEquals($expectedVariable->getIdentifier(), $variable->getIdentifier());
     $this->assertEquals($expectedVariable->getBaseType(), $variable->getBaseType());
     $this->assertEquals($expectedVariable->getCardinality(), $variable->getCardinality());
     $this->assertEquals(get_class($expectedVariable), get_class($variable));
     if ($expectedVariable->getValue() === null) {
         $this->assertSame($expectedVariable->getValue(), $variable->getValue());
     } else {
         $this->assertTrue($expectedVariable->getValue()->equals($variable->getValue()));
     }
 }
コード例 #4
0
 /**
  * Add a variable (Variable object) to the current context. Variables that can be set using this method
  * must have simple variable identifiers, in order to target the global AssessmentTestSession scope only.
  * 
  * @param Variable $variable A Variable object to add to the current context.
  * @throws OutOfRangeException If the identifier of the given $variable is not a simple variable identifier (no prefix, no sequence number).
  */
 public function setVariable(Variable $variable)
 {
     try {
         $v = new VariableIdentifier($variable->getIdentifier());
         if ($v->hasPrefix() === true) {
             $msg = "The variables set to the AssessmentTestSession global scope must have simple variable identifiers. ";
             $msg .= "'" . $v->__toString() . "' given.";
             throw new OutOfRangeException($msg);
         }
     } catch (InvalidArgumentException $e) {
         $variableIdentifier = $variable->getIdentifier();
         $msg = "The identifier '{$variableIdentifier}' of the variable to set is invalid.";
         throw new OutOfRangeException($msg, 0, $e);
     }
     $data =& $this->getDataPlaceHolder();
     $data[$v->__toString()] = $variable;
 }
コード例 #5
0
 /**
  * Processes all values of a record container and merge them into
  * a single string.
  * 
  * @param RecordContainer $variable The record to process.
  * @return string All the key/values delimited by printedVariable->delimiter. Indicator between keys and values is defined by printedVariable->mappingIndicator.
  */
 private function processRecord(Variable $variable)
 {
     $processedValues = array();
     $baseType = $variable->getBaseType();
     $mappingIndicator = $this->getComponent()->getMappingIndicator();
     foreach ($variable->getValue() as $k => $v) {
         $processedValues[] = "{$k}{$mappingIndicator}" . $this->processValue(Utils::inferBaseType($v), $v);
     }
     return implode($this->getComponent()->getDelimiter(), $processedValues);
 }
コード例 #6
0
ファイル: TemplateVariable.php プロジェクト: nagyist/qti-sdk
 /**
  * @see \qtism\runtime\common\Variable::__clone()
  */
 public function __clone()
 {
     parent::__clone();
 }
コード例 #7
0
 /**
  * Whether or not a given QTI Variable contains a QTI File value.
  * 
  * @param Variable $variable
  * @param boolean $considerNull Whether or not to consider File variables containing NULL variables.
  * @return boolean
  */
 public static function isQtiFile(Variable $variable, $considerNull = true)
 {
     $correctBaseType = $variable->getBaseType() === BaseType::FILE;
     $correctCardinality = $variable->getCardinality() === Cardinality::SINGLE;
     $nullConsideration = $considerNull === true ? true : $variable->getValue() !== null;
     return $correctBaseType === true && $correctCardinality === true && $nullConsideration === true;
 }
 /**
  * Write the value of $variable in the current binary stream.
  * 
  * @param Variable $variable A QTI Runtime Variable object.
  * @throws QtiBinaryStreamAccessException
  */
 public function writeVariableValue(Variable $variable)
 {
     try {
         $value = $variable->getValue();
         $cardinality = $variable->getCardinality();
         $baseType = $variable->getBaseType();
         if (is_null($value) === true) {
             $this->writeBoolean(true);
             return;
         }
         // Non-null value.
         $this->writeBoolean(false);
         if ($cardinality === Cardinality::RECORD) {
             // is-scalar
             $this->writeBoolean(false);
             // count
             $this->writeShort(count($value));
             // content
             foreach ($value as $k => $v) {
                 $this->writeRecordField(array($k, $v), is_null($v));
             }
         } else {
             $toCall = 'write' . ucfirst(BaseType::getNameByConstant($baseType));
             if ($cardinality === Cardinality::SINGLE) {
                 // is-scalar
                 $this->writeBoolean(true);
                 // content
                 $this->{$toCall}($value instanceof Scalar ? $value->getValue() : $value);
             } else {
                 // is-scalar
                 $this->writeBoolean(false);
                 // count
                 $this->writeShort(count($value));
                 // MULTIPLE or ORDERED
                 foreach ($value as $v) {
                     if (is_null($v) === false) {
                         $this->writeBoolean(false);
                         $this->{$toCall}($v instanceof Scalar ? $v->getValue() : $v);
                     } else {
                         $this->writeBoolean(true);
                     }
                 }
             }
         }
     } catch (BinaryStreamAccessException $e) {
         $msg = "An error occured while writing a Variable value.";
         throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::VARIABLE, $e);
     }
 }
コード例 #9
0
 /**
  * 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
  */
 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;
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #10
0
ファイル: ResponseVariable.php プロジェクト: nagyist/qti-sdk
 /**
  * @see \qtism\runtime\common\Variable::__clone()
  */
 public function __clone()
 {
     parent::__clone();
     if (($cv = $this->getCorrectResponse()) !== null) {
         $this->correctResponse = clone $cv;
     }
 }
コード例 #11
0
 /**
  * Write the value of $variable in the current binary stream.
  *
  * @param \qtism\runtime\common\Variable $variable A QTI Runtime Variable object.
  * @throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException
  */
 public function writeVariableValue(Variable $variable, $valueType = self::RW_VALUE)
 {
     switch ($valueType) {
         case self::RW_DEFAULTVALUE:
             $getterToCall = 'getDefaultValue';
             break;
         case self::RW_CORRECTRESPONSE:
             $getterToCall = 'getCorrectResponse';
             break;
         default:
             $getterToCall = 'getValue';
     }
     try {
         $value = call_user_func(array($variable, $getterToCall));
         $cardinality = $variable->getCardinality();
         $baseType = $variable->getBaseType();
         if (is_null($value) === true) {
             $this->writeBoolean(true);
             return;
         }
         // Non-null value.
         $this->writeBoolean(false);
         if ($cardinality === Cardinality::RECORD) {
             // is-scalar
             $this->writeBoolean(false);
             // count
             $this->writeShort(count($value));
             // content
             foreach ($value as $k => $v) {
                 $this->writeRecordField(array($k, $v), is_null($v));
             }
         } else {
             $toCall = 'write' . ucfirst(BaseType::getNameByConstant($baseType));
             if ($cardinality === Cardinality::SINGLE) {
                 // is-scalar
                 $this->writeBoolean(true);
                 // content
                 $this->{$toCall}($value instanceof QtiScalar ? $value->getValue() : $value);
             } else {
                 // is-scalar
                 $this->writeBoolean(false);
                 // count
                 $this->writeShort(count($value));
                 // MULTIPLE or ORDERED
                 foreach ($value as $v) {
                     if (is_null($v) === false) {
                         $this->writeBoolean(false);
                         $this->{$toCall}($v instanceof QtiScalar ? $v->getValue() : $v);
                     } else {
                         $this->writeBoolean(true);
                     }
                 }
             }
         }
     } catch (BinaryStreamAccessException $e) {
         $msg = "An error occured while writing a Variable value.";
         throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::VARIABLE, $e);
     }
 }