/** * Parse the answer string and put the coordinates of the different draggables * into the corresponding draggable objects. Creates new draggables objects * if required. */ private function parseAnswer() { $this->draggables = array(); $answer = $this->userAnswer->getAnswer(); $parts = explode(';', $answer); foreach ($parts as $part) { $partArr = explode(',', $part); if (count($partArr) == 3) { $draggable = new CqDraggable(new DOMElement('null'), $this); $draggable->setLocationXY($partArr[1], $partArr[2]); $this->draggables[] = $draggable; } } }
/** * 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->draggables = array(); $this->mappings = array(); $this->hints = 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'); 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; case 'draggable': $draggable = new CqDraggable($child, $this); if (isset($this->draggables[$draggable->getIdentifier()])) { drupal_set_message(t('Draggable identifier %identifier used more than once!', array('%identifier' => $draggable->getIdentifier())), 'warning'); } $this->draggables[$draggable->getIdentifier()] = $draggable; break; } } break; case 'mapping': $map = new CqMapping(); $map->generateFromNode($node, $this); $this->mappings[] = $map; break; case 'hint': $this->hints[] = CqFeedback::newCqFeedback($node, $this); break; case 'default': case 'startstate': $this->startstate = $node->getAttribute('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('width'); if ($item !== NULL && $this->matchImgWidth == NULL) { $this->matchImgWidth = (int) $item->value; } $item = $attribs->getNamedItem('height'); if ($item !== NULL && $this->matchImgHeight == NULL) { $this->matchImgHeight = (int) $item->value; } if ($this->userAnswer->isEmpty()) { $this->userAnswer->setAnswer($this->startstate); } $this->parseAnswer(); }