ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilForumCronNotificationDataProvider.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
27 private readonly int $ref_id;
28 private readonly int $obj_id;
29 private readonly int $forum_id;
30 private readonly string $forum_title;
33 private readonly int $thread_id;
34 private readonly string $thread_title;
35 private readonly int $post_id;
36 private readonly string $post_title;
37 private readonly string $post_message;
38 private ?string $post_date = null;
39 private ?string $post_update = null;
40 private readonly bool $post_censored;
41 private ?string $post_censored_date = null;
42 private readonly ?string $post_censored_comment;
43 private readonly string $pos_usr_alias;
44 private readonly int $pos_display_user_id;
45 private bool $is_anonymized = false;
46 private readonly string $import_name;
48 private array $attachments = [];
50 private array $cron_recipients = [];
51 private readonly int $post_update_user_id;
52 private readonly int $pos_author_id;
53 private ?string $deleted_by = '';
54 private ?string $post_user_name = null;
55 private ?string $update_user_name = null;
57
58 public function __construct(
59 array $row,
60 private readonly int $notification_type,
62 ) {
63 $this->closest_container = $row['closest_container'];
64 $this->obj_id = (int) $row['obj_id'];
65 $this->ref_id = (int) ($row['ref_id'] ?? 0);
66 $this->thread_id = (int) ($row['thread_id'] ?? 0);
67 $this->thread_title = $row['thr_subject'];
68 $this->forum_id = (int) ($row['pos_top_fk'] ?? 0);
69 $this->forum_title = $row['top_name'];
70 $this->post_id = (int) ($row['pos_pk'] ?? 0);
71 $this->post_title = $row['pos_subject'];
72 $this->post_message = $row['pos_message'];
73 $this->post_date = $row['pos_date'];
74 $this->post_update = $row['pos_update'] ?? null;
75 $this->post_update_user_id = (int) ($row['update_user'] ?? 0);
76 $this->post_censored = (bool) ($row['pos_cens'] ?? false);
77 $this->post_censored_date = $row['pos_cens_date'] ?? null;
78 $this->post_censored_comment = $row['pos_cens_com'] ?? null;
79 $this->pos_usr_alias = $row['pos_usr_alias'] ?? '';
80 $this->pos_display_user_id = (int) ($row['pos_display_user_id'] ?? 0);
81 $this->pos_author_id = (int) ($row['pos_author_id'] ?? 0);
82 $this->import_name = $row['import_name'] ?? '';
83
84 if ($notificationCache === null) {
86 }
87 $this->notificationCache = $notificationCache;
88
89 if (isset($row['deleted_by'])) {
90 //cron context
91 $this->deleted_by = $row['deleted_by'];
92 } else {
93 // fallback
94 global $DIC;
95 $this->deleted_by = $DIC->user()->getLogin();
96 }
97
98 $this->read();
99 }
100
101 protected function read(): void
102 {
103 $this->readAttachments();
104 }
105
106 private function readAttachments(): void
107 {
109 $fileDataForum = new ilFileDataForum($this->getObjId(), $this->getPostId());
110 $filesOfPost = $fileDataForum->getFilesOfPost();
111
112 foreach ($filesOfPost as $attachment) {
113 $this->attachments[] = $attachment['name'];
114 }
115 }
116 }
117
118 public function addRecipient(int $user_id): void
119 {
120 $this->cron_recipients[] = $user_id;
121 }
122
126 public function getCronRecipients(): array
127 {
129 }
130
131 public function getRefId(): int
132 {
133 return $this->ref_id;
134 }
135
136 public function getObjId(): int
137 {
138 return $this->obj_id;
139 }
140
141 public function getForumId(): int
142 {
143 return $this->forum_id;
144 }
145
146 public function closestContainer(): ?ilObject
147 {
149 }
150
151 public function providesClosestContainer(): bool
152 {
153 return $this->closest_container !== null;
154 }
155
156 public function getForumTitle(): string
157 {
158 return $this->forum_title;
159 }
160
161 public function getThreadId(): int
162 {
163 return $this->thread_id;
164 }
165
166 public function getThreadTitle(): string
167 {
168 return $this->thread_title;
169 }
170
171 public function getPostId(): int
172 {
173 return $this->post_id;
174 }
175
176 public function getPostTitle(): string
177 {
178 return $this->post_title;
179 }
180
181 public function getPostMessage(): string
182 {
183 return $this->post_message;
184 }
185
186 public function getPostDate(): string
187 {
188 return $this->post_date;
189 }
190
191 public function getPostUpdate(): string
192 {
193 return $this->post_update ?? '';
194 }
195
196 public function isPostCensored(): bool
197 {
199 }
200
201 public function getPostCensoredDate(): string
202 {
203 return $this->post_censored_date ?? '';
204 }
205
206 public function getCensorshipComment(): string
207 {
209 }
210
214 public function getAttachments(): array
215 {
216 return $this->attachments;
217 }
218
219 public function getPosDisplayUserId(): int
220 {
222 }
223
224 public function getPosUserAlias(): string
225 {
227 }
228
229 public function getPostUpdateUserId(): int
230 {
232 }
233
234 public function getPosAuthorId(): int
235 {
237 }
238
239 public function isAnonymized(): bool
240 {
242 }
243
244 public function getDeletedBy(): string
245 {
246 return $this->deleted_by;
247 }
248
249 public function getImportName(): string
250 {
251 return $this->import_name;
252 }
253
254 public function getPostUserName(ilLanguage $user_lang): string
255 {
256 if ($this->post_user_name === null) {
257 $this->post_user_name = $this->getPublicUserInformation($this->getAuthorInformation(
258 $user_lang,
259 $this->getPosAuthorId(),
260 $this->getPosDisplayUserId(),
261 $this->getPosUserAlias(),
262 $this->getImportName()
263 ));
264 }
265
267 }
268
269 public function getPostUpdateUserName(ilLanguage $user_lang): string
270 {
271 if ($this->update_user_name === null) {
272 $this->update_user_name = $this->getPublicUserInformation($this->getAuthorInformation(
273 $user_lang,
274 $this->getPosAuthorId(),
275 $this->getPostUpdateUserId(),
276 $this->getPosUserAlias(),
277 $this->getImportName()
278 ));
279 }
280
281 // Fix for #25432
282 if (
283 $this->getPosUserAlias() && $this->getPosDisplayUserId() === 0 &&
284 $this->getPosAuthorId() === $this->getPostUpdateUserId()
285 ) {
286 return $this->getPosUserAlias();
287 }
288
290 }
291
292 public function getPublicUserInformation(ilForumAuthorInformation $authorinfo): string
293 {
294 $publicName = $authorinfo->getAuthorShortName();
295
296 if ($authorinfo->hasSuffix()) {
297 $publicName = $authorinfo->getAuthorName();
298 } elseif ($authorinfo->getAuthorName() && !$this->isAnonymized()) {
299 $publicName = $authorinfo->getAuthorName();
300 }
301
302 return $publicName;
303 }
304
305 private function getAuthorInformation(
307 int $authorUsrId,
308 int $displayUserId,
309 string $usrAlias,
310 string $importName
312 $cacheKey = $this->notificationCache->createKeyByValues([
313 $this->notification_type,
314 $lng->getLangKey(),
315 $authorUsrId,
316 $displayUserId,
317 $usrAlias,
318 $importName
319 ]);
320
321 if (!$this->notificationCache->exists($cacheKey)) {
322 $authorInformation = new ilForumAuthorInformation(
323 $authorUsrId,
324 $displayUserId,
325 $usrAlias,
326 $importName,
327 [],
328 $lng
329 );
330
331 $this->notificationCache->store($cacheKey, $authorInformation);
332 }
333
334 return $this->notificationCache->fetch($cacheKey);
335 }
336}
getAuthorName(bool $without_short_name=false)
__construct(array $row, private readonly int $notification_type, ?ilForumNotificationCache $notificationCache=null)
getPublicUserInformation(ilForumAuthorInformation $authorinfo)
getAuthorInformation(ilLanguage $lng, int $authorUsrId, int $displayUserId, string $usrAlias, string $importName)
Class ilForumNotificationCache.
language handling
Class ilObject Basic functions for all objects.
Interface ilForumNotificationMailData.
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26