Public Member Functions | Data Fields

ilPCTable Class Reference

Inheritance diagram for ilPCTable:
Collaboration diagram for ilPCTable:

Public Member Functions

 ilPCTable (&$a_dom)
 Constructor public.
 setNode (&$a_node)
 create (&$a_pg_obj, $a_hier_id)
addRow ()
addCell (&$aRow, $a_data="", $a_lang="")
 addRows ($a_nr_rows, $a_nr_cols)
 add rows to table
 importSpreadsheet ($a_lang, $a_data)
 import from table
 getLanguage ()
 get table language
 setLanguage ($a_lang)
 set table language
 getWidth ()
 get table width
 setWidth ($a_width)
 set table width
 getBorder ()
 get table border width
 setBorder ($a_border)
 set table border
 getCellSpacing ()
 get table cell spacing
 setCellSpacing ($a_spacing)
 set table cell spacing
 getCellPadding ()
 get table cell padding
 setCellPadding ($a_padding)
 set table cell padding
 setHorizontalAlign ($a_halign)
 set horizontal align
 getHorizontalAlign ()
 get table cell padding
 setTDWidth ($a_hier_id, $a_width)
 set width of table data cell
 setTDClass ($a_hier_id, $a_class)
 set class of table data cell
 getCaption ()
 get caption
 getCaptionAlign ()
 get caption alignment (Top | Bottom)
 setCaption ($a_content, $a_align)
 set table caption
 importTableAttributes (&$node)
 importCellAttributes (&$node, &$par)
 importRow ($lng, &$node)
 importCell ($lng, &$cellNode, &$aRow)
 extractText (&$node)
 importHtml ($lng, $htmlTable)

Data Fields

 $dom
 $tab_node

Detailed Description

Definition at line 36 of file class.ilPCTable.php.


Member Function Documentation

& ilPCTable::addCell ( &$  aRow,
a_data = "",
a_lang = "" 
)

Definition at line 75 of file class.ilPCTable.php.

Referenced by addRows(), importCell(), and importSpreadsheet().

        {
                $new_td =& $this->dom->create_element("TableData");
                $new_td =& $aRow->append_child($new_td);
                
                // insert data if given
                if ($a_data != "")
                {
                        $new_pg =& $this->dom->create_element("PageContent");
                        $new_par =& $this->dom->create_element("Paragraph");
                        $new_par =& $new_pg->append_child($new_par);
                        $new_par->set_attribute("Language", $a_lang);
                        $new_par->set_attribute("Characteristic", "TableContent");
                        $new_par->set_content($a_data);
                        $new_td->append_child ($new_pg);
                }
                
                return $new_td;
        }

Here is the caller graph for this function:

& ilPCTable::addRow (  ) 

Definition at line 69 of file class.ilPCTable.php.

Referenced by addRows(), importRow(), and importSpreadsheet().

                            {
                $new_tr =& $this->dom->create_element("TableRow");
                $new_tr = &$this->tab_node->append_child($new_tr);
                return $new_tr;
        }

Here is the caller graph for this function:

ilPCTable::addRows ( a_nr_rows,
a_nr_cols 
)

add rows to table

Definition at line 98 of file class.ilPCTable.php.

References addCell(), and addRow().

        {
                for ($i=1; $i<=$a_nr_rows; $i++)
                {
                        $aRow = $this->addRow();
                        for ($j=1; $j<=$a_nr_cols; $j++)
                        {
                                $this->addCell($aRow);
                        }
                }
        }

Here is the call graph for this function:

ilPCTable::create ( &$  a_pg_obj,
a_hier_id 
)

Definition at line 60 of file class.ilPCTable.php.

        {
                $this->node =& $this->dom->create_element("PageContent");
                $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER);
                $this->tab_node =& $this->dom->create_element("Table");
                $this->tab_node =& $this->node->append_child($this->tab_node);
                $this->tab_node->set_attribute("Language", "");
        }

ilPCTable::extractText ( &$  node  ) 

Definition at line 486 of file class.ilPCTable.php.

References ilPageContent::$node, and $output.

Referenced by importCellAttributes(), and importTableAttributes().

                                      {
                $owner_document = $node->owner_document();
                $children = $node->child_nodes();
                $total_children = count($children);
                for ($i = 0; $i < $total_children; $i++){
                        $cur_child_node = $children[$i];
                        $output .= $owner_document->dump_node($cur_child_node);
                }
                return $output;
        }

Here is the caller graph for this function:

ilPCTable::getBorder (  ) 

get table border width

Definition at line 201 of file class.ilPCTable.php.

        {
                return $this->tab_node->get_attribute("Border");
        }

ilPCTable::getCaption (  ) 

get caption

