ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilNestedListInputGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 {
29  protected string $value = "1";
30  protected array $checked = [];
31  protected array $list_nodes = [];
32  protected ilNestedList $list;
33 
34  public function __construct(
35  string $a_title = "",
36  string $a_postvar = ""
37  ) {
38  global $DIC;
39 
40  $this->lng = $DIC->language();
41  parent::__construct($a_title, $a_postvar);
42  $this->setType("nested_list");
43 
44  $this->list = new ilNestedList();
45  $this->list->setListClass("il_Explorer");
46  }
47 
48  public function addListNode(
49  string $a_id,
50  string $a_text,
51  string $a_parent = "0",
52  bool $a_checked = false,
53  bool $a_disabled = false,
54  string $a_img_src = "",
55  string $a_img_alt = "",
56  string $a_post_var = ""
57  ) {
58  $this->list_nodes[$a_id] = array("text" => $a_text,
59  "parent" => $a_parent, "checked" => $a_checked, "disabled" => $a_disabled,
60  "img_src" => $a_img_src, "img_alt" => $a_img_alt, "post_var" => $a_post_var);
61  }
62 
63  public function setValue(string $a_value): void
64  {
65  $this->value = $a_value;
66  }
67 
68  public function getValue(): string
69  {
70  return $this->value;
71  }
72 
73  public function setValueByArray(array $a_values): void
74  {
75  // $this->setChecked($a_values[$this->getPostVar()]);
76  // foreach($this->getSubItems() as $item)
77  // {
78  // $item->setValueByArray($a_values);
79  // }
80  }
81 
82  public function checkInput(): bool
83  {
84  return true;
85  }
86 
87  public function getInput(): array
88  {
89  return $this->strArray($this->getPostVar());
90  }
91 
92  public function render(): string
93  {
94  foreach ($this->list_nodes as $id => $n) {
95  if ($n["post_var"] == "") {
96  $post_var = $this->getPostVar() . "[]";
97  } else {
98  $post_var = $n["post_var"];
99  }
100  $value = $id;
102  $n["checked"],
103  $post_var,
104  (string) $value,
105  $n["disabled"]
106  );
107  if ($n["img_src"] != "") {
108  $item_html .= ilUtil::img(
109  $n["img_src"],
110  $n["img_alt"],
111  "",
112  "",
113  0,
114  "",
115  "ilIcon"
116  ) . " ";
117  }
118  $item_html .= $n["text"];
119 
120  $this->list->addListNode($item_html, (string) $id, $n["parent"]);
121  }
122 
123  return $this->list->getHTML();
124  }
125 
126  public function insert(ilTemplate $a_tpl): void
127  {
128  $html = $this->render();
129 
130  $a_tpl->setCurrentBlock("prop_generic");
131  $a_tpl->setVariable("PROP_GENERIC", $html);
132  $a_tpl->parseCurrentBlock();
133  }
134 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
__construct(string $a_title="", string $a_postvar="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static img(string $a_src, ?string $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
addListNode(string $a_id, string $a_text, string $a_parent="0", bool $a_checked=false, bool $a_disabled=false, string $a_img_src="", string $a_img_alt="", string $a_post_var="")
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
global $DIC
Definition: shib_login.php:26
static formCheckbox(bool $checked, string $varname, string $value, bool $disabled=false)
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This class represents a (nested) list of checkboxes (could be extended for radio items, too)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(Container $dic, ilPlugin $plugin)