示例#1
0
 /**
  * Creates a new CqOption.
  *
  * @param DOMElement $node
  *   containing the option definition
  * @param CqQuestionInterface $context
  *   CqQuestionInterface The question or other object that the mapping can query for
  *   things like the current answer, draggables, hotspots and the parsing of
  *   html.
  */
 public function __construct(DOMElement $node, $context)
 {
     foreach ($node->getElementsByTagName('choice') as $choice) {
         $this->text .= cq_get_text_content($choice, $context);
     }
     foreach ($node->getElementsByTagName('description') as $description) {
         $this->description .= cq_get_text_content($description, $context);
     }
     foreach ($node->getElementsByTagName('feedback') as $fb) {
         $this->feedback[] = CqFeedback::newCqFeedback($fb, $context);
     }
     foreach ($node->getElementsByTagName('feedbackunselected') as $fb) {
         $this->feedbackUnselected[] = CqFeedback::newCqFeedback($fb, $context);
     }
     $attribs = $node->attributes;
     $item = $attribs->getNamedItem('correct');
     if ($item !== NULL) {
         $this->correct = (int) $item->value;
     }
     $item = $attribs->getNamedItem('identifier');
     if ($item === NULL) {
         $item = $attribs->getNamedItem('id');
     }
     if ($item === NULL) {
         $item = $attribs->getNamedItem('name');
     }
     if ($item !== NULL) {
         $this->identifier = $item->nodeValue;
     }
 }
 /**
  * Implements CqQuestionAbstract::getAllText()
  */
 public function getAllText()
 {
     $this->initialise();
     $retval = array();
     $retval['text']['#markup'] = $this->text;
     if ($this->correctFeeback) {
         $retval['correctFeeback']['#markup'] = $this->correctFeeback->getText();
     }
     // Hints
     if (count($this->hints) > 0) {
         $retval['hints'] = array('#theme' => 'closedquestion_feedback_list', 'extended' => TRUE);
         foreach ($this->hints as $fbitem) {
             $retval['hints']['items'][] = $fbitem->getAllText();
         }
     }
     // Options
     $retval['options'] = array('#theme' => 'closedquestion_option_list', 'items' => array(), 'extended' => TRUE);
     foreach ($this->options as $option) {
         $retval['options']['items'][] = $option->getAllText();
     }
     // Mappings
     $retval['mappings'] = array('#theme' => 'closedquestion_mapping_list', 'items' => array());
     foreach ($this->mappings as $mapping) {
         $retval['mappings']['items'][] = $mapping->getAllText();
     }
     $retval['#theme'] = 'closedquestion_question_general_text';
     return $retval;
 }
