ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
with_view_controls.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
32 function with_view_controls(): string
33 {
34  global $DIC;
35  $f = $DIC->ui()->factory();
36  $renderer = $DIC->ui()->renderer();
37  $refinery = $DIC->refinery();
38  $request_wrapper = $DIC->http()->wrapper()->query();
39 
40  $url = $DIC->http()->request()->getRequestTarget();
41 
42  $actions = $f->dropdown()->standard([
43  $f->button()->shy("ILIAS", "https://www.ilias.de"),
44  $f->button()->shy("GitHub", "https://www.github.com")
45  ]);
46  $current_presentation = 'simple';
47  if ($request_wrapper->has('mode')) {
48  $current_presentation = $request_wrapper->retrieve('mode', $refinery->kindlyTo()->string());
49  }
50  $presentation_options = [
51  'simple' => 'Simple',
52  'detailed' => 'Detailed'
53  ];
54  $modes = $f->viewControl()->mode(
55  array_reduce(
56  array_keys($presentation_options),
57  static function ($carry, $item) use ($presentation_options, $url) {
58  $carry[$presentation_options[$item]] = "$url&mode=$item";
59  return $carry;
60  },
61  []
62  ),
63  'Presentation Mode'
64  )->withActive($presentation_options[$current_presentation]);
65 
66  $content = "Just some information.";
67  if ($current_presentation === 'detailed') {
68  $content = "This is clearly a lot more information!";
69  }
70 
71  $sub1 = $f->panel()->sub("Sub Panel Title 1", $f->legacy()->content($content))
72  ->withFurtherInformation($f->card()->standard("Card Heading")->withSections(array($f->legacy()->content("Card Content"))));
73  $sub2 = $f->panel()->sub("Sub Panel Title 2", $f->legacy()->content($content));
74 
75  $block = $f->panel()->report("Report Title", [$sub1, $sub2])
76  ->withActions($actions)
77  ->withViewControls([$modes]);
78 
79  return $renderer->render($block);
80 }
$renderer
$url
Definition: shib_logout.php:66
global $DIC
Definition: shib_login.php:22
with_view_controls()
description: > Example for rendering a report panel.