/** * Overrides CqQuestionAbstract::loadXml() */ public function loadXml(DOMElement $dom) { parent::loadXml($dom); module_load_include('inc.php', 'closedquestion', 'lib/XmlLib'); foreach ($dom->childNodes as $node) { $name = drupal_strtolower($node->nodeName); switch ($name) { case 'text': $this->text = cq_get_text_content($node, $this); break; default: if (!in_array($name, $this->knownElements)) { drupal_set_message(t('Unknown node: @nodename', array('@nodename' => $node->nodeName))); } break; } } }
/** * Overrides CqQuestionAbstract::loadXml() */ public function loadXml(DOMElement $dom) { parent::loadXml($dom); module_load_include('inc.php', 'closedquestion', 'lib/XmlLib'); module_load_include('php', 'closedquestion', 'question/mapping/FactoryHotspot'); $this->hotspots = array(); $this->mappings = array(); $this->hints = array(); $this->draggables = array(); foreach ($dom->childNodes as $node) { $name = drupal_strtolower($node->nodeName); switch ($name) { case 'text': $this->text = cq_get_text_content($node, $this); break; case 'matchimg': $this->matchImgUrl = $node->getAttribute('src'); $this->matchImgHeight = $node->getAttribute('height'); $this->matchImgWidth = $node->getAttribute('width'); $this->maxChoices = $node->getAttribute('maxChoices'); foreach ($node->childNodes as $child) { switch (drupal_strtolower($child->nodeName)) { case 'hotspot': $hotspot = cq_Hotspot_from_xml($child, $this); if (is_object($hotspot)) { if (isset($this->hotspots[$hotspot->getIdentifier()])) { drupal_set_message(t('Hotspot identifier %identifier used more than once!', array('%identifier' => $hotspot->getIdentifier())), 'warning'); } $this->hotspots[$hotspot->getIdentifier()] = $hotspot; } break; } } break; case 'mapping': $map = new CqMapping(); $map->generateFromNode($node, $this); $this->mappings[] = $map; break; case 'hint': $this->hints[] = CqFeedback::newCqFeedback($node, $this); break; default: if (!in_array($name, $this->knownElements)) { drupal_set_message(t('Unknown node: @nodename', array('@nodename' => $node->nodeName))); } break; } } }
/** * Overrides CqQuestionAbstract::loadXml() */ public function loadXml(DOMElement $dom) { parent::loadXml($dom); module_load_include('inc.php', 'closedquestion', 'lib/XmlLib'); foreach ($dom->childNodes as $node) { if (in_array($node->nodeName, $this->SECTIONS)) { $this->parseSection($node); } else { $name = drupal_strtolower($node->nodeName); switch ($name) { case 'text': $this->text = cq_get_text_content($node, $this); break; case 'hint': $this->hints[] = CqFeedback::newCqFeedback($node, $this); break; case 'correct': $this->correctFeeback['all'] = CqFeedback::newCqFeedback($node, $this); break; default: if (!in_array($name, $this->knownElements)) { drupal_set_message(t('Unknown node: @nodename', array('@nodename' => $node->nodeName))); } break; } } } $attribs = $dom->attributes; $item = $attribs->getNamedItem('inlinefeedback'); if ($item !== NULL) { $this->inlineFeedback = (int) $item->value; } }
/** * Overrides CqQuestionAbstract::loadXml() */ public function loadXml(DOMElement $dom) { parent::loadXml($dom); module_load_include('inc.php', 'closedquestion', 'lib/XmlLib'); $i = 0; foreach ($dom->childNodes as $child) { if (drupal_strtolower($child->nodeName) == 'question') { $uac =& new CqUserAnswerClient($this->userAnswer, $i); $question =& cq_question_from_dom_element($child, $uac, $this->node); if ($question) { $question->loadXML($child); $this->subQuestions[] =& $question; $question->addListener($this); unset($question); $i++; } } } $answer = $this->userAnswer->getAnswer(); if (isset($_REQUEST['CqQS_' . $this->node->nid . '_Step'])) { $this->currentIndex = (int) $_REQUEST['CqQS_' . $this->node->nid . '_Step']; $answer['ci'] = $this->currentIndex; $this->userAnswer->setAnswer($answer); $this->userAnswer->store(); } else { $this->currentIndex = (int) $answer['ci']; } if ($this->currentIndex < 0 || $this->currentIndex >= count($this->subQuestions)) { $this->currentIndex = 0; } }
/** * Overrides CqQuestionAbstract::loadXml() */ public function loadXml(DOMElement $dom) { parent::loadXml($dom); module_load_include('inc.php', 'closedquestion', 'lib/XmlLib'); foreach ($dom->childNodes as $node) { $name = drupal_strtolower($node->nodeName); switch ($name) { case 'option': $this->options[] = new CqOption($node, $this); break; case 'text': $this->text = cq_get_text_content($node, $this); break; case 'prompt': $this->prompt = cq_get_text_content($node, $this); break; case 'hint': $this->hints[] = CqFeedback::newCqFeedback($node, $this); break; case 'correct': $this->correctFeeback = CqFeedback::newCqFeedback($node, $this); break; case 'mapping': // New style mapping, continues at match by default. $map = new CqMapping(); $map->generateFromNode($node, $this); if ($node->nodeName == 'sequence') { $map->setStopIfMatch(TRUE); } $this->mappings[] = $map; break; default: if (!in_array($name, $this->knownElements)) { drupal_set_message(t('Unknown node: @nodename', array('@nodename' => $node->nodeName))); } break; } } $attribs = $dom->attributes; $item = $attribs->getNamedItem('inlinefeedback'); if ($item !== NULL) { $this->inlineFeedback = (int) $item->value; } }
/** * Overrides CqQuestionAbstract::loadXml() */ public function loadXml(DOMElement $dom) { parent::loadXml($dom); module_load_include('inc.php', 'closedquestion', 'lib/XmlLib'); foreach ($dom->childNodes as $node) { $name = drupal_strtolower($node->nodeName); switch ($name) { case 'option': case 'item': $option = new CqOption($node, $this); if (is_numeric($option->getIdentifier())) { $this->sections[$option->getIdentifier()] = $option; $this->selectedBySection[$option->getIdentifier()] = array(); } if (isset($this->items[$option->getIdentifier()])) { drupal_set_message(t('Option identifier %identifier used more than once!', array('%identifier' => $option->getIdentifier())), 'warning'); } $this->items[$option->getIdentifier()] = $option; break; case 'sequence': // Old style sequence, would stop at first match. // Old style sequence, would stop at first match. case 'mapping': // New style mapping, continues at match by default. $map = new CqMapping(); $map->generateFromNode($node, $this); if ($node->nodeName == 'sequence') { $map->setStopIfMatch(TRUE); } $this->mappings[] = $map; break; case 'text': $this->text = cq_get_text_content($node, $this); break; case 'hint': $this->hints[] = CqFeedback::newCqFeedback($node, $this); break; case 'default': case 'startstate': $attribs = $node->attributes; $item = $attribs->getNamedItem('value'); if ($item !== NULL) { $this->defaultAnswer = $item->value; } break; default: if (!in_array($name, $this->knownElements)) { drupal_set_message(t('Unknown node: @nodename', array('@nodename' => $node->nodeName))); } break; } } $attribs = $dom->attributes; $item = $attribs->getNamedItem('duplicates'); if ($item !== NULL) { $this->duplicates = (int) $item->value; } $item = $attribs->getNamedItem('alignment'); if ($item !== NULL) { $this->alignment = $item->value; } $item = $attribs->getNamedItem('optionheight'); if ($item !== NULL) { $this->optionHeight = $item->value; } $answer = $this->userAnswer->getAnswer(); if (empty($answer)) { $this->userAnswer->setAnswer($this->defaultAnswer); } if (count($this->selectedBySection) == 0) { // No sections defined, make one. $this->selectedBySection[1] = array(); } }
/** * Overrides CqQuestionAbstract::handleNode() */ public function handleNode($node, $delay = FALSE) { $answer = $this->userAnswer->getAnswer(); $retval = ''; if (drupal_strtolower($node->nodeName) == 'inlinechoice') { $choice = array(); $attribs = $node->attributes; $item = $attribs->getNamedItem('identifier'); if ($item === NULL) { $item = $attribs->getNamedItem('id'); } if ($item !== NULL) { $choiceid = $item->nodeValue; } else { if (user_access(CLOSEDQUESTION_RIGHT_CREATE)) { drupal_set_message(t('Warning: inlinechoice without identifier.'), 'warning'); } $choiceid = 'noId'; } $choice['id'] = $choiceid; $freeform = $node->attributes->getNamedItem('freeform'); $style = $node->attributes->getNamedItem('style'); $groupItem = $node->attributes->getNamedItem('group'); if ($groupItem == NULL || empty($groupItem->nodeValue)) { $choice['group'] = 'default'; } else { $choice['group'] = $groupItem->nodeValue; } if (!isset($this->inlineOptionsByGroup[$choice['group']])) { $choice['group'] = 'default'; } if ($style != NULL) { $choice['style'] = $style->nodeValue; } $class = $node->attributes->getNamedItem('class'); if ($class != NULL) { $choice['class'] = $class->nodeValue; } $choice['name'] = '' . $this->formElementName . '[' . $choiceid . ']'; $choice['size'] = 8; $sizeAtt = $node->attributes->getNamedItem('size'); if ($sizeAtt != NULL) { $choice['size'] = $sizeAtt->nodeValue; } $choice['value'] = $answer[$choiceid]; $choice['freeform'] = 0; if ($freeform != NULL && $freeform->nodeValue) { $choice['freeform'] = $freeform->nodeValue; } if (!$choice['freeform']) { $choice['options'] = $this->inlineOptionsByGroup[$choice['group']]; } $this->inlineChoices[$choiceid] = $choiceid; $retval = theme('closedquestion_inline_choice', $choice); } else { $retval = parent::handleNode($node, $delay); } return $retval; }