itemtype = "multipleChoice"; } /** * 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); $title = $this->getTitleFromXML($item_dom); $this->title = $title; $this->itembody = $this->getItemBodyFromXML($item_dom); $choices = $this->getChoicesFromXML($item_dom); $this->choices = serialize($choices); $correct_choice = $this->getCorrectChoice($item_dom); $this->correct = $correct_choice; } /** * Return choices from xml * * @param DOMDocument $dom Item DOM document * * @return array Choices array */ function getChoicesFromXML($dom) { $choice_interaction = $dom->getElementsByTagName("choiceInteraction")->item(0); $choices = $choice_interaction->getElementsByTagName("simpleChoice"); $new_choices = array(); //$correct_choice = $this->getCorrectChoice($dom); 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; /*if ($correct_choice == $identifier) { $new_choices[$identifier]["correct"] = true; } else { $new_choices[$identifier]["correct"] = false; }*/ } return $new_choices; } /** * Return correct choice from xml * * @param DOMDocument $dom Item DOM document * * @return string Correct choice */ function getCorrectChoice($dom) { $correct_response = $dom->getElementsByTagName("correctResponse")->item(0); $value = $correct_response->getElementsByTagName("value")->item(0); $correct = $this->findNodeText($value); return $correct; } /** * Returns true or false based on given answer * * @param string chosen User answer * @return bool * */ function answer($chosen) { if ($chosen == $this->correct) { return true; } return false; } }