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 
17 function with_view_controls(): string
18 {
19  global $DIC;
20  $f = $DIC->ui()->factory();
21  $renderer = $DIC->ui()->renderer();
22  $refinery = $DIC->refinery();
23  $request_wrapper = $DIC->http()->wrapper()->query();
24 
25  $url = $DIC->http()->request()->getRequestTarget();
26 
27  $actions = $f->dropdown()->standard([
28  $f->button()->shy("ILIAS", "https://www.ilias.de"),
29  $f->button()->shy("GitHub", "https://www.github.com")
30  ]);
31  $current_sortation = 'abc';
32  if ($request_wrapper->has('sort')) {
33  $current_sortation = $request_wrapper->retrieve('sort', $refinery->kindlyTo()->string());
34  }
35 
36  $sortation_options = [
37  'abc' => 'Sort by Alphabet',
38  'date' => 'Sort by Date',
39  'location' => 'Sort by Location'
40  ];
41  $sortation = $f->viewControl()->sortation($sortation_options, $current_sortation)
42  ->withTargetURL($url, "sort");
43 
44  $current_presentation = 'list';
45  if ($request_wrapper->has('mode')) {
46  $current_presentation = $request_wrapper->retrieve('mode', $refinery->kindlyTo()->string());
47  }
48  $presentation_options = [
49  'list' => 'List View',
50  'tile' => 'Tile View'
51  ];
52  $modes = $f->viewControl()->mode(
53  array_reduce(
54  array_keys($presentation_options),
55  static function ($carry, $item) use ($presentation_options, $url) {
56  $carry[$presentation_options[$item]] = "$url&mode=$item";
57  return $carry;
58  },
59  []
60  ),
61  'Presentation Mode'
62  )
63  ->withActive($presentation_options[$current_presentation]);
64 
65  $current_page = 0;
66  if ($request_wrapper->has('page')) {
67  $current_page = $request_wrapper->retrieve('page', $refinery->kindlyTo()->int());
68  }
69  $pagination = $f->viewControl()->pagination()
70  ->withTargetURL($url, "page")
71  ->withTotalEntries(98)
72  ->withPageSize(10)
73  ->withCurrentPage($current_page);
74 
75  $view_controls = [
76  $sortation,
77  $modes,
78  $pagination
79  ];
80 
81  if ($current_presentation === 'list') {
82  $item1 = $f->item()->standard("Item Title")
83  ->withActions($actions)
84  ->withProperties([
85  "Origin" => "Course Title 1",
86  "Last Update" => "24.11.2011",
87  "Location" => "Room 123, Main Street 44, 3012 Bern"
88  ])
89  ->withDescription(
90  "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."
91  );
92 
93  $item2 = $f->item()->standard("Item 2 Title")
94  ->withActions($actions)
95  ->withDescription(
96  "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."
97  );
98 
99  $item3 = $f->item()->standard("Item 3 Title")
100  ->withActions($actions)
101  ->withDescription(
102  "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."
103  );
104  } else {
105  $image = $f->image()->responsive(
106  "./assets/images/logo/HeaderIcon.svg",
107  "Thumbnail Example"
108  );
109  $content = $f->listing()->descriptive(
110  [
111  "Entry 1" => "Some text",
112  "Entry 2" => "Some more text",
113  ]
114  );
115  $item1 = $item2 = $item3 = $f->card()->standard("Item Title", $image)
116  ->withSections([$content]);
117  }
118 
119  $std_list = $f->panel()->standard("List Title", [
120  $f->item()->group("Subtitle 1", [
121  $item1,
122  $item2
123  ]),
124  $f->item()->group("Subtitle 2", [
125  $item3
126  ])
127  ])
128  ->withActions($actions)
129  ->withViewControls($view_controls);
130 
131  return $renderer->render($std_list);
132 }
$renderer
with_view_controls()
description: > Example for rendering a standard panel with an all view control.
$url
Definition: shib_logout.php:63
global $DIC
Definition: shib_login.php:25