ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
with_view_controls.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
16 function with_view_controls(): string
17 {
18  global $DIC;
19  $f = $DIC->ui()->factory();
20  $renderer = $DIC->ui()->renderer();
21  $refinery = $DIC->refinery();
22  $request_wrapper = $DIC->http()->wrapper()->query();
23 
24  $url = $DIC->http()->request()->getRequestTarget();
25 
26  $actions = $f->dropdown()->standard([
27  $f->button()->shy("ILIAS", "https://www.ilias.de"),
28  $f->button()->shy("GitHub", "https://www.github.com")
29  ]);
30  $current_presentation = 'simple';
31  if ($request_wrapper->has('mode')) {
32  $current_presentation = $request_wrapper->retrieve('mode', $refinery->kindlyTo()->string());
33  }
34  $presentation_options = [
35  'simple' => 'Simple',
36  'detailed' => 'Detailed'
37  ];
38  $modes = $f->viewControl()->mode(
39  array_reduce(
40  array_keys($presentation_options),
41  static function ($carry, $item) use ($presentation_options, $url) {
42  $carry[$presentation_options[$item]] = "$url&mode=$item";
43  return $carry;
44  },
45  []
46  ),
47  'Presentation Mode'
48  )->withActive($presentation_options[$current_presentation]);
49 
50  $content = "Just some information.";
51  if ($current_presentation === 'detailed') {
52  $content = "This is clearly a lot more information!";
53  }
54 
55  $sub1 = $f->panel()->sub("Sub Panel Title 1", $f->legacy($content))
56  ->withFurtherInformation($f->card()->standard("Card Heading")->withSections(array($f->legacy("Card Content"))));
57  $sub2 = $f->panel()->sub("Sub Panel Title 2", $f->legacy($content));
58 
59  $block = $f->panel()->report("Report Title", [$sub1, $sub2])
60  ->withActions($actions)
61  ->withViewControls([$modes]);
62 
63  return $renderer->render($block);
64 }
$renderer
$url
Definition: shib_logout.php:63
global $DIC
Definition: shib_login.php:25
with_view_controls()
description: > Example for rendering a report panel.