ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilForumTopic.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.ilForumPost.php';
5
13{
14 private $id = 0;
15
16 private $forum_id = 0;
17
18 private $frm_obj_id = 0;
19
20 private $display_user_id = 0;
21
22 private $user_alias = '';
23
24 private $subject = '';
25
26 private $createdate = '0000-00-00 00:00:00';
27
28 private $changedate = '0000-00-00 00:00:00';
29
30 private $num_posts = 0;
31
32 private $last_post_string = '';
33
34 private $visits = 0;
35
36 private $import_name = '';
37
38 private $is_sticky = 0;
39
40 private $is_closed = 0;
41
42 private $orderField = '';
43
44 private $posts = array();
45
46 private $db = null;
47
48 private $is_moderator = false;
49
50 private $thr_author_id = 0;
51
55 private $average_rating = 0;
56
57 private $orderDirection = 'DESC';
58
59 protected static $possibleOrderDirections = array('ASC', 'DESC');
60
73 public function __construct($a_id = 0, $a_is_moderator = false, $preventImplicitRead = false)
74 {
75 global $ilDB;
76
77 $this->is_moderator = $a_is_moderator;
78 $this->db = $ilDB;
79 $this->id = $a_id;
80
81 if(!$preventImplicitRead)
82 {
83 $this->read();
84 }
85 }
86
90 public function assignData($data)
91 {
92 $this->setId((int) $data['thr_pk']);
93 $this->setForumId((int) $data['thr_top_fk']);
94 $this->setSubject($data['thr_subject']);
95 $this->setDisplayUserId((int) $data['thr_display_user_id']);
96 $this->setUserAlias($data['thr_usr_alias']);
97 $this->setLastPostString($data['last_post_string']);
98 $this->setCreateDate($data['thr_date']);
99 $this->setChangeDate($data['thr_update']);
100 $this->setVisits((int) $data['visits']);
101 $this->setImportName($data['import_name']);
102 $this->setSticky((int) $data['is_sticky']);
103 $this->setClosed((int) $data['is_closed']);
104 $this->setAverageRating($data['avg_rating']);
105 $this->setThrAuthorId($data['thr_author_id']);
106
107 // Aggregated values
108 $this->setNumPosts((int) $data['num_posts']);
109 $this->setNumUnreadPosts((int) $data['num_unread_posts']);
110 $this->setNumNewPosts((int) $data['num_new_posts']);
111 $this->setUserNotificationEnabled((bool) $data['usr_notification_is_enabled']);
112 }
113
120 public function insert()
121 {
122 if ($this->forum_id)
123 {
124 $nextId = $this->db->nextId('frm_threads');
125
126 $this->db->insert('frm_threads',
127 array(
128 'thr_pk' => array('integer', $nextId),
129 'thr_top_fk' => array('integer', $this->forum_id),
130 'thr_subject' => array('text', $this->subject),
131 'thr_display_user_id' => array('integer', $this->display_user_id),
132 'thr_usr_alias' => array('text', $this->user_alias),
133 'thr_num_posts' => array('integer', $this->num_posts),
134 'thr_last_post' => array('text', $this->last_post_string),
135 'thr_date' => array('timestamp', $this->createdate),
136 'thr_update' => array('timestamp', NULL),
137 'import_name' => array('text', $this->import_name),
138 'is_sticky' => array('integer', $this->is_sticky),
139 'is_closed' => array('integer', $this->is_closed),
140 'avg_rating' => array('float', $this->average_rating),
141 'thr_author_id' => array('integer', $this->thr_author_id)
142 ));
143
144 $this->id = $nextId;
145
146 return true;
147 }
148
149 return false;
150 }
151
158 public function update()
159 {
160 if ($this->id)
161 {
162 $statement = $this->db->manipulateF('
163 UPDATE frm_threads
164 SET thr_top_fk = %s,
165 thr_subject = %s,
166 thr_update = %s,
167 thr_num_posts = %s,
168 thr_last_post = %s,
169 avg_rating = %s
170 WHERE thr_pk = %s',
171 array('integer', 'text','timestamp', 'integer', 'text', 'float', 'integer'),
172 array( $this->forum_id,
173 $this->subject,
174 /* $this->changedate, */
175 date('Y-m-d H:i:s'),
176 $this->num_posts,
177 $this->last_post_string,
178 $this->average_rating,
179 $this->id
180 ));
181
182 return true;
183 }
184
185 return false;
186 }
187
195 private function read()
196 {
197
198 if ($this->id)
199 {
200 $res = $this->db->queryf('
201 SELECT frm_threads.*, top_frm_fk frm_obj_id
202 FROM frm_threads
203 INNER JOIN frm_data ON top_pk = thr_top_fk
204 WHERE thr_pk = %s',
205 array('integer'), array($this->id));
206
207 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
208
209 if (is_object($row))
210 {
211 $this->thr_pk = $row->pos_pk; // thr_pk = pos_pk ??!??!
212 $this->forum_id = $row->thr_top_fk;
213 $this->display_user_id = $row->thr_display_user_id;
214 $this->user_alias = $row->thr_usr_alias;
215 $this->subject = html_entity_decode($row->thr_subject);
216 $this->createdate = $row->thr_date;
217 $this->changedate = $row->thr_update;
218 $this->import_name = $row->import_name;
219 $this->num_posts = $row->thr_num_posts;
220 $this->last_post_string = $row->thr_last_post;
221 $this->visits = $row->visits;
222 $this->is_sticky = $row->is_sticky;
223 $this->is_closed = $row->is_closed;
224 $this->frm_obj_id = $row->frm_obj_id;
225 $this->average_rating = $row->avg_rating;
226 $this->thr_author_id = $row->thr_author_id;
227
228 return true;
229 }
230 $this->id = 0;
231 return false;
232 }
233
234 return false;
235 }
236
243 public function reload()
244 {
245 return $this->read();
246 }
247
254 public function getFirstPostId()
255 {
256 $res = $this->db->queryf('
257 SELECT * FROM frm_posts_tree
258 WHERE thr_fk = %s
259 AND parent_pos = %s',
260 array('integer', 'integer'), array($this->id, '1'));
261
262 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
263
264 return $row->pos_fk ? $row->pos_fk : 0;
265 }
266
272 public function updateVisits()
273 {
274 $checkTime = time() - (60 * 60);
275
276 if ($_SESSION['frm_visit_frm_threads_'.$this->id] < $checkTime)
277 {
278 $_SESSION['frm_visit_frm_threads_'.$this->id] = time();
279
280 $statement = $this->db->manipulateF('
281 UPDATE frm_threads
282 SET visits = visits + 1
283 WHERE thr_pk = %s',
284 array('integer'), array($this->id));
285 }
286
287 return true;
288 }
289
297 public function countPosts()
298 {
299 $res = $this->db->queryf('
300 SELECT COUNT(*) cnt
301 FROM frm_posts
302 WHERE pos_thr_fk = %s',
303 array('integer'), array($this->id));
304
305 $rec = $res->fetchRow(DB_FETCHMODE_ASSOC);
306
307 return $rec['cnt'];
308 }
309
317 public function countActivePosts()
318 {
319 global $ilUser;
320
321 $res = $this->db->queryf('
322 SELECT COUNT(*) cnt
323 FROM frm_posts
324 WHERE (pos_status = %s
325 OR (pos_status = %s AND pos_display_user_id = %s))
326 AND pos_thr_fk = %s',
327 array('integer', 'integer', 'integer', 'integer'), array('1', '0', $ilUser->getId(), $this->id));
328
329 $rec = $res->fetchRow(DB_FETCHMODE_ASSOC);
330
331 return $rec['cnt'];
332 }
333
340 public function getFirstPostNode()
341 {
342 $res = $this->db->queryf('
343 SELECT pos_pk
344 FROM frm_posts
345 INNER JOIN frm_posts_tree ON pos_fk = pos_pk
346 WHERE parent_pos = %s
347 AND thr_fk = %s',
348 array('integer', 'integer'),
349 array('0', $this->id));
350
351 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
352
353 return new ilForumPost($row->pos_pk);
354 }
355
362 public function getLastPost()
363 {
364 if ($this->id)
365 {
366 $this->db->setLimit(1);
367 $res = $this->db->queryf('
368 SELECT pos_pk
369 FROM frm_posts
370 WHERE pos_thr_fk = %s
371 ORDER BY pos_date DESC',
372 array('integer'), array($this->id));
373
374 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
375
376 return new ilForumPost($row->pos_pk);
377 }
378
379 return false;
380 }
381
388 public function getLastActivePost()
389 {
390 global $ilUser;
391
392 if ($this->id)
393 {
394 $this->db->setLimit(1);
395 $res = $this->db->queryf('
396 SELECT pos_pk
397 FROM frm_posts
398 WHERE pos_thr_fk = %s
399 AND (pos_status = %s OR
400 (pos_status = %s AND pos_display_user_id = %s))
401 ORDER BY pos_date DESC',
402 array('integer', 'integer', 'integer', 'integer'),
403 array($this->id, '1', '0', $ilUser->getId()));
404
405 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
406
407 return new ilForumPost($row->pos_pk);
408 }
409
410 return false;
411 }
412
413 public function getAllPosts()
414 {
415 $posts = array();
416
417 if($this->id)
418 {
419 $res = $this->db->queryf('
420 SELECT pos_pk
421 FROM frm_posts
422 WHERE pos_thr_fk = %s',
423 array('integer'),
424 array($this->id));
425
426 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
427 {
428 $posts[$row->pos_pk] = $row;
429 }
430 }
431
432 return is_array($posts) ? $posts : array();
433 }
434
443 public function getPostTree(ilForumPost $a_post_node)
444 {
445 global $ilUser;
446
447 $posts = array();
448
449 $data = array();
450 $data_types = array();
451
452 $query = '
453 SELECT is_author_moderator, pos_author_id, pos_pk, fpt_date, rgt, pos_top_fk, pos_thr_fk,
454 pos_display_user_id, pos_usr_alias, pos_subject,
455 pos_status, pos_message, pos_date, pos_update,
456 update_user, pos_cens, pos_cens_com, notify,
457 import_name, fpt_pk, parent_pos, lft, depth,
458 (CASE
459 WHEN fur.post_id IS NULL '.
460 ($ilUser->getId() == ANONYMOUS_USER_ID ? ' AND 1 = 2 ' : '').'
461 THEN 0
462 ELSE 1
463 END) post_read,
464 firstname, lastname, title, login
465
466 FROM frm_posts_tree
467
468 INNER JOIN frm_posts
469 ON pos_fk = pos_pk
470
471 LEFT JOIN usr_data
472 ON pos_display_user_id = usr_id
473
474 LEFT JOIN frm_user_read fur
475 ON fur.thread_id = pos_thr_fk
476 AND fur.post_id = pos_pk
477 AND fur.usr_id = %s
478
479 WHERE lft BETWEEN %s AND %s
480 AND thr_fk = %s';
481
482 array_push($data_types, 'integer', 'integer', 'integer', 'integer');
483 array_push($data, $ilUser->getId(), $a_post_node->getLft(), $a_post_node->getRgt(), $a_post_node->getThreadId());
484
485 if($this->orderField != "")
486 {
487 $query .= " ORDER BY ".$this->orderField." ".$this->getOrderDirection();
488 }
489
490 $res = $this->db->queryf($query, $data_types, $data);
491
492 $usr_ids = array();
493
494 $deactivated = array();
495 while( $row = $this->db->fetchAssoc($res) )
496 {
497 $tmp_object = new ilForumPost($row['pos_pk'], false, true);
498 $tmp_object->assignData($row);
499
500 if (!$this->is_moderator)
501 {
502 if (!$tmp_object->isActivated() && $tmp_object->getDisplayUserId() != $ilUser->getId())
503 {
504 $deactivated[] = $tmp_object;
505 unset($tmp_object);
506 continue;
507 }
508
509 foreach ($deactivated as $deactivated_node)
510 {
511 if ($deactivated_node->getLft() < $tmp_object->getLft() && $deactivated_node->getRgt() > $tmp_object->getLft())
512 {
513 $deactivated[] = $tmp_object;
514 unset($tmp_object);
515 continue 2;
516 }
517 }
518 }
519
520 if((int)$row['pos_display_user_id'])
521 {
522 $usr_ids[] = (int)$row['pos_display_user_id'];
523 }
524 if((int)$row['update_user'])
525 {
526 $usr_ids[] = (int)$row['update_user'];
527 }
528
529 $posts[] = $tmp_object;
530
531 unset($tmp_object);
532 }
533
534 require_once 'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
535 ilForumAuthorInformationCache::preloadUserObjects(array_unique($usr_ids));
536
537 return $posts;
538 }
539
550 public function movePosts($old_obj_id, $old_pk, $new_obj_id, $new_pk)
551 {
552 global $ilDB;
553
554 if ($this->id)
555 {
556 $nodes = $this->getAllPosts();
557 if(is_array($nodes))
558 {
559 // Move attachments
560 foreach($nodes as $node)
561 {
562 $file_obj = new ilFileDataForum((int)$old_obj_id, (int)$node->pos_pk);
563 $file_obj->moveFilesOfPost((int)$new_obj_id);
564 unset($file_obj);
565 }
566 }
567
568 $this->db->lockTables(
569 array(
570 0 => array('name' => 'frm_user_read', 'type' => ilDB::LOCK_WRITE),
571 1 => array('name' => 'frm_thread_access', 'type' => ilDB::LOCK_WRITE)
572 )
573 );
574
575 $this->db->manipulateF('
576 DELETE FROM frm_user_read
577 WHERE obj_id = %s AND thread_id =%s',
578 array('integer', 'integer'),
579 array($new_obj_id, $this->id));
580
581 $this->db->manipulateF('
582 UPDATE frm_user_read
583 SET obj_id = %s
584 WHERE thread_id = %s',
585 array('integer', 'integer'),
586 array($new_obj_id, $this->id));
587
588 $this->db->manipulateF('
589 DELETE FROM frm_thread_access
590 WHERE obj_id = %s AND thread_id =%s',
591 array('integer', 'integer'),
592 array($new_obj_id, $this->id));
593
594 $this->db->manipulateF('
595 UPDATE frm_thread_access
596 SET obj_id = %s
597 WHERE thread_id =%s',
598 array('integer', 'integer'),
599 array($new_obj_id, $this->id));
600
601 $this->db->unlockTables();
602
603 $this->db->manipulateF('
604 UPDATE frm_posts
605 SET pos_top_fk = %s
606 WHERE pos_thr_fk = %s',
607 array('integer', 'integer'),
608 array($new_pk, $this->id));
609
610 // update all related news
611 $posts = $ilDB->queryf('
612 SELECT * FROM frm_posts WHERE pos_thr_fk = %s',
613 array('integer'), array($this->id));
614
615 $old_obj_id = ilForum::_lookupObjIdForForumId($old_pk);
616
617 $new_obj_id = ilForum::_lookupObjIdForForumId($new_pk);
618
619 while($post = $posts->fetchRow(DB_FETCHMODE_ASSOC))
620 {
621 include_once("./Services/News/classes/class.ilNewsItem.php");
622 $news_id = ilNewsItem::getFirstNewsIdForContext($old_obj_id,
623 "frm", $post["pos_pk"], "pos");
624 $news_item = new ilNewsItem($news_id);
625 $news_item->setContextObjId($new_obj_id);
626 $news_item->update();
627 //echo "<br>-".$post["pos_pk"]."-".$old_obj_id."-".$new_obj_id."-";
628 }
629
630 return count($nodes);
631 }
632
633 return 0;
634 }
635
636 public function getNestedSetPostChildren($pos_id = null, $expandedNodes = array())
637 {
638 global $ilUser;
639
640 $data = null;
641 $objProperties = ilForumProperties::getInstance($this->getFrmObjId());
642 $is_post_activation_enabled = $objProperties->isPostActivationEnabled();
643
644 if( $pos_id !== null )
645 {
646 $res = $this->db->queryF("
647 SELECT lft, rgt
648 FROM frm_posts_tree
649 WHERE pos_fk = %s
650 AND thr_fk = %s",
651 array('integer', 'integer'),
652 array($pos_id, $this->id)
653 );
654
655 $data = $this->db->fetchAssoc($res);
656 }
657
658 $query = '
659 SELECT fpt.depth,
660 fpt.rgt,
661 fpt.parent_pos,
662 fp.pos_pk,
663 fp.pos_subject,
664 fp.pos_usr_alias,
665 fp.pos_date,
666 fp.pos_update,
667 fp.pos_status,
668 fp.pos_display_user_id,
669 fp.pos_usr_alias,
670 fp.import_name,
671 fp.pos_author_id,
672 fp.is_author_moderator,
673 fur.post_id,
674 (CASE
675 WHEN fur.post_id IS NULL '.
676 ($ilUser->getId() == ANONYMOUS_USER_ID ? ' AND 1 = 2 ' : '').'
677 THEN 0
678 ELSE 1
679 END) post_read,
680 COUNT(fpt2.pos_fk) children
681
682 FROM frm_posts_tree fpt
683
684 INNER JOIN frm_posts fp
685 ON fp.pos_pk = fpt.pos_fk
686
687 LEFT JOIN frm_posts_tree fpt2
688 ON fpt2.lft BETWEEN fpt.lft AND fpt.rgt
689 AND fpt.thr_fk = fpt2.thr_fk
690 AND fpt.pos_fk != fpt2.pos_fk ';
691
692
693 $query .= '
694 LEFT JOIN frm_user_read fur
695 ON fur.thread_id = fp.pos_thr_fk
696 AND fur.post_id = fp.pos_pk
697 AND fur.usr_id = '.$this->db->quote($ilUser->getId(), 'integer').'
698
699 LEFT JOIN usr_data ud
700 ON ud.usr_id = fp.pos_display_user_id
701
702 WHERE fpt.thr_fk = '.$this->db->quote($this->id, 'integer');
703
704 if( $data )
705 {
706 $query .= ' AND fpt.lft > '.$this->db->quote($data['lft'], 'integer').
707 ' AND fpt.lft < '.$this->db->quote($data['rgt'], 'integer').' ';
708 }
709 if($is_post_activation_enabled && !$this->is_moderator)
710 {
711 $query .= ' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_display_user_id = ' . $this->db->quote($ilUser->getId(), 'integer') . ') ';
712 }
713
714 if( $expandedNodes )
715 {
716 $query .= ' AND '.$this->db->in('fpt.parent_pos', $expandedNodes, false, 'integer').' ';
717 }
718
719 $query .= ' GROUP BY fpt.depth,
720 fpt.rgt,
721 fpt.parent_pos,
722 fp.pos_pk,
723 fp.pos_subject,
724 fp.pos_usr_alias,
725 fp.pos_date,
726 fp.pos_update,
727 fp.pos_status,
728 fp.pos_display_user_id,
729 fp.pos_usr_alias,
730 fp.import_name,
731 fp.pos_author_id,
732 fp.is_author_moderator,
733 fur.post_id
734 ORDER BY fpt.rgt DESC
735 ';
736
737 $queryCounter = '
738 SELECT pos_fk
739 FROM frm_posts_tree fpt
740 INNER JOIN frm_posts fp
741 ON fp.pos_pk = fpt.pos_fk
742 WHERE fpt.thr_fk = '.$this->db->quote($this->id, 'integer');
743
744 if($is_post_activation_enabled && !$this->is_moderator)
745 {
746 $queryCounter .= ' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_display_user_id = ' . $this->db->quote($ilUser->getId(), 'integer') . ') ';
747 }
748 $queryCounter .= ' ORDER BY fpt.rgt DESC';
749
750 $resCounter = $this->db->query($queryCounter);
751 $counter = array();
752 $i = 0;
753 while( $row = $this->db->fetchAssoc($resCounter) )
754 {
755 $counter[$row['pos_fk']] = $i++;
756 }
757
758 $res = $this->db->query($query);
759 $children = array();
760 $usr_ids = array();
761 while( $row = $this->db->fetchAssoc($res) )
762 {
763 if((int)$row['pos_display_user_id'])
764 {
765 $usr_ids[] = (int)$row['pos_display_user_id'];
766 }
767
768 $row['counter'] = $counter[$row['pos_pk']];
769 $children[] = $row;
770 }
771
772 require_once 'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
773 ilForumAuthorInformationCache::preloadUserObjects(array_unique($usr_ids));
774
775 return $children;
776 }
777
784 public function isNotificationEnabled($a_user_id)
785 {
786 if ($this->id && $a_user_id)
787 {
788 $result = $this->db->queryf('
789 SELECT COUNT(notification_id) cnt FROM frm_notification
790 WHERE user_id = %s AND thread_id = %s',
791 array('integer', 'integer'),
792 array($a_user_id, $this->id));
793
794 while($record = $this->db->fetchAssoc($result))
795 {
796 return (bool)$record['cnt'];
797 }
798
799 return false;
800 }
801
802 return false;
803 }
804
811 public function enableNotification($a_user_id)
812 {
813 if ($this->id && $a_user_id)
814 {
815 if (!$this->isNotificationEnabled($a_user_id))
816 {
817 $nextId = $this->db->nextId('frm_notification');
818 $statement = $this->db->manipulateF('
819 INSERT INTO frm_notification
820 ( notification_id,
821 user_id,
822 thread_id
823 )
824 VALUES(%s, %s, %s)',
825 array('integer', 'integer', 'integer'),
826 array($nextId, $a_user_id, $this->id));
827
828 return true;
829 }
830 return false;
831 }
832
833 return false;
834 }
835
842 public function disableNotification($a_user_id)
843 {
844 if ($this->id && $a_user_id)
845 {
846 $statement = $this->db->manipulateF('
847 DELETE FROM frm_notification
848 WHERE user_id = %s
849 AND thread_id = %s',
850 array('integer', 'integer'),
851 array($a_user_id, $this->id));
852
853 return false;
854 }
855
856 return false;
857 }
858
865 public function makeSticky()
866 {
867 if ($this->id && !$this->is_sticky)
868 {
869 $statement = $this->db->manipulateF('
870 UPDATE frm_threads
871 SET is_sticky = %s
872 WHERE thr_pk = %s',
873 array('integer', 'integer'),
874 array('1', $this->id));
875
876 $this->is_sticky = 1;
877
878 return true;
879 }
880
881 return false;
882 }
883
890 public function unmakeSticky()
891 {
892 if ($this->id && $this->is_sticky)
893 {
894 $statement = $this->db->manipulateF('
895 UPDATE frm_threads
896 SET is_sticky = %s
897 WHERE thr_pk = %s',
898 array('integer', 'integer'),
899 array('0', $this->id));
900
901 $this->is_sticky = 0;
902
903 return true;
904 }
905
906 return false;
907 }
908
915 public function close()
916 {
917 if ($this->id && !$this->is_closed)
918 {
919 $statement = $this->db->manipulateF('
920 UPDATE frm_threads
921 SET is_closed = %s
922 WHERE thr_pk = %s',
923 array('integer', 'integer'),
924 array('1', $this->id));
925
926 $this->is_closed = 1;
927
928 return true;
929 }
930
931 return false;
932 }
933
940 public function reopen()
941 {
942 if ($this->id && $this->is_closed)
943 {
944 $statement = $this->db->manipulateF('
945 UPDATE frm_threads
946 SET is_closed = %s
947 WHERE thr_pk = %s',
948 array('integer', 'integer'),
949 array('0', $this->id));
950
951 $this->is_closed = 0;
952
953 return true;
954 }
955
956 return false;
957 }
958
962 public function getAverageRating()
963 {
965 }
966
971 {
972 $this->average_rating = $average_rating;
973 }
974
975 public function setId($a_id)
976 {
977 $this->id = $a_id;
978 }
979 public function getId()
980 {
981 return $this->id;
982 }
983 public function setForumId($a_forum_id)
984 {
985 $this->forum_id = $a_forum_id;
986 }
987 public function getForumId()
988 {
989 return $this->forum_id;
990 }
991 public function setDisplayUserId($a_user_id)
992 {
993 $this->display_user_id = $a_user_id;
994 }
995 public function getDisplayUserId()
996 {
998 }
999 public function setUserAlias($a_user_alias)
1000 {
1001 $this->user_alias = $a_user_alias;
1002 }
1003 public function getUserAlias()
1004 {
1005 return $this->user_alias;
1006 }
1007 public function setSubject($a_subject)
1008 {
1009 $this->subject = $a_subject;
1010 }
1011 public function getSubject()
1012 {
1013 return $this->subject;
1014 }
1015 public function setCreateDate($a_createdate)
1016 {
1017 $this->createdate = $a_createdate;
1018 }
1019 public function getCreateDate()
1020 {
1021 return $this->createdate;
1022 }
1023 public function setChangeDate($a_changedate)
1024 {
1025 if($a_changedate == '0000-00-00 00:00:00')
1026 $this->changedate = NULL;
1027 else
1028 $this->changedate = $a_changedate;
1029 }
1030 public function getChangeDate()
1031 {
1032 return $this->changedate;
1033 }
1034 public function setImportName($a_import_name)
1035 {
1036 $this->import_name = $a_import_name;
1037 }
1038 public function getImportName()
1039 {
1040 return $this->import_name;
1041 }
1042 public function setLastPostString($a_last_post)
1043 {
1044 if($a_last_post == '') $a_last_post = NULL;
1045
1046 $this->last_post_string = $a_last_post;
1047 }
1048 public function getLastPostString()
1049 {
1051 }
1052 public function setVisits($a_visits)
1053 {
1054 $this->visits = $a_visits;
1055 }
1056 public function getVisits()
1057 {
1058 return $this->visits;
1059 }
1060 public function setSticky($a_sticky)
1061 {
1062 $this->is_sticky = $a_sticky;
1063 }
1064 public function isSticky()
1065 {
1066 return $this->is_sticky == 1 ? true : false;
1067 }
1068 public function setClosed($a_closed)
1069 {
1070 $this->is_closed = $a_closed;
1071 }
1072 public function isClosed()
1073 {
1074 return $this->is_closed == 1 ? true : false;
1075 }
1076 function setOrderField($a_order_field)
1077 {
1078 $this->orderField = $a_order_field;
1079 }
1080 function getOrderField()
1081 {
1082 return $this->orderField;
1083 }
1084 function setModeratorRight($bool)
1085 {
1086 $this->is_moderator = $bool;
1087 }
1089 {
1090 return $this->is_moderator;
1091 }
1092 function getFrmObjId()
1093 {
1094 return $this->frm_obj_id;
1095 }
1096
1101 {
1102 $this->thr_author_id = $thr_author_id;
1103 }
1104
1108 public function getThrAuthorId()
1109 {
1110 return $this->thr_author_id;
1111 }
1112
1121 public static function _lookupTitle($a_topic_id)
1122 {
1123 global $ilDB;
1124
1125 $res = $ilDB->queryf('
1126 SELECT thr_subject
1127 FROM frm_threads
1128 WHERE thr_pk = %s',
1129 array('integer'), array($a_topic_id));
1130 $row = $ilDB->fetchObject($res);
1131
1132 if(is_object($row))
1133 {
1134 return $row->thr_subject;
1135 }
1136
1137 return '';
1138 }
1139
1140 public function updateThreadTitle()
1141 {
1142 global $ilDB;
1143
1144 $ilDB->update('frm_threads',
1145 array('thr_subject' => array('text',$this->getSubject())),
1146 array('thr_pk'=> array('integer', $this->getId()))
1147 );
1148 }
1149
1154 public function setNumPosts($a_num_posts)
1155 {
1156 $this->num_posts = $a_num_posts;
1157 return $this;
1158 }
1159
1163 public function getNumPosts()
1164 {
1165 return $this->num_posts;
1166 }
1167
1172 public function setNumNewPosts($num_new_posts)
1173 {
1174 $this->num_new_posts = $num_new_posts;
1175 return $this;
1176 }
1177
1181 public function getNumNewPosts()
1182 {
1183 return $this->num_new_posts;
1184 }
1185
1190 public function setNumUnreadPosts($num_unread_posts)
1191 {
1192 $this->num_unread_posts = $num_unread_posts;
1193 return $this;
1194 }
1195
1199 public function getNumUnreadPosts()
1200 {
1201 return $this->num_unread_posts;
1202 }
1203
1208 public function setUserNotificationEnabled($user_notification_enabled)
1209 {
1210 $this->user_notification_enabled = $user_notification_enabled;
1211 return $this;
1212 }
1213
1218 {
1219 return $this->user_notification_enabled;
1220 }
1221
1222 public function setOrderDirection($direction)
1223 {
1224 if(!in_array(strtoupper($direction), self::$possibleOrderDirections))
1225 {
1226 $direction = current(self::$possibleOrderDirections);
1227 }
1228
1229 $this->orderDirection = $direction;
1230 return $this;
1231 }
1232
1233 public function getOrderDirection()
1234 {
1235 return $this->orderDirection;
1236 }
1237
1238 public static function lookupForumIdByTopicId($a_topic_id)
1239 {
1240 global $ilDB;
1241
1242 $res = $ilDB->queryF('SELECT thr_top_fk FROM frm_threads WHERE thr_pk = %s',
1243 array('integer'), array($a_topic_id));
1244
1245 $row = $ilDB->fetchAssoc($res);
1246
1247 return $row['thr_top_fk'];
1248 }
1249
1250 public function getSorting()
1251 {
1252 return $this->thread_sorting;
1253 }
1254 public function updateMergedThread()
1255 {
1256 global $ilDB;
1257
1258 $ilDB->update('frm_threads',
1259 array(
1260 'thr_num_posts' => array('integer', $this->getNumPosts()),
1261 'visits' => array('integer', $this->getVisits()),
1262 'thr_last_post' => array('text', $this->getLastPostString()),
1263 'thr_subject' => array('text', $this->getSubject())
1264 ),
1265 array('thr_pk' => array('integer', $this->getId())));
1266 }
1267
1268 public static function deleteByThreadId($thr_id)
1269 {
1270 global $ilDB;
1271
1272 $ilDB->manipulateF('DELETE FROM frm_threads WHERE thr_pk = %s',
1273 array('integer'), array($thr_id));
1274 }
1275
1276
1281 public static function _lookupDate($thread_id)
1282 {
1283 global $ilDB;
1284
1285 $res = $ilDB->queryF('SELECT thr_date FROM frm_threads WHERE thr_pk = %s',
1286 array('integer'), array((int)$thread_id));
1287
1288 $row = $ilDB->fetchAssoc($res);
1289
1290 return $row['thr_date'] ? $row['thr_date'] : '0000-00-00 00:00:00';
1291 }
1292}
$result
$_SESSION["AccountId"]
const DB_FETCHMODE_ASSOC
Definition: class.ilDB.php:10
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
const LOCK_WRITE
Definition: class.ilDB.php:30
This class handles all operations on files for the forum object.
static getInstance($a_obj_id=0)
static lookupForumIdByTopicId($a_topic_id)
reload()
Calls the private method read() to load the topic data from database into the object.
__construct($a_id=0, $a_is_moderator=false, $preventImplicitRead=false)
Constructor.
setOrderField($a_order_field)
setUserNotificationEnabled($user_notification_enabled)
setNumNewPosts($num_new_posts)
setThrAuthorId($thr_author_id)
isNotificationEnabled($a_user_id)
Check whether a user's notification about new posts in a thread is enabled (result > 0) or not (resul...
static deleteByThreadId($thr_id)
reopen()
Reopens the current topic.
static _lookupDate($thread_id)
unmakeSticky()
Sets the current topic non-sticky.
getPostTree(ilForumPost $a_post_node)
Fetches and returns an array of posts from the post tree, starting with the node object passed by the...
getFirstPostNode()
Fetches and returns an object of the first post in the current topic.
setOrderDirection($direction)
setChangeDate($a_changedate)
updateVisits()
Updates the visit counter of the current topic.
setForumId($a_forum_id)
setNumPosts($a_num_posts)
setSubject($a_subject)
update()
Updates an existing topic.
insert()
Inserts the object data into database.
setUserAlias($a_user_alias)
setDisplayUserId($a_user_id)
read()
Reads the data of the current object id from database and loads it into the object.
getNestedSetPostChildren($pos_id=null, $expandedNodes=array())
static _lookupTitle($a_topic_id)
Looks up the title/subject of a topic/thread.
setAverageRating($average_rating)
setImportName($a_import_name)
getFirstPostId()
Fetches the primary key of the first post node of the current topic from database and returns it.
countActivePosts()
Fetches and returns the number of active posts for the given user id.
makeSticky()
Sets the current topic sticky.
movePosts($old_obj_id, $old_pk, $new_obj_id, $new_pk)
Moves all posts within the current thread to a new forum.
disableNotification($a_user_id)
Disable a user's notification about new posts in a thread.
setLastPostString($a_last_post)
getLastPost()
Fetches and returns an object of the last post in the current topic.
countPosts()
Fetches and returns the number of posts for the given user id.
static $possibleOrderDirections
getLastActivePost()
Fetches and returns an object of the last active post in the current topic.
enableNotification($a_user_id)
Enable a user's notification about new posts in a thread.
setCreateDate($a_createdate)
setNumUnreadPosts($num_unread_posts)
close()
Closes the current topic.
static _lookupObjIdForForumId($a_for_id)
static getFirstNewsIdForContext($a_context_obj_id, $a_context_obj_type, $a_context_sub_obj_id="", $a_context_sub_obj_type="")
Get first new id of news set related to a certain context.
$data
global $ilDB
global $ilUser
Definition: imgupload.php:15