itemtype = "multipleResponse"; } /** * Build From XML * * @param DOMNode $resource_dom Item resource tag from manifest xml * @param DOMDocument $item_dom Item DOM document * * @return void */ function buildFromXML($resource_dom, $item_dom) { parent::buildFromXML($resource_dom, $item_dom); $title = $this->getTitleFromXML($item_dom); $this->title = $title; $this->itembody = $this->getItemBodyFromXML($item_dom); $choices = $this->getChoicesFromXML($item_dom); $this->choices = serialize($choices); $this->correct = $this->getCorrectChoices($item_dom); } /** * Return array of choices retrieved from xml * * @param DOMDocument $dom Item DOM document * * @return array */ function getChoicesFromXML($dom) { $choice_interaction = $dom->getElementsByTagName("choiceInteraction")->item(0); $choices = $choice_interaction->getElementsByTagName("simpleChoice"); $new_choices = array(); for ($i=0; $i<$choices->length; $i++) { $choice = $choices->item($i); $identifier = $choice->getAttribute("identifier"); $choice_text = $this->findNodeText($choice); $new_choices[$identifier]["choice_text"] = $choice_text; $score = $this->findChoiceScore($dom, $identifier); $new_choices[$identifier]["score"] = $score; } return $new_choices; } /** * Return given choice score from xml * * @param DOMDocument $dom Item DOM document * @param string $identifier Choice identifier * * @return float */ function findChoiceScore($dom, $identifier) { $map_entries = $dom->getElementsByTagName("mapEntry"); for ($i=0; $i<$map_entries->length; $i++) { $map_entry = $map_entries->item($i); $map_key = $map_entry->getAttribute("mapKey"); if ($identifier == $map_key) { return $map_entry->getAttribute("mappedValue"); } } return 0; } /** * Return correct choices from xml * * @param DOMDocument $dom Item DOM document * * @return array Correct choices array */ function getCorrectChoices($dom) { $correct_choices = array(); $correct_response = $dom->getElementsByTagName("correctResponse")->item(0); $values = $correct_response->getElementsByTagName("value"); for ($i=0; $i<$values->length; $i++) { $value = $values->item($i); $correct = $this->findNodeText($value); $correct_choices []= $correct; } return $correct_choices; } /** * Returns true or false based on given answer * * @param array chosen User answer * @return bool * */ function answer($chosen) { if ($chosen == $this->correct) { return true; } return false; } }