protected static function getOutcomeMaximum($outcomeIdentifier, $weightIdentifier = '', $sectionIdentifier = '', IdentifierCollection $includeCategories = null, IdentifierCollection $excludeCategories = null)
 {
     $outcomeMaximum = new OutcomeMaximum($outcomeIdentifier);
     $outcomeMaximum->setSectionIdentifier($sectionIdentifier);
     if (empty($includeCategories) === false) {
         $outcomeMaximum->setIncludeCategories($includeCategories);
     }
     if (empty($excludeCategories) === false) {
         $outcomeMaximum->setExcludeCategories($excludeCategories);
     }
     if (empty($weightIdentifier) === false) {
         $outcomeMaximum->setWeightIdentifier($weightIdentifier);
     }
     return $outcomeMaximum;
 }
예제 #2
0
 /**
  * Marshall an outcomeMaximum QTI element in its OutcomeMaximum object equivalent.
  *
  * @param \DOMElement A DOMElement object.
  * @return \qtism\data\QtiComponent The corresponding OutcomeMaximum object.
  */
 protected function unmarshall(DOMElement $element)
 {
     $baseComponent = parent::unmarshall($element);
     if (($outcomeIdentifier = static::getDOMElementAttributeAs($element, 'outcomeIdentifier')) !== null) {
         $object = new OutcomeMaximum($outcomeIdentifier);
         $object->setSectionIdentifier($baseComponent->getSectionIdentifier());
         $object->setIncludeCategories($baseComponent->getIncludeCategories());
         $object->setExcludeCategories($baseComponent->getExcludeCategories());
         if (($weightIdentifier = static::getDOMElementAttributeAs($element, 'weightIdentifier')) !== null) {
             $object->setWeightIdentifier($weightIdentifier);
         }
         return $object;
     } else {
         $msg = "The mandatory attribute 'outcomeIdentifier' is missing from element '" . $element->localName . "'.";
         throw new UnmarshallingException($msg, $element);
     }
 }
 public function testMarshall()
 {
     $sectionIdentifier = 'mySection1';
     $outcomeIdentifier = 'myOutcome1';
     $includeCategory = 'cat1';
     $excludeCategory = 'cat2 cat3';
     $weightIdentifier = 'myWeight1';
     $component = new OutcomeMaximum($outcomeIdentifier, $weightIdentifier);
     $component->setSectionIdentifier($sectionIdentifier);
     $component->setIncludeCategories(new IdentifierCollection(explode(" ", $includeCategory)));
     $component->setExcludeCategories(new IdentifierCollection(explode(" ", $excludeCategory)));
     $marshaller = $this->getMarshallerFactory()->createMarshaller($component);
     $element = $marshaller->marshall($component);
     $this->assertInstanceOf('\\DOMElement', $element);
     $this->assertEquals('outcomeMaximum', $element->nodeName);
     $this->assertEquals($sectionIdentifier, $element->getAttribute('sectionIdentifier'));
     $this->assertEquals($outcomeIdentifier, $element->getAttribute('outcomeIdentifier'));
     $this->assertEquals($weightIdentifier, $element->getAttribute('weightIdentifier'));
     $this->assertEquals($includeCategory, $element->getAttribute('includeCategory'));
     $this->assertEquals($excludeCategory, $element->getAttribute('excludeCategory'));
 }