ILIAS  release_8 Revision v8.24
expandable_async_repo.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
6
7global $DIC;
8$refinery = $DIC->refinery();
9$request_wrapper = $DIC->http()->wrapper()->query();
10
11if ($request_wrapper->has('async_ref') && $request_wrapper->retrieve('async_ref', $refinery->kindlyTo()->bool())) {
12 $ref = $request_wrapper->retrieve('async_ref', $refinery->kindlyTo()->int());
14 exit();
15}
16
17function expandable_async_repo($ref = null)
18{
19 global $DIC;
20 $ilTree = $DIC['tree'];
21
22 if (is_null($ref)) {
23 $do_async = false;
24 $ref = 1;
25 $data = array(
26 $ilTree->getNodeData(1)
27 );
28 } else {
29 $do_async = true;
30 $data = $ilTree->getChilds($ref);
31 if (count($data) === 0) {
32 return;
33 }
34 }
35
36 $recursion = new class () implements \ILIAS\UI\Component\Tree\TreeRecursion {
37 public function getChildren($record, $environment = null): array
38 {
39 return [];
40 }
41
42 public function build(
44 $record,
45 $environment = null
47 $ref_id = $record['ref_id'];
48 $label = $record['title']
49 . ' (' . $record['type'] . ', ' . $ref_id . ')';
50
51 $icon = $environment['icon_factory']->standard($record["type"], '');
52 $url = $this->getAsyncURL($environment, $ref_id);
53
54 $node = $factory->simple($label, $icon)
55 ->withAsyncURL($url);
56
57 //find these under ILIAS->Administration in the example tree
58 if ((int) $ref_id > 9 && (int) $ref_id < 20) {
59 $label = $environment['modal']->getShowSignal()->getId();
60 $node = $factory->simple($label)
61 ->withAsyncURL($url)
62 ->withOnClick($environment['modal']->getShowSignal());
63 }
64
65 return $node;
66 }
67
68 protected function getAsyncURL($environment, string $ref_id): string
69 {
70 $url = $environment['url'];
71 $base = substr($url, 0, strpos($url, '?') + 1);
72 $query = parse_url($url, PHP_URL_QUERY);
73 if ($query) {
74 parse_str($query, $params);
75 } else {
76 $params = [];
77 }
78 $params['async_ref'] = $ref_id;
79 $url = $base . http_build_query($params);
80 return $url;
81 }
82 };
83
84 $f = $DIC->ui()->factory();
85 $renderer = $DIC->ui()->renderer();
86 $image = $f->image()->responsive("src/UI/examples/Image/mountains.jpg", "Image source: https://stocksnap.io, Creative Commons CC0 license");
87 $page = $f->modal()->lightboxImagePage($image, 'Mountains');
88 $modal = $f->modal()->lightbox($page);
89
90 $environment = [
91 'url' => $DIC->http()->request()->getRequestTarget(),
92 'modal' => $modal,
93 'icon_factory' => $f->symbol()->icon()
94 ];
95
96 $tree = $f->tree()->expandable("Label", $recursion)
97 ->withEnvironment($environment)
98 ->withData($data);
99
100 if (!$do_async) {
101 return $renderer->render([$modal, $tree]);
102 } else {
103 echo $renderer->renderAsync([$modal, $tree->withIsSubTree(true)]);
104 }
105}
This describes a Tree Node.
Definition: Node.php:31
This is how the factory for UI elements looks.
Definition: Factory.php:38
exit
Definition: login.php:28
$ref_id
Definition: ltiauth.php:67
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
$factory
Definition: metadata.php:75
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if( $request_wrapper->has( 'async_ref') &&$request_wrapper->retrieve( 'async_ref', $refinery->kindlyTo() ->bool())) expandable_async_repo($ref=null)
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$base
Definition: index.php:4
$query
$url