ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
extended_example_for_developers.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24
61{
62 global $DIC;
63 $f = $DIC->ui()->factory();
64 $renderer = $DIC->ui()->renderer();
65
66 $url = $DIC->http()->request()->getUri()->__toString() . '&extended_metabar_ui=1';
67 $txt = $f->legacy()->content('<p>
68 The extended MetaBar example opens in fullscreen to showcase the
69 Notification Item async functionality in the proper page layout.
70 Use the Notification Center (bell icon) in the MetaBar and the
71 buttons below to try the async features.
72 </p>');
73
74 $page_demo = $f->link()->standard('See UI in fullscreen-mode', $url);
75
76 return $renderer->render([
77 $txt,
78 $page_demo
79 ]);
80}
81
82function buildMetabarWithNotifications($f, $notification_center)
83{
84 $help = $f->button()->bulky($f->symbol()->glyph()->help(), 'Help', '#');
85 $search = $f->button()->bulky($f->symbol()->glyph()->search(), 'Search', '#');
86 $user = $f->button()->bulky($f->symbol()->glyph()->user(), 'User', '#');
87
88
89 $metabar = $f->mainControls()->metabar()
90 ->withAdditionalEntry('search', $search)
91 ->withAdditionalEntry('help', $help)
92 ->withAdditionalEntry('notification', $notification_center)
93 ->withAdditionalEntry('user', $user);
94
95 return $metabar;
96}
97
102{
103 $f = $dic->ui()->factory();
104 $renderer = $dic->ui()->renderer();
105 $refinery = $dic->refinery();
106 $request_wrapper = $dic->http()->wrapper()->query();
107
108 $icon = $f->symbol()->icon()->standard("chtr", "chtr");
109 $title = $f->link()->standard("Some Title", "#");
110 $item = $f->item()->notification($title, $icon);
111
112 $async_close = $_SERVER['REQUEST_URI'] . '&close_item=true&async_load_replace=false&async_load_replace_content=false&async_add_aggregate=false';
113 $closable_item = $item->withCloseAction($async_close);
114 $async_replace_url = $_SERVER['REQUEST_URI'] . '&close_item=false&async_load_replace=true&async_load_replace_content=false&async_add_aggregate=false';
115 $async_replace_content_load_url = $_SERVER['REQUEST_URI'] . '&close_item=false&async_load_replace=false&async_load_replace_content=true&async_add_aggregate=false';
116 $async_add_aggregate = $_SERVER['REQUEST_URI'] . '&close_item=false&async_load_replace=false&async_load_replace_content=false&async_add_aggregate=true';
117
118 if ($request_wrapper->has('close_item') && $request_wrapper->retrieve('close_item', $refinery->kindlyTo()->string()) === "true") {
119 $js = $f->legacy()->content("")->withOnLoadCode(function ($id) use ($async_replace_content_load_url) {
120 return "
121 il.DemoScopeRemaining--;
122 il.DemoScopeItem.replaceContentByAsyncItemContent('$async_replace_content_load_url',{remaining: il.DemoScopeRemaining,added: il.DemoScopeAdded});
123 ";
124 });
125 echo $renderer->renderAsync($js);
126 exit;
127 }
128
129 if ($request_wrapper->has('async_load_replace') && $request_wrapper->retrieve('async_load_replace', $refinery->kindlyTo()->string()) === "true") {
130 $remaining = $request_wrapper->retrieve("remaining", $refinery->kindlyTo()->int());
131 $added = $request_wrapper->retrieve("added", $refinery->kindlyTo()->int());
132
133 $items = [];
134 for ($i = 1; $i < $added + 1; $i++) {
135 $items[] = $closable_item->withDescription("This item is number: " . $i . " of a fix set of 10 entries.");
136 }
137 $replacement = $item->withDescription("Number of Async non-closed Aggregates: " . $remaining . ", totally created: " . $added)
138 ->withAggregateNotifications($items);
139
140 echo $renderer->renderAsync([$replacement]);
141 exit;
142 }
143
144 if ($request_wrapper->has('async_load_replace_content') && $request_wrapper->retrieve('async_load_replace_content', $refinery->kindlyTo()->string()) === "true") {
145 $remaining = $request_wrapper->retrieve("remaining", $refinery->kindlyTo()->int());
146 $added = $request_wrapper->retrieve("added", $refinery->kindlyTo()->int());
147 $replacement = $item->withDescription("Number of Async non-closed Aggregates: " . $remaining . ", totally created: " . $added);
148 echo $renderer->renderAsync([$replacement]);
149 exit;
150 }
151
152 if ($request_wrapper->has('async_add_aggregate') && $request_wrapper->retrieve('async_add_aggregate', $refinery->kindlyTo()->string()) === "true") {
153 $added = $request_wrapper->retrieve("added", $refinery->kindlyTo()->int());
154 $new_aggregate = $closable_item->withDescription("The item has been added, Nr: " . $added);
155 echo $renderer->renderAsync([$new_aggregate]);
156 exit;
157 }
158}
159
161{
162 $f = $dic->ui()->factory();
163 $renderer = $dic->ui()->renderer();
164
165 $async_replace_url = $_SERVER['REQUEST_URI'] . '&close_item=false&async_load_replace=true&async_load_replace_content=false&async_add_aggregate=false';
166 $async_add_aggregate = $_SERVER['REQUEST_URI'] . '&close_item=false&async_load_replace=false&async_load_replace_content=false&async_add_aggregate=true';
167
168 $icon = $f->symbol()->icon()->standard("chtr", "chtr");
169 $title = $f->link()->standard("Some Title", "#");
170 $item = $f->item()->notification($title, $icon);
171 $async_close = $_SERVER['REQUEST_URI'] . '&close_item=true&async_load_replace=false&async_load_replace_content=false&async_add_aggregate=false';
172 $closable_item = $item->withCloseAction($async_close);
173
174 $add_button = $f->button()->standard("Add Chat Notification", "#")
175 ->withAdditionalOnLoadCode(function ($id) use ($async_replace_url, $async_add_aggregate) {
176 return "
177 $('#$id').click(function() {
178 il.DemoScopeItem.getCounterObjectIfAny().incrementNoveltyCount(1);
179 il.DemoScopeAdded++;
180 il.DemoScopeRemaining++;
181 il.DemoScopeItem.addAsyncAggregate('$async_add_aggregate',{remaining: il.DemoScopeAdded,added: il.DemoScopeAdded});
182 il.DemoScopeItem.replaceContentByAsyncItemContent('$async_replace_url',{remaining: il.DemoScopeRemaining,added: il.DemoScopeAdded});
183 });";
184 });
185
186 $reset_button = $f->button()->standard("Reset Chat", "#")
187 ->withAdditionalOnLoadCode(function ($id) use ($async_replace_url) {
188 return "
189 $('#$id').click(function() {
190 il.DemoScopeItem.getCounterObjectIfAny().decrementNoveltyCount(il.DemoScopeRemaining);
191 il.DemoScopeAdded = 0;
192 il.DemoScopeRemaining = 0;
193 il.DemoScopeItem.replaceByAsyncItem('$async_replace_url',{remaining: il.DemoScopeAdded,added: il.DemoScopeAdded});
194 });";
195 });
196
197 $set_button = $f->button()->standard("Set to 10 chat entries", "#")
198 ->withAdditionalOnLoadCode(function ($id) use ($async_replace_url) {
199 return "
200 $('#$id').click(function() {
201 il.DemoScopeItem.getCounterObjectIfAny().decrementNoveltyCount(il.DemoScopeRemaining);
202 il.DemoScopeItem.getCounterObjectIfAny().incrementNoveltyCount(10);
203 il.DemoScopeAdded = 10;
204 il.DemoScopeRemaining = 10;
205 il.DemoScopeItem.replaceByAsyncItem('$async_replace_url',{remaining: il.DemoScopeAdded,added: il.DemoScopeAdded});
206 });";
207 });
208
209 $async_item = $item
210 ->withDescription("This is the original Version after the Page has loaded. Will be replaced completely.")
211 ->withAdditionalOnLoadCode(function ($id) {
212 return "
213 il.DemoScopeAdded = 0;
214 il.DemoScopeRemaining = 0;
215 il.DemoScopeItem = il.UI.item.notification.getNotificationItemObject($($id));
216 ";
217 });
218
219 $async_slate = $f->mainControls()->slate()->notification("Chat", [$async_item]);
220
221 $mail_icon = $f->symbol()->icon()->standard("mail", "mail");
222 $mail_title = $f->link()->standard("Inbox", "link_to_inbox");
223 $mail_notification_item = $f->item()->notification($mail_title, $mail_icon)
224 ->withDescription("You have 23 unread mails in your inbox")
225 ->withProperties(["Time" => "3 days ago"]);
226 $mail_slate = $f->mainControls()->slate()->notification("Mail", [$mail_notification_item]);
227
228
229 $notification_glyph = $f->symbol()->glyph()->notification()
230 ->withCounter($f->counter()->novelty(1));
231
232 $notification_center = $f->mainControls()->slate()
233 ->combined("Notification Center", $notification_glyph)
234 ->withAdditionalEntry($async_slate)
235 ->withAdditionalEntry($mail_slate);
236
237 $metabar = buildMetabarWithNotifications($f, $notification_center);
238
239 $logo = $f->image()->responsive("assets/images/logo/HeaderIcon.svg", "ILIAS");
240 $responsive_logo = $f->image()->responsive("assets/images/logo/HeaderIconResponsive.svg", "ILIAS");
241 $breadcrumbs = $f->breadcrumbs([]);
242 $mainbar = $f->mainControls()->mainBar();
243 $footer = $f->mainControls()->footer()->withAdditionalText('Footer');
244 $tc = $dic->ui()->factory()->toast()->container();
245
246 $content = [
247 $f->panel()->standard(
248 'Notification Item Async Demo',
249 $f->legacy()->content(
250 "Use the Notification Center (bell icon) in the MetaBar above, then try these buttons:<br /><br />"
251 . $renderer->render([$add_button, $set_button, $reset_button])
252 )
253 ),
254 ];
255
256 $page = $f->layout()->page()->standard(
257 $content,
258 $metabar,
259 $mainbar,
260 $breadcrumbs,
261 $logo,
262 $responsive_logo,
263 "./assets/images/logo/favicon.ico",
264 $tc,
265 $footer,
266 'UI MetaBar Extended Demo',
267 'ILIAS',
268 'MetaBar Async Demo'
269 )->withUIDemo(true);
270
271 return $renderer->render($page);
272}
273
274global $DIC;
275$request_wrapper = $DIC->http()->wrapper()->query();
276$refinery = $DIC->refinery();
277
279
280if ($request_wrapper->has('extended_metabar_ui')
281 && $request_wrapper->retrieve('extended_metabar_ui', $refinery->kindlyTo()->int()) === 1
282) {
285 exit();
286}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$renderer
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
static initILIAS()
ilias initialisation
exit
$dic
Definition: ltiresult.php:33
handleAsyncRequestsIfAny(Container $dic)
Handle async requests for the notification item.
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26
$url
Definition: shib_logout.php:70