ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 $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 = '0000-00-00 00:00:00';
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 $this->db->update('frm_posts',
320 array('pos_status' => array('integer', 1),
321 'pos_activation_date' => array('timestamp', date("Y-m-d H:i:s"))),
322 array('pos_pk' => array('integer', $this->id))
323 );
324
325 $this->activateParentPosts();
326
327 return true;
328 }
329
330 return false;
331 }
332
334 {
335 if ($this->id)
336 {
337 $query = "SELECT pos_pk FROM frm_posts_tree treea "
338 . "INNER JOIN frm_posts_tree treeb ON treeb.thr_fk = treea.thr_fk "
339 . "AND treeb.lft BETWEEN treea.lft AND treea.rgt "
340 . "INNER JOIN frm_posts ON pos_pk = treeb.pos_fk "
341 . "WHERE treea.pos_fk = %s";
342 $result = $this->db->queryF(
343 $query,
344 array('integer'),
345 array($this->id)
346 );
347
348 $now = date("Y-m-d H:i:s");
349 while($row = $this->db->fetchAssoc($result))
350 {
351 $this->db->update('frm_posts',
352 array('pos_status' => array('integer', 1),
353 'pos_activation_date' => array('timestamp', $now)),
354 array('pos_pk' => array('integer', $row['pos_pk']))
355 );
356 }
357
358 $this->activateParentPosts();
359
360 return true;
361 }
362
363 return false;
364 }
365
366 public function activateParentPosts()
367 {
368 if ($this->id)
369 {
370 $query = "SELECT pos_pk FROM frm_posts "
371 . "INNER JOIN frm_posts_tree ON pos_fk = pos_pk "
372 . "WHERE lft < %s AND rgt > %s AND thr_fk = %s";
373 $result = $this->db->queryF(
374 $query,
375 array('integer', 'integer', 'integer'),
376 array($this->lft, $this->rgt, $this->thread_id)
377 );
378
379 $now = date("Y-m-d H:i:s");
380 while($row = $this->db->fetchAssoc($result))
381 {
382 $this->db->update('frm_posts',
383 array('pos_status' => array('integer', 1),
384 'pos_activation_date' => array('timestamp', $now)),
385 array('pos_pk' => array('integer', $row['pos_pk']))
386 );
387 }
388
389 return true;
390 }
391
392 return false;
393 }
394
395 public function isPostRead()
396 {
397 return $this->getIsRead();
398 }
399
400 public function isRead($a_user_id = 0)
401 {
402 if ($a_user_id && $this->id)
403 {
404
405 $res = $this->db->queryF('
406 SELECT * FROM frm_user_read
407 WHERE usr_id = %s
408 AND post_id = %s',
409 array('integer', 'integer'),
410 array($a_user_id, $this->id));
411
412 return $res->numRows() ? true : false;
413 }
414
415 return false;
416 }
417
418 public function hasReplies()
419 {
420 if ($this->id && $this->rgt && $this->lft)
421 {
422 $res = $this->db->queryF('
423 SELECT * FROM frm_posts_tree
424 WHERE lft > %s AND rgt < %s
425 AND thr_fk = %s',
426 array('integer', 'integer', 'integer'),
427 array($this->lft, $this->rgt, $this->thread_id));
428
429 return $res->numRows() ? true : false;
430 }
431
432 return false;
433 }
434
435 public function isOwner($a_user_id = 0)
436 {
437 if ($this->pos_author_id && $a_user_id)
438 {
439 if ((int) $this->pos_author_id == (int) $a_user_id)
440 {
441 return true;
442 }
443 return false;
444 }
445 return false;
446 }
447
448 public function setId($a_id)
449 {
450 $this->id = $a_id;
451 }
452 public function getId()
453 {
454 return $this->id;
455 }
456 public function setForumId($a_forum_id)
457 {
458 $this->forum_id = $a_forum_id;
459 }
460 public function getForumId()
461 {
462 return $this->forum_id;
463 }
464 public function setThreadId($a_thread_id)
465 {
466 $this->thread_id = $a_thread_id;
467 }
468 public function getThreadId()
469 {
470 return $this->thread_id;
471 }
472 public function setDisplayUserId($a_user_id)
473 {
474 $this->display_user_id = $a_user_id;
475 }
476 public function getDisplayUserId()
477 {
479 }
480 public function setUserAlias($a_user_alias)
481 {
482 $this->user_alias = $a_user_alias;
483 }
484 public function getUserAlias()
485 {
486 return $this->user_alias;
487 }
488 public function setSubject($a_subject)
489 {
490 $this->subject = $a_subject;
491 }
492 public function getSubject()
493 {
494 return $this->subject;
495 }
496 public function setMessage($a_message)
497 {
498 $this->message = $a_message;
499 }
500 public function getMessage()
501 {
502 return $this->message;
503 }
504 public function setCreateDate($a_createdate)
505 {
506 $this->createdate = $a_createdate;
507 }
508 public function getCreateDate()
509 {
510 return $this->createdate;
511 }
512 public function setChangeDate($a_changedate)
513 {
514 $this->changedate = $a_changedate;
515 }
516 public function getChangeDate()
517 {
518 return $this->changedate;
519 }
520 public function setUpdateUserId($a_user_id_update)
521 {
522 $this->user_id_update = $a_user_id_update;
523 }
524 public function getUpdateUserId()
525 {
527 }
528 public function setCensorship($a_censorship)
529 {
530 $this->censored = $a_censorship;
531 }
532 public function isCensored()
533 {
534 return $this->censored == 1 ? true : false;
535 }
536 public function setCensorshipComment($a_comment)
537 {
538 $this->censorship_comment = $a_comment;
539 }
540 public function getCensorshipComment()
541 {
543 }
544 public function setNotification($a_notification)
545 {
546 $this->notification = $a_notification;
547 }
548 public function isNotificationEnabled()
549 {
550 return $this->notification == 1 ? true : false;
551 }
552 public function setImportName($a_import_name)
553 {
554 $this->import_name = $a_import_name;
555 }
556 public function getImportName()
557 {
558 return $this->import_name;
559 }
560 public function setStatus($a_status)
561 {
562 $this->status = $a_status;
563 }
564 public function isActivated()
565 {
566 return $this->status == 1 ? true : false;
567 }
568 public function setTreeId($a_tree_id)
569 {
570 $this->tree_id = $a_tree_id;
571 }
572 public function getTreeId()
573 {
574 return $this->tree_id;
575 }
576 public function setParentId($a_parent_id)
577 {
578 $this->parent_id = $a_parent_id;
579 }
580
581 public function setIsRead($a_is_read)
582 {
583 $this->post_read = $a_is_read;
584 }
585
586 public function getIsRead()
587 {
588 return $this->post_read;
589 }
590
591 public function getParentId()
592 {
593 return $this->parent_id;
594 }
595 public function setLft($a_lft)
596 {
597 $this->lft = $a_lft;
598 }
599 public function getLft()
600 {
601 return $this->lft;
602 }
603 public function setRgt($a_rgt)
604 {
605 $this->rgt = $a_rgt;
606 }
607 public function getRgt()
608 {
609 return $this->rgt;
610 }
611 public function setDepth($a_depth)
612 {
613 $this->depth = $a_depth;
614 }
615 public function getDepth()
616 {
617 return $this->depth;
618 }
619 public function setThread(ilForumTopic $thread)
620 {
621 $this->objThread = $thread;
622 }
623 public function getThread()
624 {
625 return $this->objThread;
626 }
627
632 {
633 $this->pos_author_id = $pos_author_id;
634 }
635
639 public function getPosAuthorId()
640 {
642 }
646 public function getIsAuthorModerator()
647 {
649 }
650
655 {
656 $this->is_author_moderator = $is_author_moderator;
657 }
658
662 public function getCensoredDate()
663 {
665 }
666
670 public function getPostActivationDate()
671 {
673 }
674
679 {
680 $this->post_activation_date = $post_activation_date;
681 }
682
687 {
688 $this->censored_date = $censored_date;
689 }
690
694 public function assignData($row)
695 {
696 $this->setUserAlias($row['pos_usr_alias']);
697 $this->setSubject($row['pos_subject']);
698 $this->setCreateDate($row['pos_date']);
699 $this->setMessage($row['pos_message']);
700 $this->setForumId($row['pos_top_fk']);
701 $this->setThreadId($row['pos_thr_fk']);
702 $this->setChangeDate($row['pos_update']);
703 $this->setUpdateUserId($row['update_user']);
704 $this->setCensorship($row['pos_cens']);
705 $this->setCensoredDate($row['pos_cens_date']);
706 $this->setCensorshipComment($row['pos_cens_com']);
707 $this->setNotification($row['notify']);
708 $this->setImportName($row['import_name']);
709 $this->setStatus($row['pos_status']);
710 $this->setTreeId($row['fpt_pk']);
711 $this->setParentId($row['parent_pos']);
712 $this->setLft($row['lft']);
713 $this->setRgt($row['rgt']);
714 $this->setDepth($row['depth']);
715 $this->setIsRead($row['post_read']);
716 $this->setDisplayUserId($row['pos_display_user_id']);
717 $this->setPosAuthorId($row['pos_author_id']);
718 $this->setIsAuthorModerator($row['is_author_moderator']);
720 }
721
726 public static function mergePosts($source_thread_id, $target_thread_id)
727 {
728 global $ilDB;
729
730 $ilDB->update('frm_posts',
731 array('pos_thr_fk' => array('integer', $target_thread_id)),
732 array('pos_thr_fk' => array('integer', $source_thread_id)));
733 }
734}
$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)
ilForumPost constructor.
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)
setCensoredDate($censored_date)
setUpdateUserId($a_user_id_update)
setDisplayUserId($a_user_id)
setChangeDate($a_changedate)
setPostActivationDate($post_activation_date)
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