ILIAS  release_7 Revision v7.30-3-g800a261c036
expandable_async_repo.php File Reference

Go to the source code of this file.

Functions

if( $_GET[ 'async_ref']) expandable_async_repo ($ref=null)
 

Function Documentation

◆ expandable_async_repo()

if($_GET['async_ref']) expandable_async_repo (   $ref = null)

Definition at line 9 of file expandable_async_repo.php.

10{
11 global $DIC;
12 $ilTree = $DIC['tree'];
13
14 if (is_null($ref)) {
15 $do_async = false;
16 $ref = 1;
17 $data = array(
18 $ilTree->getNodeData(1)
19 );
20 } else {
21 $do_async = true;
22 $data = $ilTree->getChilds($ref);
23 if (count($data) === 0) {
24 return;
25 }
26 }
27
28 $recursion = new class implements \ILIAS\UI\Component\Tree\TreeRecursion {
29 public function getChildren($record, $environment = null) : array
30 {
31 return [];
32 }
33
34 public function build(
35 \ILIAS\UI\Component\Tree\Node\Factory $factory,
36 $record,
37 $environment = null
38 ) : \ILIAS\UI\Component\Tree\Node\Node {
39 $ref_id = $record['ref_id'];
40 $label = $record['title']
41 . ' (' . $record['type'] . ', ' . $ref_id . ')';
42
43 $icon = $environment['icon_factory']->standard($record["type"], '');
44 $url = $this->getAsyncURL($environment, $ref_id);
45
46 $node = $factory->simple($label, $icon)
47 ->withAsyncURL($url);
48
49 //find these under ILIAS->Administration in the example tree
50 if ((int) $ref_id > 9 && (int) $ref_id < 20) {
51 $label = $environment['modal']->getShowSignal()->getId();
52 $node = $factory->simple($label)
53 ->withAsyncURL($url)
54 ->withOnClick($environment['modal']->getShowSignal());
55 }
56
57 return $node;
58 }
59
60 protected function getAsyncURL($environment, string $ref_id) : string
61 {
62 $url = $environment['url'];
63 $base = substr($url, 0, strpos($url, '?') + 1);
64 $query = parse_url($url, PHP_URL_QUERY);
65 parse_str($query, $params);
66 $params['async_ref'] = $ref_id;
67 $url = $base . http_build_query($params);
68 return $url;
69 }
70 };
71
72 $f = $DIC->ui()->factory();
73 $renderer = $DIC->ui()->renderer();
74 $image = $f->image()->responsive("src/UI/examples/Image/mountains.jpg", "Image source: https://stocksnap.io, Creative Commons CC0 license");
75 $page = $f->modal()->lightboxImagePage($image, 'Mountains');
76 $modal = $f->modal()->lightbox($page);
77
78 $environment = [
79 'url' => $DIC->http()->request()->getRequestTarget(),
80 'modal' => $modal,
81 'icon_factory' => $f->symbol()->icon()
82 ];
83
84 $tree = $f->tree()->expandable("Label", $recursion)
85 ->withEnvironment($environment)
86 ->withData($data);
87
88 if (!$do_async) {
89 return $renderer->render([$modal, $tree]);
90 } else {
91 echo $renderer->renderAsync([$modal, $tree->withIsSubTree(true)]);
92 }
93}
global $DIC
Definition: goto.php:24
$factory
Definition: metadata.php:58
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$base
Definition: index.php:4
$query
$url
$data
Definition: storeScorm.php:23

References $base, $data, $DIC, Vendor\Package\$f, $factory, $query, and $url.