ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilForumPost.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once './Modules/Forum/classes/class.ilForumTopic.php';
5 
13 {
14  private $id = 0;
15 
16  private $forum_id = 0;
17 
18  private $thread_id = 0;
19 
20  private $display_user_id = 0;
21 
22  private $user_alias = '';
23 
24  private $subject = '';
25 
26  private $message = '';
27 
28  private $createdate = '0000-00-00 00:00:00';
29 
30  private $changedate = '0000-00-00 00:00:00';
31 
32  private $user_id_update = 0;
33 
34  private $censored = 0;
35 
36  private $censorship_comment = '';
37 
38  private $censored_date = '0000-00-00 00:00:00';
39 
40  private $notification = 0;
41 
42  private $import_name = '';
43 
44  private $status = 1;
45 
46  private $tree_id = 0;
47 
48  private $parent_id = 0;
49 
50  private $lft = 0;
51 
52  private $rgt = 0;
53 
54  private $depth = 0;
55 
56  private $fullname = '';
57 
58  private $loginname = '';
59 
63  private $objThread = null;
64 
65  private $db = null;
66 
71  private $is_moderator = false;
72 
77  private $is_author_moderator = null;
78 
79  private $post_read = false;
80 
81  private $pos_author_id = 0;
82 
83  private $post_activation_date = null;
84 
91  public function __construct($a_id = 0, $a_is_moderator = false, $preventImplicitRead = false)
92  {
93  global $ilDB;
94 
95  $this->db = $ilDB;
96  $this->id = $a_id;
97 
98  if( !$preventImplicitRead )
99  {
100  $this->read();
101  }
102  }
103 
104  public function __destruct()
105  {
106  unset($this->db);
107  unset($this->objThread);
108  }
109 
110  public function insert()
111  {
112  global $ilDB;
113 
114  if ($this->forum_id && $this->thread_id)
115  {
116  $this->id = $this->db->nextId('frm_posts');
117 
118  $ilDB->insert('frm_posts', array(
119  'pos_pk' => array('integer', $this->id),
120  'pos_top_fk' => array('integer', $this->forum_id),
121  'pos_thr_fk' => array('integer', $this->thread_id),
122  'pos_display_user_id' => array('integer', $this->display_user_id),
123  'pos_usr_alias' => array('text', $this->user_alias),
124  'pos_subject' => array('text', $this->subject),
125  'pos_message' => array('clob', $this->message),
126  'pos_date' => array('timestamp', $this->createdate),
127  'pos_update' => array('timestamp', $this->createdate),
128  'update_user' => array('integer', $this->user_id_update),
129  'pos_cens' => array('integer', $this->censored),
130  'notify' => array('integer', (int)$this->notification),
131  'import_name' => array('text', (string)$this->import_name),
132  'pos_status' => array('integer', (int)$this->status),
133  'pos_author_id' => array('integer', (int)$this->pos_author_id),
134  'is_author_moderator' => array('integer', $this->is_author_moderator),
135  'pos_activation_date' => array('timestamp', $this->createdate)
136  ));
137 
138  return true;
139  }
140 
141  return false;
142  }
143 
144  public function update()
145  {
146  global $ilDB;
147 
148  if($this->id)
149  {
150  $ilDB->update('frm_posts',
151  array(
152  'pos_top_fk' => array('integer', $this->forum_id),
153  'pos_thr_fk' => array('integer', $this->thread_id),
154  'pos_subject' => array('text', $this->subject),
155  'pos_message' => array('clob', $this->message),
156  'pos_update' => array('timestamp', $this->changedate),
157  'update_user' => array('integer', $this->user_id_update),
158  'pos_cens' => array('integer', $this->censored),
159  'pos_cens_date' => array('timestamp', $this->censored_date),
160  'pos_cens_com' => array('text', $this->censorship_comment),
161  'notify' => array('integer', (int)$this->notification),
162  'pos_status' => array('integer', (int)$this->status)
163  ),
164  array(
165  'pos_pk' => array('integer', (int)$this->id)
166  )
167  );
168 
169  if($this->objThread->getFirstPostId() == $this->id)
170  {
171  $this->objThread->setSubject($this->subject);
172  $this->objThread->update();
173  $this->objThread->reload();
174  }
175 
176  return true;
177  }
178 
179  return false;
180  }
181 
182  private function read()
183  {
184  if ($this->id)
185  {
186  $res = $this->db->queryF('
187  SELECT * FROM frm_posts
188  INNER JOIN frm_posts_tree ON pos_fk = pos_pk
189  WHERE pos_pk = %s',
190  array('integer'), array($this->id));
191  $row = $this->db->fetchObject($res);
192 
193  if (is_object($row))
194  {
195  $this->id = $row->pos_pk;
196  $this->forum_id = $row->pos_top_fk;
197  $this->thread_id = $row->pos_thr_fk;
198  $this->display_user_id = $row->pos_display_user_id;
199  $this->user_alias = $row->pos_usr_alias;
200  $this->subject = $row->pos_subject;
201  $this->message = $row->pos_message;
202  $this->createdate = $row->pos_date;
203  $this->changedate = $row->pos_update;
204  $this->user_id_update = $row->update_user;
205  $this->censored = $row->pos_cens;
206  $this->censored_date = $row->pos_cens_date;
207  $this->censorship_comment = $row->pos_cens_com;
208  $this->notification = $row->notify;
209  $this->import_name = $row->import_name;
210  $this->status = $row->pos_status;
211  $this->tree_id = $row->fpt_pk;
212  $this->parent_id = $row->parent_pos;
213  $this->lft = $row->lft;
214  $this->rgt = $row->rgt;
215  $this->depth = $row->depth;
216  $this->pos_author_id = $row->pos_author_id;
217  $this->is_author_moderator = $row->is_author_moderator;
218  $this->post_activation_date = $row->pos_activation_date;
219  $this->getUserData();
220 
221  $this->objThread = new ilForumTopic($this->thread_id, $this->is_moderator);
222 
223  return true;
224  }
225 
226  return false;
227  }
228 
229  return false;
230  }
231 
232  public function isAnyParentDeactivated()
233  {
234  if ($this->id)
235  {
236  $res = $this->db->queryF('
237  SELECT * FROM frm_posts_tree
238  INNER JOIN frm_posts ON pos_pk = pos_fk
239  WHERE pos_status = %s
240  AND lft < %s AND rgt > %s
241  AND thr_fk = %s',
242  array('integer', 'integer', 'integer', 'integer'),
243  array('0', $this->lft, $this->rgt, $this->thread_id));
244 
245  return $res->numRows();
246  }
247 
248  return false;
249  }
250 
251  protected function buildUserRelatedData($row)
252  {
253  global $lng;
254 
255  if ($row['pos_display_user_id'] && $row['pos_pk'])
256  {
257  require_once 'Services/User/classes/class.ilObjUser.php';
258  $tmp_user = new ilObjUser();
259  $tmp_user->setFirstname($row['firstname']);
260  $tmp_user->setLastname($row['lastname']);
261  $tmp_user->setUTitle($row['title']);
262  $tmp_user->setLogin($row['login']);
263 
264  $this->fullname = $tmp_user->getFullname();
265  $this->loginname = $tmp_user->getLogin();
266 
267  $this->fullname = $this->fullname ? $this->fullname : ($this->import_name ? $this->import_name : $lng->txt('unknown'));
268  }
269  }
270 
271  private function getUserData()
272  {
273  global $lng;
274 
275  if ($this->id && $this->display_user_id)
276  {
277  require_once("Modules/Forum/classes/class.ilObjForumAccess.php");
278  if(($tmp_user = ilObjForumAccess::getCachedUserInstance($this->display_user_id)))
279  {
280  $this->fullname = $tmp_user->getFullname();
281  $this->loginname = $tmp_user->getLogin();
282  unset($tmp_user);
283  }
284 
285  $this->fullname = $this->fullname ? $this->fullname : ($this->import_name ? $this->import_name : $lng->txt('unknown'));
286 
287  return true;
288  }
289 
290  return false;
291  }
292 
293  public function reload()
294  {
295  return $this->read();
296  }
297 
298  public function setFullname($a_fullname)
299  {
300  $this->fullname = $a_fullname;
301  }
302  public function getFullname()
303  {
304  return $this->fullname;
305  }
306  public function setLoginName($a_loginname)
307  {
308  $this->loginname = $a_loginname;
309  }
310  public function getLoginName()
311  {
312  return $this->loginname;
313  }
314 
315  public function activatePost()
316  {
317  if ($this->id)
318  {
319  $now = date("Y-m-d H:i:s");
320  $this->db->update('frm_posts',
321  array('pos_status' => array('integer', 1),
322  'pos_activation_date' => array('timestamp', $now)),
323  array('pos_pk' => array('integer', $this->id))
324  );
325 
326  $this->activateParentPosts();
327  $this->setPostActivationDate($now);
328  $this->setStatus(1);
329  return true;
330  }
331 
332  return false;
333  }
334 
335  public function activatePostAndChildPosts()
336  {
337  if ($this->id)
338  {
339  $query = "SELECT pos_pk FROM frm_posts_tree treea "
340  . "INNER JOIN frm_posts_tree treeb ON treeb.thr_fk = treea.thr_fk "
341  . "AND treeb.lft BETWEEN treea.lft AND treea.rgt "
342  . "INNER JOIN frm_posts ON pos_pk = treeb.pos_fk "
343  . "WHERE treea.pos_fk = %s";
344  $result = $this->db->queryF(
345  $query,
346  array('integer'),
347  array($this->id)
348  );
349 
350  $now = date("Y-m-d H:i:s");
351  while($row = $this->db->fetchAssoc($result))
352  {
353  $this->db->update('frm_posts',
354  array('pos_status' => array('integer', 1),
355  'pos_activation_date' => array('timestamp', $now)),
356  array('pos_pk' => array('integer', $row['pos_pk']))
357  );
358  }
359 
360  $this->activateParentPosts();
361 
362  return true;
363  }
364 
365  return false;
366  }
367 
368  public function activateParentPosts()
369  {
370  if ($this->id)
371  {
372  $query = "SELECT pos_pk FROM frm_posts "
373  . "INNER JOIN frm_posts_tree ON pos_fk = pos_pk "
374  . "WHERE lft < %s AND rgt > %s AND thr_fk = %s";
375  $result = $this->db->queryF(
376  $query,
377  array('integer', 'integer', 'integer'),
378  array($this->lft, $this->rgt, $this->thread_id)
379  );
380 
381  $now = date("Y-m-d H:i:s");
382  while($row = $this->db->fetchAssoc($result))
383  {
384  $this->db->update('frm_posts',
385  array('pos_status' => array('integer', 1),
386  'pos_activation_date' => array('timestamp', $now)),
387  array('pos_pk' => array('integer', $row['pos_pk']))
388  );
389  }
390 
391  return true;
392  }
393 
394  return false;
395  }
396 
397  public function isPostRead()
398  {
399  return $this->getIsRead();
400  }
401 
402  public function isRead($a_user_id = 0)
403  {
404  if ($a_user_id && $this->id)
405  {
406 
407  $res = $this->db->queryF('
408  SELECT * FROM frm_user_read
409  WHERE usr_id = %s
410  AND post_id = %s',
411  array('integer', 'integer'),
412  array($a_user_id, $this->id));
413 
414  return $res->numRows() ? true : false;
415  }
416 
417  return false;
418  }
419 
420  public function hasReplies()
421  {
422  if ($this->id && $this->rgt && $this->lft)
423  {
424  $res = $this->db->queryF('
425  SELECT * FROM frm_posts_tree
426  WHERE lft > %s AND rgt < %s
427  AND thr_fk = %s',
428  array('integer', 'integer', 'integer'),
429  array($this->lft, $this->rgt, $this->thread_id));
430 
431  return $res->numRows() ? true : false;
432  }
433 
434  return false;
435  }
436 
437  public function isOwner($a_user_id = 0)
438  {
439  if ($this->pos_author_id && $a_user_id)
440  {
441  if ((int) $this->pos_author_id == (int) $a_user_id)
442  {
443  return true;
444  }
445  return false;
446  }
447  return false;
448  }
449 
450  public function setId($a_id)
451  {
452  $this->id = $a_id;
453  }
454  public function getId()
455  {
456  return $this->id;
457  }
458  public function setForumId($a_forum_id)
459  {
460  $this->forum_id = $a_forum_id;
461  }
462  public function getForumId()
463  {
464  return $this->forum_id;
465  }
466  public function setThreadId($a_thread_id)
467  {
468  $this->thread_id = $a_thread_id;
469  }
470  public function getThreadId()
471  {
472  return $this->thread_id;
473  }
474  public function setDisplayUserId($a_user_id)
475  {
476  $this->display_user_id = $a_user_id;
477  }
478  public function getDisplayUserId()
479  {
480  return $this->display_user_id;
481  }
482  public function setUserAlias($a_user_alias)
483  {
484  $this->user_alias = $a_user_alias;
485  }
486  public function getUserAlias()
487  {
488  return $this->user_alias;
489  }
490  public function setSubject($a_subject)
491  {
492  $this->subject = $a_subject;
493  }
494  public function getSubject()
495  {
496  return $this->subject;
497  }
498  public function setMessage($a_message)
499  {
500  $this->message = $a_message;
501  }
502  public function getMessage()
503  {
504  return $this->message;
505  }
506  public function setCreateDate($a_createdate)
507  {
508  $this->createdate = $a_createdate;
509  }
510  public function getCreateDate()
511  {
512  return $this->createdate;
513  }
514  public function setChangeDate($a_changedate)
515  {
516  $this->changedate = $a_changedate;
517  }
518  public function getChangeDate()
519  {
520  return $this->changedate;
521  }
522  public function setUpdateUserId($a_user_id_update)
523  {
524  $this->user_id_update = $a_user_id_update;
525  }
526  public function getUpdateUserId()
527  {
528  return $this->user_id_update;
529  }
530  public function setCensorship($a_censorship)
531  {
532  $this->censored = $a_censorship;
533  }
534  public function isCensored()
535  {
536  return $this->censored == 1 ? true : false;
537  }
538  public function setCensorshipComment($a_comment)
539  {
540  $this->censorship_comment = $a_comment;
541  }
542  public function getCensorshipComment()
543  {
545  }
546  public function setNotification($a_notification)
547  {
548  $this->notification = $a_notification;
549  }
550  public function isNotificationEnabled()
551  {
552  return $this->notification == 1 ? true : false;
553  }
554  public function setImportName($a_import_name)
555  {
556  $this->import_name = $a_import_name;
557  }
558  public function getImportName()
559  {
560  return $this->import_name;
561  }
562  public function setStatus($a_status)
563  {
564  $this->status = $a_status;
565  }
566  public function isActivated()
567  {
568  return $this->status == 1 ? true : false;
569  }
570  public function setTreeId($a_tree_id)
571  {
572  $this->tree_id = $a_tree_id;
573  }
574  public function getTreeId()
575  {
576  return $this->tree_id;
577  }
578  public function setParentId($a_parent_id)
579  {
580  $this->parent_id = $a_parent_id;
581  }
582 
583  public function setIsRead($a_is_read)
584  {
585  $this->post_read = $a_is_read;
586  }
587 
588  public function getIsRead()
589  {
590  return $this->post_read;
591  }
592 
593  public function getParentId()
594  {
595  return $this->parent_id;
596  }
597  public function setLft($a_lft)
598  {
599  $this->lft = $a_lft;
600  }
601  public function getLft()
602  {
603  return $this->lft;
604  }
605  public function setRgt($a_rgt)
606  {
607  $this->rgt = $a_rgt;
608  }
609  public function getRgt()
610  {
611  return $this->rgt;
612  }
613  public function setDepth($a_depth)
614  {
615  $this->depth = $a_depth;
616  }
617  public function getDepth()
618  {
619  return $this->depth;
620  }
621  public function setThread(ilForumTopic $thread)
622  {
623  $this->objThread = $thread;
624  }
625  public function getThread()
626  {
627  return $this->objThread;
628  }
629 
634  {
635  $this->pos_author_id = $pos_author_id;
636  }
637 
641  public function getPosAuthorId()
642  {
643  return $this->pos_author_id;
644  }
648  public function getIsAuthorModerator()
649  {
651  }
652 
657  {
658  $this->is_author_moderator = $is_author_moderator;
659  }
660 
664  public function getCensoredDate()
665  {
666  return $this->censored_date;
667  }
668 
672  public function getPostActivationDate()
673  {
675  }
676 
681  {
682  $this->post_activation_date = $post_activation_date;
683  }
684 
689  {
690  $this->censored_date = $censored_date;
691  }
692 
696  public function assignData($row)
697  {
698  $this->setUserAlias($row['pos_usr_alias']);
699  $this->setSubject($row['pos_subject']);
700  $this->setCreateDate($row['pos_date']);
701  $this->setMessage($row['pos_message']);
702  $this->setForumId($row['pos_top_fk']);
703  $this->setThreadId($row['pos_thr_fk']);
704  $this->setChangeDate($row['pos_update']);
705  $this->setUpdateUserId($row['update_user']);
706  $this->setCensorship($row['pos_cens']);
707  $this->setCensoredDate($row['pos_cens_date']);
708  $this->setCensorshipComment($row['pos_cens_com']);
709  $this->setNotification($row['notify']);
710  $this->setImportName($row['import_name']);
711  $this->setStatus($row['pos_status']);
712  $this->setTreeId($row['fpt_pk']);
713  $this->setParentId($row['parent_pos']);
714  $this->setLft($row['lft']);
715  $this->setRgt($row['rgt']);
716  $this->setDepth($row['depth']);
717  $this->setIsRead($row['post_read']);
718  $this->setDisplayUserId($row['pos_display_user_id']);
719  $this->setPosAuthorId($row['pos_author_id']);
720  $this->setIsAuthorModerator($row['is_author_moderator']);
721  $this->buildUserRelatedData($row);
722  }
723 
728  public static function mergePosts($source_thread_id, $target_thread_id)
729  {
730  global $ilDB;
731 
732  $ilDB->update('frm_posts',
733  array('pos_thr_fk' => array('integer', $target_thread_id)),
734  array('pos_thr_fk' => array('integer', $source_thread_id)));
735  }
736 }
static getCachedUserInstance($usr_id)
isRead($a_user_id=0)
setThread(ilForumTopic $thread)
$result
setLoginName($a_loginname)
setCreateDate($a_createdate)
setNotification($a_notification)
setPostActivationDate($post_activation_date)
isOwner($a_user_id=0)
setTreeId($a_tree_id)
buildUserRelatedData($row)
__construct($a_id=0, $a_is_moderator=false, $preventImplicitRead=false)
ilForumPost constructor.
setUserAlias($a_user_alias)
setDepth($a_depth)
setImportName($a_import_name)
setForumId($a_forum_id)
setIsAuthorModerator($is_author_moderator)
setThreadId($a_thread_id)
setCensorshipComment($a_comment)
setParentId($a_parent_id)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
setDisplayUserId($a_user_id)
notification()
Definition: notification.php:2
setStatus($a_status)
setCensorship($a_censorship)
Create styles array
The data for the language used.
setPosAuthorId($pos_author_id)
setMessage($a_message)
setSubject($a_subject)
static mergePosts($source_thread_id, $target_thread_id)
global $lng
Definition: privfeed.php:17
setUpdateUserId($a_user_id_update)
global $ilDB
setChangeDate($a_changedate)
setFullname($a_fullname)
setCensoredDate($censored_date)
setIsRead($a_is_read)