ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilForumCronNotificationDataProvider.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 {
27  private ?int $notification_type = null;
28  private int $ref_id;
29  private int $obj_id;
30  private int $forum_id;
31  private string $forum_title;
33  private ?ilObject $closest_container = null;
34  private int $thread_id;
35  private string $thread_title;
36  private int $post_id;
37  private string $post_title;
38  private string $post_message;
39  private ?string $post_date = null;
40  private ?string $post_update = null;
41  private bool $post_censored;
42  private ?string $post_censored_date = null;
43  private ?string $post_censored_comment;
44  private string $pos_usr_alias;
45  private int $pos_display_user_id;
46  private bool $is_anonymized = false;
47  private string $import_name;
48  private array $attachments = [];
50  private array $cron_recipients = [];
51  private int $post_update_user_id;
52  private 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(array $row, int $notification_type, ilForumNotificationCache $notificationCache = null)
59  {
60  $this->notification_type = $notification_type;
61  $this->obj_id = (int) $row['obj_id'];
62  $this->ref_id = (int) $row['ref_id'];
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) {
85  $notificationCache = new ilForumNotificationCache();
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  {
128  return $this->cron_recipients;
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  {
198  return $this->post_censored;
199  }
200 
201  public function getPostCensoredDate(): string
202  {
203  return $this->post_censored_date ?? '';
204  }
205 
206  public function getCensorshipComment(): string
207  {
209  }
210 
211  public function getAttachments(): array
212  {
213  return $this->attachments;
214  }
215 
216  public function setNotificationType(int $notification_type): void
217  {
218  $this->notification_type = $notification_type;
219  }
220 
221  public function getPosDisplayUserId(): int
222  {
224  }
225 
226  public function getPosUserAlias(): string
227  {
228  return $this->pos_usr_alias;
229  }
230 
231  public function getPostUpdateUserId(): int
232  {
234  }
235 
236  public function setPostUpdateUserId(int $post_update_user_id): void
237  {
238  $this->post_update_user_id = $post_update_user_id;
239  }
240 
241  public function setPosAuthorId(int $pos_author_id): void
242  {
243  $this->pos_author_id = $pos_author_id;
244  }
245 
246  public function getPosAuthorId(): int
247  {
248  return $this->pos_author_id;
249  }
250 
251  public function isAnonymized(): bool
252  {
253  return $this->is_anonymized;
254  }
255 
256  public function getDeletedBy(): string
257  {
258  return $this->deleted_by;
259  }
260 
261  public function getImportName(): string
262  {
263  return $this->import_name;
264  }
265 
266  public function getPostUserName(ilLanguage $user_lang): string
267  {
268  if ($this->post_user_name === null) {
269  $this->post_user_name = $this->getPublicUserInformation($this->getAuthorInformation(
270  $user_lang,
271  $this->getPosAuthorId(),
272  $this->getPosDisplayUserId(),
273  $this->getPosUserAlias(),
274  $this->getImportName()
275  ));
276  }
277 
278  return (string) $this->post_user_name;
279  }
280 
281  public function getPostUpdateUserName(ilLanguage $user_lang): string
282  {
283  if ($this->update_user_name === null) {
284  $this->update_user_name = $this->getPublicUserInformation($this->getAuthorInformation(
285  $user_lang,
286  $this->getPosAuthorId(),
287  $this->getPostUpdateUserId(),
288  $this->getPosUserAlias(),
289  $this->getImportName()
290  ));
291  }
292 
293  // Fix for #25432
294  if (
295  $this->getPosUserAlias() && $this->getPosDisplayUserId() === 0 &&
296  $this->getPosAuthorId() === $this->getPostUpdateUserId()
297  ) {
298  return $this->getPosUserAlias();
299  }
300 
301  return (string) $this->update_user_name;
302  }
303 
304  public function getPublicUserInformation(ilForumAuthorInformation $authorinfo): string
305  {
306  $publicName = $authorinfo->getAuthorShortName();
307 
308  if ($authorinfo->hasSuffix()) {
309  $publicName = $authorinfo->getAuthorName();
310  } elseif ($authorinfo->getAuthorName() && !$this->isAnonymized()) {
311  $publicName = $authorinfo->getAuthorName();
312  }
313 
314  return $publicName;
315  }
316 
317  private function getAuthorInformation(
319  int $authorUsrId,
320  int $displayUserId,
321  string $usrAlias,
322  string $importName
324  $cacheKey = $this->notificationCache->createKeyByValues([
325  $this->notification_type,
326  $lng->getLangKey(),
327  $authorUsrId,
328  $displayUserId,
329  $usrAlias,
330  $importName
331  ]);
332 
333  if (false === $this->notificationCache->exists($cacheKey)) {
334  $authorInformation = new ilForumAuthorInformation(
335  $authorUsrId,
336  $displayUserId,
337  $usrAlias,
338  $importName,
339  [],
340  $lng
341  );
342 
343  $this->notificationCache->store($cacheKey, $authorInformation);
344  }
345 
346  return $this->notificationCache->fetch($cacheKey);
347  }
348 }
getPublicUserInformation(ilForumAuthorInformation $authorinfo)
$lng
__construct(array $row, int $notification_type, ilForumNotificationCache $notificationCache=null)
getLangKey()
Return lang key.
global $DIC
Definition: feed.php:28
getAuthorInformation(ilLanguage $lng, int $authorUsrId, int $displayUserId, string $usrAlias, string $importName)
Class ilForumNotificationCache.
Interface ilForumNotificationMailData.
This class handles all operations on files for the forum object.
getAuthorName(bool $without_short_name=false)