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