ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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 
11 {
15  protected $ref_id = 0;
16 
20  protected $obj_id = 0;
21 
25  protected $post_user_name = '';
29  public $pos_author_id = 0;
33  protected $forum_id = 0;
34 
38  protected $forum_title = '';
39 
43  protected $thread_title = '';
44 
48  protected $attachments = array();
49 
53  public $objPost;
54 
60  {
61  $this->objPost = $objPost;
62  $this->ref_id = $ref_id;
63  $this->obj_id = ilObject::_lookupObjId($ref_id);
64  $this->read();
65  }
66 
70  public function getRefId()
71  {
72  return $this->ref_id;
73  }
74 
78  public function getObjId()
79  {
80  return $this->obj_id;
81  }
82 
86  public function getThreadId()
87  {
88  return $this->objPost->getThreadId();
89  }
90 
94  public function getPostId()
95  {
96  return $this->objPost->getId();
97  }
98 
102  public function getForumId()
103  {
104  return $this->forum_id;
105  }
106 
110  public function getForumTitle()
111  {
112  return $this->forum_title;
113  }
114 
118  public function getThreadTitle()
119  {
120  return $this->thread_title;
121  }
122 
126  public function getPostTitle()
127  {
128  return $this->objPost->getSubject();
129  }
130 
134  public function getPostMessage()
135  {
136  return $this->objPost->getMessage();
137  }
138 
142  public function getPosDisplayUserId()
143  {
144  return $this->objPost->getDisplayUserId();
145  }
146 
150  public function getPostUserName($user_lang)
151  {
152  // GET AUTHOR OF NEW POST
153  if($this->objPost->getDisplayUserId())
154  {
155  $this->post_user_name = ilObjUser::_lookupLogin($this->objPost->getDisplayUserId());
156  }
157  else if(strlen($this->objPost->getUserAlias()))
158  {
159  $this->post_user_name = $this->objPost->getUserAlias() . ' (' . $user_lang->txt('frm_pseudonym') . ')';
160  }
161 
162  if($this->post_user_name == '')
163  {
164  $this->post_user_name = $user_lang->txt('forums_anonymous');
165  }
166 
167  return $this->post_user_name;
168  }
169 
173  public function getPostDate()
174  {
175  return $this->objPost->getCreateDate();
176  }
177 
181  public function getPostUpdate()
182  {
183  return $this->objPost->getChangeDate();
184  }
185 
189  public function getPostUpdateUserName($user_lang)
190  {
191  // GET AUTHOR OF UPDATED POST
192  if($this->objPost->getUpdateUserId() > 0)
193  {
194  $this->post_user_name = ilObjUser::_lookupLogin($this->objPost->getUpdateUserId());
195  }
196 
197  if($this->objPost->getDisplayUserId() == 0 && $this->objPost->getPosAuthorId() == $this->objPost->getUpdateUserId())
198  {
199  if(strlen($this->objPost->getUserAlias()))
200  {
201  $this->post_user_name = $this->objPost->getUserAlias() . ' (' . $user_lang->txt('frm_pseudonym') . ')';
202  }
203 
204  if($this->post_user_name == '')
205  {
206  $this->post_user_name = $user_lang->txt('forums_anonymous');
207  }
208  }
209 
210  return $this->post_user_name;
211  }
212 
216  public function getPostCensored()
217  {
218  return $this->objPost->isCensored();
219  }
220 
224  public function getPostCensoredDate()
225  {
226  return $this->objPost->getCensoredDate();
227  }
228 
229  public function getCensorshipComment()
230  {
231  return $this->objPost->getCensorshipComment();
232  }
233 
237  public function getAttachments()
238  {
239  return $this->attachments;
240  }
241 
245  public function getPosUserAlias()
246  {
247  return $this->objPost->getUserAlias();
248  }
249 
253  protected function read()
254  {
255  $this->readForumData();
256  $this->readThreadTitle();
257  $this->readAttachments();
258  }
259 
263  private function readThreadTitle()
264  {
265  global $ilDB;
266 
267  $result = $ilDB->queryf('
268  SELECT thr_subject FROM frm_threads
269  WHERE thr_pk = %s',
270  array('integer'), array($this->objPost->getThreadId()));
271 
272  $row = $ilDB->fetchAssoc($result);
273  $this->thread_title = $row['thr_subject'];
274  }
275 
279  private function readForumData()
280  {
281  global $ilDB;
282 
283  $result = $ilDB->queryf('
284  SELECT top_pk, top_name FROM frm_data
285  WHERE top_frm_fk = %s',
286  array('integer'), array($this->getObjId()));
287 
288  $row = $ilDB->fetchAssoc($result);
289  $this->forum_id = $row['top_pk'];
290  $this->forum_title = $row['top_name'];
291  }
292 
296  private function readAttachments()
297  {
298  require_once 'Modules/Forum/classes/class.ilFileDataForum.php';
299  $fileDataForum = new ilFileDataForum($this->getObjId(), $this->objPost->getId());
300  $filesOfPost = $fileDataForum->getFilesOfPost();
301 
302  foreach($filesOfPost as $attachment)
303  {
304  $this->attachments[] = $attachment['name'];
305  }
306  }
307 
312  {
313  global $ilDB, $ilAccess, $ilUser;
314 
315  $res = $ilDB->queryf('
316  SELECT frm_notification.user_id FROM frm_notification, frm_data
317  WHERE frm_data.top_pk = %s
318  AND frm_notification.frm_id = frm_data.top_frm_fk
319  AND frm_notification.user_id <> %s
320  GROUP BY frm_notification.user_id',
321  array('integer', 'integer'),
322  array($this->getForumId(), $ilUser->getId()));
323 
324  // get all references of obj_id
325  $frm_references = ilObject::_getAllReferences($this->getObjId());
326  $rcps = array();
327  while($row = $ilDB->fetchAssoc($res))
328  {
329  // do rbac check before sending notification
330  foreach((array)$frm_references as $ref_id)
331  {
332  if($ilAccess->checkAccessOfUser($row['user_id'], 'read', '', $ref_id))
333  {
334  $rcps[] = $row['user_id'];
335  }
336  }
337  }
338 
339 
340  return array_unique($rcps);
341  }
342 
347  {
348  global $ilDB, $ilAccess, $ilUser;
349 
350  // GET USERS WHO WANT TO BE INFORMED ABOUT NEW POSTS
351  $res = $ilDB->queryf('
352  SELECT user_id FROM frm_notification
353  WHERE thread_id = %s
354  AND user_id <> %s',
355  array('integer', 'integer'),
356  array($this->getThreadId(), $_SESSION['AccountId']));
357 
358  // get all references of obj_id
359  $frm_references = ilObject::_getAllReferences($this->getObjId());
360  $rcps = array();
361  while($row = $ilDB->fetchAssoc($res))
362  {
363  // do rbac check before sending notification
364  foreach((array)$frm_references as $ref_id)
365  {
366  if($ilAccess->checkAccessOfUser($row['user_id'], 'read', '', $ref_id))
367  {
368  $rcps[] = $row['user_id'];
369  }
370  }
371  }
372  return $rcps;
373  }
374 
378  public function getPostAnsweredRecipients()
379  {
380  include_once './Modules/Forum/classes/class.ilForumPost.php';
381  $parent_objPost = new ilForumPost($this->objPost->getParentId());
382 
383  $rcps = array();
384  $rcps[] = $parent_objPost->getPosAuthorId();
385 
386  return $rcps;
387  }
388 
392  public function getPostActivationRecipients()
393  {
394  include_once './Modules/Forum/classes/class.ilForum.php';
395  // get moderators to notify about needed activation
396  $rcps = ilForum::_getModerators($this->getRefId());
397  return (array)$rcps;
398  }
403  {
404  $this->pos_author_id = $pos_author_id;
405  }
406 
410  public function getPosAuthorId()
411  {
412  return $this->pos_author_id;
413  }
414 }
static _lookupLogin($a_user_id)
lookup login
$_SESSION["AccountId"]
Class ilObjForumNotificationDataProvider.
$result
static _getAllReferences($a_id)
get all reference ids of object
static _lookupObjId($a_id)
Interface ilForumNotificationMailData.
global $ilUser
Definition: imgupload.php:15
This class handles all operations on files for the forum object.
global $ilDB
_getModerators($a_ref_id)
get all users assigned to local role il_frm_moderator_<frm_ref_id> (static)