示例#1
0
文件: Q.php 项目: nagyist/qti-sdk
 /**
  * Set the cite attribute's value.
  *
  * @param string $cite
  * @throws \InvalidArgumentException If $cite is not a valid URI.
  */
 public function setCite($cite)
 {
     if (Format::isUri($cite) === true) {
     } else {
         $msg = "The 'cite' argument must be a valid URI, '" . $cite . "' given.";
         throw new InvalidArgumentException($msg);
     }
 }
示例#2
0
 /**
  * @see \qtism\data\content\Flow::setXmlBase()
  */
 public function setXmlBase($xmlBase = '')
 {
     if (is_string($xmlBase) && (empty($xmlBase) || Format::isUri($xmlBase))) {
         $this->xmlBase = $xmlBase;
     } else {
         $msg = "The 'xmlBase' argument must be an empty string or a valid URI, '" . $xmlBase . "' given";
         throw new InvalidArgumentException($msg);
     }
 }
示例#3
0
 /**
  * Set the href attribute.
  * 
  * @param string $href A URI (Uniform Resource Identifier).
  * @throws InvalidArgumentException If $href is not a URI.
  */
 public function setHref($href)
 {
     if (Format::isUri($href) === true) {
         $this->href = $href;
     } else {
         $msg = "The 'href' argument must be a URI, '" . $href . "' given.";
         throw new InvalidArgumentException($msg);
     }
 }
示例#4
0
 /**
  * Set the optional response processing template location. An empty string ('') indicates
  * there is no template location description.
  *
  * @param string $templateLocaton The URI of the template location.
  * @throws \InvalidArgumentException If $templateLocation is not a valid URI nor an empty string.
  */
 public function setTemplateLocation($templateLocation)
 {
     if (Format::isUri($templateLocation) === true || gettype($templateLocation) === 'string' && empty($templateLocation) === true) {
         $this->templateLocation = $templateLocation;
     } else {
         $msg = "The given templateLocation '{$templateLocation}' is not a valid URI.";
         throw new InvalidArgumentException($msg);
     }
 }
示例#5
0
 /**
  * Get the hyper-text reference to the actual content of the TestFeedback.
  * 
  * @param string $href
  */
 public function setHref($href)
 {
     if (Format::isUri($href) === true) {
         $this->href = $href;
     } else {
         $msg = "'{$href}' is not a valid URI.";
         throw new InvalidArgumentException($msg);
     }
 }
 /**
  * @dataProvider validUriFormatProvider
  */
 public function testValidUriFormat($string)
 {
     $this->assertTrue(Format::isUri($string));
 }
示例#7
0
 /**
  * Transform a string representing a QTI valueType value in a
  * the correct datatype.
  *
  * @param string $string The QTI valueType value as a string.
  * @param integer $baseType The QTI baseType that defines the datatype of $string.
  * @return mixed A converted object/primitive type.
  * @throws \InvalidArgumentException If $baseType is not a value from the BaseType enumeration.
  * @throws \UnexpectedValueException If $string cannot be transformed in a Value expression with the given $baseType.
  */
 public static function stringToDatatype($string, $baseType)
 {
     if (in_array($baseType, BaseType::asArray())) {
         $value = null;
         switch ($baseType) {
             case BaseType::BOOLEAN:
                 if (Format::isBoolean($string)) {
                     $value = Format::toLowerTrim($string) == 'true' ? true : false;
                     return $value;
                 } else {
                     $msg = "'{$string}' cannot be transformed into boolean.";
                     throw new UnexpectedValueException($msg);
                 }
                 break;
             case BaseType::INTEGER:
                 if (Format::isInteger($string)) {
                     $value = intval($string);
                     return $value;
                 } else {
                     $msg = "'{$string}' cannot be transformed into integer.";
                     throw new UnexpectedValueException($msg);
                 }
                 break;
             case BaseType::FLOAT:
                 if (Format::isFloat($string)) {
                     $value = floatval($string);
                     return $value;
                 } else {
                     $msg = "'{$string}' cannot be transformed into float.";
                     throw new UnexpectedValueException($msg);
                 }
                 break;
             case BaseType::URI:
                 if (Format::isUri($string)) {
                     return $string;
                 } else {
                     $msg = "'{$string}' is not a valid URI.";
                     throw new UnexpectedValueException($msg);
                 }
                 break;
             case BaseType::IDENTIFIER:
                 if (Format::isIdentifier($string)) {
                     return $string;
                 } else {
                     $msg = "'{$string}' is not a valid QTI Identifier.";
                     throw new UnexpectedValueException($msg);
                 }
                 break;
             case BaseType::INT_OR_IDENTIFIER:
                 if (Format::isIdentifier($string)) {
                     return $string;
                 } elseif (Format::isInteger($string)) {
                     return intval($string);
                 } else {
                     $msg = "'{$string}' is not a valid QTI Identifier nor a valid integer.";
                     throw new UnexpectedValueException($msg);
                 }
                 break;
             case BaseType::PAIR:
                 if (Format::isPair($string)) {
                     $pair = explode(" ", $string);
                     return new Pair($pair[0], $pair[1]);
                 } else {
                     $msg = "'{$string}' is not a valid pair.";
                     throw new UnexpectedValueException($msg);
                 }
                 break;
             case BaseType::DIRECTED_PAIR:
                 if (Format::isDirectedPair($string)) {
                     $pair = explode(" ", $string);
                     return new DirectedPair($pair[0], $pair[1]);
                 } else {
                     $msg = "'{$string}' is not a valid directed pair.";
                     throw new UnexpectedValueException($msg);
                 }
                 break;
             case BaseType::DURATION:
                 if (Format::isDuration($string)) {
                     return new Duration($string);
                 } else {
                     $msg = "'{$string}' is not a valid duration.";
                     throw new UnexpectedValueException($msg);
                 }
                 break;
             case BaseType::FILE:
                 throw new \RuntimeException("Unsupported baseType: file.");
                 break;
             case BaseType::STRING:
                 return '' . $string;
                 break;
             case BaseType::POINT:
                 if (Format::isPoint($string)) {
                     $parts = explode(" ", $string);
                     return new Point(intval($parts[0]), intval($parts[1]));
                 } else {
                     $msg = "'{$string}' is not valid point.";
                     throw new UnexpectedValueException($msg);
                 }
                 break;
             default:
                 throw new \RuntimeException("Unknown baseType.");
                 break;
         }
     } else {
         $msg = "BaseType must be a value from the BaseType enumeration.";
         throw new InvalidArgumentException($msg);
     }
 }
示例#8
0
 /**
  * Get the longdesc attribute.
  * 
  * @param string $longdesc A valid URI.
  * @throws InvalidArgumentException If $longdesc is not a valid URI.
  */
 public function setLongdesc($longdesc)
 {
     if (Format::isUri($longdesc) === true || is_string($longdesc) === true && empty($longdesc) === true) {
         $this->longdesc = $longdesc;
     } else {
         $msg = "The 'longdesc' argument must be a valid URI, '" . $longdesc . "' given.";
         throw new InvalidArgumentException($msg);
     }
 }