Public Member Functions | Data Fields

ilXML2SQL Class Reference

Class for importing XML documents into a relational database. More...

Public Member Functions

 ilXML2SQL ($a_xmltree, $a_lo_id)
 constructor init db-handler
 insertDocument ()
 insertNode ($a_node)
 updateNode ($a_node)
 insertNodeData ($a_node)
 insertElement ($a_node)
 insertElement private
 insertText ($a_node)
 insertText private
 insertComment ($a_node)
 insertComment private
 insertAttributes ($a_node)
 insertAttributes private
 getEntryId ($a_table, $a_column, $a_return_value, $a_value)
 getEntryId checks if a single value exists in database private
 getLastInsertId ()
 getLastInsertId private
 prepareData ($a_data)
 prepare db insertion with addslashes() private
 insertStructureIntoTree ($a_nodes, $a_id)

Data Fields

 $obj_id
 $mapping
 $ilias

Detailed Description

Class for importing XML documents into a relational database.

Author:
Sascha Hofmann <shofmann@databay.de>
Version:
Id:
class.ilXML2SQL.php 4946 2004-09-14 14:42:37Z bblackmoor

Definition at line 31 of file class.ilXML2SQL.php.


Member Function Documentation

ilXML2SQL::getEntryId ( a_table,
a_column,
a_return_value,
a_value 
)

getEntryId checks if a single value exists in database private

Parameters:
string db table name
string table column
string value you seek
Returns:
boolean true when value exists

Definition at line 278 of file class.ilXML2SQL.php.

References $q, $res, and $row.

Referenced by insertAttributes(), and insertElement().

        {
                $q = "SELECT DISTINCT ".$a_return_value." FROM ".$a_table." ".
                         "WHERE ".$a_column."='".$a_value."'";
                         
                $res = $this->ilias->db->query($q,DB_FETCHMODE_ASSOC);
                
                if ($res->numRows() == 0)
                {
                        return false;
                }

                $row = $res->fetchRow();
                return $row[0];
        }

Here is the caller graph for this function:

ilXML2SQL::getLastInsertId (  ) 

getLastInsertId private

Returns:
integer

Definition at line 299 of file class.ilXML2SQL.php.

Referenced by insertAttributes(), insertElement(), and insertNode().

        {
                return $this->ilias->db->getLastInsertId();
        }

Here is the caller graph for this function:

ilXML2SQL::ilXML2SQL ( a_xmltree,
a_lo_id 
)

constructor init db-handler

public

Definition at line 63 of file class.ilXML2SQL.php.

References $ilias.

        {
                global $ilias;
                
                $this->ilias =& $ilias;
                $this->xmltree = $a_xmltree;
                $this->obj_id = $a_lo_id;
        }

ilXML2SQL::insertAttributes ( a_node  ) 

insertAttributes private

Parameters:
array node data
Returns:
boolean

Definition at line 226 of file class.ilXML2SQL.php.

References $q, getEntryId(), and getLastInsertId().

