ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
NodeRetrievalGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
30
35{
36 protected const string PARENT_NODE_ID_PARAMETER = 'parent_node_id';
37 protected const int MAX_BRANCH_NODE_DEPTH = 2; // @todo: declare realistic depth
38
39 protected UINodeRetrieval $node_retrieval;
45 protected \ILIAS\Refinery\Factory $refinery;
46 protected \ilObjMainMenuAccess $access;
47 protected \ilCtrlInterface $ctrl;
48
49 public function __construct()
50 {
51 global $DIC;
52
53 $this->ui_factory = $DIC->ui()->factory();
54 $this->renderer = $DIC->ui()->renderer();
55 $this->get_request = $DIC->http()->wrapper()->query();
56 $this->http = $DIC->http();
57 $this->refinery = $DIC->refinery();
58 $this->ctrl = $DIC->ctrl();
59
60 // keep those goddamn parameters alive...
61 $this->ctrl->saveParameterByClass(self::class, 'ref_id');
62
63 $data_factory = new \ILIAS\Data\Factory();
64 $async_node_url_builder = new URLBuilder(
65 $data_factory->uri(
66 ILIAS_HTTP_PATH . '/' .
67 $this->ctrl->getLinkTargetByClass([self::class], null, null, true)
68 ),
69 );
70 [$async_node_url_builder, $this->async_node_id_parameter] = $async_node_url_builder->acquireParameter(
71 explode('\\', __NAMESPACE__),
72 self::PARENT_NODE_ID_PARAMETER,
73 );
74
76 $object_definition = $DIC['objDefinition'];
77
78 $branch_node_types = $object_definition->getExplorerContainerTypes();
79 $leaf_node_types = array_diff($object_definition->getAllRepositoryTypes(false), $branch_node_types);
80
81 $this->node_retrieval = new NodeRetrieval(
82 $DIC->language(),
83 $data_factory,
84 $this->async_node_id_parameter,
85 $async_node_url_builder,
86 $DIC->access(),
87 $DIC->repositoryTree(),
88 $branch_node_types,
89 $leaf_node_types,
90 (int) ($DIC->settings()->get('rep_tree_limit_number') ?? self::MAX_BRANCH_NODE_DEPTH),
91 // ensures the root node is included as well.
92 $DIC->repositoryTree()->getParentId(
93 $DIC->repositoryTree()->getRootId(),
94 ),
95 );
96 }
97
98 public function executeCommand(): void
99 {
100 if (!$this->ctrl->isAsynch()) {
101 throw new \RuntimeException(self::class . ' must be called asynchronously.');
102 }
103 if ($this->ctrl->getNextClass($this)) {
104 throw new \LogicException(self::class . ' must be the only command class.');
105 }
106
107 if (!$this->get_request->has($this->async_node_id_parameter->getName())) {
108 $this->sendHtmlResponse('');
109 return;
110 }
111 $parent_node_id = (int) $this->get_request->retrieve(
112 $this->async_node_id_parameter->getName(),
113 $this->refinery->kindlyTo()->int(),
114 );
115 $this->renderAsyncNodeChildren($parent_node_id);
116 }
117
118 public function getNodeRetrieval(): UINodeRetrieval
119 {
121 }
122
123 protected function renderAsyncNodeChildren(int $parent_node_id): void
124 {
125 $child_node_iterator = $this->node_retrieval->getNodes(
126 $this->ui_factory->input()->field()->node(),
127 $this->ui_factory->symbol()->icon(),
128 (string) $parent_node_id,
129 );
130
131 $html = '';
132 foreach ($child_node_iterator as $node) {
133 $html .= $this->renderer->renderAsync($node);
134 }
135 $this->sendHtmlResponse($html);
136 }
137
138 protected function sendHtmlResponse(string $html): void
139 {
140 $this->http->saveResponse(
141 $this->http->response()
142 ->withHeader('Content-Type', 'text/html; charset=utf-8')
143 ->withBody(Streams::ofString($html))
144 );
145 $this->http->sendResponse();
146 $this->http->close();
147 }
148
149}
renderer()
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Stream factory which enables the user to create streams without the knowledge of the concrete class.
Definition: Streams.php:32
URLBuilderToken $async_node_id_parameter
UINodeRetrieval $node_retrieval
const int MAX_BRANCH_NODE_DEPTH
RequestWrapper $get_request
GlobalHttpState $http
ilObjMainMenuAccess $access
ilCtrlInterface $ctrl
ILIAS Refinery Factory $refinery
renderAsyncNodeChildren(int $parent_node_id)
sendHtmlResponse(string $html)
const string PARENT_NODE_ID_PARAMETER
Interface GlobalHttpState.
Interface RequestWrapper.
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26