Public Member Functions | Data Fields

ilTableGUI Class Reference

Public Member Functions

 ilTableGUI ($a_data=0, $a_global_tpl=true)
 Constructor.
 setTemplate (&$a_tpl)
 set template public
getTemplateObject ()
 setData ($a_data)
 set table data public
 getData ()
 setTitle ($a_title, $a_icon=0, $a_icon_alt=0)
 set table title public
 setHelp ($a_help_page, $a_help_icon, $a_help_icon_alt=0)
 set table help page public
 setHeaderNames ($a_header_names)
 set table header names public
 setHeaderVars ($a_header_vars, $a_header_params=0)
 set table header vars public
 setColumnWidth ($a_column_width)
 set table column widths public
 setOneColumnWidth ($a_column_width, $a_column_number)
 set one table column width public
 setMaxCount ($a_max_count)
 set max.
 setLimit ($a_limit=0, $a_default_limit=0)
 set max.
 setPrefix ($a_prefix)
 set prefix for sort and offset fields (if you have two or more tables on a page that you want to sort separately) public
 setOffset ($a_offset)
 set dataset offset public
 setOrderColumn ($a_order_column=0, $a_default_column=0)
 set order column public
 setOrderDirection ($a_order_direction)
 set order direction public
 setFooter ($a_style, $a_previous=0, $a_next=0)
 set order direction public
 enable ($a_module_name)
 enables particular modules of table public
 disable ($a_module_name)
 diesables particular modules of table public
 sortData ()
 render ()
 render table public
 setStyle ($a_element, $a_style)
 getStyle ($a_element)

Data Fields

 $title
 $icon
 $icon_alt
 $help_page
 $help_icon
 $help_icon_alt
 $header_names
 $header_vars
 $linkbar_vars
 $data
 $column_count
 $column_width
 $max_count
 $limit
 $max_limit = false
 $offset
 $order_column
 $order_direction
 $footer_style
 $footer_previous
 $footer_next
 $lang_support = true
 $global_tpl
 $prefix
 $enabled
 $styles

Detailed Description

Definition at line 35 of file class.ilTableGUI.php.


Member Function Documentation

ilTableGUI::disable ( a_module_name  ) 

diesables particular modules of table public

Parameters:
string module name

Definition at line 404 of file class.ilTableGUI.php.

        {
                if (!in_array($a_module_name,array_keys($this->enabled)))
                {
                        return false;
                }

                $this->enabled[$a_module_name] = false;
        }

ilTableGUI::enable ( a_module_name  ) 

enables particular modules of table public

Parameters:
string module name

Definition at line 389 of file class.ilTableGUI.php.

        {
                if (!in_array($a_module_name,array_keys($this->enabled)))
                {
                        return false;
                }

                $this->enabled[$a_module_name] = true;
        } 

ilTableGUI::getData (  ) 

Definition at line 157 of file class.ilTableGUI.php.

        {
                return $this->data;
        }

ilTableGUI::getStyle ( a_element  ) 

Definition at line 654 of file class.ilTableGUI.php.

Referenced by render().

        {
                return $this->styles[$a_element];
        }

Here is the caller graph for this function:

& ilTableGUI::getTemplateObject (  ) 

Definition at line 139 of file class.ilTableGUI.php.

        {
                return $this->tpl;
        }

ilTableGUI::ilTableGUI ( a_data = 0,
a_global_tpl = true 
)

Constructor.

Parameters:
array content data (optional)
boolean use global template (default) public

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

References $ilias, $lng, $tpl, and setData().

        {
                global $ilias, $tpl, $lng;

                $this->global_tpl = $a_global_tpl;
                $this->ilias =& $ilias;
                $this->header_vars = array();
                $this->header_params = array();
                $this->enabled["form"] = true;
                if ($this->global_tpl)
                {
                        $this->tpl =& $tpl;
                }
                else
                {
                        $this->tpl = new ilTemplate("tpl.table.html",true,true);
                }

                //$this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));

                $this->lng =& $lng;

                if (!$this->lng)
                {
                        $this->lang_support = false;
                }

                $this->setData($a_data);
        }

Here is the call graph for this function:

ilTableGUI::render (  ) 

render table public

Definition at line 428 of file class.ilTableGUI.php.

