/**
  * Marshall an numberCorrect QTI element in its NumberCorrect object equivalent.
  *
  * @param \DOMElement $element A DOMElement object.
  * @return \qtism\data\QtiComponent The corresponding NumberCorrect object.
  */
 protected function unmarshall(DOMElement $element)
 {
     $baseComponent = parent::unmarshall($element);
     // Please PHP core development team, give us real method overloading !!! :'(
     $object = new NumberCorrect();
     $object->setSectionIdentifier($baseComponent->getSectionIdentifier());
     $object->setIncludeCategories($baseComponent->getIncludeCategories());
     $object->setExcludeCategories($baseComponent->getExcludeCategories());
     return $object;
 }
 public function testMarshall()
 {
     $sectionIdentifier = 'mySection1';
     $includeCategory = 'cat1';
     $excludeCategory = 'cat2 cat3';
     $component = new NumberCorrect();
     $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('numberCorrect', $element->nodeName);
     $this->assertEquals($sectionIdentifier, $element->getAttribute('sectionIdentifier'));
     $this->assertEquals($includeCategory, $element->getAttribute('includeCategory'));
     $this->assertEquals($excludeCategory, $element->getAttribute('excludeCategory'));
 }
 protected static function getNumberCorrect($sectionIdentifier = '', IdentifierCollection $includeCategories = null, IdentifierCollection $excludeCategories = null)
 {
     $numberCorrect = new NumberCorrect();
     $numberCorrect->setSectionIdentifier($sectionIdentifier);
     if (empty($includeCategories) === false) {
         $numberCorrect->setIncludeCategories($includeCategories);
     }
     if (empty($excludeCategories) === false) {
         $numberCorrect->setExcludeCategories($excludeCategories);
     }
     return $numberCorrect;
 }
 /**
  * Append the outcome processing rules to populate an outcome variable with the number of items correctly responded related to a given category.
  * 
  * This method will append a QTI outcome processing to a given QTI-SDK AssessmentTest $test, dedicated to count the number
  * of correctly responded items related to a given QTI $category.
  * 
  * In case of an outcome processing rule targetting a variable name $varName already exists in the test, the outcome
  * processing rule is not appended to the test.
  * 
  * @param qtism\data\AssessmentTest $test A QTI-SDK AssessmentTest object.
  * @param string $category A QTI category identifier.
  * @param string $varName The QTI identifier of the variable to be populated by the outcome processing rule.
  */
 public static function appendNumberCorrectOutcomeProcessing(AssessmentTest $test, $category, $varName)
 {
     if (self::isVariableSetOutcomeValueTarget($test, $varName) === false) {
         $numberCorrectExpression = new NumberCorrect();
         $numberCorrectExpression->setIncludeCategories(new IdentifierCollection(array($category)));
         $setOutcomeValue = new SetOutcomeValue($varName, $numberCorrectExpression);
         self::appendOutcomeRule($test, $setOutcomeValue);
     }
 }