ILIAS  release_8 Revision v8.24
class.ilObjStudyProgrammeTreeExplorerGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
30{
32 protected ilLanguage $lng;
36
37 protected int $tree_root_id;
38
42 protected string $modal_id;
43
47 protected array $js_conf;
48
52 protected array $class_configuration = [
53 'node' => [
54 'node_title' => 'title',
55 'node_point' => 'points',
56 'node_current' => 'ilHighlighted current_node',
57 'node_buttons' => 'tree_button'
58 ],
59 'lp_object' => 'lp-object',
60 ];
61
62 protected string $js_study_programme_path = "./Modules/StudyProgramme/templates/js/ilStudyProgramme.js";
63 protected string $css_study_programme_path = "./Modules/StudyProgramme/templates/css/ilStudyProgrammeTree.css";
64
68 public function __construct(int $tree_root_id, string $modal_id, string $expl_id, $parent_obj, string $parent_cmd)
69 {
71
72 global $DIC;
73 $this->access = $DIC['ilAccess'];
74 $this->lng = $DIC['lng'];
75 $this->tpl = $DIC['tpl'];
76 $this->toolbar = $DIC['ilToolbar'];
77 $this->ctrl = $DIC['ilCtrl'];
78 $this->request_wrapper = $DIC->http()->wrapper()->query();
79 $this->refinery = $DIC->refinery();
80
81 $this->tree_root_id = $tree_root_id;
82 $this->modal_id = $modal_id;
83
84 $this->js_conf = array();
85
86 $this->lng->loadLanguageModule("prg");
87
88 $this->setAjax(true);
89
90 if ($this->checkAccess('write', $tree_root_id)) {
91 $this->setEnableDnd(true);
92 }
93 }
94
95
101 public function getNodeContent($a_node): string
102 {
103 $current_ref_id = -1;
104 if ($this->request_wrapper->has("ref_id")) {
105 $current_ref_id = $this->request_wrapper->retrieve("ref_id", $this->refinery->kindlyTo()->int());
106 }
107
108 $is_current_node = ($a_node->getRefId() == $current_ref_id);
109 $is_study_programme = ($a_node instanceof ilObjStudyProgramme);
110 $is_root_node = ($is_study_programme && $a_node->getRoot() == null);
111
112 // show delete only on not current elements and not root
113 $is_delete_enabled = ($is_study_programme && ($is_current_node || $is_root_node)) ? false : $this->checkAccess("delete", $current_ref_id);
114
115 $is_creation_enabled = ($this->checkAccess("create", $current_ref_id));
116
117 $node_config = array(
118 'current_ref_id' => $current_ref_id,
119 'is_current_node' => $is_current_node,
120 'is_delete_enabled' => $is_delete_enabled,
121 'is_creation_enabled' => $is_creation_enabled,
122 'is_study_programme' => $is_study_programme,
123 'is_root_node' => $is_root_node
124 );
125
126 // TODO: find way to remove a-tag around the content, to create valid html
127 $tpl = $this->getNodeTemplateInstance();
128
129 // add the tree buttons
130 if ($this->checkAccess('write', $a_node->getRefId())) {
131 if ($is_study_programme) {
132 $this->parseStudyProgrammeNodeButtons($a_node, $node_config, $tpl);
133 } else {
134 $this->parseLeafNodeButtons($a_node, $node_config, $tpl);
135 }
136 }
137
138 $tpl->setCurrentBlock('node-content-block');
139 $tpl->setVariable('NODE_TITLE_CLASSES', implode(' ', $this->getNodeTitleClasses($node_config)));
140 $tpl->setVariable('NODE_TITLE', $a_node->getTitle());
141
142 if ($is_study_programme) {
143 $tpl->setVariable('NODE_POINT_CLASSES', $this->class_configuration['node']['node_point']);
144 $tpl->setVariable('NODE_POINTS', $this->formatPointValue($a_node->getPoints()));
145 }
146
147 $tpl->parseCurrentBlock('node-content-block');
148
149 return $tpl->get();
150 }
151
155 protected function getNodeTitleClasses(array $node_config): array
156 {
157 $node_title_classes = array($this->class_configuration['node']['node_title']);
158 if ($node_config['is_study_programme']) {
159 if ($node_config['is_current_node']) {
160 $node_title_classes[] = $this->class_configuration['node']['node_current'];
161 }
162 } else {
163 $node_title_classes[] = $this->class_configuration['lp_object'];
164 }
165
166 return $node_title_classes;
167 }
168
169
179 array $node_config,
181 ): void {
182 $tpl->setCurrentBlock('enable-tree-buttons');
183
184 // show info button only when it not the current node
185 $info_button = $this->getNodeButtonActionLink(
186 'ilObjStudyProgrammeSettingsGUI',
187 'view',
188 array('ref_id' => $node->getRefId(), 'currentNode' => $node_config['is_current_node']),
190 );
191 $tpl->setVariable('NODE_INFO_BUTTON', $info_button);
192
193 // only show add button when create permission is set
194 if ($node_config['is_creation_enabled']) {
195 $create_button = $this->getNodeButtonActionLink(
196 'ilObjStudyProgrammeTreeGUI',
197 'create',
198 array('ref_id' => $node->getRefId()),
200 );
201 $tpl->setVariable('NODE_CREATE_BUTTON', $create_button);
202 }
203
204 // only show delete button when its not the current node, not the root-node and delete permissions are set
205 if ($node_config['is_delete_enabled']) {
206 $delete_button = $this->getNodeButtonActionLink(
207 'ilObjStudyProgrammeTreeGUI',
208 'delete',
209 array('ref_id' => $node->getRefId(), 'item_ref_id' => $node_config['current_ref_id']),
211 );
212 $tpl->setVariable('NODE_DELETE_BUTTON', $delete_button);
213 }
214
215 $tpl->parseCurrentBlock('enable-tree-buttons');
216 }
217
225 protected function parseLeafNodeButtons(ilObject $node, array $node_config, ilTemplate $tpl): void
226 {
227 $tpl->setCurrentBlock('enable-tree-buttons');
228
229 // only show delete button when its not the current node
230 if ($node_config['is_delete_enabled']) {
231 $delete_button = $this->getNodeButtonActionLink(
232 'ilObjStudyProgrammeTreeGUI',
233 'delete',
234 array('ref_id' => $node->getRefId(), 'item_ref_id' => $node_config['current_ref_id']),
236 );
237 $tpl->setVariable('NODE_DELETE_BUTTON', $delete_button);
238 }
239
240 $tpl->parseCurrentBlock('enable-tree-buttons');
241 }
242
247 {
248 return new ilTemplate("tpl.tree_node_content.html", true, true, "Modules/StudyProgramme");
249 }
250
254 protected function formatPointValue(int $points): string
255 {
256 return '(' . $points . " " . $this->lng->txt('prg_points') . ')';
257 }
258
262 protected function getNodeButtonActionLink(
263 string $target_class,
264 string $cmd,
265 array $params,
266 string $content,
267 bool $async = true
268 ): string {
269 foreach ($params as $param_name => $param_value) {
270 $this->ctrl->setParameterByClass($target_class, $param_name, $param_value);
271 }
272
273 $tpl = $this->getNodeTemplateInstance();
274 $tpl->setCurrentBlock('tree-button-block');
275
276 $classes = array($this->class_configuration['node']['node_buttons']);
277 $classes[] = 'cmd_' . $cmd;
278
279 $tpl->setVariable('LINK_HREF', $this->ctrl->getLinkTargetByClass($target_class, $cmd, '', true, false));
280 $tpl->setVariable('LINK_CLASSES', implode(' ', $classes));
281
282 if ($async) {
283 $tpl->touchBlock('enable-async-link');
284 $tpl->setVariable('LINK_DATA_TARGET', '#' . $this->modal_id);
285 }
286
287 $tpl->setVariable('LINK_CONTENT', $content);
288
289 return $tpl->get();
290 }
291
296 {
297 $node = ilObjStudyProgramme::getInstanceByRefId($this->tree_root_id);
298 return $node;
299 }
300
301 public function getNodeIcon($node): string
302 {
303 global $DIC;
304 $ilias = $DIC['ilias'];
305
306 $obj_id = ilObject::_lookupObjId($node->getRefId());
307 if ($ilias->getSetting('custom_icons')) {
308 //TODO: implement custom icon functionality
309 }
310
311 return ilObject::_getIcon($obj_id, "tiny");
312 }
313
314 public function getNodeHref($node): string
315 {
316 global $DIC;
317 $ilCtrl = $DIC['ilCtrl'];
318
319 if ($ilCtrl->getCmd() === "performPaste") {
320 $ilCtrl->setParameterByClass("ilObjStudyProgrammeGUI", "target_node", $node->getRefId());
321 }
322
323 $ilCtrl->setParameterByClass("ilObjStudyProgrammeGUI", "ref_id", $node->getRefId());
324
325 return '#';
326 }
327
328 public function getChildsOfNode($a_parent_node_id): array
329 {
330 $parent_obj = ilObjectFactoryWrapper::singleton()->getInstanceByRefId((int) $a_parent_node_id);
331
332 $children_with_permission = array();
333
334 // its currently only possible to have children on StudyProgrammes
335 if ($parent_obj instanceof ilObjStudyProgramme) {
336 $children = ($parent_obj->hasChildren()) ? $parent_obj->getChildren() : $parent_obj->getLPChildren();
337
338 if (is_array($children)) {
339 foreach ($children as $node) {
340 if ($this->checkAccess('visible', $node->getRefId())) {
341 $children_with_permission[] = $node;
342 }
343 }
344 }
345 }
346
347 return $children_with_permission;
348 }
349
350 public function getNodeId($a_node): ?int
351 {
352 if (!is_null($a_node)) {
353 return $a_node->getRefId();
354 }
355 return null;
356 }
357
358 public function listItemStart(ilTemplate $tpl, $a_node): void
359 {
360 $tpl->setCurrentBlock("list_item_start");
361
362 if (
363 ($this->getAjax() && $this->nodeHasVisibleChilds($a_node)) ||
364 ($a_node instanceof ilObjStudyProgramme && $a_node->getParent() === null)
365 ) {
366 $tpl->touchBlock("li_closed");
367 }
368
369 $tpl->setVariable(
370 "DOM_NODE_ID",
371 $this->getDomNodeIdForNodeId($this->getNodeId($a_node))
372 );
373 $tpl->parseCurrentBlock();
374 $tpl->touchBlock("tag");
375 }
376
377
382 public function getHTML(): string
383 {
384 $this->tpl->addJavascript($this->js_study_programme_path);
385 $this->tpl->addCss($this->css_study_programme_path);
386
387 $this->tpl->addOnLoadCode(
388 '$("#' . $this->getContainerId() . '").study_programme_tree(' . json_encode(
389 $this->js_conf,
390 JSON_THROW_ON_ERROR
391 ) . ');'
392 );
393
394 return parent::getHTML();
395 }
396
397
404 public function closeCertainNode($node_id): void
405 {
406 if (in_array($node_id, $this->open_nodes)) {
407 $k = array_search($node_id, $this->open_nodes);
408 unset($this->open_nodes[$k]);
409 }
410 $this->store->set("on_" . $this->id, serialize($this->open_nodes));
411 }
412
419 public function openCertainNode($node_id): void
420 {
421 $id = $this->getNodeIdForDomNodeId($node_id);
422 if (!in_array($id, $this->open_nodes)) {
423 $this->open_nodes[] = $id;
424 }
425 $this->store->set("on_" . $this->id, serialize($this->open_nodes));
426 }
427
428
432 protected function checkAccess(string $permission, int $ref_id): bool
433 {
434 return $this->access->checkAccess($permission, '', $ref_id);
435 }
436
440 protected function checkAccessOrFail(string $permission, int $ref_id): void
441 {
442 if (!$this->checkAccess($permission, $ref_id)) {
443 throw new ilException("You have no permission for " . $permission . " Object with ref_id " . $ref_id . "!");
444 }
445 }
446
450 public function addJsConf(string $key, string $value): void
451 {
452 $this->js_conf[$key] = $value;
453 }
454
458 public function getJsConf(string $key): string
459 {
460 return $this->js_conf[$key];
461 }
462}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Builds data types.
Definition: Factory.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilGlobalTemplateInterface $tpl
setEnableDnd(bool $enable_dnd)
static get(string $a_glyph, string $a_text="")
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getChildsOfNode($a_parent_node_id)
Get children of node.
getNodeTitleClasses(array $node_config)
Returns array with all css classes of the title node element.
openCertainNode($node_id)
Open certain node in the tree session The open nodes of a tree are stored in a session.
getNodeButtonActionLink(string $target_class, string $cmd, array $params, string $content, bool $async=true)
Generate link-element.
getJsConf(string $key)
Returns setting of the study-programme-tree.
closeCertainNode($node_id)
Closes certain node in the tree session The open nodes of a tree are stored in a session.
parseStudyProgrammeNodeButtons(ilObjStudyProgramme $node, array $node_config, ilTemplate $tpl)
Generates the buttons for a study-programme node.
checkAccessOrFail(string $permission, int $ref_id)
Checks permission of a object and throws an exception if they are not granted.
__construct(int $tree_root_id, string $modal_id, string $expl_id, $parent_obj, string $parent_cmd)
checkAccess(string $permission, int $ref_id)
Checks permission of current tree or certain child of it.
parseLeafNodeButtons(ilObject $node, array $node_config, ilTemplate $tpl)
Generates the buttons for a study programme leaf.
array $class_configuration
default classes of the tree [key=>class_name]
getHTML()
Returns the output of the complete tree There are added some additional javascripts before output the...
listItemStart(ilTemplate $tpl, $a_node)
List item start.
addJsConf(string $key, string $value)
Adds configuration to the study-programme-tree jquery plugin.
getNodeTemplateInstance()
Factory method for a new instance of a node template.
formatPointValue(int $points)
Returns formatted point value.
getParent()
Get the parent ilObjStudyProgramme of this object.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
static _lookupObjId(int $ref_id)
special template class to simplify handling of ITX/PEAR
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
Interface RequestWrapper.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
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.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$ref_id
Definition: ltiauth.php:67
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
string $key
Consumer key/client ID value.
Definition: System.php:193