References $_SESSION, $key, ilUtil::getImagePath(), getStyle(), ilUtil::Linkbar(), setMaxCount(), sortData(), and ilUtil::switchColor().

        {
                if($this->enabled['table'])
                {
                        $this->tpl->setVariable("CSS_TABLE",$this->getStyle("table"));
                }

                // table title icon
                if ($this->enabled["icon"] && $this->enabled["title"])
                {
                        $this->tpl->setCurrentBlock("tbl_header_title_icon");
                        $this->tpl->setVariable("TBL_TITLE_IMG",ilUtil::getImagePath($this->icon));
                        $this->tpl->setVariable("TBL_TITLE_IMG_ALT",$this->icon_alt);
                        $this->tpl->parseCurrentBlock();
                }
                // table title help
                if ($this->enabled["help"] && $this->enabled["title"])
                {
                        $this->tpl->setCurrentBlock("tbl_header_title_help");
                        $this->tpl->setVariable("TBL_HELP_IMG",ilUtil::getImagePath($this->help_icon));
                        $this->tpl->setVariable("TBL_HELP_LINK",$this->help_page);
                        $this->tpl->setVariable("TBL_HELP_IMG_ALT",$this->help_icon_alt);
                        $this->tpl->parseCurrentBlock();
                }

                // hits per page selector
                if ($this->enabled["hits"] && $this->enabled["title"])
                {
                        $this->tpl->setCurrentBlock("tbl_header_hits_page");
                        $this->tpl->setVariable("LIMIT",$_SESSION["tbl_limit"]);
                        $this->tpl->setVariable("HITS_PER_PAGE",$this->lng->txt("hits_per_page"));
                        $this->tpl->parseCurrentBlock();
                }
                
                // table title
                if ($this->enabled["title"])
                {
                        $this->tpl->setCurrentBlock("tbl_header_title");
                        $this->tpl->setVariable("COLUMN_COUNT",$this->column_count);
                        $this->tpl->setVariable("TBL_TITLE",$this->title);
                        $this->tpl->parseCurrentBlock();
                }

                // table header
                if ($this->enabled["header"])
                {
                        foreach ($this->header_names as $key => $tbl_header_cell)
                        {
                                if (!$this->enabled["sort"])
                                {
                                        $this->tpl->setCurrentBlock("tbl_header_no_link");
                                        if ($this->column_width[$key])
                                        {
                                                $this->tpl->setVariable("TBL_COLUMN_WIDTH_NO_LINK"," width=\"".$this->column_width[$key]."\"");
                                        }
                                        $this->tpl->setVariable("TBL_HEADER_CELL_NO_LINK",$tbl_header_cell);
                                        $this->tpl->parseCurrentBlock();
                                        continue;
                                }
                                if (($key == $this->order_column) && ($this->order_direction != ""))
                                {
                                        if (strcmp($this->header_vars[$key], "") != 0)
                                        {
                                                $this->tpl->setCurrentBlock("tbl_order_image");
                                                $this->tpl->setVariable("IMG_ORDER_DIR",ilUtil::getImagePath($this->order_direction."_order.gif"));
                                                $this->tpl->parseCurrentBlock();
                                        }
                                }
        
                                $this->tpl->setCurrentBlock("tbl_header_cell");
                                $this->tpl->setVariable("TBL_HEADER_CELL",$tbl_header_cell);
                                
                                // only set width if a value is given for that column
                                if ($this->column_width[$key])
                                {
                                        $this->tpl->setVariable("TBL_COLUMN_WIDTH"," width=\"".$this->column_width[$key]."\"");
                                }
        
                                $lng_sort_column = ($this->lang_support) ? $this->lng->txt("sort_by_this_column") : "Sort by this column";
                                $this->tpl->setVariable("TBL_ORDER_ALT",$lng_sort_column);
                        
                                $order_dir = "asc";

                                if ($key == $this->order_column)
                                { 
                                        $order_dir = $this->sort_order;
        
                                        $lng_change_sort = ($this->lang_support) ? $this->lng->txt("change_sort_direction") : "Change sort direction";
                                        $this->tpl->setVariable("TBL_ORDER_ALT",$lng_change_sort);
                                }
                        
                                $this->tpl->setVariable("TBL_ORDER_LINK",basename($_SERVER["PHP_SELF"])."?".$this->link_params.$this->prefix."sort_by=".$this->header_vars[$key]."&".$this->prefix."sort_order=".$order_dir."&".$this->prefix."offset=".$this->offset);
                                $this->tpl->parseCurrentBlock();
                        }
                        
                        $this->tpl->setCurrentBlock("tbl_header");
                        $this->tpl->parseCurrentBlock();
                }

                // table data
                // the table content may be skipped to use an individual template blockfile
                // To do so don't set $this->data and parse your table content by yourself
                // The template block name for the blockfile MUST be 'TBL_CONTENT'

                if ($this->enabled["content"] && is_array($this->data))
                {
                        if($this->enabled['auto_sort'])
                        {
                                $this->setMaxCount(count($this->data));
                                $this->sortData();
                        }
                        $count = 0;
                        
                        foreach ($this->data as $tbl_content_row)
                        {
                                foreach ($tbl_content_row as $key => $tbl_content_cell)
                                {
                    if (is_array($tbl_content_cell))
                    {
                        $this->tpl->setCurrentBlock("tbl_cell_subtitle");
                                            $this->tpl->setVariable("TBL_CELL_SUBTITLE",$tbl_content_cell[1]);
                                            $this->tpl->parseCurrentBlock();
                                            $tbl_content_cell = "<b>".$tbl_content_cell[0]."</b>";
                    }
                    
                    $this->tpl->setCurrentBlock("tbl_content_cell");
                                        $this->tpl->setVariable("TBL_CONTENT_CELL",$tbl_content_cell);
                                        $this->tpl->parseCurrentBlock();
                                }

                                $this->tpl->setCurrentBlock("tbl_content_row");
                                $rowcolor = ilUtil::switchColor($count,"tblrow1","tblrow2");
                                $this->tpl->setVariable("ROWCOLOR", $rowcolor);
                                $this->tpl->parseCurrentBlock();
                        
                                $count++;
                        }
                }
                // table footer numinfo
                if ($this->enabled["numinfo"] && $this->enabled["footer"])
                {
                        $start = $this->offset + 1;                             // compute num info
                        $end = $this->offset + $this->limit;
                        
                        if ($end > $this->max_count or $this->limit == 0)
                        {
                                $end = $this->max_count;
                        }
                        
                        if ($this->lang_support)
                        {
                                $numinfo = "(".$this->lng->txt("dataset")." ".$start." - ".$end." ".strtolower($this->lng->txt("of"))." ".$this->max_count.")";
                        }
                        else
                        {
                                $numinfo = "(Dataset ".$start." - ".$end." of ".$this->max_count.")";
                        }
                        if ($this->max_count > 0)
                        {
                                //$numinfo = $this->lng->txt("no_datasets");
                                $this->tpl->setCurrentBlock("tbl_footer_numinfo");
                                $this->tpl->setVariable("NUMINFO", $numinfo);
                                $this->tpl->parseCurrentBlock();
                        }
                }
                // table footer linkbar
                if ($this->enabled["linkbar"] && $this->enabled["footer"] && $this->limit  != 0
                         && $this->max_count > 0)
                {
                        $params = array(
                                                        "sort_by"               => $this->header_vars[$this->order_column],
                                                        "sort_order"    => $this->order_direction
                                                        );
                        $params = array_merge($this->header_params,$params);
                        
                        $layout = array(
                                                        "link"  => $this->footer_style,
                                                        "prev"  => $this->footer_previous,
                                                        "next"  => $this->footer_next,
                                                        );
                        $linkbar = ilUtil::Linkbar(basename($_SERVER["PHP_SELF"]),$this->max_count,$this->limit,$this->offset,$params,$layout);
                        $this->tpl->setCurrentBlock("tbl_footer_linkbar");
                        $this->tpl->setVariable("LINKBAR", $linkbar);
                        $this->tpl->parseCurrentBlock();
                }
                                                
                // table footer
                if ($this->enabled["footer"] && $this->max_count > 0)
                {
                        $this->tpl->setCurrentBlock("tbl_footer");
                        $this->tpl->setVariable("COLUMN_COUNT",$this->column_count);
                        $this->tpl->parseCurrentBlock();
                }

                if ($this->enabled["form"])
                {
                        $this->tpl->touchBlock("tbl_form_footer");
                }

                if($this->enabled['table'])
                {
                        $this->tpl->touchBlock("tbl_table_end");
                }

                if (!$this->global_tpl)
                {
                        return $this->tpl->get();
                }
        }

