ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
expandable_async_repo.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 global $DIC;
24 $refinery = $DIC->refinery();
25 $request_wrapper = $DIC->http()->wrapper()->query();
26 
27 if ($request_wrapper->has('async_ref') && $request_wrapper->retrieve('async_ref', $refinery->kindlyTo()->bool())) {
28  $ref = $request_wrapper->retrieve('async_ref', $refinery->kindlyTo()->int());
30  exit();
31 }
32 
42 function expandable_async_repo($ref = null)
43 {
44  global $DIC;
45  $ilTree = $DIC['tree'];
46 
47  if (is_null($ref)) {
48  $do_async = false;
49  $ref = 1;
50  $data = array(
51  $ilTree->getNodeData(1)
52  );
53  } else {
54  $do_async = true;
55  $data = $ilTree->getChilds($ref);
56  if (count($data) === 0) {
57  return;
58  }
59  }
60 
61  $recursion = new class () implements \ILIAS\UI\Component\Tree\TreeRecursion {
62  public function getChildren($record, $environment = null): array
63  {
64  return [];
65  }
66 
67  public function build(
68  \ILIAS\UI\Component\Tree\Node\Factory $factory,
69  $record,
70  $environment = null
71  ): \ILIAS\UI\Component\Tree\Node\Node {
72  $ref_id = $record['ref_id'];
73  $label = $record['title']
74  . ' (' . $record['type'] . ', ' . $ref_id . ')';
75 
76  $icon = $environment['icon_factory']->standard($record["type"], '');
77  $url = $this->getAsyncURL($environment, (string) $ref_id);
78 
79  $node = $factory->simple($label, $icon)
80  ->withAsyncURL($url);
81 
82  //find these under ILIAS->Administration in the example tree
83  if ((int) $ref_id > 9 && (int) $ref_id < 20) {
84  $label = $environment['modal']->getShowSignal()->getId();
85  $node = $factory->simple($label)
86  ->withAsyncURL($url)
87  ->withOnClick($environment['modal']->getShowSignal());
88  }
89 
90  return $node;
91  }
92 
93  protected function getAsyncURL($environment, string $ref_id): string
94  {
95  $url = $environment['url'];
96  $base = substr($url, 0, strpos($url, '?') + 1);
97  $query = parse_url($url, PHP_URL_QUERY);
98  if ($query) {
99  parse_str($query, $params);
100  } else {
101  $params = [];
102  }
103  $params['async_ref'] = $ref_id;
104  $url = $base . http_build_query($params);
105  return $url;
106  }
107  };
108 
109  $f = $DIC->ui()->factory();
110  $renderer = $DIC->ui()->renderer();
111  $image = $f->image()->responsive("assets/ui-examples/images/Image/mountains.jpg", "Image source: https://stocksnap.io, Creative Commons CC0 license");
112  $page = $f->modal()->lightboxImagePage($image, 'Mountains');
113  $modal = $f->modal()->lightbox($page);
114 
115  $environment = [
116  'url' => $DIC->http()->request()->getRequestTarget(),
117  'modal' => $modal,
118  'icon_factory' => $f->symbol()->icon()
119  ];
120 
121  $tree = $f->tree()->expandable("Label", $recursion)
122  ->withEnvironment($environment)
123  ->withData($data);
124 
125  if (!$do_async) {
126  return $renderer->render([$modal, $tree]);
127  } else {
128  echo $renderer->renderAsync([$modal, $tree->withIsSubTree(true)]);
129  }
130 }
$renderer
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
Interface Observer Contains several chained tasks and infos about them.
$url
Definition: shib_logout.php:66
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$ref_id
Definition: ltiauth.php:65
exit
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)
description: > Example for rendering an expandable tree with asynchronous repositories.