示例#3
0
 /**
  * Constructor for the Range object.
  *
  * @param DOMElement $node
  *   The XML node to use for initalisation
  * @param <type> $context
  *   CqQuestionInterface The question or other object that the mapping can query for
  *   things like the current answer, draggables, hotspots and the parsing of
  *   html.
  */
 public function __construct(DOMElement $node, $context)
 {
     module_load_include('inc.php', 'closedquestion', 'lib/XmlLib');
     $nodeList = $node->getElementsByTagName('minval');
     $item = $nodeList->item(0);
     if ($item != NULL) {
         $this->minValue = trim(cq_get_text_content($item, $context));
     }
     $nodeList = $node->getElementsByTagName('maxval');
     $item = $nodeList->item(0);
     if ($item != NULL) {
         $this->maxValue = trim(cq_get_text_content($item, $context));
     }
     foreach ($node->getElementsByTagName('feedback') as $fb) {
         $this->feedback[] = CqFeedback::newCqFeedback($fb, $context);
     }
     $attribs = $node->attributes;
     $item = $attribs->getNamedItem('correct');
     if ($item !== NULL) {
         $this->correct = (int) $item->value;
     }
 }
 /**
  * Initialises a mapping item using data from an XML node.
  *
  * @param $node
  *   DOMElement The node to use for initialisation.
  * @param $context
  *   CqQuestionInterface The question or other object that the mapping can query for
  *   things like the current answer, draggables, hotspots and the parsing of
  *   html.
  * @param $topParent
  *   The highest parent in this mapping tree.
  */
 public function generateFromNode($node, &$context, $topParent = NULL)
 {
     $this->params = array();
     $this->children = array();
     $this->feedback = array();
     $this->context =& $context;
     $this->topParent =& $topParent;
     if (is_null($topParent)) {
         $topParent =& $this;
     }
     foreach ($node->attributes as $attrib) {
         $this->params[strtolower($attrib->nodeName)] = $attrib->nodeValue;
     }
     foreach ($node->childNodes as $child) {
         switch ($child->nodeName) {
             case 'feedback':
                 $newchild = CqFeedback::newCqFeedback($child, $context);
                 $newchild->topParent =& $topParent;
                 $this->feedback[] = $newchild;
                 continue 2;
                 // continue to the next child.
             // continue to the next child.
             case '#text':
             case '#comment':
                 continue 2;
                 // continue to the next child.
             // continue to the next child.
             case 'pattern':
                 // Old style patterns are now handled by CqMatch
                 $newchild = new CqMatch();
                 $newchild->context =& $context;
                 $newchild->params['pattern'] = $child->nodeValue;
                 $this->children[] = $newchild;
                 continue 2;
                 // continue to the next child.
             // continue to the next child.
             case 'mapping':
                 $newchild = new CqMapping();
                 break;
             case 'and':
                 $newchild = new CqMappingAnd();
                 break;
             case 'or':
                 $newchild = new CqMappingOr();
                 break;
             case 'not':
                 $newchild = new CqMappingNot();
                 break;
             case 'combination':
             case 'match':
                 $newchild = new CqMatch();
                 break;
             case 'range':
                 $newchild = new CqMatchRange();
                 break;
             default:
                 drupal_set_message(t('Unknown node type: @nodename', array('@nodename' => $child->nodeName)));
                 continue 2;
                 // continue to the next child.
         }
         $newchild->generateFromNode($child, $context, $topParent);
         $this->children[] = $newchild;
     }
 }
 /**
  * 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;
     }
 }
 /**
  * Implements CqQuestionAbstract::getExtraFeedbackItems()
  */
 public function getExtraFeedbackItems($caller, $tries)
 {
     $retval = array();
     if (!empty($this->backNext)) {
         $fbItem = new CqFeedback();
         $fbItem->initWithValues($this->backNext, 0, 9999);
         $retval[] = $fbItem;
     }
     $retval = array_merge($retval, $this->fireGetExtraFeedbackItems($this, $tries));
     return $retval;
 }
 /**
  * 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 'range':
                 $this->ranges[] = new CqRange($node, $this);
                 break;
             case 'unit':
                 $this->unit = cq_get_text_content($node, $this);
                 break;
             case 'text':
                 $this->text = 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;
             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) {
         $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::loadXml()
  */
 public function loadXml(DOMElement $dom)
 {
     parent::loadXml($dom);
     module_load_include('inc.php', 'closedquestion', 'lib/XmlLib');
     $textNode = NULL;
     foreach ($dom->childNodes as $node) {
         $name = drupal_strtolower($node->nodeName);
         switch ($name) {
             case 'inlineoption':
                 $option = new CqInlineOption($node, $this);
                 if (isset($this->inlineOptions[$option->getIdentifier()])) {
                     drupal_set_message(t('Inlineoption identifier %identifier used more than once!', array('%identifier' => $option->getIdentifier())), 'warning');
                 }
                 $this->inlineOptions[$option->getIdentifier()] = $option;
                 $this->inlineOptionsByGroup[$option->getGroup()][$option->getIdentifier()] = $option;
                 break;
             case 'mapping':
                 $map = new CqMapping();
                 $map->generateFromNode($node, $this);
                 $this->mappings[] = $map;
                 break;
             case 'text':
                 $textNode = $node;
                 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;
         }
     }
     if ($textNode != NULL) {
         $this->text = cq_get_text_content($textNode, $this);
     }
 }
示例#11
0
 /**
  * Creates a new CqFeedback and initialises it from an XML node.
  *
  * @param DOMElement $node
  *   The node to use for initalisation
  * @param CqQuestionInterface $context
  *   The question or other object that the item can query for
  *   things like the current answer, draggables and hotspots.
  *
  * @return CqFeedback
  *   A new CqFeedback instance.
  */
 public static function newCqFeedback(DOMElement $node, $context)
 {
     $fbItem = new CqFeedback();
     $fbItem->initFromElement($node, $context);
     return $fbItem;
 }