ILIAS  release_7 Revision v7.30-3-g800a261c036
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
11{
12 private $id = 0;
13
14 private $forum_id = 0;
15
16 private $frm_obj_id = 0;
17
18 private $display_user_id = 0;
19
20 private $user_alias = '';
21
22 private $subject = '';
23
24 private $createdate = null;
25
26 private $changedate = null;
27
28 private $num_posts = 0;
29
30 private $last_post_string = '';
31
32 private $visits = 0;
33
34 private $import_name = '';
35
36 private $is_sticky = 0;
37
38 private $is_closed = 0;
39
40 private $orderField = '';
41
43 private $last_post = null;
44
45 private $db = null;
46
47 private $is_moderator = false;
48
49 private $thr_author_id = 0;
50
54 private $average_rating = 0;
55
56 private $orderDirection = 'DESC';
57
58 protected static $possibleOrderDirections = array('ASC', 'DESC');
59
72 public function __construct($a_id = 0, $a_is_moderator = false, $preventImplicitRead = false)
73 {
74 global $DIC;
75
76 $this->is_moderator = $a_is_moderator;
77 $this->db = $DIC->database();
78 $this->user = $DIC->user();
79 $this->id = $a_id;
80
81 if (!$preventImplicitRead) {
82 $this->read();
83 }
84 }
85
89 public function assignData($data)
90 {
91 $this->setId((int) $data['thr_pk']);
92 $this->setForumId((int) $data['thr_top_fk']);
93 $this->setSubject($data['thr_subject']);
94 $this->setDisplayUserId((int) $data['thr_display_user_id']);
95 $this->setUserAlias($data['thr_usr_alias']);
96 $this->setLastPostString($data['last_post_string']);
97 $this->setCreateDate($data['thr_date']);
98 $this->setChangeDate($data['thr_update']);
99 $this->setVisits((int) $data['visits']);
100 $this->setImportName($data['import_name']);
101 $this->setSticky((int) $data['is_sticky']);
102 $this->setClosed((int) $data['is_closed']);
103 $this->setAverageRating($data['avg_rating']);
104 $this->setThrAuthorId($data['thr_author_id']);
105
106 // Aggregated values
107 $this->setNumPosts((int) $data['num_posts']);
108 $this->setNumUnreadPosts((int) $data['num_unread_posts']);
109 $this->setNumNewPosts((int) $data['num_new_posts']);
110 $this->setUserNotificationEnabled((bool) $data['usr_notification_is_enabled']);
111 }
112
119 public function insert()
120 {
121 if ($this->forum_id) {
122 $nextId = $this->db->nextId('frm_threads');
123
124 $this->db->insert(
125 'frm_threads',
126 array(
127 'thr_pk' => array('integer', $nextId),
128 'thr_top_fk' => array('integer', $this->forum_id),
129 'thr_subject' => array('text', $this->subject),
130 'thr_display_user_id' => array('integer', $this->display_user_id),
131 'thr_usr_alias' => array('text', $this->user_alias),
132 'thr_num_posts' => array('integer', $this->num_posts),
133 'thr_last_post' => array('text', $this->last_post_string),
134 'thr_date' => array('timestamp', $this->createdate),
135 'thr_update' => array('timestamp', null),
136 'import_name' => array('text', $this->import_name),
137 'is_sticky' => array('integer', $this->is_sticky),
138 'is_closed' => array('integer', $this->is_closed),
139 'avg_rating' => array('float', $this->average_rating),
140 'thr_author_id' => array('integer', $this->thr_author_id)
141 )
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 $this->db->manipulateF(
162 '
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
183 return true;
184 }
185
186 return false;
187 }
188
196 private function read()
197 {
198 if ($this->id) {
199 $res = $this->db->queryf(
200 '
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'),
206 array($this->id)
207 );
208
209 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
210
211 if (is_object($row)) {
212 $this->thr_pk = $row->pos_pk; // thr_pk = pos_pk ??!??!
213 $this->forum_id = $row->thr_top_fk;
214 $this->display_user_id = $row->thr_display_user_id;
215 $this->user_alias = $row->thr_usr_alias;
216 $this->subject = html_entity_decode($row->thr_subject);
217 $this->createdate = $row->thr_date;
218 $this->changedate = $row->thr_update;
219 $this->import_name = $row->import_name;
220 $this->num_posts = $row->thr_num_posts;
221 $this->last_post_string = $row->thr_last_post;
222 $this->visits = $row->visits;
223 $this->is_sticky = $row->is_sticky;
224 $this->is_closed = $row->is_closed;
225 $this->frm_obj_id = $row->frm_obj_id;
226 $this->average_rating = $row->avg_rating;
227 $this->thr_author_id = $row->thr_author_id;
228
229 return true;
230 }
231 $this->id = 0;
232 return false;
233 }
234
235 return false;
236 }
237
244 public function reload()
245 {
246 return $this->read();
247 }
248
255 public function getFirstPostId()
256 {
257 $this->db->setLimit(1);
258 $res = $this->db->queryf(
259 '
260 SELECT * FROM frm_posts_tree
261 WHERE thr_fk = %s
262 AND parent_pos != %s
263 AND depth = %s
264 ORDER BY rgt DESC',
265 array('integer', 'integer', 'integer'),
266 array($this->id, '0', 2)
267 );
268
269 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
270
271 return $row->pos_fk ? $row->pos_fk : 0;
272 }
273
279 public function updateVisits()
280 {
281 $checkTime = time() - (60 * 60);
282
283 if ($_SESSION['frm_visit_frm_threads_' . $this->id] < $checkTime) {
284 $_SESSION['frm_visit_frm_threads_' . $this->id] = time();
285
286 $this->db->manipulateF(
287 '
288 UPDATE frm_threads
289 SET visits = visits + 1
290 WHERE thr_pk = %s',
291 array('integer'),
292 array($this->id)
293 );
294 }
295
296 return true;
297 }
298
306 public function countPosts($ignoreRoot = false)
307 {
308 $res = $this->db->queryf(
309 '
310 SELECT COUNT(*) cnt
311 FROM frm_posts
312 INNER JOIN frm_posts_tree ON frm_posts_tree.pos_fk = pos_pk
313 WHERE pos_thr_fk = %s' . ($ignoreRoot ? ' AND parent_pos != 0 ' : ''),
314 array('integer'),
315 array($this->id)
316 );
317
318 $rec = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
319
320 return $rec['cnt'];
321 }
322
330 public function countActivePosts($ignoreRoot = false)
331 {
332 $res = $this->db->queryf(
333 '
334 SELECT COUNT(*) cnt
335 FROM frm_posts
336 INNER JOIN frm_posts_tree ON frm_posts_tree.pos_fk = pos_pk
337 WHERE (pos_status = %s
338 OR (pos_status = %s AND pos_display_user_id = %s))
339 AND pos_thr_fk = %s' . ($ignoreRoot ? ' AND parent_pos != 0 ' : ''),
340 array('integer', 'integer', 'integer', 'integer'),
341 array('1', '0', $this->user->getId(), $this->id)
342 );
343
344 $rec = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
345
346 return $rec['cnt'];
347 }
348
355 public function getFirstPostNode($isModerator = false, $preventImplicitRead = false)
356 {
357 $res = $this->db->queryF(
358 '
359 SELECT *
360 FROM frm_posts
361 INNER JOIN frm_posts_tree ON pos_fk = pos_pk
362 WHERE parent_pos = %s
363 AND thr_fk = %s',
364 array('integer', 'integer'),
365 array(0, $this->id)
366 );
367
368 $row = $this->db->fetchAssoc($res);
369
370 $post = new ilForumPost($row['pos_pk'], $isModerator, $preventImplicitRead);
371 $post->assignData($row);
372
373 return $post;
374 }
375
382 public function getLastPost()
383 {
384 if ($this->id) {
385 $this->db->setLimit(1);
386 $res = $this->db->queryf(
387 '
388 SELECT pos_pk
389 FROM frm_posts
390 WHERE pos_thr_fk = %s
391 ORDER BY pos_date DESC',
392 array('integer'),
393 array($this->id)
394 );
395
396 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
397
398 return new ilForumPost($row->pos_pk);
399 }
400
401 return false;
402 }
403
410 public function getLastActivePost()
411 {
412 if ($this->id) {
413 $this->db->setLimit(1);
414 $res = $this->db->queryf(
415 '
416 SELECT pos_pk
417 FROM frm_posts
418 WHERE pos_thr_fk = %s
419 AND (pos_status = %s OR
420 (pos_status = %s AND pos_display_user_id = %s))
421 ORDER BY pos_date DESC',
422 array('integer', 'integer', 'integer', 'integer'),
423 array($this->id, '1', '0', $this->user->getId())
424 );
425
426 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
427
428 return new ilForumPost($row->pos_pk);
429 }
430
431 return false;
432 }
433
434 public function getAllPosts()
435 {
436 $posts = array();
437
438 if ($this->id) {
439 $res = $this->db->queryf(
440 '
441 SELECT pos_pk
442 FROM frm_posts
443 WHERE pos_thr_fk = %s',
444 array('integer'),
445 array($this->id)
446 );
447
448 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
449 $posts[$row->pos_pk] = $row;
450 }
451 }
452
453 return is_array($posts) ? $posts : array();
454 }
455
464 public function getPostTree(ilForumPost $a_post_node)
465 {
466 $posts = array();
467
468 $data = array();
469 $data_types = array();
470
471 $query = '
472 SELECT is_author_moderator, pos_author_id, pos_pk, fpt_date, rgt, pos_top_fk, pos_thr_fk,
473 pos_display_user_id, pos_usr_alias, pos_subject,
474 pos_status, pos_message, pos_date, pos_update,
475 update_user, pos_cens, pos_cens_com, notify,
476 import_name, fpt_pk, parent_pos, lft, depth,
477 (CASE
478 WHEN fur.post_id IS NULL ' .
479 ($this->user->getId() == ANONYMOUS_USER_ID ? ' AND 1 = 2 ' : '') . '
480 THEN 0
481 ELSE 1
482 END) post_read,
483 firstname, lastname, title, login
484
485 FROM frm_posts_tree
486
487 INNER JOIN frm_posts
488 ON pos_fk = pos_pk
489
490 LEFT JOIN usr_data
491 ON pos_display_user_id = usr_id
492
493 LEFT JOIN frm_user_read fur
494 ON fur.thread_id = pos_thr_fk
495 AND fur.post_id = pos_pk
496 AND fur.usr_id = %s
497
498 WHERE lft > %s AND lft < %s
499 AND thr_fk = %s';
500
501 array_push($data_types, 'integer', 'integer', 'integer', 'integer');
502 array_push($data, $this->user->getId(), $a_post_node->getLft(), $a_post_node->getRgt(), $a_post_node->getThreadId());
503
504 if ($this->orderField != "") {
505 $query .= " ORDER BY " . $this->orderField . " " . $this->getOrderDirection();
506 }
507
508 $res = $this->db->queryF($query, $data_types, $data);
509
510 $usr_ids = [];
511 while ($row = $this->db->fetchAssoc($res)) {
512 $post = new ilForumPost($row['pos_pk'], false, true);
513 $post->assignData($row);
514
515 if (!$this->is_moderator) {
516 if (!$post->isActivated() && $post->getPosAuthorId() != $this->user->getId()) {
517 continue;
518 }
519 }
520
521 if ((int) $row['pos_display_user_id']) {
522 $usr_ids[(int) $row['pos_display_user_id']] = (int) $row['pos_display_user_id'];
523 }
524 if ((int) $row['update_user']) {
525 $usr_ids[(int) $row['update_user']] = (int) $row['update_user'];
526 }
527
528 $posts[] = $post;
529 }
530
532
533 return $posts;
534 }
535
546 public function movePosts($old_obj_id, $old_pk, $new_obj_id, $new_pk)
547 {
548 if ($this->id) {
549 $nodes = $this->getAllPosts();
550 if (is_array($nodes)) {
551 $postsMoved = array();
552 // Move attachments
553 try {
554 foreach ($nodes as $node) {
555 $file_obj = new ilFileDataForum((int) $old_obj_id, (int) $node->pos_pk);
556 $moved = $file_obj->moveFilesOfPost((int) $new_obj_id);
557
558 if (true === $moved) {
559 $postsMoved[] = array(
560 'from' => $old_obj_id,
561 'to' => $new_obj_id,
562 'position_id' => (int) $node->pos_pk
563 );
564 }
565
566 unset($file_obj);
567 }
568 } catch (\ilFileUtilsException $exception) {
569 foreach ($postsMoved as $postedInformation) {
570 $file_obj = new ilFileDataForum($postedInformation['to'], $postedInformation['position_id']);
571 $file_obj->moveFilesOfPost($postedInformation['from']);
572 }
573
574 throw $exception;
575 }
576 }
577
578 $current_id = $this->id;
579
580 $ilAtomQuery = $this->db->buildAtomQuery();
581 $ilAtomQuery->addTableLock('frm_user_read');
582 $ilAtomQuery->addTableLock('frm_thread_access');
583
584 $ilAtomQuery->addQueryCallable(function (ilDBInterface $ilDB) use ($new_obj_id, $current_id) {
585 $ilDB->manipulateF(
586 '
587 DELETE FROM frm_user_read
588 WHERE obj_id = %s AND thread_id =%s',
589 array('integer', 'integer'),
590 array($new_obj_id, $current_id)
591 );
592
593 $ilDB->manipulateF(
594 '
595 UPDATE frm_user_read
596 SET obj_id = %s
597 WHERE thread_id = %s',
598 array('integer', 'integer'),
599 array($new_obj_id, $current_id)
600 );
601
602 $ilDB->manipulateF(
603 '
604 DELETE FROM frm_thread_access
605 WHERE obj_id = %s AND thread_id =%s',
606 array('integer', 'integer'),
607 array($new_obj_id, $current_id)
608 );
609
610 $ilDB->manipulateF(
611 '
612 UPDATE frm_thread_access
613 SET obj_id = %s
614 WHERE thread_id =%s',
615 array('integer', 'integer'),
616 array($new_obj_id, $current_id)
617 );
618 });
619
620 $ilAtomQuery->run();
621
622 $this->db->manipulateF(
623 '
624 UPDATE frm_posts
625 SET pos_top_fk = %s
626 WHERE pos_thr_fk = %s',
627 array('integer', 'integer'),
628 array($new_pk, $this->id)
629 );
630
631 // update all related news
632 $posts = $this->db->queryf(
633 '
634 SELECT * FROM frm_posts WHERE pos_thr_fk = %s',
635 array('integer'),
636 array($this->id)
637 );
638
639 $old_obj_id = ilForum::_lookupObjIdForForumId($old_pk);
640
641 $new_obj_id = ilForum::_lookupObjIdForForumId($new_pk);
642
643 while ($post = $posts->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
645 $old_obj_id,
646 "frm",
647 $post["pos_pk"],
648 "pos"
649 );
650 $news_item = new ilNewsItem($news_id);
651 $news_item->setContextObjId($new_obj_id);
652 $news_item->update();
653 }
654
655 return count($nodes);
656 }
657
658 return 0;
659 }
660
661 public function getNestedSetPostChildren($pos_id = null, $levels = null)
662 {
663 $data = null;
664 $objProperties = ilForumProperties::getInstance($this->getFrmObjId());
665 $is_post_activation_enabled = $objProperties->isPostActivationEnabled();
666
667 if ($pos_id !== null) {
668 $res = $this->db->queryF(
669 "
670 SELECT lft, rgt, depth
671 FROM frm_posts_tree
672 WHERE pos_fk = %s
673 AND thr_fk = %s",
674 array('integer', 'integer'),
675 array($pos_id, $this->id)
676 );
677
678 $data = $this->db->fetchAssoc($res);
679 }
680
681 $query = '
682 SELECT fpt.depth,
683 fpt.rgt,
684 fpt.parent_pos,
685 fp.pos_pk,
686 fp.pos_subject,
687 fp.pos_usr_alias,
688 fp.pos_date,
689 fp.pos_update,
690 fp.pos_status,
691 fp.pos_display_user_id,
692 fp.pos_usr_alias,
693 fp.import_name,
694 fp.pos_author_id,
695 fp.is_author_moderator,
696 fur.post_id,
697 (CASE
698 WHEN fur.post_id IS NULL ' .
699 ($this->user->getId() == ANONYMOUS_USER_ID ? ' AND 1 = 2 ' : '') . '
700 THEN 0
701 ELSE 1
702 END) post_read,
703 COUNT(fpt2.pos_fk) children
704
705 FROM frm_posts_tree fpt
706
707 INNER JOIN frm_posts fp
708 ON fp.pos_pk = fpt.pos_fk
709
710 LEFT JOIN frm_posts_tree fpt2
711 ON fpt2.lft BETWEEN fpt.lft AND fpt.rgt
712 AND fpt.thr_fk = fpt2.thr_fk
713 AND fpt.pos_fk != fpt2.pos_fk ';
714
715
716 $query .= '
717 LEFT JOIN frm_user_read fur
718 ON fur.thread_id = fp.pos_thr_fk
719 AND fur.post_id = fp.pos_pk
720 AND fur.usr_id = ' . $this->db->quote($this->user->getId(), 'integer') . '
721
722 LEFT JOIN usr_data ud
723 ON ud.usr_id = fp.pos_display_user_id
724
725 WHERE fpt.thr_fk = ' . $this->db->quote($this->id, 'integer');
726
727 if ($data) {
728 $query .= ' AND fpt.lft > ' . $this->db->quote($data['lft'], 'integer') .
729 ' AND fpt.lft < ' . $this->db->quote($data['rgt'], 'integer') . ' ';
730 }
731 if ($is_post_activation_enabled && !$this->is_moderator) {
732 $query .= ' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_display_user_id = ' . $this->db->quote($this->user->getId(), 'integer') . ') ';
733 }
734
735 if ($data && is_numeric($levels)) {
736 $query .= ' AND fpt.depth <= ' . $this->db->quote($data['depth'] + $levels, 'integer') . ' ';
737 }
738
739 $query .= ' GROUP BY fpt.depth,
740 fpt.rgt,
741 fpt.parent_pos,
742 fp.pos_pk,
743 fp.pos_subject,
744 fp.pos_usr_alias,
745 fp.pos_date,
746 fp.pos_update,
747 fp.pos_status,
748 fp.pos_display_user_id,
749 fp.pos_usr_alias,
750 fp.import_name,
751 fp.pos_author_id,
752 fp.is_author_moderator,
753 fur.post_id
754 ORDER BY fpt.rgt DESC
755 ';
756
757 $queryCounter = '
758 SELECT pos_fk
759 FROM frm_posts_tree fpt
760 INNER JOIN frm_posts fp
761 ON fp.pos_pk = fpt.pos_fk
762 WHERE fpt.thr_fk = ' . $this->db->quote($this->id, 'integer');
763
764 if ($is_post_activation_enabled && !$this->is_moderator) {
765 $queryCounter .= ' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_display_user_id = ' . $this->db->quote($this->user->getId(), 'integer') . ') ';
766 }
767 $queryCounter .= ' ORDER BY fpt.rgt DESC';
768
769 $resCounter = $this->db->query($queryCounter);
770 $counter = array();
771 $i = 0;
772 while ($row = $this->db->fetchAssoc($resCounter)) {
773 $counter[$row['pos_fk']] = $i++;
774 }
775
776 $res = $this->db->query($query);
777 $children = array();
778 $usr_ids = array();
779 while ($row = $this->db->fetchAssoc($res)) {
780 if ((int) $row['pos_display_user_id']) {
781 $usr_ids[] = (int) $row['pos_display_user_id'];
782 }
783
784 $row['counter'] = $counter[$row['pos_pk']];
785 $children[] = $row;
786 }
787
789
790 return $children;
791 }
792
799 public function isNotificationEnabled($a_user_id)
800 {
801 if ($this->id && $a_user_id) {
802 $result = $this->db->queryf(
803 '
804 SELECT COUNT(notification_id) cnt FROM frm_notification
805 WHERE user_id = %s AND thread_id = %s',
806 array('integer', 'integer'),
807 array($a_user_id, $this->id)
808 );
809
810 while ($record = $this->db->fetchAssoc($result)) {
811 return (bool) $record['cnt'];
812 }
813
814 return false;
815 }
816
817 return false;
818 }
819
826 public function enableNotification($a_user_id)
827 {
828 if ($this->id && $a_user_id) {
829 if (!$this->isNotificationEnabled($a_user_id)) {
830 $nextId = $this->db->nextId('frm_notification');
831 $this->db->manipulateF(
832 '
833 INSERT INTO frm_notification
834 ( notification_id,
835 user_id,
836 thread_id
837 )
838 VALUES(%s, %s, %s)',
839 array('integer', 'integer', 'integer'),
840 array($nextId, $a_user_id, $this->id)
841 );
842
843 return true;
844 }
845 return false;
846 }
847
848 return false;
849 }
850
857 public function disableNotification($a_user_id)
858 {
859 if ($this->id && $a_user_id) {
860 $this->db->manipulateF(
861 '
862 DELETE FROM frm_notification
863 WHERE user_id = %s
864 AND thread_id = %s',
865 array('integer', 'integer'),
866 array($a_user_id, $this->id)
867 );
868
869 return false;
870 }
871
872 return false;
873 }
874
881 public function makeSticky()
882 {
883 if ($this->id && !$this->is_sticky) {
884 $this->db->manipulateF(
885 '
886 UPDATE frm_threads
887 SET is_sticky = %s
888 WHERE thr_pk = %s',
889 array('integer', 'integer'),
890 array('1', $this->id)
891 );
892
893 $this->is_sticky = 1;
894
895 return true;
896 }
897
898 return false;
899 }
900
907 public function unmakeSticky()
908 {
909 if ($this->id && $this->is_sticky) {
910 $this->db->manipulateF(
911 '
912 UPDATE frm_threads
913 SET is_sticky = %s
914 WHERE thr_pk = %s',
915 array('integer', 'integer'),
916 array('0', $this->id)
917 );
918
919 $this->is_sticky = 0;
920
921 return true;
922 }
923
924 return false;
925 }
926
933 public function close()
934 {
935 if ($this->id && !$this->is_closed) {
936 $this->db->manipulateF(
937 '
938 UPDATE frm_threads
939 SET is_closed = %s
940 WHERE thr_pk = %s',
941 array('integer', 'integer'),
942 array('1', $this->id)
943 );
944
945 $this->is_closed = 1;
946
947 return true;
948 }
949
950 return false;
951 }
952
959 public function reopen()
960 {
961 if ($this->id && $this->is_closed) {
962 $this->db->manipulateF(
963 '
964 UPDATE frm_threads
965 SET is_closed = %s
966 WHERE thr_pk = %s',
967 array('integer', 'integer'),
968 array('0', $this->id)
969 );
970
971 $this->is_closed = 0;
972
973 return true;
974 }
975
976 return false;
977 }
978
982 public function getAverageRating()
983 {
985 }
986
991 {
992 $this->average_rating = $average_rating;
993 }
994
995 public function setId($a_id)
996 {
997 $this->id = $a_id;
998 }
999 public function getId()
1000 {
1001 return $this->id;
1002 }
1003 public function setForumId($a_forum_id)
1004 {
1005 $this->forum_id = $a_forum_id;
1006 }
1007 public function getForumId()
1008 {
1009 return $this->forum_id;
1010 }
1011 public function setDisplayUserId($a_user_id)
1012 {
1013 $this->display_user_id = $a_user_id;
1014 }
1015 public function getDisplayUserId()
1016 {
1018 }
1019 public function setUserAlias($a_user_alias)
1020 {
1021 $this->user_alias = $a_user_alias;
1022 }
1023 public function getUserAlias()
1024 {
1025 return $this->user_alias;
1026 }
1027 public function setSubject($a_subject)
1028 {
1029 $this->subject = $a_subject;
1030 }
1031 public function getSubject()
1032 {
1033 return $this->subject;
1034 }
1035 public function setCreateDate($a_createdate)
1036 {
1037 $this->createdate = $a_createdate;
1038 }
1039 public function getCreateDate()
1040 {
1041 return $this->createdate;
1042 }
1043 public function setChangeDate($a_changedate)
1044 {
1045 if ($a_changedate == '0000-00-00 00:00:00') {
1046 $this->changedate = null;
1047 } else {
1048 $this->changedate = $a_changedate;
1049 }
1050 }
1051 public function getChangeDate()
1052 {
1053 return $this->changedate;
1054 }
1055 public function setImportName($a_import_name)
1056 {
1057 $this->import_name = $a_import_name;
1058 }
1059 public function getImportName()
1060 {
1061 return $this->import_name;
1062 }
1063 public function setLastPostString($a_last_post)
1064 {
1065 if ($a_last_post == '') {
1066 $a_last_post = null;
1067 }
1068
1069 $this->last_post_string = $a_last_post;
1070 }
1071 public function getLastPostString()
1072 {
1074 }
1075 public function setVisits($a_visits)
1076 {
1077 $this->visits = $a_visits;
1078 }
1079 public function getVisits()
1080 {
1081 return $this->visits;
1082 }
1083 public function setSticky($a_sticky)
1084 {
1085 $this->is_sticky = $a_sticky;
1086 }
1087 public function isSticky()
1088 {
1089 return $this->is_sticky == 1 ? true : false;
1090 }
1091 public function setClosed($a_closed)
1092 {
1093 $this->is_closed = $a_closed;
1094 }
1095 public function isClosed()
1096 {
1097 return $this->is_closed == 1 ? true : false;
1098 }
1099 public function setOrderField($a_order_field)
1100 {
1101 $this->orderField = $a_order_field;
1102 }
1103 public function getOrderField()
1104 {
1105 return $this->orderField;
1106 }
1107 public function setModeratorRight($bool)
1108 {
1109 $this->is_moderator = $bool;
1110 }
1111 public function getModeratorRight()
1112 {
1113 return $this->is_moderator;
1114 }
1115 public function getFrmObjId()
1116 {
1117 return $this->frm_obj_id;
1118 }
1119
1124 {
1125 $this->thr_author_id = $thr_author_id;
1126 }
1127
1131 public function getThrAuthorId()
1132 {
1133 return $this->thr_author_id;
1134 }
1135
1144 public static function _lookupTitle($a_topic_id)
1145 {
1146 global $DIC;
1147 $ilDB = $DIC->database();
1148
1149 $res = $ilDB->queryf(
1150 '
1151 SELECT thr_subject
1152 FROM frm_threads
1153 WHERE thr_pk = %s',
1154 array('integer'),
1155 array($a_topic_id)
1156 );
1157 $row = $ilDB->fetchObject($res);
1158
1159 if (is_object($row)) {
1160 return $row->thr_subject;
1161 }
1162
1163 return '';
1164 }
1165
1166 public function updateThreadTitle()
1167 {
1168 $this->db->update(
1169 'frm_threads',
1170 array('thr_subject' => array('text',$this->getSubject())),
1171 array('thr_pk' => array('integer', $this->getId()))
1172 );
1173
1174 $first_node = $this->getFirstPostNode();
1175 $first_node->setSubject($this->getSubject());
1176 $first_node->update();
1177 }
1178
1183 public function setNumPosts($a_num_posts)
1184 {
1185 $this->num_posts = $a_num_posts;
1186 return $this;
1187 }
1188
1192 public function getNumPosts()
1193 {
1194 return $this->num_posts;
1195 }
1196
1201 public function setNumNewPosts($num_new_posts)
1202 {
1203 $this->num_new_posts = $num_new_posts;
1204 return $this;
1205 }
1206
1210 public function getNumNewPosts()
1211 {
1212 return $this->num_new_posts;
1213 }
1214
1219 public function setNumUnreadPosts($num_unread_posts)
1220 {
1221 $this->num_unread_posts = $num_unread_posts;
1222 return $this;
1223 }
1224
1228 public function getNumUnreadPosts()
1229 {
1230 return $this->num_unread_posts;
1231 }
1232
1237 public function setUserNotificationEnabled($user_notification_enabled)
1238 {
1239 $this->user_notification_enabled = $user_notification_enabled;
1240 return $this;
1241 }
1242
1247 {
1248 return $this->user_notification_enabled;
1249 }
1250
1251 public function setOrderDirection($direction)
1252 {
1253 if (!in_array(strtoupper($direction), self::$possibleOrderDirections)) {
1254 $direction = current(self::$possibleOrderDirections);
1255 }
1256
1257 $this->orderDirection = $direction;
1258 return $this;
1259 }
1260
1261 public function getOrderDirection()
1262 {
1263 return $this->orderDirection;
1264 }
1265
1266 public static function lookupForumIdByTopicId($a_topic_id)
1267 {
1268 global $DIC;
1269 $ilDB = $DIC->database();
1270
1271 $res = $ilDB->queryF(
1272 'SELECT thr_top_fk FROM frm_threads WHERE thr_pk = %s',
1273 array('integer'),
1274 array($a_topic_id)
1275 );
1276
1277 $row = $ilDB->fetchAssoc($res);
1278
1279 return $row['thr_top_fk'];
1280 }
1281
1282 public function getSorting()
1283 {
1284 return $this->thread_sorting;
1285 }
1286 public function updateMergedThread()
1287 {
1288 $this->db->update(
1289 'frm_threads',
1290 array(
1291 'thr_num_posts' => array('integer', $this->getNumPosts()),
1292 'visits' => array('integer', $this->getVisits()),
1293 'thr_last_post' => array('text', $this->getLastPostString()),
1294 'thr_subject' => array('text', $this->getSubject())
1295 ),
1296 array('thr_pk' => array('integer', $this->getId()))
1297 );
1298 }
1299
1304 public static function _lookupDate($thread_id)
1305 {
1306 global $DIC;
1307 $ilDB = $DIC->database();
1308
1309 $res = $ilDB->queryF(
1310 'SELECT thr_date FROM frm_threads WHERE thr_pk = %s',
1311 array('integer'),
1312 array((int) $thread_id)
1313 );
1314
1315 $row = $ilDB->fetchAssoc($res);
1316
1317 return $row['thr_date'] ? $row['thr_date'] : '0000-00-00 00:00:00';
1318 }
1319
1324 {
1325 return $this->last_post;
1326 }
1327
1332 {
1333 $this->last_post = $post;
1334 }
1335}
$result
user()
Definition: user.php:4
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
return true
Flag indicating whether or not HTTP headers will be sent when outputting captcha image/audio.
This class handles all operations on files for the forum object.
Class to report exception.
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...
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...
setOrderDirection($direction)
setChangeDate($a_changedate)
updateVisits()
Updates the visit counter of the current topic.
setForumId($a_forum_id)
setNumPosts($a_num_posts)
countPosts($ignoreRoot=false)
Fetches and returns the number of posts for the given user id.
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)
getFirstPostNode($isModerator=false, $preventImplicitRead=false)
Fetches and returns an object of the first post in the current topic.
setImportName($a_import_name)
getFirstPostId()
Fetches the primary key of the first post node of the current topic from database and returns it.
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.
static $possibleOrderDirections
getLastActivePost()
Fetches and returns an object of the last active post in the current topic.
countActivePosts($ignoreRoot=false)
Fetches and returns the number of active posts for the given user id.
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.
setLastPostForThreadOverview(ilForumPost $post)
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.
const ANONYMOUS_USER_ID
Definition: constants.php:25
global $DIC
Definition: goto.php:24
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$i
Definition: metadata.php:24
$query
foreach($_POST as $key=> $value) $res
global $ilDB
$data
Definition: storeScorm.php:23