コード例 #1
0
 protected function unmarshall(DOMElement $element)
 {
     if (($identifier = static::getDOMElementAttributeAs($element, 'identifier')) !== null) {
         if (($navigationMode = static::getDOMElementAttributeAs($element, 'navigationMode')) !== null) {
             if (($submissionMode = static::getDOMElementAttributeAs($element, 'submissionMode')) !== null) {
                 // We do not use the regular DOMElement::getElementsByTagName method
                 // because it is recursive. We only want the first level elements with
                 // tagname = 'assessmentSection'.
                 $assessmentSectionElts = self::getChildElementsByTagName($element, 'assessmentSection');
                 $assessmentSections = new AssessmentSectionCollection();
                 foreach ($assessmentSectionElts as $sectElt) {
                     $marshaller = $this->getMarshallerFactory()->createMarshaller($sectElt);
                     $assessmentSections[] = $marshaller->unmarshall($sectElt);
                 }
                 if (count($assessmentSections) > 0) {
                     // We can instantiate because all mandatory attributes/elements were found.
                     $navigationMode = NavigationMode::getConstantByName($navigationMode);
                     $submissionMode = SubmissionMode::getConstantByName($submissionMode);
                     $object = new TestPart($identifier, $assessmentSections, $navigationMode, $submissionMode);
                     // preConditions
                     $preConditionElts = self::getChildElementsByTagName($element, 'preCondition');
                     $preConditions = new PreConditionCollection();
                     foreach ($preConditionElts as $preConditionElt) {
                         $marshaller = $this->getMarshallerFactory()->createMarshaller($preConditionElt);
                         $preConditions[] = $marshaller->unmarshall($preConditionElt);
                     }
                     $object->setPreConditions($preConditions);
                     // branchRules
                     $branchRuleElts = self::getChildElementsByTagName($element, 'branchRule');
                     $branchRules = new BranchRuleCollection();
                     foreach ($branchRuleElts as $branchRuleElt) {
                         $marshaller = $this->getMarshallerFactory()->createMarshaller($branchRuleElt);
                         $branchRules[] = $marshaller->unmarshall($branchRuleElt);
                     }
                     $object->setBranchRules($branchRules);
                     // itemSessionControl
                     $itemSessionControlElts = self::getChildElementsByTagName($element, 'itemSessionControl');
                     if (count($itemSessionControlElts) === 1) {
                         $marshaller = $this->getMarshallerFactory()->createMarshaller($itemSessionControlElts[0]);
                         $itemSessionControl = $marshaller->unmarshall($itemSessionControlElts[0]);
                         $object->setItemSessionControl($itemSessionControl);
                     }
                     // timeLimits
                     $timeLimitsElts = self::getChildElementsByTagName($element, 'timeLimits');
                     if (count($timeLimitsElts) === 1) {
                         $marshaller = $this->getMarshallerFactory()->createMarshaller($timeLimitsElts[0]);
                         $timeLimits = $marshaller->unmarshall($timeLimitsElts[0]);
                         $object->setTimeLimits($timeLimits);
                     }
                     // testFeedbacks
                     $testFeedbackElts = self::getChildElementsByTagName($element, 'testFeedback');
                     $testFeedbacks = new TestFeedbackCollection();
                     foreach ($testFeedbackElts as $testFeedbackElt) {
                         $marshaller = $this->getMarshallerFactory()->createMarshaller($testFeedbackElt);
                         $testFeedbacks[] = $marshaller->unmarshall($testFeedbackElt);
                     }
                     $object->setTestFeedbacks($testFeedbacks);
                     return $object;
                 } else {
                     $msg = "A testPart element must contain at least one assessmentSection.";
                     throw new UnmarshallingException($msg, $element);
                 }
             } else {
                 $msg = "The mandatory attribute 'submissionMode' is missing from element '" . $element->localName . "'.";
                 throw new UnmarshallingException($msg, $element);
             }
         } else {
             $msg = "The mandatory attribute 'navigationMode' is missing from element '" . $element->localName . "'.";
             throw new UnmarshallingException($msg, $element);
         }
     } else {
         $msg = "The mandatory attribute 'identifier' is missing from element '" . $element->localName . "'.";
         throw new UnmarshallingException($msg, $element);
     }
 }
コード例 #2
0
 /**
  * Set the submission mode of the Test Part.
  * 
  * @param int $submissionMode A value of the SubmissionMode enumeration.
  * @throws InvalidArgumentException If $submissionMode is not a value from the SubmissionMode enumeration.
  */
 public function setSubmissionMode($submissionMode)
 {
     if (in_array($submissionMode, SubmissionMode::asArray())) {
         $this->submissionMode = $submissionMode;
     } else {
         $msg = "'{$submissionMode}' is not a valid value for SubmissionMode.";
         throw new InvalidArgumentException($msg);
     }
 }