Referenced by insertNodeData().

        {
                if (is_array($a_node["attr_list"]))
                {
                        foreach ($a_node["attr_list"] as $attr => $value)
                        {
                                $attribute_id = $this->getEntryId("lo_attribute_name","attribute","attribute_id",$attr);

                                // insert attribute first if it does not exist
                                if ($attribute_id == false)
                                {
                                        $q = "INSERT INTO lo_attribute_name (attribute) ".
                                                 "VALUES ('".$attr."')";
                                        $this->ilias->db->query($q);
                        
                                        $attribute_id = $this->getLastInsertId();
                                }

                                $value_id = $this->getEntryId("lo_attribute_value","value","value_id",$value);

                                // insert attribute value first if it does not exist
                                if ($value_id == false)
                                {
                                        $q = "INSERT INTO lo_attribute_value (value) ".
                                                 "VALUES ('".$value."')";
                                        $this->ilias->db->query($q);
                        
                                        $value_id = $this->getLastInsertId();
                                }

                                // create reference entry
                                $q = "INSERT INTO lo_attribute_idx (node_id,attribute_id,value_id) ".
                                         "VALUES ".
                                         "('".$a_node["node"]."','".$attribute_id."','".$value_id."')";
                                $this->ilias->db->query($q);
                        }
                        
                        return true;
                }
                
                return false;
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilXML2SQL::insertComment ( a_node  ) 

insertComment private

Parameters:
array node data

Definition at line 211 of file class.ilXML2SQL.php.

References $q.

Referenced by insertNodeData().

        {
                $q = "INSERT INTO lo_comment ".
                         "(node_id,comment) ".
                         "VALUES ".
                         "('".$a_node["node"]."','".$a_node["content"]."')";
                $this->ilias->db->query($q);
        } 

Here is the caller graph for this function:

ilXML2SQL::insertDocument (  ) 

Definition at line 72 of file class.ilXML2SQL.php.

References $id, insertNode(), insertNodeData(), and updateNode().

        { 
                // insert basic structure of document
                foreach ($this->xmltree as $id => $node) {
                        $node_id = $this->insertNode($node);
                        $this->mapping[$id] = $node_id;
                } 
                // re-map node_ids
                foreach ($this->xmltree as $id => $node) {
                        $this->xmltree[$id]["parent"] = $this->mapping[$node["parent"]];
                        $this->xmltree[$id]["prev"] = $this->mapping[$node["prev"]];
                        $this->xmltree[$id]["next"] = $this->mapping[$node["next"]];
                        $this->xmltree[$id]["first"] = $this->mapping[$node["first"]];
                        $this->xmltree[$id]["node"] = $this->mapping[$id];
                } 

                foreach ($this->xmltree as $id => $node) {
                        $this->updateNode($node);
                        $this->insertNodeData($node);
                } 

                return $this->xmltree;
        } 

Here is the call graph for this function:

ilXML2SQL::insertElement ( a_node  ) 

insertElement private

Parameters:
array node data

Definition at line 169 of file class.ilXML2SQL.php.

References $q, getEntryId(), and getLastInsertId().

Referenced by insertNodeData().

        {
                $element_id = $this->getEntryId("lo_element_name","element","element_id",$a_node["name"]);
                
                // insert element first if it does not exist
                if ($element_id == false)
                {
                        $q = "INSERT INTO lo_element_name (element) ".
                                 "VALUES ('".$a_node["name"]."')";
                        $this->ilias->db->query($q);
                        
                        $element_id = $this->getLastInsertId();
                }
                
                // create reference entry
                $q = "INSERT INTO lo_element_idx (node_id,element_id) ".
                         "VALUES ('".$a_node["node"]."','".$element_id."')";
                $this->ilias->db->query($q);
        } 

Here is the call graph for this function:

Here is the caller graph for this function:

ilXML2SQL::insertNode ( a_node  ) 

Definition at line 96 of file class.ilXML2SQL.php.

References $q, and getLastInsertId().

Referenced by insertDocument().

        {
                $q = "INSERT INTO lo_tree ".
                         "(lo_id,lft,rgt,node_type_id,depth,struct) ".
                         "VALUES ".
                         "('".$this->obj_id."','".$a_node["left"].
                         "','".$a_node["right"]."','".$a_node["type"].
                         "','".$a_node["depth"]."','".$a_node["struct"]."') ";
                $this->ilias->db->query($q);

                return $this->getLastInsertId();
        } 

Here is the call graph for this function:

Here is the caller graph for this function:

ilXML2SQL::insertNodeData ( a_node  ) 

Definition at line 121 of file class.ilXML2SQL.php.

References insertAttributes(), insertComment(), insertElement(), insertText(), and prepareData().

Referenced by insertDocument().

        {
                //echo "<PRE>";echo var_dump($a_node);echo "</PRE>";
                $a_node = $this->prepareData($a_node);
                
                //echo "<PRE>";echo var_dump($a_node);echo "</PRE>";

                switch ($a_node["type"]) {
                        case 1:
                                $this->insertElement($a_node);
                                $this->insertAttributes($a_node);
                                break;

                        case 3:
                                $this->insertText($a_node);
                                break;

                        case 4: 
                                // $this->insertCData($a_node);
                                break;

                        case 5: 
                                // $this->insertEntityRef($a_node);
                                break;

                        case 6: 
                                // $this->insertEntity($a_node);
                                break;

                        case 7: 
                                // $this->insertPI($a_node);
                                break;

                        case 8:
                                $this->insertComment($a_node);
                                break;

                        default: 
                                // nix
                                break;
                } // switch
        } 

Here is the call graph for this function:

Here is the caller graph for this function:

ilXML2SQL::insertStructureIntoTree ( a_nodes,
a_id 
)

Definition at line 325 of file class.ilXML2SQL.php.

References $key.

        {
                // init tree
                $lm_tree = new ilTree($a_id,$a_id);
                
                //prepare array and kick all nodes with no children
                foreach ($a_nodes as $key => $nodes)
                {
                        if (!is_array($nodes[key($nodes)]))
                        {
                                array_splice($a_nodes,$key);
                                break;
                        }
                }

                // insert first_node
                $parent_id = $a_id;
                $lm_tree->insertNode(key($a_nodes[0]),$parent_id,0);
                
                // traverse array to build tree structure by inserting nodes to db-table tree
                foreach ($a_nodes as $key => $nodes)
                {
                        $parent_parent_id = $parent_id;
                        $parent_id = key($nodes);

                        foreach (array_reverse($nodes[$parent_id]) as $child_id)
                        {
                                $lm_tree->insertNode($child_id,$parent_id,$parent_parent_id);
                        }
                }
        }

ilXML2SQL::insertText ( a_node  ) 

insertText private

Parameters:
array node data

Definition at line 194 of file class.ilXML2SQL.php.

References $q, and trimDeluxe().

Referenced by insertNodeData().

        {
                // klappt nicht, weil die spaces maskiert sind :-(
                $content = trimDeluxe($a_node["content"]);
        
                $q = "INSERT INTO lo_text ".
                         "(node_id,textnode) ".
                         "VALUES ".
                         "('".$a_node["node"]."','".$content."')";
                $this->ilias->db->query($q);
        } 

Here is the call graph for this function:

Here is the caller graph for this function:

ilXML2SQL::prepareData ( a_data  ) 

prepare db insertion with addslashes() private

Parameters:
array 
Returns:
arrayr

Definition at line 310 of file class.ilXML2SQL.php.

References $data, and $key.

Referenced by insertNodeData().

        {
                foreach ($a_data as $key => $value)
                {
                        if (is_string($value))
                                $data[$key] = addslashes($value);
                        else
                                $data[$key] = $value;                   
                }
                
                return $data;
        }

Here is the caller graph for this function:

ilXML2SQL::updateNode ( a_node  ) 

Definition at line 109 of file class.ilXML2SQL.php.

References $q.

Referenced by insertDocument().

        {
                $q = "UPDATE lo_tree SET ".
                         "parent_node_id = '".$a_node["parent"]."',".
                         "prev_sibling_node_id = '".$a_node["prev"]."',".
                         "next_sibling_node_id = '".$a_node["next"]."',".
                         "first_child_node_id = '".$a_node["first"]."' ".
                         "WHERE node_id = '".$a_node["node"]."' ".
                         "AND lo_id = '".$this->obj_id."'";
                $this->ilias->db->query($q);
        } 

Here is the caller graph for this function:


Field Documentation

ilXML2SQL::$ilias

Definition at line 55 of file class.ilXML2SQL.php.

Referenced by ilXML2SQL().

ilXML2SQL::$mapping

Definition at line 47 of file class.ilXML2SQL.php.

ilXML2SQL::$obj_id

Definition at line 39 of file class.ilXML2SQL.php.


The documentation for this class was generated from the following file: