19declare(strict_types=1);
40 public function render(
Component $component, RendererInterface $default_renderer): string
43 return $this->renderNotification($component, $default_renderer);
44 } elseif ($component instanceof
Group) {
45 return $this->
renderGroup($component, $default_renderer);
46 } elseif ($component instanceof
Standard) {
48 } elseif ($component instanceof
Shy) {
49 return $this->
renderShy($component, $default_renderer);
54 protected function renderGroup(
Group $component, RendererInterface $default_renderer): string
56 $tpl = $this->
getTemplate(
"tpl.group.html",
true,
true);
61 foreach ($items as $item) {
62 $tpl->setCurrentBlock(
"item");
63 $tpl->setVariable(
"ITEM", $default_renderer->render($item));
64 $tpl->parseCurrentBlock();
68 $tpl->setCurrentBlock(
"title");
69 $tpl->setVariable(
"TITLE", $title);
70 $tpl->parseCurrentBlock();
75 if ($actions !==
null) {
76 $tpl->setVariable(
"ACTIONS", $default_renderer->render($actions));
78 $tpl->setVariable(
"ACTIONS",
"");
86 $tpl = $this->
getTemplate(
"tpl.item_standard.html",
true,
true);
88 $this->
renderTitle($component, $default_renderer, $tpl);
93 $color = $component->getColor();
94 if ($color !==
null) {
95 $tpl->setCurrentBlock(
"color");
96 $tpl->setVariable(
"COLOR", $color->asHex());
97 $tpl->parseCurrentBlock();
101 $lead = $component->getLead();
102 $progress = $component->getProgress();
104 if (is_string($lead)) {
105 if ($progress !=
null) {
106 $tpl->setCurrentBlock(
"lead_text_with_progress");
107 $tpl->touchBlock(
"item_with_lead_and_progress");
109 $tpl->setCurrentBlock(
"lead_text");
110 $tpl->touchBlock(
"item_with_lead_only");
112 $tpl->setVariable(
"LEAD_TEXT", $lead);
113 $tpl->parseCurrentBlock();
115 if ($lead instanceof
Image) {
116 if ($progress !=
null) {
117 $tpl->setCurrentBlock(
"lead_image_with_progress");
118 $tpl->touchBlock(
"item_with_lead_and_progress");
120 $tpl->setCurrentBlock(
"lead_image");
121 $tpl->touchBlock(
"item_with_lead_only");
123 $tpl->setVariable(
"LEAD_IMAGE", $default_renderer->render($lead));
124 $tpl->parseCurrentBlock();
126 if ($lead instanceof
Icon || $lead instanceof
Avatar) {
127 $tpl->setCurrentBlock(
"lead_icon");
128 $tpl->setVariable(
"LEAD_ICON", $default_renderer->render($lead));
129 $tpl->parseCurrentBlock();
130 $tpl->setCurrentBlock(
"lead_start_icon");
131 $tpl->parseCurrentBlock();
133 $tpl->setCurrentBlock(
"lead_start");
134 $tpl->parseCurrentBlock();
136 if ($progress !=
null && ($lead instanceof
Icon || $lead instanceof
Avatar)) {
137 $tpl->setCurrentBlock(
"progress_end_with_lead_icon");
138 $tpl->setVariable(
"PROGRESS", $default_renderer->render($progress));
139 $tpl->parseCurrentBlock();
140 } elseif ($progress !=
null) {
141 $tpl->setCurrentBlock(
"progress_end");
142 $tpl->setVariable(
"PROGRESS", $default_renderer->render($progress));
143 $tpl->parseCurrentBlock();
145 $tpl->touchBlock(
"lead_end");
147 } elseif ($progress !=
null) {
148 $tpl->touchBlock(
"item_with_progress_only");
149 $tpl->setCurrentBlock(
"progress_end");
150 $tpl->setVariable(
"PROGRESS", $default_renderer->render($progress));
151 $tpl->parseCurrentBlock();
155 $main_action = $component->getMainAction();
156 if ($main_action !==
null) {
157 $tpl->setCurrentBlock(
"main_action");
158 $tpl->setVariable(
"MAIN_ACTION", $default_renderer->render($main_action));
159 $tpl->parseCurrentBlock();
163 $actions = $component->getActions();
164 if ($actions !==
null) {
165 $tpl->setCurrentBlock(
"actions");
166 $tpl->setVariable(
"ACTIONS", $default_renderer->render($actions));
167 $tpl->parseCurrentBlock();
173 protected function renderShy(
Shy $component, RendererInterface $default_renderer): string
175 $tpl = $this->
getTemplate(
"tpl.item_shy.html",
true,
true);
177 $this->
renderTitle($component, $default_renderer, $tpl);
180 if ($component->getProperties() !== []) {
181 foreach ($component->getProperties() as $name => $value) {
182 $name = htmlentities($name);
184 $value = $default_renderer->render($value);
186 $value = htmlentities($value);
188 $tpl->setCurrentBlock(
"property_row");
189 $tpl->setVariable(
"PROP_NAME_A", $name);
190 $tpl->setVariable(
"PROP_VAL_A", $value);
191 $tpl->parseCurrentBlock();
193 $tpl->setCurrentBlock(
"properties");
194 $tpl->parseCurrentBlock();
197 if ($component->getLeadIcon() !==
null) {
198 $tpl->setCurrentBlock(
"lead_icon");
199 $tpl->setVariable(
"LEAD_ICON", $default_renderer->render($component->getLeadIcon()));
200 $tpl->parseCurrentBlock();
203 if ($component->getClose() !==
null) {
204 $tpl->setCurrentBlock(
"close");
205 $tpl->setVariable(
"CLOSE", $default_renderer->render($component->getClose()));
206 $tpl->parseCurrentBlock();
210 $tpl->setCurrentBlock(
"id");
212 $tpl->parseCurrentBlock();
218 protected function renderNotification(
Notification $component, RendererInterface $default_renderer): string
220 $tpl = $this->
getTemplate(
"tpl.item_notification.html",
true,
true);
221 $this->
renderTitle($component, $default_renderer, $tpl);
223 if (!is_null($desc) && trim($desc) !=
"") {
224 $tpl->setCurrentBlock(
"desc");
225 $tpl->setVariable(
"DESC", $desc);
226 $tpl->parseCurrentBlock();
229 $tpl->setVariable(
"LEAD_ICON", $default_renderer->render($component->
getLeadIcon()));
233 if ($actions !==
null) {
234 $tpl->setVariable(
"ACTIONS", $default_renderer->render($actions));
239 $tpl->setCurrentBlock(
"additional_content");
240 $tpl->setVariable(
"ADDITIONAL_CONTENT", $default_renderer->render($component->
getAdditionalContent()));
241 $tpl->parseCurrentBlock();
246 $aggregates_html = $default_renderer->render(
258 $component = $component->withAdditionalOnLoadCode(
259 fn(
$id) =>
"il.UI.item.notification.getNotificationItemObject($('#$id')).registerAggregates($toggleable);"
265 $tpl->setCurrentBlock(
"aggregate_notifications");
266 $tpl->setVariable(
"AGGREGATES", $aggregates_html);
267 $tpl->setVariable(
"PARENT_ID", $item_id);
268 $tpl->parseCurrentBlock();
276 $close_action = $this->
getUIFactory()->button()->close()->withAdditionalOnLoadCode(
277 fn(
$id) =>
"il.UI.item.notification.getNotificationItemObject($('#$id')).registerCloseAction('$url',1);"
279 $tpl->setVariable(
"CLOSE_ACTION", $default_renderer->render($close_action));
282 $tpl->setCurrentBlock(
"id");
283 $tpl->setVariable(
'ID', $item_id);
284 $tpl->parseCurrentBlock();
292 if ($title instanceof
Button\
Shy || $title instanceof
Link) {
293 $title = $default_renderer->render($title);
295 $title = htmlentities($title);
304 if (!is_null($desc) && trim($desc) !=
"") {
313 RendererInterface $default_renderer,
317 $audio = $component->getAudioPlayer();
318 if (!is_null($audio)) {
320 $tpl->
setVariable(
"AUDIO", $default_renderer->render($audio));
328 if (count($props) > 0) {
330 foreach ($props as $name => $value) {
331 $name = htmlentities($name);
333 $value = $default_renderer->render($value);
363 parent::registerResources($registry);
364 $registry->
register(
'assets/js/notification.js');
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
renderAudioPlayer(Item $component, RendererInterface $default_renderer, Template $tpl)
renderGroup(Group $component, RendererInterface $default_renderer)
renderShy(Shy $component, RendererInterface $default_renderer)
registerResources(ResourceRegistry $registry)
Announce resources this renderer requires.
renderStandard(Item $component, RendererInterface $default_renderer)
render(Component $component, RendererInterface $default_renderer)
renderTitle(Item $component, RendererInterface $default_renderer, Template $tpl)
renderProperties(Item $component, RendererInterface $default_renderer, Template $tpl)
renderDescription(Item $component, Template $tpl)
Base class for all component renderers.
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.
txt(string $id)
Get a text from the language file.
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.
getUIFactory()
Get a UI factory.
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
A component is the most general form of an entity in the UI.
Common interface to item groups.
getTitle()
Gets the title of the group.
getActions()
Get the actions Dropdown of the group.
getItems()
Gets item of the group.
Common interface to all items.
getProperties()
Get the properties of the appointment.
getDescription()
Get the description of the item.
getTitle()
Gets the title of the item.
getAggregateNotifications()
Get the list of Notification Items, this Notification Item aggregates or an empty list.
getAdditionalContent()
Get the additional content of the item or null.
getCloseAction()
Get the url attached to this Notification Item.
getActions()
Get the actions of the item.
getLeadIcon()
Get icon as lead.
getOnLoadCode()
Get the currently bound on load code.
This describes how a letter or a picture avatar could be modified during construction of UI.
This describes how an icon could be modified during construction of UI.
Registry for resources required by rendered output like Javascript or CSS.
register(string $name)
Add a dependency.
Interface to templating as it is used in the UI framework.
setVariable(string $name, $value)
Set a variable in the current block.
setCurrentBlock(string $name)
Set the block to work on.
parseCurrentBlock()
Parse the block that is currently worked on.
An entity that renders components to a string output.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.