ILIAS  release_8 Revision v8.24
class.ilRepositorySelectorInputGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
31{
32 protected array $clickable_types = [];
33 protected string $hm = "";
34 protected string $select_text = "";
36 protected ilTree $tree;
37 protected ilObjUser $user;
39 protected array $options = [];
40 protected int $value = 0;
41 protected array $container_types = array("root", "cat", "grp", "fold", "crs");
42
43 public function __construct(
44 string $a_title = "",
45 string $a_postvar = ""
46 ) {
47 global $DIC;
48
49 $this->lng = $DIC->language();
50 $this->tpl = $DIC["tpl"];
51 $this->ctrl = $DIC->ctrl();
52 $this->tree = $DIC->repositoryTree();
53 $this->user = $DIC->user();
54 $this->obj_data_cache = $DIC["ilObjDataCache"];
55 $lng = $DIC->language();
56
57 parent::__construct($a_title, $a_postvar);
58 $this->setClickableTypes($this->container_types);
59 $this->setHeaderMessage($lng->txt('search_area_info'));
60 $this->setType("rep_select");
61 $this->setSelectText($lng->txt("select"));
62 }
63
68 public function setValue($a_value): void
69 {
70 $this->value = (int) $a_value;
71 }
72
73 public function getValue(): int
74 {
75 return $this->value;
76 }
77
78 public function setValueByArray(array $a_values): void
79 {
80 $this->setValue($a_values[$this->getPostVar()] ?? "");
81 }
82
83 public function setSelectText(string $a_val): void
84 {
85 $this->select_text = $a_val;
86 }
87
88 public function getSelectText(): string
89 {
90 return $this->select_text;
91 }
92
93 public function setHeaderMessage(string $a_val): void
94 {
95 $this->hm = $a_val;
96 }
97
98 public function getHeaderMessage(): string
99 {
100 return $this->hm;
101 }
102
103 public function setClickableTypes(array $a_types): void
104 {
105 $this->clickable_types = $a_types;
106 }
107
108 public function getClickableTypes(): array
109 {
111 }
112
113 public function checkInput(): bool
114 {
116
117 if ($this->getRequired() && trim($this->str($this->getPostVar())) == "") {
118 $this->setAlert($lng->txt("msg_input_is_required"));
119 return false;
120 }
121 return true;
122 }
123
124 public function getInput(): int
125 {
126 return (int) trim($this->str($this->getPostVar()));
127 }
128
129 public function showRepositorySelection(): void
130 {
132 $ilCtrl = $this->ctrl;
133
134 $ilCtrl->setParameter($this, "postvar", $this->getPostVar());
135
136 $this->tpl->setOnScreenMessage('info', $this->getHeaderMessage());
137
139 $this,
140 "showRepositorySelection",
141 $this,
142 "selectRepositoryItem",
143 "root_id"
144 );
145 $exp->setTypeWhiteList($this->getVisibleTypes());
146 $exp->setClickableTypes($this->getClickableTypes());
147
148 if ($this->getValue()) {
149 $exp->setPathOpen($this->getValue());
150 $exp->setHighlightedNode((string) $this->getHighlightedNode());
151 }
152
153 if ($exp->handleCommand()) {
154 return;
155 }
156 // build html-output
157 $tpl->setContent($exp->getHTML());
158 }
159
160 public function selectRepositoryItem(): void
161 {
162 $ilCtrl = $this->ctrl;
163
164 $this->setValue((string) $this->int("root_id"));
165 $this->writeToSession();
166
167 $ilCtrl->returnToParent($this);
168 }
169
170 public function reset(): void
171 {
172 $ilCtrl = $this->ctrl;
173
174 $this->setValue("");
175 $this->writeToSession();
176
177 $ilCtrl->returnToParent($this);
178 }
179
180 public function render($a_mode = "property_form"): string
181 {
183 $ilCtrl = $this->ctrl;
184 $ilObjDataCache = $this->obj_data_cache;
186 $parent_gui = "";
187
188 $tpl = new ilTemplate("tpl.prop_rep_select.html", true, true, "Services/Form");
189
190 $tpl->setVariable("POST_VAR", $this->getPostVar());
191 $tpl->setVariable("ID", $this->getFieldId());
192 $tpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput((string) $this->getValue()));
193 $tpl->setVariable("TXT_SELECT", $this->getSelectText());
194 $tpl->setVariable("TXT_RESET", $lng->txt("reset"));
195 switch ($a_mode) {
196 case "property_form":
197 $parent_gui = "ilpropertyformgui";
198 break;
199
200 case "table_filter":
201 $parent_gui = get_class($this->getParentTable());
202 break;
203 }
204
205 $ilCtrl->setParameterByClass(
206 "ilrepositoryselectorinputgui",
207 "postvar",
208 $this->getPostVar()
209 );
210 $tpl->setVariable(
211 "HREF_SELECT",
212 $ilCtrl->getLinkTargetByClass(
213 array($parent_gui, "ilformpropertydispatchgui", "ilrepositoryselectorinputgui"),
214 "showRepositorySelection"
215 )
216 );
218 "HREF_RESET",
219 $ilCtrl->getLinkTargetByClass(
220 array($parent_gui, "ilformpropertydispatchgui", "ilrepositoryselectorinputgui"),
221 "reset"
222 )
223 );
224
225 if ($this->getValue() > 0 && $this->getValue() != ROOT_FOLDER_ID) {
226 $tpl->setVariable(
227 "TXT_ITEM",
228 $ilObjDataCache->lookupTitle($ilObjDataCache->lookupObjId($this->getValue()))
229 );
230 } else {
232 $title = $nd["title"];
233 if ($title == "ILIAS") {
234 $title = $lng->txt("repository");
235 }
236 if (in_array($nd["type"], $this->getClickableTypes())) {
237 $tpl->setVariable("TXT_ITEM", $title);
238 }
239 }
240 return $tpl->get();
241 }
242
243 public function insert(ilTemplate $a_tpl): void
244 {
245 $a_tpl->setCurrentBlock("prop_generic");
246 $a_tpl->setVariable("PROP_GENERIC", $this->render());
247 $a_tpl->parseCurrentBlock();
248 }
249
250 public function getTableFilterHTML(): string
251 {
252 $html = $this->render("table_filter");
253 return $html;
254 }
255
256 protected function getHighlightedNode(): int
257 {
259
260 if (!in_array(ilObject::_lookupType($this->getValue(), true), $this->getVisibleTypes())) {
261 return $tree->getParentId($this->getValue());
262 }
263
264 return $this->getValue();
265 }
266
267 protected function getVisibleTypes(): array
268 {
269 return array_merge($this->container_types, $this->getClickableTypes());
270 }
271}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
@inheritDoc
This class represents a property in a property form.
ilFormPropertyGUI $parent_gui
getParentTable()
Get parent table.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static prepareFormOutput($a_str, bool $a_strip=false)
User class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupType(int $id, bool $reference=false)
Explorer for selecting repository items.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkInput()
Check input, strip slashes etc.
__construct(string $a_title="", string $a_postvar="")
getTableFilterHTML()
Get input item HTML to be inserted into table filters.
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
getParentId(int $a_node_id)
get parent id of given node
const ROOT_FOLDER_ID
Definition: constants.php:32
$nd
Definition: error.php:12
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setContent(string $a_html)
Sets content for standard template.
setVariable(string $variable, $value='')
Sets the given variable to the given value.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc