예제 #1
0
 /**
  * @see \qtism\data\storage\xml\marshalling\OperatorMarshaller::unmarshallChildrenKnown()
  */
 protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children)
 {
     $object = new Equal($children);
     if (($toleranceMode = static::getDOMElementAttributeAs($element, 'toleranceMode')) !== null) {
         $toleranceMode = ToleranceMode::getConstantByName($toleranceMode);
         $object->setToleranceMode($toleranceMode);
     }
     if (($tolerance = static::getDOMElementAttributeAs($element, 'tolerance')) !== null) {
         $tolerance = explode(" ", $tolerance);
         if (count($tolerance) < 1) {
             $msg = "No 'tolerance' could be extracted from element '" . $element->localName . "'.";
             throw new UnmarshallingException($msg, $element);
         } elseif (count($tolerance) > 2) {
             $msg = "'tolerance' attribute not correctly formatted in element '" . $element->localName . "'.";
             throw new UnmarshallingException($msg, $element);
         } else {
             $finalTolerance = array();
             foreach ($tolerance as $t) {
                 $finalTolerance[] = Format::isFloat($t) ? floatval($t) : $t;
             }
             $object->setTolerance($finalTolerance);
         }
     }
     if (($includeLowerBound = static::getDOMElementAttributeAs($element, 'includeLowerBound', 'boolean')) !== null) {
         $object->setIncludeLowerBound($includeLowerBound);
     }
     if (($includeUpperBound = static::getDOMElementAttributeAs($element, 'includeUpperBound', 'boolean')) !== null) {
         $object->setIncludeUpperBound($includeUpperBound);
     }
     return $object;
 }
예제 #2
0
    public function createFakeExpression($toleranceMode, array $tolerance = array(), $includeLowerBound = true, $includeUpperBound = true)
    {
        $tm = $toleranceMode != ToleranceMode::EXACT ? 'tolerance="' . implode(' ', $tolerance) . '"' : '';
        $toleranceMode = ToleranceMode::getNameByConstant($toleranceMode);
        $iL = $includeLowerBound === true ? 'true' : 'false';
        $iU = $includeUpperBound === true ? 'true' : 'false';
        $str = '
			<equal toleranceMode="' . $toleranceMode . '" ' . $tm . ' includeLowerBound="' . $iL . '" includeUpperBound="' . $iU . '">
				<baseValue baseType="integer">10</baseValue>
				<baseValue baseType="integer">10</baseValue>
			</equal>
		';
        return $this->createComponentFromXml($str);
    }
예제 #3
0
파일: Equal.php 프로젝트: nagyist/qti-sdk
 /**
  * Set the tolerance mode.
  *
  * @param integer $toleranceMode A value from the ToleranceMode enumeration.
  * @throws \InvalidArgumentException If $toleranceMode is not a value from the ToleranceMode enumeration.
  */
 public function setToleranceMode($toleranceMode)
 {
     if (in_array($toleranceMode, ToleranceMode::asArray())) {
         $this->toleranceMode = $toleranceMode;
     } else {
         $msg = "The toleranceMode argument must be a value from the ToleranceMode enumeration, '" . $toleranceMode . "' given.";
         throw new InvalidArgumentException($msg);
     }
 }