Beispiel #1
0
 function addHierIDs()
 {
     $this->hier_ids = array();
     $this->first_row_ids = array();
     $this->first_col_ids = array();
     $this->list_item_ids = array();
     $this->file_item_ids = array();
     // set hierarchical ids for Paragraphs, Tables, TableRows and TableData elements
     $xpc = xpath_new_context($this->dom);
     //$path = "//Paragraph | //Table | //TableRow | //TableData";
     $sep = $path = "";
     foreach ($this->id_elements as $el) {
         $path .= $sep . "//" . $el;
         $sep = " | ";
     }
     $res =& xpath_eval($xpc, $path);
     for ($i = 0; $i < count($res->nodeset); $i++) {
         $cnode = $res->nodeset[$i];
         $ctag = $cnode->node_name();
         // get hierarchical id of previous sibling
         $sib_hier_id = "";
         while ($cnode =& $cnode->previous_sibling()) {
             if ($cnode->node_type() == XML_ELEMENT_NODE && $cnode->has_attribute("HierId")) {
                 $sib_hier_id = $cnode->get_attribute("HierId");
                 //$sib_hier_id = $id_attr->value();
                 break;
             }
         }
         if ($sib_hier_id != "") {
             require_once "./Services/COPage/classes/class.ilPageContent.php";
             $node_hier_id = ilPageContent::incEdId($sib_hier_id);
             $res->nodeset[$i]->set_attribute("HierId", $node_hier_id);
             $this->hier_ids[] = $node_hier_id;
             if ($ctag == "TableData") {
                 if (substr($par_hier_id, strlen($par_hier_id) - 2) == "_1") {
                     $this->first_row_ids[] = $node_hier_id;
                 }
             }
             if ($ctag == "ListItem") {
                 $this->list_item_ids[] = $node_hier_id;
             }
             if ($ctag == "FileItem") {
                 $this->file_item_ids[] = $node_hier_id;
             }
         } else {
             // get hierarchical id of next parent
             $cnode = $res->nodeset[$i];
             $par_hier_id = "";
             while ($cnode =& $cnode->parent_node()) {
                 if ($cnode->node_type() == XML_ELEMENT_NODE && $cnode->has_attribute("HierId")) {
                     $par_hier_id = $cnode->get_attribute("HierId");
                     //$par_hier_id = $id_attr->value();
                     break;
                 }
             }
             //echo "<br>par:".$par_hier_id." ($ctag)";
             if ($par_hier_id != "" && $par_hier_id != "pg") {
                 $node_hier_id = $par_hier_id . "_1";
                 $res->nodeset[$i]->set_attribute("HierId", $node_hier_id);
                 $this->hier_ids[] = $node_hier_id;
                 if ($ctag == "TableData") {
                     $this->first_col_ids[] = $node_hier_id;
                     if (substr($par_hier_id, strlen($par_hier_id) - 2) == "_1") {
                         $this->first_row_ids[] = $node_hier_id;
                     }
                 }
                 if ($ctag == "ListItem") {
                     $this->list_item_ids[] = $node_hier_id;
                 }
                 if ($ctag == "FileItem") {
                     $this->file_item_ids[] = $node_hier_id;
                 }
             } else {
                 $node_hier_id = "1";
                 $res->nodeset[$i]->set_attribute("HierId", $node_hier_id);
                 $this->hier_ids[] = $node_hier_id;
             }
         }
     }
     // set special hierarchical id "pg" for pageobject
     $xpc = xpath_new_context($this->dom);
     $path = "//PageObject";
     $res =& xpath_eval($xpc, $path);
     for ($i = 0; $i < count($res->nodeset); $i++) {
         $res->nodeset[$i]->set_attribute("HierId", "pg");
         $this->hier_ids[] = "pg";
     }
     unset($xpc);
 }