ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 = null;
27
28 private $changedate = null;
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
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
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(ilDBConstants::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(ilDBConstants::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
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
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
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(ilDBConstants::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 $current_id = $this->id;
569
570 $ilAtomQuery = $ilDB->buildAtomQuery();
571 $ilAtomQuery->addTableLock('frm_user_read');
572 $ilAtomQuery->addTableLock('frm_thread_access');
573
574 $ilAtomQuery->addQueryCallable(function (ilDBInterface $ilDB) use ($new_obj_id, $current_id) {
575 $ilDB->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, $current_id));
580
581 $ilDB->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, $current_id));
587
588 $ilDB->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, $current_id));
593
594 $ilDB->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, $current_id));
600 });
601
602 $ilAtomQuery->run();
603
604 $this->db->manipulateF('
605 UPDATE frm_posts
606 SET pos_top_fk = %s
607 WHERE pos_thr_fk = %s',
608 array('integer', 'integer'),
609 array($new_pk, $this->id));
610
611 // update all related news
612 $posts = $ilDB->queryf('
613 SELECT * FROM frm_posts WHERE pos_thr_fk = %s',
614 array('integer'), array($this->id));
615
616 $old_obj_id = ilForum::_lookupObjIdForForumId($old_pk);
617
618 $new_obj_id = ilForum::_lookupObjIdForForumId($new_pk);
619
620 while($post = $posts->fetchRow(ilDBConstants::FETCHMODE_ASSOC))
621 {
622 include_once("./Services/News/classes/class.ilNewsItem.php");
623 $news_id = ilNewsItem::getFirstNewsIdForContext($old_obj_id,
624 "frm", $post["pos_pk"], "pos");
625 $news_item = new ilNewsItem($news_id);
626 $news_item->setContextObjId($new_obj_id);
627 $news_item->update();
628 //echo "<br>-".$post["pos_pk"]."-".$old_obj_id."-".$new_obj_id."-";
629 }
630
631 return count($nodes);
632 }
633
634 return 0;
635 }
636
637 public function getNestedSetPostChildren($pos_id = null, $levels = null)
638 {
639 global $ilUser;
640
641 $data = null;
642 $objProperties = ilForumProperties::getInstance($this->getFrmObjId());
643 $is_post_activation_enabled = $objProperties->isPostActivationEnabled();
644
645 if( $pos_id !== null )
646 {
647 $res = $this->db->queryF("
648 SELECT lft, rgt, depth
649 FROM frm_posts_tree
650 WHERE pos_fk = %s
651 AND thr_fk = %s",
652 array('integer', 'integer'),
653 array($pos_id, $this->id)
654 );
655
656 $data = $this->db->fetchAssoc($res);
657 }
658
659 $query = '
660 SELECT fpt.depth,
661 fpt.rgt,
662 fpt.parent_pos,
663 fp.pos_pk,
664 fp.pos_subject,
665 fp.pos_usr_alias,
666 fp.pos_date,
667 fp.pos_update,
668 fp.pos_status,
669 fp.pos_display_user_id,
670 fp.pos_usr_alias,
671 fp.import_name,
672 fp.pos_author_id,
673 fp.is_author_moderator,
674 fur.post_id,
675 (CASE
676 WHEN fur.post_id IS NULL '.
677 ($ilUser->getId() == ANONYMOUS_USER_ID ? ' AND 1 = 2 ' : '').'
678 THEN 0
679 ELSE 1
680 END) post_read,
681 COUNT(fpt2.pos_fk) children
682
683 FROM frm_posts_tree fpt
684
685 INNER JOIN frm_posts fp
686 ON fp.pos_pk = fpt.pos_fk
687
688 LEFT JOIN frm_posts_tree fpt2
689 ON fpt2.lft BETWEEN fpt.lft AND fpt.rgt
690 AND fpt.thr_fk = fpt2.thr_fk
691 AND fpt.pos_fk != fpt2.pos_fk ';
692
693
694 $query .= '
695 LEFT JOIN frm_user_read fur
696 ON fur.thread_id = fp.pos_thr_fk
697 AND fur.post_id = fp.pos_pk
698 AND fur.usr_id = '.$this->db->quote($ilUser->getId(), 'integer').'
699
700 LEFT JOIN usr_data ud
701 ON ud.usr_id = fp.pos_display_user_id
702
703 WHERE fpt.thr_fk = '.$this->db->quote($this->id, 'integer');
704
705 if( $data )
706 {
707 $query .= ' AND fpt.lft > '.$this->db->quote($data['lft'], 'integer').
708 ' AND fpt.lft < '.$this->db->quote($data['rgt'], 'integer').' ';
709 }
710 if($is_post_activation_enabled && !$this->is_moderator)
711 {
712 $query .= ' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_display_user_id = ' . $this->db->quote($ilUser->getId(), 'integer') . ') ';
713 }
714
715 if( $data && is_numeric($levels) )
716 {
717 $query .= ' AND fpt.depth <= '.$this->db->quote($data['depth'] + $levels, 'integer').' ';
718 }
719
720 $query .= ' GROUP BY fpt.depth,
721 fpt.rgt,
722 fpt.parent_pos,
723 fp.pos_pk,
724 fp.pos_subject,
725 fp.pos_usr_alias,
726 fp.pos_date,
727 fp.pos_update,
728 fp.pos_status,
729 fp.pos_display_user_id,
730 fp.pos_usr_alias,
731 fp.import_name,
732 fp.pos_author_id,
733 fp.is_author_moderator,
734 fur.post_id
735 ORDER BY fpt.rgt DESC
736 ';
737
738 $queryCounter = '
739 SELECT pos_fk
740 FROM frm_posts_tree fpt
741 INNER JOIN frm_posts fp
742 ON fp.pos_pk = fpt.pos_fk
743 WHERE fpt.thr_fk = '.$this->db->quote($this->id, 'integer');
744
745 if($is_post_activation_enabled && !$this->is_moderator)
746 {
747 $queryCounter .= ' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_display_user_id = ' . $this->db->quote($ilUser->getId(), 'integer') . ') ';
748 }
749 $queryCounter .= ' ORDER BY fpt.rgt DESC';
750
751 $resCounter = $this->db->query($queryCounter);
752 $counter = array();
753 $i = 0;
754 while( $row = $this->db->fetchAssoc($resCounter) )
755 {
756 $counter[$row['pos_fk']] = $i++;
757 }
758
759 $res = $this->db->query($query);
760 $children = array();
761 $usr_ids = array();
762 while( $row = $this->db->fetchAssoc($res) )
763 {
764 if((int)$row['pos_display_user_id'])
765 {
766 $usr_ids[] = (int)$row['pos_display_user_id'];
767 }
768
769 $row['counter'] = $counter[$row['pos_pk']];
770 $children[] = $row;
771 }
772
773 require_once 'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
774 ilForumAuthorInformationCache::preloadUserObjects(array_unique($usr_ids));
775
776 return $children;
777 }
778
785 public function isNotificationEnabled($a_user_id)
786 {
787 if ($this->id && $a_user_id)
788 {
789 $result = $this->db->queryf('
790 SELECT COUNT(notification_id) cnt FROM frm_notification
791 WHERE user_id = %s AND thread_id = %s',
792 array('integer', 'integer'),
793 array($a_user_id, $this->id));
794
795 while($record = $this->db->fetchAssoc($result))
796 {
797 return (bool)$record['cnt'];
798 }
799
800 return false;
801 }
802
803 return false;
804 }
805
812 public function enableNotification($a_user_id)
813 {
814 if ($this->id && $a_user_id)
815 {
816 if (!$this->isNotificationEnabled($a_user_id))
817 {
818 $nextId = $this->db->nextId('frm_notification');
819 $statement = $this->db->manipulateF('
820 INSERT INTO frm_notification
821 ( notification_id,
822 user_id,
823 thread_id
824 )
825 VALUES(%s, %s, %s)',
826 array('integer', 'integer', 'integer'),
827 array($nextId, $a_user_id, $this->id));
828
829 return true;
830 }
831 return false;
832 }
833
834 return false;
835 }
836
843 public function disableNotification($a_user_id)
844 {
845 if ($this->id && $a_user_id)
846 {
847 $statement = $this->db->manipulateF('
848 DELETE FROM frm_notification
849 WHERE user_id = %s
850 AND thread_id = %s',
851 array('integer', 'integer'),
852 array($a_user_id, $this->id));
853
854 return false;
855 }
856
857 return false;
858 }
859
866 public function makeSticky()
867 {
868 if ($this->id && !$this->is_sticky)
869 {
870 $statement = $this->db->manipulateF('
871 UPDATE frm_threads
872 SET is_sticky = %s
873 WHERE thr_pk = %s',
874 array('integer', 'integer'),
875 array('1', $this->id));
876
877 $this->is_sticky = 1;
878
879 return true;
880 }
881
882 return false;
883 }
884
891 public function unmakeSticky()
892 {
893 if ($this->id && $this->is_sticky)
894 {
895 $statement = $this->db->manipulateF('
896 UPDATE frm_threads
897 SET is_sticky = %s
898 WHERE thr_pk = %s',
899 array('integer', 'integer'),
900 array('0', $this->id));
901
902 $this->is_sticky = 0;
903
904 return true;
905 }
906
907 return false;
908 }
909
916 public function close()
917 {
918 if ($this->id && !$this->is_closed)
919 {
920 $statement = $this->db->manipulateF('
921 UPDATE frm_threads
922 SET is_closed = %s
923 WHERE thr_pk = %s',
924 array('integer', 'integer'),
925 array('1', $this->id));
926
927 $this->is_closed = 1;
928
929 return true;
930 }
931
932 return false;
933 }
934
941 public function reopen()
942 {
943 if ($this->id && $this->is_closed)
944 {
945 $statement = $this->db->manipulateF('
946 UPDATE frm_threads
947 SET is_closed = %s
948 WHERE thr_pk = %s',
949 array('integer', 'integer'),
950 array('0', $this->id));
951
952 $this->is_closed = 0;
953
954 return true;
955 }
956
957 return false;
958 }
959
963 public function getAverageRating()
964 {
966 }
967
972 {
973 $this->average_rating = $average_rating;
974 }
975
976 public function setId($a_id)
977 {
978 $this->id = $a_id;
979 }
980 public function getId()
981 {
982 return $this->id;
983 }
984 public function setForumId($a_forum_id)
985 {
986 $this->forum_id = $a_forum_id;
987 }
988 public function getForumId()
989 {
990 return $this->forum_id;
991 }
992 public function setDisplayUserId($a_user_id)
993 {
994 $this->display_user_id = $a_user_id;
995 }
996 public function getDisplayUserId()
997 {
999 }
1000 public function setUserAlias($a_user_alias)
1001 {
1002 $this->user_alias = $a_user_alias;
1003 }
1004 public function getUserAlias()
1005 {
1006 return $this->user_alias;
1007 }
1008 public function setSubject($a_subject)
1009 {
1010 $this->subject = $a_subject;
1011 }
1012 public function getSubject()
1013 {
1014 return $this->subject;
1015 }
1016 public function setCreateDate($a_createdate)
1017 {
1018 $this->createdate = $a_createdate;
1019 }
1020 public function getCreateDate()
1021 {
1022 return $this->createdate;
1023 }
1024 public function setChangeDate($a_changedate)
1025 {
1026 if($a_changedate == '0000-00-00 00:00:00')
1027 $this->changedate = NULL;
1028 else
1029 $this->changedate = $a_changedate;
1030 }
1031 public function getChangeDate()
1032 {
1033 return $this->changedate;
1034 }
1035 public function setImportName($a_import_name)
1036 {
1037 $this->import_name = $a_import_name;
1038 }
1039 public function getImportName()
1040 {
1041 return $this->import_name;
1042 }
1043 public function setLastPostString($a_last_post)
1044 {
1045 if($a_last_post == '') $a_last_post = NULL;
1046
1047 $this->last_post_string = $a_last_post;
1048 }
1049 public function getLastPostString()
1050 {
1052 }
1053 public function setVisits($a_visits)
1054 {
1055 $this->visits = $a_visits;
1056 }
1057 public function getVisits()
1058 {
1059 return $this->visits;
1060 }
1061 public function setSticky($a_sticky)
1062 {
1063 $this->is_sticky = $a_sticky;
1064 }
1065 public function isSticky()
1066 {
1067 return $this->is_sticky == 1 ? true : false;
1068 }
1069 public function setClosed($a_closed)
1070 {
1071 $this->is_closed = $a_closed;
1072 }
1073 public function isClosed()
1074 {
1075 return $this->is_closed == 1 ? true : false;
1076 }
1077 function setOrderField($a_order_field)
1078 {
1079 $this->orderField = $a_order_field;
1080 }
1081 function getOrderField()
1082 {
1083 return $this->orderField;
1084 }
1085 function setModeratorRight($bool)
1086 {
1087 $this->is_moderator = $bool;
1088 }
1090 {
1091 return $this->is_moderator;
1092 }
1093 function getFrmObjId()
1094 {
1095 return $this->frm_obj_id;
1096 }
1097
1102 {
1103 $this->thr_author_id = $thr_author_id;
1104 }
1105
1109 public function getThrAuthorId()
1110 {
1111 return $this->thr_author_id;
1112 }
1113
1122 public static function _lookupTitle($a_topic_id)
1123 {
1124 global $ilDB;
1125
1126 $res = $ilDB->queryf('
1127 SELECT thr_subject
1128 FROM frm_threads
1129 WHERE thr_pk = %s',
1130 array('integer'), array($a_topic_id));
1131 $row = $ilDB->fetchObject($res);
1132
1133 if(is_object($row))
1134 {
1135 return $row->thr_subject;
1136 }
1137
1138 return '';
1139 }
1140
1141 public function updateThreadTitle()
1142 {
1143 global $ilDB;
1144
1145 $ilDB->update('frm_threads',
1146 array('thr_subject' => array('text',$this->getSubject())),
1147 array('thr_pk'=> array('integer', $this->getId()))
1148 );
1149 }
1150
1155 public function setNumPosts($a_num_posts)
1156 {
1157 $this->num_posts = $a_num_posts;
1158 return $this;
1159 }
1160
1164 public function getNumPosts()
1165 {
1166 return $this->num_posts;
1167 }
1168
1173 public function setNumNewPosts($num_new_posts)
1174 {
1175 $this->num_new_posts = $num_new_posts;
1176 return $this;
1177 }
1178
1182 public function getNumNewPosts()
1183 {
1184 return $this->num_new_posts;
1185 }
1186
1191 public function setNumUnreadPosts($num_unread_posts)
1192 {
1193 $this->num_unread_posts = $num_unread_posts;
1194 return $this;
1195 }
1196
1200 public function getNumUnreadPosts()
1201 {
1202 return $this->num_unread_posts;
1203 }
1204
1209 public function setUserNotificationEnabled($user_notification_enabled)
1210 {
1211 $this->user_notification_enabled = $user_notification_enabled;
1212 return $this;
1213 }
1214
1219 {
1220 return $this->user_notification_enabled;
1221 }
1222
1223 public function setOrderDirection($direction)
1224 {
1225 if(!in_array(strtoupper($direction), self::$possibleOrderDirections))
1226 {
1227 $direction = current(self::$possibleOrderDirections);
1228 }
1229
1230 $this->orderDirection = $direction;
1231 return $this;
1232 }
1233
1234 public function getOrderDirection()
1235 {
1236 return $this->orderDirection;
1237 }
1238
1239 public static function lookupForumIdByTopicId($a_topic_id)
1240 {
1241 global $ilDB;
1242
1243 $res = $ilDB->queryF('SELECT thr_top_fk FROM frm_threads WHERE thr_pk = %s',
1244 array('integer'), array($a_topic_id));
1245
1246 $row = $ilDB->fetchAssoc($res);
1247
1248 return $row['thr_top_fk'];
1249 }
1250
1251 public function getSorting()
1252 {
1253 return $this->thread_sorting;
1254 }
1255 public function updateMergedThread()
1256 {
1257 global $ilDB;
1258
1259 $ilDB->update('frm_threads',
1260 array(
1261 'thr_num_posts' => array('integer', $this->getNumPosts()),
1262 'visits' => array('integer', $this->getVisits()),
1263 'thr_last_post' => array('text', $this->getLastPostString()),
1264 'thr_subject' => array('text', $this->getSubject())
1265 ),
1266 array('thr_pk' => array('integer', $this->getId())));
1267 }
1268
1269 public static function deleteByThreadId($thr_id)
1270 {
1271 global $ilDB;
1272
1273 $ilDB->manipulateF('DELETE FROM frm_threads WHERE thr_pk = %s',
1274 array('integer'), array($thr_id));
1275 }
1276
1277
1282 public static function _lookupDate($thread_id)
1283 {
1284 global $ilDB;
1285
1286 $res = $ilDB->queryF('SELECT thr_date FROM frm_threads WHERE thr_pk = %s',
1287 array('integer'), array((int)$thread_id));
1288
1289 $row = $ilDB->fetchAssoc($res);
1290
1291 return $row['thr_date'] ? $row['thr_date'] : '0000-00-00 00:00:00';
1292 }
1293}
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$result
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
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, $levels=null)
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.
$counter
Interface ilDBInterface.
global $ilDB
$ilUser
Definition: imgupload.php:18