ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
server.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25use ILIAS\UI;
26
43function server(): string
44{
45 global $DIC;
46 $http = $DIC->http();
47 $uri = $http->request()->getUri();
48 $request = $http->wrapper()->query();
49 $factory = $DIC->ui()->factory();
50 $renderer = $DIC->ui()->renderer();
51 $data_factory = new \ILIAS\Data\Factory();
52
53 $endpoint_flag = 'progress_bar_example_endpoint';
54 $endpoint_url = $uri . "&$endpoint_flag=1";
55 $endpoint_url = $data_factory->uri($endpoint_url);
56
57 $progress_bar = $factory->progress()->bar('waiting about 10 seconds', $endpoint_url);
58
59 $trigger = $factory->button()->standard('start making progress', '#');
60 $trigger = $trigger->withAdditionalOnLoadCode(
61 static fn(string $id) => "
62 document.getElementById('$id')?.addEventListener('click', (event) => {
63 // always 'kick off' async progress bars with an indeterminate state.
64 il.UI.Progress.Bar.indeterminate('{$progress_bar->getUpdateSignal()}', 'Estimating...');
65 event.target.disabled = true;
66 });
67 "
68 );
69
70 if ($request->has($endpoint_flag)) {
72 }
73
74 return $renderer->render([$progress_bar, $trigger]);
75}
76
78{
80
81 $task_progress = getTaskProgress();
82
83 $state = match ($task_progress) {
84 1 => $state = $factory->progress()->state()->bar()->determinate(10, 'Start processing...'),
85 2 => $state = $factory->progress()->state()->bar()->determinate(20),
86 3 => $state = $factory->progress()->state()->bar()->determinate(30),
87 4 => $state = $factory->progress()->state()->bar()->determinate(40),
88 5 => $state = $factory->progress()->state()->bar()->determinate(50, 'Still processing...'),
89 6 => $state = $factory->progress()->state()->bar()->determinate(60),
90 7 => $state = $factory->progress()->state()->bar()->determinate(70),
91 8 => $state = $factory->progress()->state()->bar()->determinate(80),
92 9 => $state = $factory->progress()->state()->bar()->determinate(90),
93 10 => $state = $factory->progress()->state()->bar()->success("All done!"),
94 default => $state = $factory->progress()->state()->bar()->failure("An error ocurred."),
95 };
96
97 if (10 > $task_progress) {
99 } else {
100 resetTask();
101 }
102
103 $html = $renderer->renderAsync($state);
104
105 $http->saveResponse(
106 $http->response()
107 ->withHeader('Content-Type', 'text/html; charset=utf-8')
108 ->withBody(Streams::ofString($html))
109 );
110 $http->sendResponse();
111 $http->close();
112}
113
115{
116 if (!\ilSession::has(__NAMESPACE__ . '_example_task_progress')) {
117 \ilSession::set(__NAMESPACE__ . '_example_task_progress', 1);
118 }
119}
120
121function incrementTaskProgress(): void
122{
123 $previous_value = \ilSession::get(__NAMESPACE__ . '_example_task_progress');
124 \ilSession::set(__NAMESPACE__ . '_example_task_progress', (int) $previous_value + 1);
125}
126
128{
129 return \ilSession::get(__NAMESPACE__ . '_example_task_progress') ?? 1;
130}
131
132function resetTask(): void
133{
134 \ilSession::clear(__NAMESPACE__ . '_example_task_progress');
135}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$renderer
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Stream factory which enables the user to create streams without the knowledge of the concrete class.
Definition: Streams.php:32
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:41
Definition: UI.php:24
static get(string $a_var)
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.
static has($a_var)
$http
Definition: deliver.php:30
Interface GlobalHttpState.
An entity that renders components to a string output.
Definition: Renderer.php:31
get(string $class_name)
callArtificialTaskEndpoint(GlobalHttpState $http, UI\Factory $factory, UI\Renderer $renderer)
Definition: server.php:77
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26