44 protected \ILIAS\DI\UIServices
$ui;
51 string $a_node_parameter_name =
"node_id"
55 $this->httpRequest =
$DIC->http()->request();
56 $this->
ui = $DIC->ui();
57 $this->
lng = $DIC->language();
59 $this->tree = $a_tree;
69 bool $a_numeric =
false
71 $this->order_field = $a_val;
72 $this->order_field_numeric = $a_numeric;
77 return $this->order_field;
86 $this->type_white_list = $a_val;
95 return $this->type_white_list;
104 $this->type_black_list = $a_val;
113 return $this->type_black_list;
118 $this->preload_childs = $a_val;
123 return $this->preload_childs;
128 $subtree = $this->tree->getSubTree($this->getRootNode());
129 foreach ($subtree as $s) {
130 $wl = $this->getTypeWhiteList();
131 if (is_array($wl) && count($wl) > 0 && !in_array($s[
"type"], $wl)) {
134 $bl = $this->getTypeBlackList();
135 if (is_array($bl) && count($bl) > 0 && in_array($s[
"type"], $bl)) {
138 $this->childs[$s[
"parent"]][] = $s;
139 $this->all_childs[$s[
"child"]] = $s;
142 if ($this->order_field !==
"") {
143 foreach ($this->childs as $k => $childs) {
148 $this->order_field_numeric
154 if ($this->order_field ===
"") {
158 foreach ($this->all_childs as $k =>
$c) {
160 $this->all_childs[$prev][
"next_node_id"] = $k;
162 $this->all_childs[$k][
"prev_node_id"] = $prev;
163 $this->all_childs[$k][
"next_node_id"] =
false;
168 $this->preloaded =
true;
183 if ($this->order_field !==
"") {
184 die(
"ilTreeExplorerGUI::getSuccessorNode not implemented for order field " . $this->order_field);
187 if ($this->preloaded) {
188 $next_id = $a_node_id;
189 while (($next_id = $this->all_childs[$next_id][
"next_node_id"]) && $a_type !==
"" &&
190 $this->all_childs[$next_id][
"type"] !== $a_type) {
194 return $this->all_childs[$next_id];
198 return $this->getTree()->fetchSuccessorNode($a_node_id, $a_type);
210 if ($this->preloaded && $this->getSearchTerm() ===
"") {
211 if (isset($this->childs[$a_parent_node_id]) && is_array($this->childs[$a_parent_node_id])) {
212 return $this->childs[$a_parent_node_id];
217 $wl = $this->getTypeWhiteList();
218 if (count($wl) > 0) {
219 $childs = $this->tree->getChildsByTypeFilter($a_parent_node_id, $wl, $this->getOrderField());
221 $childs = $this->tree->getChilds($a_parent_node_id, $this->getOrderField());
225 $bl = $this->getTypeBlackList();
226 if (is_array($bl) && count($bl) > 0) {
227 $bl_childs = array();
228 foreach ($childs as $k =>
$c) {
229 if (!in_array(
$c[
"type"], $bl,
true) && ($this->matches(
$c) || !$this->isNodeRequested($a_parent_node_id))) {
237 foreach ($childs as $k =>
$c) {
238 if ($this->isNodeVisible(
$c)
239 && ($this->matches(
$c) || !$this->isNodeRequested($a_parent_node_id))) {
240 $final_childs[$k] =
$c;
243 return $final_childs;
254 $this->getSearchTerm() ===
"" ||
255 is_int(ilStr::striPos($this->getNodeContent($node), $this->getSearchTerm()))
268 return $a_node[
"child"];
280 return $lng->txt(
"icon") .
" " .
$lng->txt(
"obj_" . ($a_node[
"type"] ??
''));
290 if (!isset($this->root_node_data)) {
291 $this->root_node_data = $this->getTree()->getNodeData($this->getRootId());
293 return $this->root_node_data;
301 $this->root_id = $a_root;
306 return $this->root_id
307 ?: $this->getTree()->readRootId();
317 $path = $this->getTree()->getPathId($a_id);
319 $this->setNodeOpen(
$id);
330 if ($this->getPreloadChilds()) {
331 $this->preloadChilds();
334 return parent::getHTML();
336 return $this->render();
343 return $this->getChildsOfNode($record[
"child"]);
353 $nodeIconPath = $this->getNodeIcon($record);
356 if ($nodeIconPath !==
'') {
361 ->custom($nodeIconPath, $this->getNodeIconAlt($record));
364 return $factory->simple($this->getNodeContent($record), $icon);
383 $node = $this->createNode($factory, $record);
385 $href = $this->getNodeHref($record);
386 if ($href !==
'' &&
'#' !== $href && $this->isNodeClickable($record)) {
387 $node = $node->withLink(
new \
ILIAS\Data\URI(ILIAS_HTTP_PATH .
'/' . $href));
390 if ($this->isNodeOpen((
int) $this->getNodeId($record))) {
391 $node = $node->withExpanded(
true);
394 $nodeStateToggleCmdClasses = $this->getNodeStateToggleCmdClasses($record);
395 $cmdClass = end($nodeStateToggleCmdClasses);
397 if (is_string($cmdClass) && $cmdClass !==
'') {
398 $node = $node->withAdditionalOnLoadCode(
function (
$id) use ($record, $nodeStateToggleCmdClasses, $cmdClass):
string {
399 $serverNodeId = $this->getNodeId($record);
401 $this->
ctrl->setParameterByClass($cmdClass, $this->node_parameter_name, $serverNodeId);
402 $url = $this->
ctrl->getLinkTargetByClass($nodeStateToggleCmdClasses,
'toggleExplorerNodeState',
'',
true,
false);
403 $this->
ctrl->setParameterByClass($cmdClass, $this->node_parameter_name,
null);
405 $javascript =
"il.UI.tree.registerToggleNodeAsyncAction('$id', '$url', 'prior_state');";
416 return $this->tree_label;
421 $f = $this->
ui->factory();
422 $tree = $this->getTree();
424 if (!$this->getSkipRootNode()) {
432 $label = $this->getTreeLabel();
433 if ($this->getTreeLabel() ===
"" && $this->getNodeContent($this->getRootNode())) {
434 $label = $this->getNodeContent($this->getRootNode());
437 $tree =
$f->tree()->expandable($label, $this)
439 ->withHighlightOnNodeClick(
true);
449 $nodeId = (
int) ($this->httpRequest->getQueryParams()[$this->node_parameter_name] ?? 0);
450 $priorState = (
int) ($this->httpRequest->getQueryParams()[
'prior_state'] ?? 0);
453 if (0 === $priorState && !in_array($nodeId, $this->open_nodes)) {
454 $this->open_nodes[] = $nodeId;
455 } elseif (1 === $priorState && in_array($nodeId, $this->open_nodes)) {
456 $key = array_search($nodeId, $this->open_nodes);
457 unset($this->open_nodes[$key]);
460 $this->store->set(
'on_' . $this->
id, serialize($this->open_nodes));
467 $r = $this->
ui->renderer();
470 $this->getTreeComponent()
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Explorer class that works on tree objects (Services/Tree)
getNodeStateToggleCmdClasses($record)
Should return an array of ilCtrl-enabled command classes which should be used to build the URL for th...
setOrderField(string $a_val, bool $a_numeric=false)
matches($node)
Does a node match a search term (or is search term empty)
getRootNode()
Get root node.
getChildren($record, $environment=null)
Get a list of records (that list can also be empty).
createNode(\ILIAS\UI\Component\Tree\Node\Factory $factory, $record)
Creates at tree node, can be overwritten in derivatives if another node type should be used.
setPathOpen($a_id)
Set node path to be opened.
getTypeWhiteList()
Get type white list.
getNodeId($a_node)
Get id for node.
getSuccessorNode( $a_node_id, string $a_type="")
Get successor node (currently only(!) based on lft/rgt tree values)
bool $order_field_numeric
getChildsOfNode($a_parent_node_id)
Get childs of node.
toggleExplorerNodeState()
Should be called by an ilCtrl-enabled command class if a tree node toggle action should be processed.
getTypeBlackList()
Get type black list.
__construct(string $a_expl_id, $a_parent_obj, string $a_parent_cmd, ilTree $a_tree, string $a_node_parameter_name="node_id")
getNodeIconAlt($a_node)
Get node icon alt attribute.
setTypeBlackList(array $a_val)
Set type black list.
build(\ILIAS\UI\Component\Tree\Node\Factory $factory, $record, $environment=null)
setTypeWhiteList(array $a_val)
Set type white list.
setPreloadChilds(bool $a_val)
getHTML($new=false)
Get HTML.
Psr Http Message ServerRequestInterface $httpRequest
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.
getChilds(int $a_node_id, string $a_order="", string $a_direction="ASC")
get child nodes of given node
Interface for mapping data-structures to the Tree.
This describes a Tree Control.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.