ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
4 include_once './Modules/Forum/interfaces/interface.ilForumNotificationMailData.php';
5 include_once './Modules/Forum/classes/class.ilForumProperties.php';
6 require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
7 
13 {
17  protected $ref_id = 0;
18 
22  protected $obj_id = 0;
23 
27  protected $post_user_name = null;
28 
32  protected $update_user_name = null;
33 
37  public $pos_author_id = 0;
41  protected $forum_id = 0;
42 
46  protected $forum_title = '';
47 
51  protected $thread_title = '';
52 
56  protected $attachments = array();
57 
61  public $objPost;
65  protected $is_anonymized = false;
66 
72  {
73  $this->objPost = $objPost;
74  $this->ref_id = $ref_id;
75  $this->obj_id = ilObject::_lookupObjId($ref_id);
76  $this->read();
77  }
78 
82  public function getRefId()
83  {
84  return $this->ref_id;
85  }
86 
90  public function getObjId()
91  {
92  return $this->obj_id;
93  }
94 
98  public function getThreadId()
99  {
100  return $this->objPost->getThreadId();
101  }
102 
106  public function getPostId()
107  {
108  return $this->objPost->getId();
109  }
110 
114  public function getForumId()
115  {
116  return $this->forum_id;
117  }
118 
122  public function getForumTitle()
123  {
124  return $this->forum_title;
125  }
126 
130  public function getThreadTitle()
131  {
132  return $this->thread_title;
133  }
134 
138  public function getPostTitle()
139  {
140  return $this->objPost->getSubject();
141  }
142 
146  public function getPostMessage()
147  {
148  return $this->objPost->getMessage();
149  }
150 
154  public function getPosDisplayUserId()
155  {
156  return $this->objPost->getDisplayUserId();
157  }
158 
162  public function getPostDate()
163  {
164  return $this->objPost->getCreateDate();
165  }
166 
170  public function getPostUpdate()
171  {
172  return $this->objPost->getChangeDate();
173  }
177  public function getPostCensored()
178  {
179  return $this->objPost->isCensored();
180  }
181 
185  public function getPostCensoredDate()
186  {
187  return $this->objPost->getCensoredDate();
188  }
189 
190  public function getCensorshipComment()
191  {
192  return $this->objPost->getCensorshipComment();
193  }
194 
198  public function getAttachments()
199  {
200  return $this->attachments;
201  }
202 
206  public function getPosUserAlias()
207  {
208  return $this->objPost->getUserAlias();
209  }
210 
214  public function isAnonymized()
215  {
216  return $this->is_anonymized;
217  }
221  public function getImportName()
222  {
223  return $this->objPost->getImportName();
224  }
225 
229  public function getPostUpdateUserId()
230  {
231  return $this->objPost->getUpdateUserId();
232  }
233 
237  public function getPostUserName(\ilLanguage $user_lang)
238  {
239  if ($this->post_user_name === null) {
240  $authorinfo = new ilForumAuthorInformation(
241  $this->getPosAuthorId(),
242  $this->getPosDisplayUserId(),
243  $this->getPosUserAlias(),
244  $this->getImportName(),
245  array(),
246  $user_lang
247  );
248  $this->post_user_name = $this->getPublicUserInformation($authorinfo);
249  }
250 
251  return (string)$this->post_user_name;
252  }
253 
257  public function getPostUpdateUserName(\ilLanguage $user_lang)
258  {
259  if ($this->update_user_name === null) {
260  $authorinfo = new ilForumAuthorInformation(
261  $this->getPosAuthorId(),
262  $this->getPostUpdateUserId(),
263  $this->getPosUserAlias(),
264  $this->getImportName(),
265  array(),
266  $user_lang
267  );
268  $this->update_user_name = $this->getPublicUserInformation($authorinfo);
269  }
270 
271  return (string)$this->update_user_name;
272  }
273 
279  {
280  if($authorinfo->hasSuffix())
281  {
282  $public_name = $authorinfo->getAuthorName();
283  }
284  else
285  {
286  $public_name = $authorinfo->getAuthorShortName();
287 
288  if($authorinfo->getAuthorName() && !$this->isAnonymized())
289  {
290  $public_name = $authorinfo->getAuthorName();
291  }
292  }
293 
294  return $public_name;
295  }
296 
300  protected function read()
301  {
302  $this->readForumData();
303  $this->readThreadTitle();
304  $this->readAttachments();
305  }
306 
310  private function readThreadTitle()
311  {
312  global $ilDB;
313 
314  $result = $ilDB->queryf('
315  SELECT thr_subject FROM frm_threads
316  WHERE thr_pk = %s',
317  array('integer'), array($this->objPost->getThreadId()));
318 
319  $row = $ilDB->fetchAssoc($result);
320  $this->thread_title = $row['thr_subject'];
321  }
322 
326  private function readForumData()
327  {
328  global $ilDB;
329 
330  $result = $ilDB->queryf('
331  SELECT top_pk, top_name, frm_settings.anonymized FROM frm_data
332  INNER JOIN frm_settings ON top_frm_fk = frm_settings.obj_id
333  WHERE top_frm_fk = %s',
334  array('integer'), array($this->getObjId()));
335 
336  $row = $ilDB->fetchAssoc($result);
337  $this->forum_id = $row['top_pk'];
338  $this->forum_title = $row['top_name'];
339  $this->is_anonymized = (bool)$row['anonymized'];
340  }
341 
345  private function readAttachments()
346  {
347  if(ilForumProperties::isSendAttachmentsByMailEnabled())
348  {
349  require_once 'Modules/Forum/classes/class.ilFileDataForum.php';
350  $fileDataForum = new ilFileDataForum($this->getObjId(), $this->objPost->getId());
351  $filesOfPost = $fileDataForum->getFilesOfPost();
352 
353  require_once 'Services/Mail/classes/class.ilFileDataMail.php';
354  $fileDataMail = new ilFileDataMail(ANONYMOUS_USER_ID);
355 
356  foreach($filesOfPost as $attachment)
357  {
358  $this->attachments[$attachment['path']] = $attachment['name'];
359  $fileDataMail->copyAttachmentFile($attachment['path'], $attachment['name']);
360  }
361  }
362  }
363 
368  {
369  global $ilDB, $ilAccess, $ilUser;
370 
371  $res = $ilDB->queryf('
372  SELECT frm_notification.user_id FROM frm_notification, frm_data
373  WHERE frm_data.top_pk = %s
374  AND frm_notification.frm_id = frm_data.top_frm_fk
375  AND frm_notification.user_id <> %s
376  GROUP BY frm_notification.user_id',
377  array('integer', 'integer'),
378  array($this->getForumId(), $ilUser->getId()));
379 
380  // get all references of obj_id
381  $frm_references = ilObject::_getAllReferences($this->getObjId());
382  $rcps = array();
383  while($row = $ilDB->fetchAssoc($res))
384  {
385  // do rbac check before sending notification
386  foreach((array)$frm_references as $ref_id)
387  {
388  if($ilAccess->checkAccessOfUser($row['user_id'], 'read', '', $ref_id))
389  {
390  $rcps[] = $row['user_id'];
391  }
392  }
393  }
394 
395  return array_unique($rcps);
396  }
397 
402  {
403  global $ilDB, $ilAccess, $ilUser;
404 
405  // GET USERS WHO WANT TO BE INFORMED ABOUT NEW POSTS
406  $res = $ilDB->queryf('
407  SELECT user_id FROM frm_notification
408  WHERE thread_id = %s
409  AND user_id <> %s',
410  array('integer', 'integer'),
411  array($this->getThreadId(), $GLOBALS['DIC']['ilUser']->getId()));
412 
413  // get all references of obj_id
414  $frm_references = ilObject::_getAllReferences($this->getObjId());
415  $rcps = array();
416  while($row = $ilDB->fetchAssoc($res))
417  {
418  // do rbac check before sending notification
419  foreach((array)$frm_references as $ref_id)
420  {
421  if($ilAccess->checkAccessOfUser($row['user_id'], 'read', '', $ref_id))
422  {
423  $rcps[] = $row['user_id'];
424  }
425  }
426  }
427  return $rcps;
428  }
429 
433  public function getPostAnsweredRecipients()
434  {
435  include_once './Modules/Forum/classes/class.ilForumPost.php';
436  $parent_objPost = new ilForumPost($this->objPost->getParentId());
437 
438  $rcps = array();
439  $rcps[] = $parent_objPost->getPosAuthorId();
440 
441  return $rcps;
442  }
443 
447  public function getPostActivationRecipients()
448  {
449  include_once './Modules/Forum/classes/class.ilForum.php';
450  // get moderators to notify about needed activation
451  $rcps = ilForum::_getModerators($this->getRefId());
452  return (array)$rcps;
453  }
454 
459  {
460  $this->pos_author_id = $pos_author_id;
461  }
462 
466  public function getPosAuthorId()
467  {
468  return $this->pos_author_id;
469  }
470 }
Class ilObjForumNotificationDataProvider.
$result
This class handles all operations on files (attachments) in directory ilias_data/mail.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
getAuthorName($without_short_name=false)
static _getAllReferences($a_id)
get all reference ids of object
static _lookupObjId($a_id)
getPublicUserInformation(ilForumAuthorInformation $authorinfo)
$ilUser
Definition: imgupload.php:18
Create styles array
The data for the language used.
Interface ilForumNotificationMailData.
This class handles all operations on files for the forum object.
global $ilDB
language handling
static _getModerators($a_ref_id)
get all users assigned to local role il_frm_moderator_<frm_ref_id> (static)