Example #1
0
 /**
  * Unmarshall a DOMElement object corresponding to an XHTML table element.
  *
  * @param \DOMElement $element A DOMElement object.
  * @return \qtism\data\QtiComponent A Table object.
  * @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
  */
 protected function unmarshall(DOMElement $element)
 {
     $tbodyElts = self::getChildElementsByTagName($element, 'tbody');
     if (count($tbodyElts) > 0) {
         $tbodies = new TbodyCollection();
         foreach ($tbodyElts as $tbodyElt) {
             $marshaller = $this->getMarshallerFactory()->createMarshaller($tbodyElt);
             $tbodies[] = $marshaller->unmarshall($tbodyElt);
         }
         $component = new Table($tbodies);
         if (($summary = self::getDOMElementAttributeAs($element, 'summary')) !== null) {
             $component->setSummary($summary);
         }
         if (($xmlBase = self::getXmlBase($element)) !== false) {
             $component->setXmlBase($xmlBase);
         }
         $captionElts = self::getChildElementsByTagName($element, 'caption');
         if (count($captionElts) > 0) {
             $marshaller = $this->getMarshallerFactory()->createMarshaller($captionElts[0]);
             $component->setCaption($marshaller->unmarshall($captionElts[0]));
         }
         $colElts = self::getChildElementsByTagName($element, 'col');
         if (count($colElts) > 0) {
             $cols = new ColCollection();
             foreach ($colElts as $c) {
                 $marshaller = $this->getMarshallerFactory()->createMarshaller($c);
                 $cols[] = $marshaller->unmarshall($c);
             }
             $component->setCols($cols);
         }
         $colgroupElts = self::getChildElementsByTagName($element, 'colgroup');
         if (count($colgroupElts) > 0) {
             $colgroups = new ColgroupCollection();
             foreach ($colgroupElts as $c) {
                 $marshaller = $this->getMarshallerFactory()->createMarshaller($c);
                 $colgroups[] = $marshaller->unmarshall($c);
             }
             $component->setColgroups($colgroups);
         }
         $theadElts = self::getChildElementsByTagName($element, 'thead');
         if (count($theadElts) > 0) {
             $marshaller = $this->getMarshallerFactory()->createMarshaller($theadElts[0]);
             $component->setThead($marshaller->unmarshall($theadElts[0]));
         }
         $tfootElts = self::getChildElementsByTagName($element, 'tfoot');
         if (count($tfootElts) > 0) {
             $marshaller = $this->getMarshallerFactory()->createMarshaller($tfootElts[0]);
             $component->setTfoot($marshaller->unmarshall($tfootElts[0]));
         }
         $this->fillBodyElement($component, $element);
         return $component;
     } else {
         $msg = "A 'table' element must contain at lease one 'tbody' element.";
         throw new UnmarshallingException($msg, $element);
     }
 }