65 public array
$enabled = array(
"table" =>
true,
75 "numinfo_header" =>
false,
84 "table" =>
"fullwidth" 93 bool $a_global_tpl =
true 97 $tpl = $DIC->ui()->mainTemplate();
98 $lng = $DIC->language();
100 $this->global_tpl = $a_global_tpl;
101 $this->header_vars = array();
102 $this->header_params = array();
103 $this->enabled[
"form"] =
true;
104 $this->action_buttons = array();
105 if ($this->global_tpl) {
108 $this->tpl =
new ilTemplate(
"tpl.table.html",
true,
true,
"Services/Table");
114 $this->lang_support =
false;
135 $this->data = $a_data;
148 public function setTitle(
string $a_title,
string $a_icon =
"",
string $a_icon_alt =
""): void
150 $this->title = $a_title;
151 $this->icon = $a_icon;
152 $this->icon_alt = $a_icon_alt;
155 $this->enabled[
"icon"] =
false;
160 if (!$this->icon_alt) {
163 $this->enabled[
"icon"] =
true;
166 public function setHelp(
string $a_help_page,
string $a_help_icon,
string $a_help_icon_alt =
""): void
168 $this->help_page = $a_help_page;
169 $this->help_icon = $a_help_icon;
170 $this->help_icon_alt = $a_help_icon_alt;
172 if (!$this->help_icon_alt) {
179 $this->header_names = $a_header_names;
180 $this->column_count = count($this->header_names);
188 public function setHeaderVars(array $a_header_vars, array $a_header_params = []): void
190 $this->header_vars = $a_header_vars;
191 $this->header_params = $a_header_params;
192 $this->link_params =
"";
193 foreach ($a_header_params as
$key => $val) {
194 $this->link_params .=
$key .
"=" . $val .
"&";
203 $this->column_width = $a_column_width;
208 $this->column_width[$a_column_number] = $a_column_width;
218 $this->max_count = $a_max_count;
220 if ($this->max_limit) {
228 public function setLimit(
int $a_limit = 0,
int $a_default_limit = 0): void
230 $this->limit = ($a_limit) ?: $a_default_limit;
232 if ($this->limit == 0) {
233 $this->max_limit =
true;
249 $this->prefix = $a_prefix ?:
"";
257 $this->offset = ($a_offset) ?: 0;
266 string $a_order_column =
"",
267 string $a_default_column =
"" 270 if (empty($a_order_column)) {
271 if (!empty($a_default_column)) {
272 $oc = array_search($a_default_column, $this->header_vars);
277 $oc = array_search($a_order_column, $this->header_vars);
280 $this->order_column = $oc ?:
"";
290 if (strtolower($a_order_direction) ==
"desc") {
291 $this->order_direction =
"desc";
292 $this->sort_order =
"asc";
294 $this->order_direction =
"asc";
295 $this->sort_order =
"desc";
306 string $a_previous =
"",
309 $this->footer_style = $a_style;
310 $this->footer_previous = $a_previous ?:
"<<<";
311 $this->footer_next = $a_next ?:
">>>";
317 public function enable(
string $a_module_name): void
319 if (!in_array($a_module_name, array_keys($this->enabled))) {
323 $this->enabled[$a_module_name] =
true;
329 public function disable(
string $a_module_name): void
331 if (!in_array($a_module_name, array_keys($this->enabled))) {
335 $this->enabled[$a_module_name] =
false;
341 if ($this->enabled[
"sort"]) {
344 $this->data = array_slice($this->data, $this->offset, $this->limit);
349 if ($this->enabled[
'table']) {
350 $this->tpl->setVariable(
"CSS_TABLE",
"table table-striped" );
354 if ($this->enabled[
"icon"] && $this->enabled[
"title"]) {
355 $this->tpl->setCurrentBlock(
"tbl_header_title_icon");
357 $this->tpl->setVariable(
"TBL_TITLE_IMG_ALT", $this->icon_alt);
358 $this->tpl->parseCurrentBlock();
361 if ($this->enabled[
"help"] && $this->enabled[
"title"]) {
362 $this->tpl->setCurrentBlock(
"tbl_header_title_help");
364 $this->tpl->setVariable(
"TBL_HELP_LINK", $this->help_page);
365 $this->tpl->setVariable(
"TBL_HELP_IMG_ALT", $this->help_icon_alt);
366 $this->tpl->parseCurrentBlock();
370 if ($this->enabled[
"hits"] && $this->enabled[
"title"]) {
371 $this->tpl->setCurrentBlock(
"tbl_header_hits_page");
372 $this->tpl->setVariable(
"HITS_PER_PAGE", $this->
lng->txt(
"hits_per_page"));
373 $this->tpl->parseCurrentBlock();
377 if ($this->enabled[
"title"]) {
378 $this->tpl->setCurrentBlock(
"tbl_header_title");
379 $this->tpl->setVariable(
"COLUMN_COUNT", $this->column_count);
380 $this->tpl->setVariable(
"TBL_TITLE", $this->title);
381 $this->tpl->parseCurrentBlock();
385 if ($this->enabled[
"header"]) {
394 if ($this->enabled[
"content"]) {
395 if ($this->enabled[
'auto_sort']) {
401 foreach ($this->data as $tbl_content_row) {
402 foreach ($tbl_content_row as
$key => $tbl_content_cell) {
403 if (is_array($tbl_content_cell)) {
404 $this->tpl->setCurrentBlock(
"tbl_cell_subtitle");
405 $this->tpl->setVariable(
"TBL_CELL_SUBTITLE", $tbl_content_cell[1]);
406 $this->tpl->parseCurrentBlock();
407 $tbl_content_cell =
"<b>" . $tbl_content_cell[0] .
"</b>";
410 $this->tpl->setCurrentBlock(
"tbl_content_cell");
411 $this->tpl->setVariable(
"TBL_CONTENT_CELL", $tbl_content_cell);
412 $this->tpl->parseCurrentBlock();
415 $this->tpl->setCurrentBlock(
"tbl_content_row");
416 $this->tpl->setVariable(
"ROWCOLOR",
" ");
417 $this->tpl->parseCurrentBlock();
423 if ($this->enabled[
"select_all"]) {
425 $this->tpl->setVariable(
'SELECT_PREFIX', $this->prefix);
426 $this->tpl->setVariable(
"SELECT_ALL_TXT_SELECT_ALL", $this->
lng->txt(
"select_all"));
428 $this->tpl->setVariable(
"SELECT_ALL_FORM_NAME", $this->
getFormName());
429 if (!($this->enabled[
"numinfo"] && $this->enabled[
"footer"])) {
436 if ($this->enabled[
"numinfo_header"]) {
437 $start = $this->offset + 1;
440 if ($end > $this->max_count or $this->limit == 0) {
444 if ($this->lang_support) {
445 $numinfo =
"(" . $this->
lng->txt(
"dataset") .
" " . $start .
" - " . $end .
" " . strtolower($this->
lng->txt(
"of")) .
" " . $this->max_count .
")";
447 $numinfo =
"(Dataset " . $start .
" - " . $end .
" of " . $this->max_count .
")";
449 if ($this->max_count > 0) {
451 $this->tpl->setCurrentBlock(
"tbl_header_numinfo");
452 $this->tpl->setVariable(
"NUMINFO_HEADER", $numinfo);
453 $this->tpl->setVariable(
"COLUMN_COUNT_HEADER", $this->
getColumnCount());
454 $this->tpl->parseCurrentBlock();
458 if ($this->enabled[
"numinfo"] && $this->enabled[
"footer"]) {
459 $start = $this->offset + 1;
462 if ($end > $this->max_count or $this->limit == 0) {
466 if ($this->lang_support) {
467 $numinfo =
"(" . $this->
lng->txt(
"dataset") .
" " . $start .
" - " . $end .
" " . strtolower($this->
lng->txt(
"of")) .
" " . $this->max_count .
")";
469 $numinfo =
"(Dataset " . $start .
" - " . $end .
" of " . $this->max_count .
")";
471 if ($this->max_count > 0) {
473 $this->tpl->setCurrentBlock(
"tbl_footer_numinfo");
474 $this->tpl->setVariable(
"NUMINFO", $numinfo);
475 $this->tpl->parseCurrentBlock();
479 if ($this->enabled[
"linkbar"] && $this->enabled[
"footer"] && $this->limit != 0
480 && $this->max_count > 0) {
482 $this->prefix .
"sort_by" => $this->header_vars[$this->order_column],
483 $this->prefix .
"sort_order" => $this->order_direction
488 "link" => $this->footer_style,
489 "prev" => $this->footer_previous,
490 "next" => $this->footer_next,
493 $base = ($this->
getBase() ==
"")
497 $linkbar = $this->
linkbar($base, $this->max_count, $this->limit, $this->offset,
$params, $layout, $this->prefix);
498 $this->tpl->setCurrentBlock(
"tbl_footer_linkbar");
499 $this->tpl->setVariable(
"LINKBAR", $linkbar);
500 $this->tpl->parseCurrentBlock();
504 if ($this->enabled[
"footer"] && $this->max_count > 0) {
505 $this->tpl->setCurrentBlock(
"tbl_footer");
506 $this->tpl->setVariable(
"COLUMN_COUNT", $this->column_count);
507 $this->tpl->parseCurrentBlock();
511 if ($this->enabled[
"action"]) {
512 foreach ($this->action_buttons as $button) {
513 $this->tpl->setCurrentBlock(
"tbl_action_btn");
514 $this->tpl->setVariable(
"BTN_NAME", $button[
"name"]);
515 $this->tpl->setVariable(
"BTN_VALUE", $button[
"value"]);
516 $this->tpl->parseCurrentBlock();
518 $this->tpl->setCurrentBlock(
"tbl_action_row");
520 $this->tpl->setVariable(
"ALT_ARROW", $this->
lng->txt(
"arrow_downright.svg"));
522 $this->tpl->parseCurrentBlock();
525 if ($this->enabled[
"form"]) {
526 $this->tpl->touchBlock(
"tbl_form_footer");
529 if ($this->enabled[
'table']) {
530 $this->tpl->touchBlock(
"tbl_table_end");
533 if (!$this->global_tpl) {
534 return $this->tpl->get();
544 array $AParams = array(),
545 array $ALayout = array(),
552 $layout_prev =
"<<";
553 $layout_next =
">>";
556 if ((is_array($ALayout) && (count($ALayout) > 0))) {
557 if ($ALayout[
"link"]) {
558 $layout_link =
" class=\"" . $ALayout[
"link"] .
"\"";
561 if ($ALayout[
"prev"]) {
562 $layout_prev = $ALayout[
"prev"];
565 if ($ALayout[
"next"]) {
566 $layout_next = $ALayout[
"next"];
572 if ($AHits > $ALimit || $AOffset > 0) {
573 if (!empty($AParams)) {
574 foreach ($AParams as
$key => $value) {
579 if (strpos($AScript,
'&')) {
580 $link = $AScript .
"&" .
$params . $prefix .
"offset=";
582 $link = $AScript .
"?" .
$params . $prefix .
"offset=";
587 $prevoffset = $AOffset - $ALimit;
588 if ($prevoffset < 0) {
591 $LinkBar .=
"<a" . $layout_link .
" href=\"" . $link . $prevoffset .
"\">" . $layout_prev .
" </a>";
595 $pages = intval($AHits / $ALimit);
598 if (($AHits % $ALimit)) {
606 for (
$i = 1 ;
$i <= $pages ;
$i++) {
607 $newoffset = $ALimit * (
$i - 1);
609 if ($newoffset == $AOffset) {
610 $LinkBar .=
"[" .
$i .
"] ";
612 $LinkBar .=
'<a ' . $layout_link .
' href="' .
613 $link . $newoffset .
'">[' .
$i .
']</a> ';
620 if (!(($AOffset / $ALimit) == ($pages - 1)) && ($pages != 1)) {
621 $newoffset = $AOffset + $ALimit;
622 $LinkBar .=
"<a" . $layout_link .
" href=\"" . $link . $newoffset .
"\"> " . $layout_next .
"</a>";
632 foreach ($this->header_names as
$key => $tbl_header_cell) {
633 if (!$this->enabled[
"sort"]) {
634 $this->tpl->setCurrentBlock(
"tbl_header_no_link");
635 if ($this->column_width[
$key]) {
636 $this->tpl->setVariable(
"TBL_COLUMN_WIDTH_NO_LINK",
" width=\"" . $this->column_width[$key] .
"\"");
638 $this->tpl->setVariable(
"TBL_HEADER_CELL_NO_LINK", $tbl_header_cell);
639 $this->tpl->parseCurrentBlock();
642 if ((
$key == $this->order_column) && ($this->order_direction !=
"")) {
643 if (strcmp($this->header_vars[
$key],
"") != 0) {
644 $this->tpl->setCurrentBlock(
"tbl_order_image");
645 $this->tpl->parseCurrentBlock();
649 $this->tpl->setCurrentBlock(
"tbl_header_cell");
650 $this->tpl->setVariable(
"TBL_HEADER_CELL", $tbl_header_cell);
653 if ($this->column_width[
$key]) {
654 $this->tpl->setVariable(
"TBL_COLUMN_WIDTH",
" width=\"" . $this->column_width[$key] .
"\"");
657 $lng_sort_column = (
$this->lang_support) ? $this->
lng->txt(
"sort_by_this_column") :
"Sort by this column";
658 $this->tpl->setVariable(
"TBL_ORDER_ALT", $lng_sort_column);
662 if ($key == $this->order_column) {
665 $lng_change_sort = (
$this->lang_support) ? $this->
lng->txt(
"change_sort_direction") :
"Change sort direction";
666 $this->tpl->setVariable(
"TBL_ORDER_ALT", $lng_change_sort);
670 $this->tpl->parseCurrentBlock();
673 $this->tpl->setCurrentBlock(
"tbl_header");
674 $this->tpl->parseCurrentBlock();
679 $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);
686 $this->styles[$a_element] = $a_style;
689 public function getStyle(
string $a_element): string
691 return $this->styles[$a_element];
699 $this->
base = $a_base;
717 $this->form_name = $a_name;
730 $this->select_all_checkbox = $a_select_all_checkbox;
735 $this->action_buttons = array();
740 $this->action_buttons[] = array(
742 "value" => $btn_value
setOffset(int $a_offset)
set dataset offset
static linkbar(string $AScript, int $AHits, int $ALimit, int $AOffset, array $AParams=array(), array $ALayout=array(), string $prefix='')
enable(string $a_module_name)
getStyle(string $a_element)
setSelectAllCheckbox(string $a_select_all_checkbox)
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setHelp(string $a_help_page, string $a_help_icon, string $a_help_icon_alt="")
setLimit(int $a_limit=0, int $a_default_limit=0)
set max.
setColumnWidth(array $a_column_width)
set table column widths
setStyle(string $a_element, string $a_style)
setOrderDirection(string $a_order_direction)
addActionButton(string $btn_name, string $btn_value)
setTemplate(ilTemplate $a_tpl)
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setOrderLink(string $key, string $order_dir)
setHeaderVars(array $a_header_vars, array $a_header_params=[])
getFormName()
get the name of the parent form
setOneColumnWidth(string $a_column_width, int $a_column_number)
setPrefix(string $a_prefix)
set prefix for sort and offset fields (if you have two or more tables on a page that you want to sort...
setData(array $a_data)
Set table data.
setFooter(string $a_style, string $a_previous="", string $a_next="")
setHeaderNames(array $a_header_names)
setFormName(string $a_name="cmd")
disable(string $a_module_name)
__construct(array $a_data=[], bool $a_global_tpl=true)
setOrderColumn(string $a_order_column="", string $a_default_column="")
string $select_all_checkbox
getSelectAllCheckbox()
get the name of the checkbox that should be toggled with a select all button
setMaxCount(int $a_max_count)
set max.
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)