Here is the call graph for this function:

ilTableGUI::setColumnWidth ( a_column_width  ) 

set table column widths public

Parameters:
array column widths

Definition at line 248 of file class.ilTableGUI.php.

        {
                $this->column_width = $a_column_width;
        }

ilTableGUI::setData ( a_data  ) 

set table data public

Parameters:
array table data

Definition at line 149 of file class.ilTableGUI.php.

Referenced by ilTableGUI().

        {
                if (is_array($a_data))
                {
                        $this->data = $a_data;
                }
        }

Here is the caller graph for this function:

ilTableGUI::setFooter ( a_style,
a_previous = 0,
a_next = 0 
)

set order direction public

Parameters:
string css format for links
string value of previous link
string value of next link

Definition at line 376 of file class.ilTableGUI.php.

        {
                $this->footer_style = $a_style;

                $this->footer_previous = ($a_previous) ? $a_previous : "<<<";
                $this->footer_next = ($a_next) ? $a_next : ">>>";
        }

ilTableGUI::setHeaderNames ( a_header_names  ) 

set table header names public

Parameters:
array table header names

Definition at line 212 of file class.ilTableGUI.php.

        {
                $this->header_names = $a_header_names;
                $this->column_count = count($this->header_names);
        }

ilTableGUI::setHeaderVars ( a_header_vars,
a_header_params = 0 
)

set table header vars public

Parameters:
array table header vars
array additional link params

Definition at line 224 of file class.ilTableGUI.php.

References $key.

        {
                $this->header_vars = $a_header_vars;
                
                if ($a_header_params == 0 or !is_array($a_header_params))
                {
                        $this->link_params = "";
                }
                else
                {
                        $this->header_params = $a_header_params;        // temp. solution for linkbar

                        foreach ($a_header_params as $key => $val)
                        {
                                $this->link_params .= $key."=".$val."&";
                        }
                }
        }

ilTableGUI::setHelp ( a_help_page,
a_help_icon,
a_help_icon_alt = 0 
)

set table help page public

Parameters:
string help page file name
string file name of help icon
string alternative text for help icon

Definition at line 195 of file class.ilTableGUI.php.

        {
                $this->help_page = $a_help_page;
                $this->help_icon = $a_help_icon;
                $this->help_icon_alt = $a_help_icon_alt;

                if (!$this->help_icon_alt)
                {
                        $this->help_icon_alt = $this->help_icon;
                }
        }

ilTableGUI::setLimit ( a_limit = 0,
a_default_limit = 0 
)

set max.

datasets displayed per page public

Parameters:
integer limit
integer default limit

Definition at line 287 of file class.ilTableGUI.php.

        {
                $this->limit = ($a_limit) ? $a_limit : $a_default_limit;

                if ($this->limit == 0)
                {
                        $this->max_limit = true;
                }
        }

ilTableGUI::setMaxCount ( a_max_count  ) 

set max.

count of database query you don't need to set max count if using integrated content rendering feature if max_limit is true, no limit is given -> set limit to max_count public

Parameters:
integer max_count

Definition at line 271 of file class.ilTableGUI.php.

Referenced by render().

        {
                $this->max_count = $a_max_count;

                if ($this->max_limit)
                {
                        $this->limit = $this->max_count;
                }
        }

Here is the caller graph for this function:

ilTableGUI::setOffset ( a_offset  ) 

set dataset offset public

Parameters:
integer offset

Definition at line 312 of file class.ilTableGUI.php.

        {
                $this->offset = ($a_offset) ? $a_offset : 0;
        }

ilTableGUI::setOneColumnWidth ( a_column_width,
a_column_number 
)

set one table column width public

Parameters:
string column width
integer column number

Definition at line 259 of file class.ilTableGUI.php.

        {
                $this->column_width[$a_column_number] = $a_column_width;
        }

ilTableGUI::setOrderColumn ( a_order_column = 0,
a_default_column = 0 
)

set order column public

Parameters:
string order column
string default column

Definition at line 323 of file class.ilTableGUI.php.

        {
                // set default sort column to first column
                if (empty($a_order_column))
                {
                        if (!empty($a_default_column))
                        {
                                $this->order_column = array_search($a_default_column,$this->header_vars);       
                        }
                        else
                        {
                                $this->order_column = 0;
                                return;
                        }
                }
                else
                {
                        $this->order_column = array_search($a_order_column,$this->header_vars);
                }

                if ($this->order_column === false)
                {
                        // if not found, set default sort column to first column
                        $this->order_column = 0;
                }
        }

ilTableGUI::setOrderDirection ( a_order_direction  ) 

set order direction public

Parameters:
string order direction

Definition at line 355 of file class.ilTableGUI.php.

        {
                if ($a_order_direction == "desc")
                {
                        $this->order_direction = "desc";
                        $this->sort_order = "asc";
                }
                else
                {
                        $this->order_direction = "asc"; // set default sort order to "ASC"
                        $this->sort_order = "desc";
                }
        }

