ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilNotificationConfig.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25use ilObjUser;
26use stdClass;
27
32{
33 final public const TTL_LONG = 1800;
34 final public const TTL_SHORT = 120;
35 final public const DEFAULT_TTS = 5;
36
38 private array $links = [];
40 private string $iconPath;
43 private bool $disableAfterDelivery = false;
44 private int $validForSeconds = 0;
45 protected int $visibleForSeconds = 0;
47 private array $handlerParams = [];
48
49 public function __construct(private readonly string $provider, private ?NotificationIdentification $identification = null)
50 {
51 if ($identification === null) {
52 $identification = new NotificationIdentification($provider, 'default');
53 }
54 $this->identification = $identification;
55 }
56
57 public function getType(): string
58 {
59 return $this->provider;
60 }
61
62 public function setAutoDisable(bool $value): void
63 {
64 $this->disableAfterDelivery = $value;
65 }
66
67 public function hasDisableAfterDeliverySet(): bool
68 {
70 }
71
75 public function setLinks(array $links): void
76 {
77 $this->links = $links;
78 }
79
83 public function getLinks(): array
84 {
85 return $this->links;
86 }
87
88 public function setIconPath(string $path): void
89 {
90 $this->iconPath = $path;
91 }
92
93 public function getIconPath(): ?string
94 {
95 return $this->iconPath;
96 }
97
101 public function setTitleVar(string $name, array $parameters = [], string $language_module = 'notification'): void
102 {
103 $this->title = new ilNotificationParameter($name, $parameters, $language_module);
104 }
105
106 public function getTitleVar(): string
107 {
108 return $this->title->getName();
109 }
110
114 public function setShortDescriptionVar(
115 string $name,
116 array $parameters = [],
117 string $language_module = 'notification'
118 ): void {
119 $this->short_description = new ilNotificationParameter($name, $parameters, $language_module);
120 }
121
122 public function getShortDescriptionVar(): string
123 {
124 return $this->short_description->getName();
125 }
126
130 public function setLongDescriptionVar(
131 string $name,
132 array $parameters = [],
133 string $language_module = 'notification'
134 ): void {
135 $this->long_description = new ilNotificationParameter($name, $parameters, $language_module);
136 }
137
138 public function getLongDescriptionVar(): string
139 {
140 return $this->long_description->getName();
141 }
142
146 public function getLanguageParameters(): array
147 {
148 $params = [
149 'title' => $this->title,
150 'longDescription' => $this->long_description,
151 'shortDescription' => $this->short_description,
152 ];
153
154 foreach ($this->links as $id => $link) {
155 $params['link_' . $id] = $link->getTitleParameter();
156 }
157
158 return $params;
159 }
160
161 public function setValidForSeconds(int $seconds): void
162 {
163 $this->validForSeconds = $seconds;
164 }
165
166 public function getValidForSeconds(): int
167 {
168 return $this->validForSeconds;
169 }
170
171 public function getVisibleForSeconds(): int
172 {
173 return $this->visibleForSeconds;
174 }
175
179 public function setVisibleForSeconds(int $visibleForSeconds): void
180 {
181 $this->visibleForSeconds = $visibleForSeconds;
182 }
183
184 protected function beforeSendToUsers(): void
185 {
186 }
187
188 protected function afterSendToUsers(): void
189 {
190 }
191
192 protected function beforeSendToListeners(): void
193 {
194 }
195
196 protected function afterSendToListeners(): void
197 {
198 }
199
203 final public function notifyByUsers(array $recipients, bool $processAsync = false): void
204 {
205 $this->beforeSendToUsers();
206 ilNotificationSystem::sendNotificationToUsers($this, $recipients, $processAsync);
207 $this->afterSendToUsers();
208 }
209
210 final public function notifyByListeners(int $ref_id, bool $processAsync = false): void
211 {
212 $this->beforeSendToListeners();
213 ilNotificationSystem::sendNotificationToListeners($this, $ref_id, $processAsync);
214 $this->afterSendToListeners();
215 }
216
220 final public function notifyByRoles(array $roles, bool $processAsync = false): void
221 {
222 ilNotificationSystem::sendNotificationToRoles($this, $roles, $processAsync);
223 }
224
228 public function getUserInstance(ilObjUser $user, array $languageVars, string $defaultLanguage): ilNotificationObject
229 {
230 $notificationObject = new ilNotificationObject($this, $user);
231
232 $title = $this->title->getName();
233 if (isset($languageVars[$this->title->getName()])) {
234 $var = $languageVars[$this->title->getName()]->lang;
235 if (isset($var[$user->getLanguage()])) {
236 $title = $var[$user->getLanguage()];
237 } elseif (isset($var[$defaultLanguage])) {
238 $title = $var[$defaultLanguage];
239 }
240 }
241 $notificationObject->title = $title;
242
243 $short = $this->short_description->getName();
244 if (isset($languageVars[$this->short_description->getName()])) {
245 $var = $languageVars[$this->short_description->getName()]->lang;
246 if (isset($var[$user->getLanguage()])) {
247 $short = $var[$user->getLanguage()];
248 } elseif (isset($var[$defaultLanguage])) {
249 $short = $var[$defaultLanguage];
250 }
251 }
252 $notificationObject->shortDescription = $short;
253
254 $long = $this->long_description->getName();
255 if (isset($languageVars[$this->long_description->getName()])) {
256 $var = $languageVars[$this->long_description->getName()]->lang;
257 if (isset($var[$user->getLanguage()])) {
258 $long = $var[$user->getLanguage()];
259 } elseif (isset($var[$defaultLanguage])) {
260 $long = $var[$defaultLanguage];
261 }
262 }
263 $notificationObject->longDescription = $long;
264
265 $process_links = [];
266 foreach ($this->links as $link) {
267 $link_title = $link->getTitleParameter()->getName();
268 if (isset($languageVars[$link->getTitleParameter()->getName()])) {
269 $var = $languageVars[$link->getTitleParameter()->getName()]->lang;
270 if (isset($var[$user->getLanguage()])) {
271 $link_title = $var[$user->getLanguage()];
272 } elseif (isset($var[$defaultLanguage])) {
273 $link_title = $var[$defaultLanguage];
274 }
275 }
276
277 $process_link = clone $link;
278 $process_link->setTitle($link_title);
279 $process_links[] = $process_link;
280 }
281 $notificationObject->links = $process_links;
282
283 $notificationObject->iconPath = $this->iconPath;
284
285 return $notificationObject;
286 }
287
288 public function setHandlerParam(string $name, string $value): void
289 {
290 if (strpos($name, '.')) {
291 $nsParts = explode('.', $name, 2);
292 $ns = $nsParts[0];
293 $field = $nsParts[1];
294 $this->handlerParams[$ns][$field] = $value;
295 } else {
296 $this->handlerParams[''][$name] = $value;
297 }
298 }
299
303 public function getHandlerParams(): array
304 {
305 return $this->handlerParams;
306 }
307
308 public function unsetHandlerParam(string $name): void
309 {
310 unset($this->handlerParams[$name]);
311 }
312
313 public function setIdentification(NotificationIdentification $identification): void
314 {
315 $this->identification = $identification;
316 }
317
319 {
320 return $this->identification;
321 }
322}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
setTitleVar(string $name, array $parameters=[], string $language_module='notification')
notifyByListeners(int $ref_id, bool $processAsync=false)
notifyByUsers(array $recipients, bool $processAsync=false)
setIdentification(NotificationIdentification $identification)
getUserInstance(ilObjUser $user, array $languageVars, string $defaultLanguage)
notifyByRoles(array $roles, bool $processAsync=false)
__construct(private readonly string $provider, private ?NotificationIdentification $identification=null)
setLongDescriptionVar(string $name, array $parameters=[], string $language_module='notification')
setShortDescriptionVar(string $name, array $parameters=[], string $language_module='notification')
description of a localized parameter this information is used locate translations while processing no...
User class.
$ref_id
Definition: ltiauth.php:66
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
$path
Definition: ltiservices.php:30
$provider
Definition: ltitoken.php:80
$defaultLanguage
Definition: xapiexit.php:23