ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilObjForumNotificationDataProvider.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once './Modules/Forum/interfaces/interface.ilForumNotificationMailData.php';
5include_once './Modules/Forum/classes/class.ilForumProperties.php';
6
12{
16 protected $ref_id = 0;
17
21 protected $obj_id = 0;
22
26 protected $post_user_name = null;
27
31 protected $update_user_name = null;
32
36 public $pos_author_id = 0;
40 protected $forum_id = 0;
41
45 protected $forum_title = '';
46
50 protected $thread_title = '';
51
55 protected $attachments = array();
56
60 public $objPost;
61
62 private $db;
63 private $access;
64 private $user;
65
69 protected $is_anonymized = false;
70
76 {
77 global $DIC;
78 $this->db = $DIC->database();
79 $this->access = $DIC->access();
80 $this->user = $DIC->user();
81
82 $this->objPost = $objPost;
83 $this->ref_id = $ref_id;
84 $this->obj_id = ilObject::_lookupObjId($ref_id);
85 $this->read();
86 }
87
91 public function getRefId()
92 {
93 return $this->ref_id;
94 }
95
99 public function getObjId()
100 {
101 return $this->obj_id;
102 }
103
107 public function getThreadId()
108 {
109 return $this->objPost->getThreadId();
110 }
111
115 public function getPostId()
116 {
117 return $this->objPost->getId();
118 }
119
123 public function getForumId()
124 {
125 return $this->forum_id;
126 }
127
131 public function getForumTitle()
132 {
133 return $this->forum_title;
134 }
135
139 public function getThreadTitle()
140 {
141 return $this->thread_title;
142 }
143
147 public function getPostTitle()
148 {
149 return $this->objPost->getSubject();
150 }
151
155 public function getPostMessage()
156 {
157 return $this->objPost->getMessage();
158 }
159
163 public function getPosDisplayUserId()
164 {
165 return $this->objPost->getDisplayUserId();
166 }
167
171 public function getPostDate()
172 {
173 return $this->objPost->getCreateDate();
174 }
175
179 public function getPostUpdate()
180 {
181 return $this->objPost->getChangeDate();
182 }
186 public function getPostCensored()
187 {
188 return $this->objPost->isCensored();
189 }
190
194 public function getPostCensoredDate()
195 {
196 return $this->objPost->getCensoredDate();
197 }
198
199 public function getCensorshipComment()
200 {
201 return $this->objPost->getCensorshipComment();
202 }
203
207 public function getAttachments()
208 {
209 return $this->attachments;
210 }
211
215 public function getPosUserAlias()
216 {
217 return $this->objPost->getUserAlias();
218 }
219
223 public function isAnonymized()
224 {
226 }
230 public function getImportName()
231 {
232 return $this->objPost->getImportName();
233 }
234
238 public function getPostUpdateUserId()
239 {
240 return $this->objPost->getUpdateUserId();
241 }
242
246 public function getPostUserName(\ilLanguage $user_lang)
247 {
248 if ($this->post_user_name === null) {
249 $authorinfo = new ilForumAuthorInformation(
250 $this->getPosAuthorId(),
251 $this->getPosDisplayUserId(),
252 $this->getPosUserAlias(),
253 $this->getImportName(),
254 array(),
255 $user_lang
256 );
257 $this->post_user_name = $this->getPublicUserInformation($authorinfo);
258 }
259
260 return (string) $this->post_user_name;
261 }
262
266 public function getPostUpdateUserName(\ilLanguage $user_lang)
267 {
268 if ($this->update_user_name === null) {
269 $authorinfo = new ilForumAuthorInformation(
270 $this->getPosAuthorId(),
271 $this->getPostUpdateUserId(),
272 $this->getPosUserAlias(),
273 $this->getImportName(),
274 array(),
275 $user_lang
276 );
277 $this->update_user_name = $this->getPublicUserInformation($authorinfo);
278 }
279
280 // Possible Fix for #25432
281 if ($this->objPost->getUserAlias() && $this->objPost->getDisplayUserId() == 0
282 && $this->objPost->getPosAuthorId() == $this->objPost->getUpdateUserId()) {
283 return (string) $this->objPost->getUserAlias();
284 }
285
286 return (string) $this->update_user_name;
287 }
288
294 {
295 if ($authorinfo->hasSuffix()) {
296 $public_name = $authorinfo->getAuthorName();
297 } else {
298 $public_name = $authorinfo->getAuthorShortName();
299
300 if ($authorinfo->getAuthorName() && !$this->isAnonymized()) {
301 $public_name = $authorinfo->getAuthorName();
302 }
303 }
304
305 return $public_name;
306 }
307
311 protected function read()
312 {
313 $this->readForumData();
314 $this->readThreadTitle();
315 $this->readAttachments();
316 }
317
321 private function readThreadTitle()
322 {
323 $result = $this->db->queryf(
324 '
325 SELECT thr_subject FROM frm_threads
326 WHERE thr_pk = %s',
327 array('integer'),
328 array($this->objPost->getThreadId())
329 );
330
331 $row = $this->db->fetchAssoc($result);
332 $this->thread_title = $row['thr_subject'];
333 }
334
338 private function readForumData()
339 {
340 $result = $this->db->queryf(
341 '
342 SELECT top_pk, top_name, frm_settings.anonymized FROM frm_data
343 INNER JOIN frm_settings ON top_frm_fk = frm_settings.obj_id
344 WHERE top_frm_fk = %s',
345 array('integer'),
346 array($this->getObjId())
347 );
348
349 $row = $this->db->fetchAssoc($result);
350 $this->forum_id = $row['top_pk'];
351 $this->forum_title = $row['top_name'];
352 $this->is_anonymized = (bool) $row['anonymized'];
353 }
354
358 private function readAttachments()
359 {
361 require_once 'Modules/Forum/classes/class.ilFileDataForum.php';
362 $fileDataForum = new ilFileDataForum($this->getObjId(), $this->objPost->getId());
363 $filesOfPost = $fileDataForum->getFilesOfPost();
364
365 require_once 'Services/Mail/classes/class.ilFileDataMail.php';
366 $fileDataMail = new ilFileDataMail(ANONYMOUS_USER_ID);
367
368 foreach ($filesOfPost as $attachment) {
369 $this->attachments[$attachment['path']] = $attachment['name'];
370 $fileDataMail->copyAttachmentFile($attachment['path'], $attachment['name']);
371 }
372 }
373 }
374
379 {
380 $res = $this->db->queryf(
381 '
382 SELECT frm_notification.user_id FROM frm_notification, frm_data
383 WHERE frm_data.top_pk = %s
384 AND frm_notification.frm_id = frm_data.top_frm_fk
385 AND frm_notification.user_id != %s
386 GROUP BY frm_notification.user_id',
387 array('integer', 'integer'),
388 array($this->getForumId(), $this->user->getId())
389 );
390
391 // get all references of obj_id
392 $frm_references = ilObject::_getAllReferences($this->getObjId());
393 $rcps = array();
394 while ($row = $this->db->fetchAssoc($res)) {
395 // do rbac check before sending notification
396 foreach ((array) $frm_references as $ref_id) {
397 if ($this->access->checkAccessOfUser($row['user_id'], 'read', '', $ref_id)) {
398 $rcps[] = $row['user_id'];
399 }
400 }
401 }
402
403
404 return array_unique($rcps);
405 }
406
411 {
412 if (!$this->getThreadId()) {
413 return [];
414 }
415
416 $res = $this->db->queryf(
417 '
418 SELECT frm_notification.user_id
419 FROM frm_notification
420 INNER JOIN frm_threads ON frm_threads.thr_pk = frm_notification.thread_id
421 WHERE frm_notification.thread_id = %s
422 AND frm_notification.user_id != %s',
423 array('integer', 'integer'),
424 array($this->getThreadId(), $this->user->getId())
425 );
426
427
428 $frm_references = \ilObject::_getAllReferences($this->getObjId());
429 $usrIds = [];
430 while ($row = $this->db->fetchAssoc($res)) {
431 foreach ((array) $frm_references as $ref_id) {
432 if ($this->access->checkAccessOfUser($row['user_id'], 'read', '', $ref_id)) {
433 $usrIds[] = $row['user_id'];
434 }
435 }
436 }
437
438 return array_unique($usrIds);
439 }
440
445 {
446 include_once './Modules/Forum/classes/class.ilForumPost.php';
447 $parent_objPost = new ilForumPost($this->objPost->getParentId());
448
449 $rcps = array();
450 $rcps[] = $parent_objPost->getPosAuthorId();
451
452 return $rcps;
453 }
454
459 {
460 include_once './Modules/Forum/classes/class.ilForum.php';
461 // get moderators to notify about needed activation
462 $rcps = ilForum::_getModerators($this->getRefId());
463 return (array) $rcps;
464 }
465
470 {
471 $this->pos_author_id = $pos_author_id;
472 }
473
477 public function getPosAuthorId()
478 {
480 }
481
485 public function getDeletedBy()
486 {
487 global $DIC;
488
489 if ($this->shouldUsePseudonym()) {
490 return (string) $this->objPost->getUserAlias();
491 }
492 return $DIC->user()->getLogin();
493 }
494
498 private function shouldUsePseudonym()
499 {
500 global $DIC;
501
502 if ($this->objPost->getUserAlias() && $this->objPost->getDisplayUserId() == 0
503 && $this->objPost->getPosAuthorId() == $DIC->user()->getId()) {
504 return true;
505 }
506 return false;
507 }
508}
$result
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
This class handles all operations on files for the forum object.
This class handles all operations on files (attachments) in directory ilias_data/mail.
getAuthorName($without_short_name=false)
static _getModerators($a_ref_id)
get all users assigned to local role il_frm_moderator_<frm_ref_id> (static)
language handling
getPublicUserInformation(ilForumAuthorInformation $authorinfo)
static _lookupObjId($a_id)
static _getAllReferences($a_id)
get all reference ids of object
Interface ilForumNotificationMailData.
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res