ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSystemStyleMessageStack.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27{
31 protected array $messages = [];
34 {
35 $this->main_tpl = $main_tpl;
36 }
37
42 {
43 array_unshift($this->messages, $message);
44 }
45
50 {
51 $this->messages[] = $message;
52 }
53
58 public function getUIComponentsMessages(\ILIAS\UI\Factory $f): array
59 {
60 $messages = [];
61 foreach ($this->getJoinedMessages() as $type => $joined_message) {
62 switch ($type) {
64 $messages[] = $f->messageBox()->success($joined_message);
65 break;
67 $messages[] = $f->messageBox()->info($joined_message);
68 break;
70 $messages[] = $f->messageBox()->failure($joined_message);
71 break;
72 }
73 }
74 return $messages;
75 }
76
82 public function getJoinedMessages(): array
83 {
84 $joined_messages = [];
85 foreach ($this->getMessages() as $message) {
86 if (!array_key_exists($message->getTypeId(), $joined_messages)) {
87 $joined_messages[$message->getTypeId()] = '';
88 }
89 $joined_messages[$message->getTypeId()] .= $message->getMessageOutput();
90 }
91 return $joined_messages;
92 }
93
97 public function getMessages(): array
98 {
99 return $this->messages;
100 }
101
105 public function setMessages(array $messages): void
106 {
107 $this->messages = $messages;
108 }
109
113 public function hasMessages(): bool
114 {
115 return count($this->getMessages()) > 0;
116 }
117
121 public function sendMessages(bool $keep = true): void
122 {
123 foreach ($this->getJoinedMessages() as $type => $joined_message) {
124 switch ($type) {
126 $this->main_tpl->setOnScreenMessage('success', $joined_message, $keep);
127 break;
129 $this->main_tpl->setOnScreenMessage('info', $joined_message, $keep);
130 break;
132 $this->main_tpl->setOnScreenMessage('failure', $joined_message, $keep);
133 break;
134 }
135 }
136 }
137}
Used to stack messages to be shown to the user.
hasMessages()
Return wheter there are any message at all stored in the stack.
__construct(ilGlobalTemplateInterface $main_tpl)
prependMessage(ilSystemStyleMessage $message)
Add a message to be displayed before all others.
getJoinedMessages()
Return an array containing a string with all messages for each type.
getUIComponentsMessages(\ILIAS\UI\Factory $f)
Return Messages as UI Component.
addMessage(ilSystemStyleMessage $message)
Add a message to be displayed by the stack.
sendMessages(bool $keep=true)
Send messages via ilUtil to be displayed, still needed for messagees, that need to survive a redirect...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
$message
Definition: xapiexit.php:31