Definition at line 349 of file class.ilPCTable.php.

References ilPageContent::$hier_id, $res, ilPageContent::getHierId(), xpath_eval(), and xpath_new_context().

        {
                $hier_id = $this->getHierId();
                if(!empty($hier_id))
                {
                        $xpc = xpath_new_context($this->dom);
                        $path = "//PageContent[@HierId = '".$hier_id."']/Table/Caption";
                        $res =& xpath_eval($xpc, $path);

                        if (count($res->nodeset) == 1)
                        {
                                return $res->nodeset[0]->get_content();
                        }
                }
        }

Here is the call graph for this function:

ilPCTable::getCaptionAlign (  ) 

get caption alignment (Top | Bottom)

Definition at line 368 of file class.ilPCTable.php.

References ilPageContent::$hier_id, $res, ilPageContent::getHierId(), xpath_eval(), and xpath_new_context().

        {
                $hier_id = $this->getHierId();
                if(!empty($hier_id))
                {
                        $xpc = xpath_new_context($this->dom);
                        $path = "//PageContent[@HierId = '".$hier_id."']/Table/Caption";
                        $res =& xpath_eval($xpc, $path);
                        if (count($res->nodeset) == 1)
                        {
                                return $res->nodeset[0]->get_attribute("Align");
                        }
                }
        }

Here is the call graph for this function:

ilPCTable::getCellPadding (  ) 

get table cell padding

Definition at line 257 of file class.ilPCTable.php.

        {
                return $this->tab_node->get_attribute("CellPadding");
        }

ilPCTable::getCellSpacing (  ) 

get table cell spacing

Definition at line 229 of file class.ilPCTable.php.

        {
                return $this->tab_node->get_attribute("CellSpacing");
        }

ilPCTable::getHorizontalAlign (  ) 

get table cell padding

Definition at line 293 of file class.ilPCTable.php.

        {
                return $this->tab_node->get_attribute("HorizontalAlign");
        }

ilPCTable::getLanguage (  ) 

get table language

Definition at line 150 of file class.ilPCTable.php.

        {
                return $this->tab_node->get_attribute("Language");
        }

ilPCTable::getWidth (  ) 

get table width

Definition at line 171 of file class.ilPCTable.php.

        {
                return $this->tab_node->get_attribute("Width");
        }

ilPCTable::ilPCTable ( &$  a_dom  ) 

Constructor public.

Definition at line 46 of file class.ilPCTable.php.

References ilPageContent::ilPageContent(), and ilPageContent::setType().

        {
                parent::ilPageContent();
                $this->setType("tab");

                $this->dom =& $a_dom;
        }

Here is the call graph for this function:

ilPCTable::importCell ( lng,
&$  cellNode,
&$  aRow 
)

Definition at line 474 of file class.ilPCTable.php.

References $lng, addCell(), and importCellAttributes().

