ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilRepositorySelectorInputGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
32{
33 protected array $clickable_types = [];
34 protected string $hm = "";
35 protected string $select_text = "";
37 protected ilTree $tree;
38 protected ilObjUser $user;
40 protected array $options = [];
41 protected int $value = 0;
42 protected array $container_types = array("root", "cat", "grp", "fold", "crs");
43
44 public function __construct(
45 string $a_title = "",
46 string $a_postvar = ""
47 ) {
48 global $DIC;
49
50 $this->lng = $DIC->language();
51 $this->tpl = $DIC["tpl"];
52 $this->ctrl = $DIC->ctrl();
53 $this->tree = $DIC->repositoryTree();
54 $this->user = $DIC->user();
55 $this->obj_data_cache = $DIC["ilObjDataCache"];
56 $lng = $DIC->language();
57
58 parent::__construct($a_title, $a_postvar);
59 $this->setClickableTypes($this->container_types);
60 $this->setHeaderMessage($lng->txt('search_area_info'));
61 $this->setType("rep_select");
62 $this->setSelectText($lng->txt("select"));
63 }
64
69 public function setValue($a_value): void
70 {
71 $this->value = (int) $a_value;
72 }
73
74 public function getValue(): int
75 {
76 return $this->value;
77 }
78
79 public function setValueByArray(array $a_values): void
80 {
81 $this->setValue($a_values[$this->getPostVar()] ?? "");
82 }
83
84 public function setSelectText(string $a_val): void
85 {
86 $this->select_text = $a_val;
87 }
88
89 public function getSelectText(): string
90 {
91 return $this->select_text;
92 }
93
94 public function setHeaderMessage(string $a_val): void
95 {
96 $this->hm = $a_val;
97 }
98
99 public function getHeaderMessage(): string
100 {
101 return $this->hm;
102 }
103
104 public function setClickableTypes(array $a_types): void
105 {
106 $this->clickable_types = $a_types;
107 }
108
109 public function getClickableTypes(): array
110 {
112 }
113
114 public function checkInput(): bool
115 {
117
118 if ($this->getRequired() && trim($this->str($this->getPostVar())) == "") {
119 $this->setAlert($lng->txt("msg_input_is_required"));
120 return false;
121 }
122 return true;
123 }
124
125 public function getInput(): int
126 {
127 return (int) trim($this->str($this->getPostVar()));
128 }
129
130 public function showRepositorySelection(): void
131 {
133 $ilCtrl = $this->ctrl;
134
135 $ilCtrl->setParameter($this, "postvar", $this->getPostVar());
136
137 $this->tpl->setOnScreenMessage('info', $this->getHeaderMessage());
138
140 $this,
141 "showRepositorySelection",
142 $this,
143 "selectRepositoryItem",
144 "root_id"
145 );
146 $exp->setTypeWhiteList($this->getVisibleTypes());
147 $exp->setClickableTypes($this->getClickableTypes());
148
149 if ($this->getValue()) {
150 $exp->setPathOpen($this->getValue());
151 $exp->setHighlightedNode((string) $this->getHighlightedNode());
152 }
153
154 if ($exp->handleCommand()) {
155 return;
156 }
157 // build html-output
158 $tpl->setContent($exp->getHTML());
159 }
160
161 public function selectRepositoryItem(): void
162 {
163 $ilCtrl = $this->ctrl;
164
165 $this->setValue((string) $this->int("root_id"));
166 $this->writeToSession();
167
168 $ilCtrl->returnToParent($this);
169 }
170
171 public function reset(): void
172 {
173 $ilCtrl = $this->ctrl;
174
175 $this->setValue("");
176 $this->writeToSession();
177
178 $ilCtrl->returnToParent($this);
179 }
180
181 public function render($a_mode = "property_form"): string
182 {
184 $ilCtrl = $this->ctrl;
185 $ilObjDataCache = $this->obj_data_cache;
187 $parent_gui = "";
188
189 $tpl = new ilTemplate("tpl.prop_rep_select.html", true, true, "components/ILIAS/Form");
190
191 $tpl->setVariable("POST_VAR", $this->getPostVar());
192 $tpl->setVariable("ID", $this->getFieldId());
193 $tpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput((string) $this->getValue()));
194 $tpl->setVariable("TXT_SELECT", $this->getSelectText());
195 $tpl->setVariable("TXT_RESET", $lng->txt("reset"));
196 switch ($a_mode) {
197 case "property_form":
198 $parent_gui = "ilpropertyformgui";
199 break;
200
201 case "table_filter":
202 $parent_gui = get_class($this->getParentTable());
203 break;
204 }
205
206 $ilCtrl->setParameterByClass(
207 "ilrepositoryselectorinputgui",
208 "postvar",
209 $this->getPostVar()
210 );
211 $tpl->setVariable(
212 "HREF_SELECT",
213 $ilCtrl->getLinkTargetByClass(
214 array($parent_gui, "ilformpropertydispatchgui", "ilrepositoryselectorinputgui"),
215 "showRepositorySelection"
216 )
217 );
219 "HREF_RESET",
220 $ilCtrl->getLinkTargetByClass(
221 array($parent_gui, "ilformpropertydispatchgui", "ilrepositoryselectorinputgui"),
222 "reset"
223 )
224 );
225
226 if ($this->getValue() > 0 && $this->getValue() != ROOT_FOLDER_ID) {
227 $tpl->setVariable(
228 "TXT_ITEM",
229 $ilObjDataCache->lookupTitle($ilObjDataCache->lookupObjId($this->getValue()))
230 );
231 } else {
233 $title = $nd["title"];
234 if ($title == "ILIAS") {
235 $title = $lng->txt("repository");
236 }
237 if (in_array($nd["type"], $this->getClickableTypes())) {
238 $tpl->setVariable("TXT_ITEM", $title);
239 }
240 }
241 return $tpl->get();
242 }
243
244 public function insert(ilTemplate $a_tpl): void
245 {
246 $a_tpl->setCurrentBlock("prop_generic");
247 $a_tpl->setVariable("PROP_GENERIC", $this->render());
248 $a_tpl->parseCurrentBlock();
249 }
250
251 public function getTableFilterHTML(): string
252 {
253 $html = $this->render("table_filter");
254 return $html;
255 }
256
257 protected function getHighlightedNode(): int
258 {
260
261 if (!in_array(ilObject::_lookupType($this->getValue(), true), $this->getVisibleTypes())) {
262 return $tree->getParentId($this->getValue());
263 }
264
265 return $this->getValue();
266 }
267
268 protected function getVisibleTypes(): array
269 {
270 return array_merge($this->container_types, $this->getClickableTypes());
271 }
272}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
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.
class ilObjectDataCache
static _lookupType(int $id, bool $reference=false)
Explorer for selecting repository items.
This class represents a repository selector in a property form.
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)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
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:30
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.
setContent(string $a_html)
Sets content for standard template.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26