• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/Table/classes/class.ilTable2GUI.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2005 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 require_once("Services/Table/classes/class.ilTableGUI.php");
00025 
00034 class ilTable2GUI extends ilTableGUI
00035 {
00036         protected $close_command = "";
00037         
00042         public function __construct($a_parent_obj, $a_parent_cmd = "")
00043         {
00044                 global $ilUser;
00045                 
00046                 parent::__construct(0, false);
00047                 $this->parent_obj = $a_parent_obj;
00048                 $this->parent_cmd = $a_parent_cmd;
00049                 $this->buttons = array();
00050                 $this->header_commands = array();
00051                 $this->multi = array();
00052                 $this->formname = "table";
00053                 $this->tpl = new ilTemplate("tpl.table2.html", true, true, "Services/Table");
00054                 
00055                 $this->setLimit($ilUser->getPref("hits_per_page"));
00056         }
00057         
00065         public function getParentObject()
00066         {
00067                 return $this->parent_obj;
00068         }
00069         
00075         function setNoEntriesText($a_text)
00076         {
00077                 $this->noentriestext = $a_text;
00078         }
00079 
00085         function getNoEntriesText()
00086         {
00087                 return $this->noentriestext;
00088         }
00089 
00095         function setEnableTitle($a_enabletitle)
00096         {
00097                 $this->enabled["title"] = $a_enabletitle;
00098         }
00099 
00105         function getEnableTitle()
00106         {
00107                 return $this->enabled["title"];
00108         }
00109 
00115         function setEnableHeader($a_enableheader)
00116         {
00117                 $this->enabled["header"] = $a_enableheader;
00118         }
00119 
00125         function getEnableHeader()
00126         {
00127                 return $this->enabled["header"];
00128         }
00129 
00130         final public function setTitle($a_title, $a_icon = 0, $a_icon_alt = 0)
00131         {
00132                 parent::setTitle($a_title, $a_icon, $a_icon_alt);
00133         }
00134         
00140         function setOrderField($a_order_field)
00141         {
00142                 $this->order_field = $a_order_field;
00143         }
00144 
00145         function getOrderField()
00146         {
00147                 return $this->order_field;
00148         }
00149 
00150         final public function setData($a_data)
00151         {
00152                 $this->row_data = $a_data;
00153         }
00154         
00155         final public function getData()
00156         {
00157                 return $this->row_data;
00158         }
00159 
00160         final public function setPrefix($a_prefix)
00161         {
00162                 $this->prefix = $a_prefix;
00163         }
00164 
00170         final public function setFormAction($a_form_action)
00171         {
00172                 $this->form_action = $a_form_action;
00173         }
00174         
00180         final public function getFormAction()
00181         {
00182                 return $this->form_action;
00183         }
00184         
00190         function setFormName($a_formname)
00191         {
00192                 $this->formname = $a_formname;
00193         }
00194 
00200         function getFormName()
00201         {
00202                 return $this->formname;
00203         }
00204         
00210         function getSelectAllCheckbox()
00211         {
00212                 return $this->select_all_checkbox;
00213         }
00214         
00220         function setSelectAllCheckbox($a_select_all_checkbox)
00221         {
00222                 $this->select_all_checkbox = $a_select_all_checkbox;
00223         }
00224 
00231         final public function setRowTemplate($a_template, $a_template_dir = "")
00232         {
00233                 $this->row_template = $a_template;
00234                 $this->row_template_dir = $a_template_dir;
00235         }
00236         
00242         function setDefaultOrderField($a_defaultorderfield)
00243         {
00244                 $this->defaultorderfield = $a_defaultorderfield;
00245         }
00246 
00252         function getDefaultOrderField()
00253         {
00254                 return $this->defaultorderfield;
00255         }
00256 
00262         function setDefaultOrderDirection($a_defaultorderdirection)
00263         {
00264                 $this->defaultorderdirection = $a_defaultorderdirection;
00265         }
00266 
00272         function getDefaultOrderDirection()
00273         {
00274                 return $this->defaultorderdirection;
00275         }
00276         
00283         function addCommandButton($a_cmd, $a_text)
00284         {
00285                 $this->buttons[] = array("cmd" => $a_cmd, "text" => $a_text);
00286         }
00287         
00288         
00294         function setCloseCommand($a_link)
00295         {
00296                 $this->close_command = $a_link;
00297         }
00298 
00305         function addMultiCommand($a_cmd, $a_text)
00306         {
00307                 $this->multi[] = array("cmd" => $a_cmd, "text" => $a_text);
00308         }
00309 
00316         function addHeaderCommand($a_href, $a_text, $a_target = "", $a_img = "")
00317         {
00318                 $this->header_commands[] = array("href" => $a_href, "text" => $a_text,
00319                         "target" => $a_target, "img" => $a_img);
00320         }
00321 
00329         final public function addColumn($a_text, $a_sort_field = "", $a_width = "")
00330         {
00331                 $this->column[] = array(
00332                         "text" => $a_text,
00333                         "sort_field" => $a_sort_field,
00334                         "width" => $a_width);
00335                 $this->column_count = count($this->column);
00336         }
00337         
00338         final public function getNavParameter()
00339         {
00340                 return $this->prefix."_table_nav";
00341         }
00342         
00343         function setOrderLink($sort_field, $order_dir)
00344         {
00345                 global $ilCtrl;
00346                 
00347                 $old = $_GET[$this->getNavParameter()];
00348                 
00349                 // set order link
00350                 $ilCtrl->setParameter($this->parent_obj,
00351                         $this->getNavParameter(),
00352                         $sort_field.":".$order_dir.":".$this->offset);
00353                 $this->tpl->setVariable("TBL_ORDER_LINK",
00354                         $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd));
00355                 
00356                 // set old value of nav variable
00357                 $ilCtrl->setParameter($this->parent_obj,
00358                         $this->getNavParameter(), $old);
00359         }
00360 
00361         function fillHeader()
00362         {
00363                 foreach ($this->column as $column)
00364                 {
00365                         if (!$this->enabled["sort"] || $column["sort_field"] == "")
00366                         {
00367                                 $this->tpl->setCurrentBlock("tbl_header_no_link");
00368                                 if ($column["width"] != "")
00369                                 {
00370                                         $this->tpl->setVariable("TBL_COLUMN_WIDTH_NO_LINK"," width=\"".$column["width"]."\"");
00371                                 }
00372                                 $this->tpl->setVariable("TBL_HEADER_CELL_NO_LINK",
00373                                         $column["text"]);
00374                                 $this->tpl->parseCurrentBlock();
00375                                 $this->tpl->touchBlock("tbl_header_th");
00376                                 continue;
00377                         }
00378                         if (($column["sort_field"] == $this->order_field) && ($this->order_direction != ""))
00379                         {
00380                                 $this->tpl->setCurrentBlock("tbl_order_image");
00381                                 $this->tpl->setVariable("IMG_ORDER_DIR",ilUtil::getImagePath($this->order_direction."_order.gif"));
00382                                 $this->tpl->parseCurrentBlock();
00383                         }
00384 
00385                         $this->tpl->setCurrentBlock("tbl_header_cell");
00386                         $this->tpl->setVariable("TBL_HEADER_CELL", $column["text"]);
00387                         
00388                         // only set width if a value is given for that column
00389                         if ($column["width"] != "")
00390                         {
00391                                 $this->tpl->setVariable("TBL_COLUMN_WIDTH"," width=\"".$column["width"]."\"");
00392                         }
00393 
00394                         $lng_sort_column = $this->lng->txt("sort_by_this_column");
00395                         $this->tpl->setVariable("TBL_ORDER_ALT",$lng_sort_column);
00396                 
00397                         $order_dir = "asc";
00398 
00399                         if ($column["sort_field"] == $this->order_field)
00400                         { 
00401                                 $order_dir = $this->sort_order;
00402 
00403                                 $lng_change_sort = $this->lng->txt("change_sort_direction");
00404                                 $this->tpl->setVariable("TBL_ORDER_ALT",$lng_change_sort);
00405                         }
00406                 
00407                         $this->setOrderLink($column["sort_field"], $order_dir);
00408                         $this->tpl->parseCurrentBlock();
00409                         $this->tpl->touchBlock("tbl_header_th");
00410                 }
00411                 
00412                 $this->tpl->setCurrentBlock("tbl_header");
00413                 $this->tpl->parseCurrentBlock();
00414         }
00415 
00416         
00417         final public function getHTML()
00418         {
00419                 global $lng;
00420                 
00421                 $this->nav_value = ($_POST[$this->getNavParameter()] != "")
00422                         ? $_POST[$this->getNavParameter()]
00423                         : $_GET[$this->getNavParameter()];
00424                 $nav = explode(":", $this->nav_value);
00425                 
00426                 // $nav[0] is order by
00427                 $this->setOrderField(($nav[0] != "") ? $nav[0] : $this->getDefaultOrderField());
00428                 $this->setOrderDirection(($nav[1] != "") ? $nav[1] : $this->getDefaultOrderDirection());
00429                 $this->setOffset($nav[2]);
00430                 $this->setMaxCount(count($this->row_data));
00431                 $this->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
00432                 
00433                 // sort
00434                 $data = $this->getData();
00435                 $data = ilUtil::sortArray($data, $this->getOrderField(),
00436                         $this->getOrderDirection());
00437                                 
00438                 // slice
00439                 $data = array_slice($data, $this->getOffset(), $this->getLimit());
00440 
00441                 // fill rows
00442                 if(count($data) > 0)
00443                 {
00444                         $this->tpl->addBlockFile("TBL_CONTENT", "tbl_content", $this->row_template,
00445                                 $this->row_template_dir);
00446         
00447                         foreach($data as $set)
00448                         {
00449                                 $this->tpl->setCurrentBlock("tbl_content");
00450                                 $this->css_row = ($this->css_row != "tblrow1")
00451                                         ? "tblrow1"
00452                                         : "tblrow2";
00453                                 $this->tpl->setVariable("CSS_ROW", $this->css_row);
00454 
00455                                 $this->fillRow($set);
00456                                 $this->tpl->setCurrentBlock("tbl_content");
00457                                 $this->tpl->parseCurrentBlock();
00458                         }
00459                 }
00460                 else if (trim($this->getNoEntriesText()) != '')
00461                 {
00462                         $this->css_row = ($this->css_row != "tblrow1")
00463                                         ? "tblrow1"
00464                                         : "tblrow2";                            
00465                         
00466                         $this->tpl->setVariable('TBL_NO_ENTRY_CSS_ROW', $this->css_row);
00467                         $this->tpl->setVariable('TBL_NO_ENTRY_COLUMN_COUNT', $this->column_count);
00468                         $this->tpl->setVariable('TBL_NO_ENTRY_TEXT', trim($this->getNoEntriesText()));                  
00469                 }
00470                 
00471                 // set form action              
00472                 if ($this->form_action != "")
00473                 {
00474                         $this->tpl->setCurrentBlock("tbl_form_header");
00475                         $this->tpl->setVariable("FORMACTION", $this->getFormAction());
00476                         $this->tpl->setVariable("FORMNAME", $this->getFormName());
00477                         $this->tpl->parseCurrentBlock();
00478                         $this->tpl->touchBlock("tbl_form_footer");
00479                 }
00480                 
00481                 $this->fillFooter();
00482                                 
00483                 $this->fillActionRow();
00484 
00485                 return $this->render();
00486         }
00487 
00488 
00493         function render()
00494         {
00495                 global $lng;
00496                 
00497                 $this->tpl->setVariable("CSS_TABLE",$this->getStyle("table"));
00498                 
00499                 // table title and icon
00500                 if ($this->enabled["title"])
00501                 {
00502                         if ($this->enabled["icon"])
00503                         {
00504                                 $this->tpl->setCurrentBlock("tbl_header_title_icon");
00505                                 $this->tpl->setVariable("TBL_TITLE_IMG",ilUtil::getImagePath($this->icon));
00506                                 $this->tpl->setVariable("TBL_TITLE_IMG_ALT",$this->icon_alt);
00507                                 $this->tpl->parseCurrentBlock();
00508                         }
00509                         
00510                         foreach($this->header_commands as $command)
00511                         {
00512                                 $this->tpl->setCurrentBlock("tbl_header_img_link");
00513                                 if ($command["target"] != "")
00514                                 {
00515                                         $this->tpl->setVariable("TARGET_IMG_LINK",
00516                                                 'target="'.$command["target"].'"');
00517                                 }
00518                                 $this->tpl->setVariable("ALT_IMG_LINK", $command["txt"]);
00519                                 $this->tpl->setVariable("HREF_IMG_LINK", $command["href"]);
00520                                 $this->tpl->setVariable("SRC_IMG_LINK",
00521                                         $command["img"]);
00522                                 $this->tpl->parseCurrentBlock();
00523                         }
00524                         
00525                         // close command
00526                         if ($this->close_command != "")
00527                         {
00528                                 $this->tpl->setCurrentBlock("tbl_header_img_link");
00529                                 $this->tpl->setVariable("ALT_IMG_LINK",$lng->txt("close"));
00530                                 $this->tpl->setVariable("HREF_IMG_LINK",$this->close_command);
00531                                 $this->tpl->setVariable("SRC_IMG_LINK",ilUtil::getImagePath("icon_close2.gif"));
00532                                 $this->tpl->parseCurrentBlock();
00533                         }
00534 
00535                         $this->tpl->setCurrentBlock("tbl_header_title");
00536                         $this->tpl->setVariable("COLUMN_COUNT",$this->column_count);
00537                         $this->tpl->setVariable("TBL_TITLE",$this->title);
00538                         $this->tpl->parseCurrentBlock();
00539                 }
00540 
00541                 // table header
00542                 if ($this->enabled["header"])
00543                 {
00544                         $this->fillHeader();
00545                 }
00546 
00547                 $this->tpl->touchBlock("tbl_table_end");
00548 
00549                 return $this->tpl->get();
00550         }
00551 
00558         protected function fillRow($a_set)
00559         {
00560                 foreach ($a_set as $key => $value)
00561                 {
00562                         $this->tpl->setVariable("VAL_".strtoupper($key), $value);
00563                 }
00564         }
00565         
00566         
00570         function fillFooter()
00571         {
00572                 global $lng, $ilCtrl;
00573 
00574                 $footer = false;
00575                 
00576                 // select all checkbox
00577                 if ((strlen($this->getFormName())) && (strlen($this->getSelectAllCheckbox())))
00578                 {
00579                         $this->tpl->setCurrentBlock("select_all_checkbox");
00580                         $this->tpl->setVariable("SELECT_ALL_TXT_SELECT_ALL", $lng->txt("select_all"));
00581                         $this->tpl->setVariable("SELECT_ALL_CHECKBOX_NAME", $this->getSelectAllCheckbox());
00582                         $this->tpl->setVariable("SELECT_ALL_FORM_NAME", $this->getFormName());
00583                         $this->tpl->parseCurrentBlock();
00584                         $footer = true;
00585                 }
00586                 
00587                 // table footer numinfo
00588                 if ($this->enabled["numinfo"] && $this->enabled["footer"])
00589                 {
00590                         $start = $this->offset + 1;                             // compute num info
00591                         $end = $this->offset + $this->limit;
00592                         
00593                         if ($end > $this->max_count or $this->limit == 0)
00594                         {
00595                                 $end = $this->max_count;
00596                         }
00597                         
00598                         if ($this->lang_support)
00599                         {
00600                                 $numinfo = "(".$this->lng->txt("dataset")." ".$start." - ".$end." ".strtolower($this->lng->txt("of"))." ".$this->max_count.")";
00601                         }
00602                         else
00603                         {
00604                                 $numinfo = "(Dataset ".$start." - ".$end." of ".$this->max_count.")";
00605                         }
00606                         if ($this->max_count > 0)
00607                         {
00608                                 //$numinfo = $this->lng->txt("no_datasets");
00609                                 $this->tpl->setCurrentBlock("tbl_footer_numinfo");
00610                                 $this->tpl->setVariable("NUMINFO", $numinfo);
00611                                 $this->tpl->parseCurrentBlock();
00612                         }
00613                         $footer = true;
00614                 }
00615 
00616                 // table footer linkbar
00617                 if ($this->enabled["linkbar"] && $this->enabled["footer"] && $this->limit  != 0
00618                          && $this->max_count > 0)
00619                 {
00620                         $layout = array(
00621                                                         "link"  => $this->footer_style,
00622                                                         "prev"  => $this->footer_previous,
00623                                                         "next"  => $this->footer_next,
00624                                                         );
00625                         $linkbar = $this->getLinkbar();
00626                         $this->tpl->setCurrentBlock("tbl_footer_linkbar");
00627                         $this->tpl->setVariable("LINKBAR", $linkbar);
00628                         $this->tpl->parseCurrentBlock();
00629                         $footer = true;
00630                 }
00631 
00632                 if ($footer)
00633                 {
00634                         $this->tpl->setCurrentBlock("tbl_footer");
00635                         $this->tpl->setVariable("COLUMN_COUNT", $this->getColumnCount());
00636                         $this->tpl->parseCurrentBlock();
00637                 }
00638         }
00639         
00647         function getLinkbar()
00648         {
00649                 global $ilCtrl, $lng;
00650                 
00651                 $link = $ilCtrl->getLinkTargetByClass(get_class($this->parent_obj), $this->parent_cmd).
00652                         "&".$this->getNavParameter()."=".
00653                         $this->getOrderField().":".$this->getOrderDirection().":";
00654                 
00655                 $LinkBar = "";
00656                 $layout_prev = $lng->txt("previous");
00657                 $layout_next = $lng->txt("next");
00658                 
00659                 // if more entries then entries per page -> show link bar
00660                 if ($this->max_count > $this->getLimit())
00661                 {
00662                         // previous link
00663                         if ($this->getOffset() >= 1)
00664                         {
00665                                 $prevoffset = $this->getOffset() - $this->getLimit();
00666                                 $LinkBar .= "<a class=\"small\" href=\"".$link.$prevoffset."\">".$layout_prev."&nbsp;</a>";
00667                         }
00668 
00669                         // calculate number of pages
00670                         $pages = intval($this->max_count / $this->getLimit());
00671 
00672                         // add a page if a rest remains
00673                         if (($this->max_count % $this->getLimit()))
00674                                 $pages++;
00675 
00676                         // links to other pages
00677                         $offset_arr = array();
00678                         for ($i = 1 ;$i <= $pages ; $i++)
00679                         {
00680                                 $newoffset = $this->getLimit() * ($i-1);
00681 
00682                                 $nav_value = $this->getOrderField().":".$this->getOrderDirection().":".$newoffset;
00683                                 $offset_arr[$nav_value] = $i;
00684                                 if ($newoffset == $this->getOffset())
00685                                 {
00686                                 //      $LinkBar .= "[".$i."] ";
00687                                 }
00688                                 else
00689                                 {
00690                                 //      $LinkBar .= '<a '.$layout_link.' href="'.
00691                                 //              $link.$newoffset.'">['.$i.']</a> ';
00692                                 }
00693                         }
00694                         
00695                         // show next link (if not last page)
00696                         if (! ( ($this->getOffset() / $this->getLimit())==($pages-1) ) && ($pages!=1) )
00697                         {
00698                                 if ($LinkBar != "")
00699                                         $LinkBar .= "<span class=\"small\" > | </span>"; 
00700                                 $newoffset = $this->getOffset() + $this->getLimit();
00701                                 $LinkBar .= "<a class=\"small\" href=\"".$link.$newoffset."\">&nbsp;".$layout_next."</a>";
00702 
00703                         }
00704                         
00705                         if (count($offset_arr))
00706                         {                               
00707                                 $LinkBar .= "&nbsp;&nbsp;&nbsp;&nbsp;".ilUtil::formSelect($this->nav_value,
00708                                         $this->getNavParameter(), $offset_arr, false, true, 0, "ilEditSelect").
00709                                         ' <input class="ilEditSubmit" type="submit" name="cmd['.$this->parent_cmd.']" value="'.
00710                                         $lng->txt("select_page").'"> ';
00711                         }
00712 
00713                         return $LinkBar;
00714                 }
00715                 else
00716                 {
00717                         return false;
00718                 }
00719         }
00720 
00724         function fillActionRow()
00725         {
00726                 global $lng;
00727                 
00728                 // action row
00729                 $action_row = false;
00730                 $arrow = false;
00731                 
00732                 // add buttons
00733                 if (count($this->buttons) > 0)
00734                 {
00735                         foreach ($this->buttons as $button)
00736                         {
00737                                 $this->tpl->setCurrentBlock("plain_button");
00738                                 $this->tpl->setVariable("PBTN_NAME", $button["cmd"]);
00739                                 $this->tpl->setVariable("PBTN_VALUE", $button["text"]);
00740                                 $this->tpl->parseCurrentBlock();
00741                         }
00742                         $this->tpl->setCurrentBlock("plain_buttons");
00743                         $this->tpl->parseCurrentBlock();
00744                         
00745                         $action_row = true;
00746                 }
00747                 
00748                 // multi selection 
00749                 if (count($this->multi) > 0)
00750                 {
00751                         $this->tpl->setCurrentBlock("tbl_cmd_select");
00752                         $sel = array();
00753                         foreach ($this->multi as $mc)
00754                         {
00755                                 $sel[$mc["cmd"]] = $mc["text"];
00756                         }
00757                         $this->tpl->setVariable("SELECT_CMDS",
00758                                 ilUtil::formSelect("", "selected_cmd", $sel, false, true));
00759                         $this->tpl->setVariable("TXT_EXECUTE", $lng->txt("execute"));
00760                         $this->tpl->parseCurrentBlock();
00761                         $arrow = true;
00762                         $action_row = true;
00763                 }
00764 
00765                 if ($arrow)
00766                 {
00767                         $this->tpl->setCurrentBlock("tbl_action_img_arrow");
00768                         $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
00769                         $this->tpl->setVariable("ALT_ARROW", $lng->txt("action"));
00770                         $this->tpl->parseCurrentBlock();
00771                 }
00772                 
00773                 if ($action_row)
00774                 {
00775                         $this->tpl->setCurrentBlock("tbl_action_row");
00776                         $this->tpl->setVariable("COLUMN_COUNTS", $this->getColumnCount());
00777                         $this->tpl->parseCurrentBlock();
00778                 }
00779         }
00780         
00781 }
00782 ?>

Generated on Fri Dec 13 2013 17:57:01 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1