ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
extended_notifications.php
Go to the documentation of this file.
1 <?php
30 {
31  //Set up the gears as always
32  global $DIC;
33  $f = $DIC->ui()->factory();
34  $renderer = $DIC->ui()->renderer();
35 
36  //Create some bare UI Components Notification Item to be used all over the place
37  $icon = $f->symbol()->icon()->standard("chtr", "chtr");
38  $title = $f->link()->standard("Some Title", "#");
39  $item = $f->item()->notification($title, $icon);
40 
41  //We provide 4 async endpoints here
42  //Endpoint if element ist closed
43  $async_close = $_SERVER['REQUEST_URI'] . '&close_item=true&async_load_replace=false&async_load_replace_content=false&async_add_aggregate=false';
44  //Attach this directly to all items to be closable (showing the Close Button)
45  $closable_item = $item->withCloseAction($async_close);
46  //Endpoint if replace button is pressed
47  $async_replace_url = $_SERVER['REQUEST_URI'] . '&close_item=false&async_load_replace=true&async_load_replace_content=false&async_add_aggregate=false';
48  //Endpoint if for only replacing data of the item (description, title etc.)
49  $async_replace_content_load_url = $_SERVER['REQUEST_URI'] . '&close_item=false&async_load_replace=false&async_load_replace_content=true&async_add_aggregate=false';
50  //Endpoint for adding one single aggreate item
51  $async_add_aggregate = $_SERVER['REQUEST_URI'] . '&close_item=false&async_load_replace=false&async_load_replace_content=false&async_add_aggregate=true';
52 
53  if ($_GET['close_item'] === "true") {
54  //Note that we passe back JS logic here for further processing here
55  $js = $f->legacy("")->withOnLoadCode(function ($id) use ($async_replace_content_load_url) {
56  return "
57  il.DemoScopeRemaining--;
58  il.DemoScopeItem.replaceContentByAsyncItemContent('$async_replace_content_load_url',{remaining: il.DemoScopeRemaining,added: il.DemoScopeAdded});
59  ";
60  });
61  echo $renderer->renderAsync($js);
62  exit;
63  }
64 
65  if ($_GET['async_load_replace'] === "true") {
66  $remaining = $_GET["remaining"];
67  $added = $_GET["added"];
68 
69  //We create the amount of aggregates send to us by get and put an according
70  //description into the newly create Notification Item
71  $items = [];
72  for ($i = 1; $i < $added + 1; $i++) {
73  $items[] = $closable_item->withDescription("This item is number: " . $i . " of a fix set of 10 entries.");
74  }
75  $replacement = $item->withDescription("Number of Async non-closed Aggregates: " . $remaining . ", totally created: " . $added)
76  ->withAggregateNotifications($items);
77 
78  echo $renderer->renderAsync([$replacement]);
79  exit;
80  }
81 
82  if ($_GET['async_load_replace_content'] === "true") {
83  $remaining = $_GET["remaining"];
84  $added = $_GET["added"];
85  $replacement = $item->withDescription("Number of Async non-closed Aggregates: " . $remaining . ", totally created: " . $added);
86  echo $renderer->renderAsync([$replacement]);
87  exit;
88  }
89 
90  if ($_GET['async_add_aggregate'] === "true") {
91  $remaining = $_GET["remaining"];
92  $added = $_GET["added"];
93 
94  $new_aggregate = $closable_item->withDescription("The item has been added, Nr: " . $added);
95 
96  echo $renderer->renderAsync([$new_aggregate]);
97  exit;
98  }
99 
100  //Button with attached js logic to add one new Notification, note, that
101  //we also change the description of the already existing parent Notification
102  //Item holding the aggregates.
103  $add_button = $f->button()->standard("Add Chat Notification", "#")
104  ->withAdditionalOnLoadCode(function ($id) use ($async_replace_url, $async_add_aggregate) {
105  return "
106  $('#$id').click(function() {
107  il.DemoScopeItem.getCounterObjectIfAny().incrementNoveltyCount(1);
108  il.DemoScopeAdded++;
109  il.DemoScopeRemaining++;
110  il.DemoScopeItem.addAsyncAggregate('$async_add_aggregate',{remaining: il.DemoScopeAdded,added: il.DemoScopeAdded});
111  il.DemoScopeItem.replaceContentByAsyncItemContent('$async_replace_url',{remaining: il.DemoScopeRemaining,added: il.DemoScopeAdded});
112  });";
113  });
114 
115  //Resetting all counts to 0, remove all aggregates
116  $reset_button = $f->button()->standard("Reset Chat", "#")
117  ->withAdditionalOnLoadCode(function ($id) use ($async_replace_url) {
118  return "
119  $('#$id').click(function() {
120  il.DemoScopeItem.getCounterObjectIfAny().decrementNoveltyCount(il.DemoScopeRemaining);
121  il.DemoScopeAdded = 0;
122  il.DemoScopeRemaining = 0;
123  il.DemoScopeItem.replaceByAsyncItem('$async_replace_url',{remaining: il.DemoScopeAdded,added: il.DemoScopeAdded});
124  });";
125  });
126 
127  //Set all counts to a fixed value of ten.
128  $set_button = $f->button()->standard("Set to 10 chat entries", "#")
129  ->withAdditionalOnLoadCode(function ($id) use ($async_replace_url) {
130  return "
131  $('#$id').click(function() {
132  il.DemoScopeItem.getCounterObjectIfAny().decrementNoveltyCount(il.DemoScopeRemaining);
133  il.DemoScopeItem.getCounterObjectIfAny().incrementNoveltyCount(10);
134  il.DemoScopeAdded = 10;
135  il.DemoScopeRemaining = 10;
136  il.DemoScopeItem.replaceByAsyncItem('$async_replace_url',{remaining: il.DemoScopeAdded,added: il.DemoScopeAdded});
137  });";
138  });
139 
145  $async_item = $item
146  ->withDescription("This is the original Version after the Page has loaded. Will be replaced completely.")
147  ->withAdditionalOnLoadCode(function ($id) {
148  return "
149  il.DemoScopeAdded = 0;
150  il.DemoScopeRemaining = 0;
151  il.DemoScopeItem = il.UI.item.notification.getNotificationItemObject($($id));
152  ";
153  });
154 
160  return usuallyDoneByGlobalScreenProbablyIgnore($async_item, $f, $renderer, $add_button, $set_button, $reset_button);
161 }
162 
163 function usuallyDoneByGlobalScreenProbablyIgnore($async_item, $f, $renderer, $add_button, $set_button, $reset_button)
164 {
165  //Put the item in some slate.
166  $async_slate = $f->mainControls()->slate()->notification("Chat", [$async_item]);
167 
168 
169  //Just some candy, to give the whole example a more realistic look.
170  $mail_icon = $f->symbol()->icon()->standard("mail", "mail");
171  $mail_title = $f->link()->standard("Inbox", "link_to_inbox");
172  $mail_notification_item = $f->item()->notification($mail_title, $mail_icon)
173  ->withDescription("You have 23 unread mails in your inbox")
174  ->withProperties(["Time" => "3 days ago"]);
175  $mail_slate = $f->mainControls()->slate()->notification("Mail", [$mail_notification_item]);
176 
177 
178  //Note
179  $notification_glyph = $f->symbol()->glyph()->notification("notification", "notification")
180  ->withCounter($f->counter()->novelty(1));
181 
182  $notification_center = $f->mainControls()->slate()
183  ->combined("Notification Center", $notification_glyph)
184  ->withAdditionalEntry($async_slate)
185  ->withAdditionalEntry($mail_slate);
186 
187  $css_fix = "<style>.panel-primary .il-maincontrols-metabar{flex-direction: column;} .panel-primary .il-metabar-slates{position: relative;top: 0px;}</style>";
188  return $css_fix . $renderer->render([buildMetabarWithNotifications($f, $notification_center),$add_button,$set_button,$reset_button]);
189 }
190 
191 function buildMetabarWithNotifications($f, $notification_center)
192 {
193  $help = $f->button()->bulky($f->symbol()->glyph()->help(), 'Help', '#');
194  $search = $f->button()->bulky($f->symbol()->glyph()->search(), 'Search', '#');
195  $user = $f->button()->bulky($f->symbol()->glyph()->user(), 'User', '#');
196 
197 
198  $metabar = $f->mainControls()->metabar()
199  ->withAdditionalEntry('search', $search)
200  ->withAdditionalEntry('help', $help)
201  ->withAdditionalEntry('notification', $notification_center)
202  ->withAdditionalEntry('user', $user);
203 
204  return $metabar;
205 }
buildMetabarWithNotifications($f, $notification_center)
extended_notifications()
This is a rather extended example on the usage of the Notification Item async functionality provided ...
exit
Definition: login.php:29
$_GET["client_id"]
usuallyDoneByGlobalScreenProbablyIgnore($async_item, $f, $renderer, $add_button, $set_button, $reset_button)
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
$DIC
Definition: xapitoken.php:46
$i
Definition: metadata.php:24