Referenced by importRow().

                                                       {
                /*echo "add Cell";
                var_dump($cellNode);*/
                $aCell = $this->addCell($aRow);
                $par = new ilPCParagraph($this->dom);
                $par->createAtNode($aCell);
                $par->setText($par->input2xml($this->extractText ($cellNode)));
                $par->setCharacteristic("TableContent");
                $par->setLanguage($lng);
                $this->importCellAttributes($cellNode, $aCell);
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilPCTable::importCellAttributes ( &$  node,
&$  par 
)

Definition at line 433 of file class.ilPCTable.php.

References ilPageContent::$node, and extractText().

Referenced by importCell().

                                                      {
                /*echo "importing table attributes";
                var_dump($tableNode);*/
                if ($node->has_attributes ())
                {
                        foreach($node->attributes() as $n)
                        {

                                switch (strtolower($n->node_name ())) {
                                        case "class":
                                        $par->set_attribute("Class", $this->extractText($n));
                                        break;
                                        case "width":
                                        $par->set_attribute("Width", $this->extractText($n));
                                        break;
                                }

                        }
                }
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilPCTable::importHtml ( lng,
htmlTable 
)

Definition at line 497 of file class.ilPCTable.php.

References $_SESSION, $dom, $lng, ilPageContent::$node, $res, domxml_open_mem(), importRow(), importTableAttributes(), ilUtil::stripSlashes(), xpath_eval(), and xpath_new_context().

                                               {
                $dummy = ilUtil::stripSlashes($htmlTable, false);
                //echo htmlentities($dummy);
                $dom = @domxml_open_mem($dummy,DOMXML_LOAD_PARSING, $error);

                if ($dom)
                {
                        $xpc = @xpath_new_context($dom);
                        // extract first table object
                        $path = "//table[1] | //Table[1]";
                        $res = @xpath_eval($xpc, $path);

                        if (count($res->nodeset) == 0)
                        {
                                $error = "Could not find a table root node";
                        }

                        if (empty ($error)) 
                        {
                                for($i = 0; $i < count($res->nodeset); $i++)
                                {
                                        $node = $res->nodeset[$i];

                                        $this->importTableAttributes ($node);

                                        if ($node->has_child_nodes())
                                        {
                                                foreach($node->child_nodes() as $n)
                                                {
                                                        if ($n->node_type() == XML_ELEMENT_NODE &&
                                                        strcasecmp($n->node_name (), "tr") == 0)
                                                        {

                                                                $this->importRow ($lng, $n);
                                                        }
                                                }
                                        }
                                }                               
                        }
                        $dom->free ();
                }
                if (is_array($error)) {
                        $errmsg = "";
                        foreach ($error as $errorline) {    # Loop through all errors
                                $errmsg .=  "[" . $errorline['line'] . ", " . $errorline['col'] . "]: ".$errorline['errormessage']." at Node '". $errorline['nodename'] . "'<br />";
                        }
                }else
                {
                        $errmsg = $error;
                }
                
                if (empty ($errmsg)) {
                        return true;
                }
                
                $_SESSION["message"] = $errmsg;
                return false;
        }

Here is the call graph for this function:

ilPCTable::importRow ( lng,
&$  node 
)

Definition at line 455 of file class.ilPCTable.php.

References $lng, ilPageContent::$node, addRow(), and importCell().

Referenced by importHtml().

                                          {
                /*echo "add Row";
                var_dump($node);*/

                $aRow = $this->addRow();

                if ($node->has_child_nodes())
                {
                        foreach($node->child_nodes() as $n)
                        {
                                if ($n->node_type() == XML_ELEMENT_NODE &&
                                strcasecmp($n->node_name (), "td") == 0)
                                {
                                        $this->importCell ($lng, $n, $aRow);
                                }
                        }
                }
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilPCTable::importSpreadsheet ( a_lang,
a_data 
)

import from table

Definition at line 113 of file class.ilPCTable.php.

References $data, $row, addCell(), and addRow().

        {
                str_replace($a_data, "\r", "\n");
                str_replace($a_data, "\n\n", "\n");
                $target_rows = array();
                $rows = explode("\n", $a_data);

                // get maximum of cols in a row and
                // put data in target_row arrays
                foreach($rows as $row)
                {
                        $cells = explode("\t", $row);
                        $max_cols = ($max_cols > count($cells))
                                ? $max_cols
                                : count($cells);
                        $target_rows[] = $cells;
                }

                // iterate target row arrays and insert data
                foreach($target_rows as $row)
                {
                        $aRow = $this->addRow();
                        for ($j=0; $j<$max_cols; $j++)
                        {
                                // mask html
                                $data = str_replace("&","&amp;", $row[$j]);
                                $data = str_replace("<","&lt;", $data);
                                $data = str_replace(">","&gt;", $data);

                                $this->addCell($aRow, $data, $a_lang);
                        }
                }
        }

Here is the call graph for this function:

ilPCTable::importTableAttributes ( &$  node  ) 

Definition at line 401 of file class.ilPCTable.php.

References ilPageContent::$node, extractText(), setBorder(), setCellPadding(), setCellSpacing(), setHorizontalAlign(), and setWidth().

Referenced by importHtml().

                                                {
                /*echo "importing table attributes";
                var_dump($tableNode);*/
                if ($node->has_attributes ())
                {
                        foreach($node->attributes() as $n)
                        {

                                switch (strtolower($n->node_name ())) {
                                        case "border":
                                        $this->setBorder ($this->extractText($n));
                                        break;
                                        case "align":
                                        $this->setHorizontalAlign(ucfirst(strtolower($this->extractText($n))));
                                        break;
                                        case "cellspacing":
                                        $this->setCellSpacing($this->extractText($n));
                                        break;
                                        case "cellpadding":
                                        $this->setCellPadding($this->extractText($n));
                                        break;
                                        case "width":
                                        $this->setWidth($this->extractText($n));
                                        break;

                                }

                        }
                }
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilPCTable::setBorder ( a_border  ) 

set table border

Parameters:
string $a_border table border

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

Referenced by importTableAttributes().

        {
                if($a_border != "")
                {
                        $this->tab_node->set_attribute("Border", $a_border);
                }
                else
                {
                        if ($this->tab_node->has_attribute("Border"))
                        {
                                $this->tab_node->remove_attribute("Border");
                        }
                }
        }

Here is the caller graph for this function:

ilPCTable::setCaption ( a_content,
a_align 
)

set table caption

Definition at line 386 of file class.ilPCTable.php.

References ilDOMUtil::deleteAllChildsByName(), and ilDOMUtil::setFirstOptionalElement().

        {
                if ($a_content != "")
                {
                        ilDOMUtil::setFirstOptionalElement($this->dom, $this->tab_node, "Caption",
                        array("Summary", "TableRow"), $a_content,
                        array("Align" => $a_align));
                }
                else
                {
                        ilDOMUtil::deleteAllChildsByName($this->tab_node, array("Caption"));
                }
        }

Here is the call graph for this function:

ilPCTable::setCellPadding ( a_padding  ) 

set table cell padding

Parameters:
string $a_padding table cell padding

Definition at line 267 of file class.ilPCTable.php.

Referenced by importTableAttributes().

        {
                if($a_padding != "")
                {
                        $this->tab_node->set_attribute("CellPadding", $a_padding);
                }
                else
                {
                        if ($this->tab_node->has_attribute("CellPadding"))
                        {
                                $this->tab_node->remove_attribute("CellPadding");
                        }
                }
        }

Here is the caller graph for this function:

ilPCTable::setCellSpacing ( a_spacing  ) 

set table cell spacing

Parameters:
string $a_spacing table cell spacing

Definition at line 239 of file class.ilPCTable.php.

Referenced by importTableAttributes().

        {
                if($a_spacing != "")
                {
                        $this->tab_node->set_attribute("CellSpacing", $a_spacing);
                }
                else
                {
                        if ($this->tab_node->has_attribute("CellSpacing"))
                        {
                                $this->tab_node->remove_attribute("CellSpacing");
                        }
                }
        }

Here is the caller graph for this function:

ilPCTable::setHorizontalAlign ( a_halign  ) 

set horizontal align

Definition at line 285 of file class.ilPCTable.php.

Referenced by importTableAttributes().

        {
                $this->tab_node->set_attribute("HorizontalAlign", $a_halign);
        }

Here is the caller graph for this function:

ilPCTable::setLanguage ( a_lang  ) 

set table language

Parameters:
string $a_lang language code

Definition at line 160 of file class.ilPCTable.php.

        {
                if($a_lang != "")
                {
                        $this->tab_node->set_attribute("Language", $a_lang);
                }
        }

ilPCTable::setNode ( &$  a_node  ) 

Reimplemented from ilPageContent.

Definition at line 54 of file class.ilPCTable.php.

        {
                parent::setNode($a_node);               // this is the PageContent node
                $this->tab_node =& $a_node->first_child();              // this is the Table node
        }

ilPCTable::setTDClass ( a_hier_id,
a_class 
)

set class of table data cell

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

References $res, xpath_eval(), and xpath_new_context().

        {
                $xpc = xpath_new_context($this->dom);
                $path = "//TableData[@HierId = '".$a_hier_id."']";
                $res =& xpath_eval($xpc, $path);
                if (count($res->nodeset) == 1)
                {
                        if($a_class != "")
                        {
                                $res->nodeset[0]->set_attribute("Class", $a_class);
                        }
                        else
                        {
                                if ($res->nodeset[0]->has_attribute("Class"))
                                {
                                        $res->nodeset[0]->remove_attribute("Class");
                                }
                        }
                }
        }

Here is the call graph for this function:

ilPCTable::setTDWidth ( a_hier_id,
a_width 
)

set width of table data cell

Definition at line 301 of file class.ilPCTable.php.

References $res, xpath_eval(), and xpath_new_context().

        {
                $xpc = xpath_new_context($this->dom);
                $path = "//TableData[@HierId = '".$a_hier_id."']";
                $res =& xpath_eval($xpc, $path);
                if (count($res->nodeset) == 1)
                {
                        if($a_width != "")
                        {
                                $res->nodeset[0]->set_attribute("Width", $a_width);
                        }
                        else
                        {
                                if ($res->nodeset[0]->has_attribute("Width"))
                                {
                                        $res->nodeset[0]->remove_attribute("Width");
                                }
                        }
                }
        }

Here is the call graph for this function:

ilPCTable::setWidth ( a_width  ) 

set table width

Parameters:
string $a_width table width

Definition at line 181 of file class.ilPCTable.php.

Referenced by importTableAttributes().

        {
                if($a_width != "")
                {
                        $this->tab_node->set_attribute("Width", $a_width);
                }
                else
                {
                        if ($this->tab_node->has_attribute("Width"))
                        {
                                $this->tab_node->remove_attribute("Width");
                        }
                }
        }

Here is the caller graph for this function:


Field Documentation

ilPCTable::$dom

Definition at line 38 of file class.ilPCTable.php.

Referenced by importHtml().

ilPCTable::$tab_node

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


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