ilTableGUI::setPrefix ( a_prefix  ) 

set prefix for sort and offset fields (if you have two or more tables on a page that you want to sort separately) public

Parameters:
string prefix

Definition at line 302 of file class.ilTableGUI.php.

        {
                $this->prefix = ($a_prefix) ? $a_prefix : "";
        }

ilTableGUI::setStyle ( a_element,
a_style 
)

Definition at line 644 of file class.ilTableGUI.php.

        {
                $this->styles[$a_element] = $a_style;
        }

ilTableGUI::setTemplate ( &$  a_tpl  ) 

set template public

Parameters:
object template object

Definition at line 134 of file class.ilTableGUI.php.

        {
                $this->tpl =& $a_tpl;
        }

ilTableGUI::setTitle ( a_title,
a_icon = 0,
a_icon_alt = 0 
)

set table title public

Parameters:
string table title
string file name of title icon
string alternative text for title icon

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

        {
                $this->title = $a_title;
                $this->icon = $a_icon;
                $this->icon_alt = $a_icon_alt;

                if (!$this->icon)
                {
                        $this->enabled["icon"] = false;

                        return;
                }

                if (!$this->icon_alt)
                {
                        $this->icon_alt = $this->icon;
                }
        }

ilTableGUI::sortData (  ) 

Definition at line 415 of file class.ilTableGUI.php.

References ilUtil::sortArray().

Referenced by render().

        {
                if($this->enabled["sort"])
                {
                        $this->data = ilUtil::sortArray($this->data,$this->order_column,$this->order_direction);
                }
                $this->data = array_slice($this->data,$this->offset,$this->limit);
        }

Here is the call graph for this function:

Here is the caller graph for this function:


Field Documentation

ilTableGUI::$column_count

Definition at line 51 of file class.ilTableGUI.php.

ilTableGUI::$column_width

Definition at line 52 of file class.ilTableGUI.php.

ilTableGUI::$data

Definition at line 49 of file class.ilTableGUI.php.

ilTableGUI::$enabled
Initial value:
 array( "table"                 =>  true,
                                                        "title"                 =>      true,
                                                        "icon"                  =>      true,
                                                        "help"                  =>      false,
                                                        "content"               =>      true,
                                                        "action"                =>      false,
                                                        "header"        =>  true,
                                                        "footer"                =>      true,
                                                        "linkbar"               =>      true,
                                                        "numinfo"               =>      true,
                                                        "sort"                  =>  true,
                                                        "hits"          =>  false,
                                                        "auto_sort"     =>  true
                                                )

Definition at line 71 of file class.ilTableGUI.php.

ilTableGUI::$footer_next

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

ilTableGUI::$footer_previous

Definition at line 62 of file class.ilTableGUI.php.

ilTableGUI::$footer_style

Definition at line 61 of file class.ilTableGUI.php.

ilTableGUI::$global_tpl

Definition at line 66 of file class.ilTableGUI.php.

ilTableGUI::$header_names

Definition at line 45 of file class.ilTableGUI.php.

ilTableGUI::$header_vars

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

ilTableGUI::$help_icon

Definition at line 42 of file class.ilTableGUI.php.

ilTableGUI::$help_icon_alt

Definition at line 43 of file class.ilTableGUI.php.

ilTableGUI::$help_page

Definition at line 41 of file class.ilTableGUI.php.

ilTableGUI::$icon

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

ilTableGUI::$icon_alt

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

ilTableGUI::$lang_support = true

Definition at line 65 of file class.ilTableGUI.php.

ilTableGUI::$limit

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

ilTableGUI::$linkbar_vars

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

ilTableGUI::$max_count

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

ilTableGUI::$max_limit = false

Definition at line 56 of file class.ilTableGUI.php.

ilTableGUI::$offset

Definition at line 57 of file class.ilTableGUI.php.

ilTableGUI::$order_column

Definition at line 58 of file class.ilTableGUI.php.

ilTableGUI::$order_direction

Definition at line 59 of file class.ilTableGUI.php.

ilTableGUI::$prefix

Definition at line 68 of file class.ilTableGUI.php.

ilTableGUI::$styles
Initial value:
 array(
                                                        "table"         => "fullwidth"
                                                )

Definition at line 87 of file class.ilTableGUI.php.

ilTableGUI::$title

Definition at line 37 of file class.ilTableGUI.php.


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