72 public function __construct($a_id = 0, $a_is_moderator =
false, $preventImplicitRead =
false)
76 $this->is_moderator = $a_is_moderator;
77 $this->db = $DIC->database();
78 $this->
user = $DIC->user();
81 if (!$preventImplicitRead) {
101 $this->
setSticky((
int) $data[
'is_sticky']);
102 $this->
setClosed((
int) $data[
'is_closed']);
121 if ($this->forum_id) {
122 $nextId = $this->db->nextId(
'frm_threads');
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)
161 $this->db->manipulateF(
171 array(
'integer',
'text',
'timestamp',
'integer',
'text',
'float',
'integer'),
172 array( $this->forum_id,
177 $this->last_post_string,
178 $this->average_rating,
199 $res = $this->db->queryf(
201 SELECT frm_threads.*, top_frm_fk frm_obj_id 203 INNER JOIN frm_data ON top_pk = thr_top_fk 211 if (is_object(
$row)) {
212 $this->thr_pk =
$row->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;
246 return $this->
read();
257 $res = $this->db->queryf(
259 SELECT * FROM frm_posts_tree 261 AND parent_pos = %s',
262 array(
'integer',
'integer'),
263 array($this->
id,
'1')
268 return $row->pos_fk ?
$row->pos_fk : 0;
278 $checkTime = time() - (60 * 60);
280 if (
$_SESSION[
'frm_visit_frm_threads_' . $this->
id] < $checkTime) {
283 $this->db->manipulateF(
286 SET visits = visits + 1 305 $res = $this->db->queryf(
309 INNER JOIN frm_posts_tree ON frm_posts_tree.pos_fk = pos_pk 310 WHERE pos_thr_fk = %s' . ($ignoreRoot ?
' AND parent_pos != 0 ' :
''),
329 $res = $this->db->queryf(
333 INNER JOIN frm_posts_tree ON frm_posts_tree.pos_fk = pos_pk 334 WHERE (pos_status = %s 335 OR (pos_status = %s AND pos_display_user_id = %s)) 336 AND pos_thr_fk = %s' . ($ignoreRoot ?
' AND parent_pos != 0 ' :
''),
337 array(
'integer',
'integer',
'integer',
'integer'),
354 $res = $this->db->queryF(
358 INNER JOIN frm_posts_tree ON pos_fk = pos_pk 359 WHERE parent_pos = %s 361 array(
'integer',
'integer'),
382 $this->db->setLimit(1);
383 $res = $this->db->queryf(
387 WHERE pos_thr_fk = %s 388 ORDER BY pos_date DESC',
410 $this->db->setLimit(1);
411 $res = $this->db->queryf(
415 WHERE pos_thr_fk = %s 416 AND (pos_status = %s OR 417 (pos_status = %s AND pos_display_user_id = %s)) 418 ORDER BY pos_date DESC',
419 array(
'integer',
'integer',
'integer',
'integer'),
420 array($this->
id,
'1',
'0', $this->
user->getId())
436 $res = $this->db->queryf(
440 WHERE pos_thr_fk = %s',
450 return is_array($posts) ? $posts : array();
466 $data_types = array();
469 SELECT is_author_moderator, pos_author_id, pos_pk, fpt_date, rgt, pos_top_fk, pos_thr_fk, 470 pos_display_user_id, pos_usr_alias, pos_subject, 471 pos_status, pos_message, pos_date, pos_update, 472 update_user, pos_cens, pos_cens_com, notify, 473 import_name, fpt_pk, parent_pos, lft, depth, 475 WHEN fur.post_id IS NULL ' .
476 ($this->
user->getId() == ANONYMOUS_USER_ID ?
' AND 1 = 2 ' :
'') .
' 480 firstname, lastname, title, login 488 ON pos_display_user_id = usr_id 490 LEFT JOIN frm_user_read fur 491 ON fur.thread_id = pos_thr_fk 492 AND fur.post_id = pos_pk 495 WHERE lft > %s AND lft < %s 498 array_push($data_types,
'integer',
'integer',
'integer',
'integer');
501 if ($this->orderField !=
"") {
508 while (
$row = $this->db->fetchAssoc(
$res)) {
512 if (!$this->is_moderator) {
513 if (!
$post->isActivated() &&
$post->getPosAuthorId() != $this->
user->getId()) {
518 if ((
int)
$row[
'pos_display_user_id']) {
519 $usr_ids[(int)
$row[
'pos_display_user_id']] = (
int)
$row[
'pos_display_user_id'];
521 if ((
int)
$row[
'update_user']) {
522 $usr_ids[(int)
$row[
'update_user']] = (
int)
$row[
'update_user'];
543 public function movePosts($old_obj_id, $old_pk, $new_obj_id, $new_pk)
548 $postsMoved = array();
551 foreach (
$nodes as $node) {
552 $file_obj =
new ilFileDataForum((
int) $old_obj_id, (
int) $node->pos_pk);
553 $moved = $file_obj->moveFilesOfPost((
int) $new_obj_id);
555 if (
true === $moved) {
556 $postsMoved[] = array(
557 'from' => $old_obj_id,
559 'position_id' => (
int) $node->pos_pk
566 foreach ($postsMoved as $postedInformation) {
567 $file_obj =
new ilFileDataForum($postedInformation[
'to'], $postedInformation[
'position_id']);
568 $file_obj->moveFilesOfPost($postedInformation[
'from']);
577 $ilAtomQuery = $this->db->buildAtomQuery();
578 $ilAtomQuery->addTableLock(
'frm_user_read');
579 $ilAtomQuery->addTableLock(
'frm_thread_access');
581 $ilAtomQuery->addQueryCallable(
function (
ilDBInterface $ilDB) use ($new_obj_id, $current_id) {
584 DELETE FROM frm_user_read 585 WHERE obj_id = %s AND thread_id =%s',
586 array(
'integer',
'integer'),
587 array($new_obj_id, $current_id)
594 WHERE thread_id = %s',
595 array(
'integer',
'integer'),
596 array($new_obj_id, $current_id)
601 DELETE FROM frm_thread_access 602 WHERE obj_id = %s AND thread_id =%s',
603 array(
'integer',
'integer'),
604 array($new_obj_id, $current_id)
609 UPDATE frm_thread_access 611 WHERE thread_id =%s',
612 array(
'integer',
'integer'),
613 array($new_obj_id, $current_id)
619 $this->db->manipulateF(
623 WHERE pos_thr_fk = %s',
624 array(
'integer',
'integer'),
625 array($new_pk, $this->
id)
629 $posts = $this->db->queryf(
631 SELECT * FROM frm_posts WHERE pos_thr_fk = %s',
648 $news_item->setContextObjId($new_obj_id);
649 $news_item->update();
663 $is_post_activation_enabled = $objProperties->isPostActivationEnabled();
665 if ($pos_id !== null) {
666 $res = $this->db->queryF(
668 SELECT lft, rgt, depth 672 array(
'integer',
'integer'),
673 array($pos_id, $this->
id)
689 fp.pos_display_user_id, 693 fp.is_author_moderator, 696 WHEN fur.post_id IS NULL ' .
697 ($this->
user->getId() == ANONYMOUS_USER_ID ?
' AND 1 = 2 ' :
'') .
' 701 COUNT(fpt2.pos_fk) children 703 FROM frm_posts_tree fpt 705 INNER JOIN frm_posts fp 706 ON fp.pos_pk = fpt.pos_fk 708 LEFT JOIN frm_posts_tree fpt2 709 ON fpt2.lft BETWEEN fpt.lft AND fpt.rgt 710 AND fpt.thr_fk = fpt2.thr_fk 711 AND fpt.pos_fk != fpt2.pos_fk ';
715 LEFT JOIN frm_user_read fur 716 ON fur.thread_id = fp.pos_thr_fk 717 AND fur.post_id = fp.pos_pk 718 AND fur.usr_id = ' . $this->db->quote($this->
user->getId(),
'integer') .
' 720 LEFT JOIN usr_data ud 721 ON ud.usr_id = fp.pos_display_user_id 723 WHERE fpt.thr_fk = ' . $this->db->quote($this->id,
'integer');
726 $query .=
' AND fpt.lft > ' . $this->db->quote(
$data[
'lft'],
'integer') .
727 ' AND fpt.lft < ' . $this->db->quote(
$data[
'rgt'],
'integer') .
' ';
729 if ($is_post_activation_enabled && !$this->is_moderator) {
730 $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 if (
$data && is_numeric($levels)) {
734 $query .=
' AND fpt.depth <= ' . $this->db->quote(
$data[
'depth'] + $levels,
'integer') .
' ';
737 $query .=
' GROUP BY fpt.depth, 746 fp.pos_display_user_id, 750 fp.is_author_moderator, 752 ORDER BY fpt.rgt DESC 757 FROM frm_posts_tree fpt 758 INNER JOIN frm_posts fp 759 ON fp.pos_pk = fpt.pos_fk 760 WHERE fpt.thr_fk = ' . $this->db->quote($this->
id,
'integer');
762 if ($is_post_activation_enabled && !$this->is_moderator) {
763 $queryCounter .=
' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_display_user_id = ' . $this->db->quote($this->
user->getId(),
'integer') .
') ';
765 $queryCounter .=
' ORDER BY fpt.rgt DESC';
767 $resCounter = $this->db->query($queryCounter);
770 while (
$row = $this->db->fetchAssoc($resCounter)) {
771 $counter[
$row[
'pos_fk']] =
$i++;
777 while (
$row = $this->db->fetchAssoc(
$res)) {
778 if ((
int)
$row[
'pos_display_user_id']) {
779 $usr_ids[] = (int)
$row[
'pos_display_user_id'];
782 $row[
'counter'] = $counter[
$row[
'pos_pk']];
799 if ($this->
id && $a_user_id) {
802 SELECT COUNT(notification_id) cnt FROM frm_notification 803 WHERE user_id = %s AND thread_id = %s',
804 array(
'integer',
'integer'),
805 array($a_user_id, $this->
id)
808 while ($record = $this->db->fetchAssoc(
$result)) {
809 return (
bool) $record[
'cnt'];
826 if ($this->
id && $a_user_id) {
828 $nextId = $this->db->nextId(
'frm_notification');
829 $this->db->manipulateF(
831 INSERT INTO frm_notification 837 array(
'integer',
'integer',
'integer'),
838 array($nextId, $a_user_id, $this->
id)
857 if ($this->
id && $a_user_id) {
858 $this->db->manipulateF(
860 DELETE FROM frm_notification 863 array(
'integer',
'integer'),
864 array($a_user_id, $this->
id)
881 if ($this->
id && !$this->is_sticky) {
882 $this->db->manipulateF(
887 array(
'integer',
'integer'),
888 array(
'1', $this->
id)
891 $this->is_sticky = 1;
907 if ($this->
id && $this->is_sticky) {
908 $this->db->manipulateF(
913 array(
'integer',
'integer'),
914 array(
'0', $this->
id)
917 $this->is_sticky = 0;
933 if ($this->
id && !$this->is_closed) {
934 $this->db->manipulateF(
939 array(
'integer',
'integer'),
940 array(
'1', $this->
id)
943 $this->is_closed = 1;
959 if ($this->
id && $this->is_closed) {
960 $this->db->manipulateF(
965 array(
'integer',
'integer'),
966 array(
'0', $this->
id)
969 $this->is_closed = 0;
1003 $this->forum_id = $a_forum_id;
1011 $this->display_user_id = $a_user_id;
1019 $this->user_alias = $a_user_alias;
1027 $this->subject = $a_subject;
1035 $this->createdate = $a_createdate;
1043 if ($a_changedate ==
'0000-00-00 00:00:00') {
1044 $this->changedate = null;
1046 $this->changedate = $a_changedate;
1055 $this->import_name = $a_import_name;
1063 if ($a_last_post ==
'') {
1064 $a_last_post = null;
1067 $this->last_post_string = $a_last_post;
1075 $this->visits = $a_visits;
1083 $this->is_sticky = $a_sticky;
1087 return $this->is_sticky == 1 ? true :
false;
1091 $this->is_closed = $a_closed;
1095 return $this->is_closed == 1 ? true :
false;
1099 $this->orderField = $a_order_field;
1107 $this->is_moderator = $bool;
1145 $ilDB = $DIC->database();
1157 if (is_object(
$row)) {
1158 return $row->thr_subject;
1168 array(
'thr_subject' => array(
'text',$this->
getSubject())),
1169 array(
'thr_pk' => array(
'integer', $this->
getId()))
1173 $first_node->setSubject($this->
getSubject());
1174 $first_node->update();
1183 $this->num_posts = $a_num_posts;
1201 $this->num_new_posts = $num_new_posts;
1210 return $this->num_new_posts;
1219 $this->num_unread_posts = $num_unread_posts;
1228 return $this->num_unread_posts;
1237 $this->user_notification_enabled = $user_notification_enabled;
1246 return $this->user_notification_enabled;
1251 if (!in_array(strtoupper($direction), self::$possibleOrderDirections)) {
1252 $direction = current(self::$possibleOrderDirections);
1255 $this->orderDirection = $direction;
1267 $ilDB = $DIC->database();
1270 'SELECT thr_top_fk FROM frm_threads WHERE thr_pk = %s',
1277 return $row[
'thr_top_fk'];
1282 return $this->thread_sorting;
1289 'thr_num_posts' => array(
'integer', $this->
getNumPosts()),
1290 'visits' => array(
'integer', $this->
getVisits()),
1292 'thr_subject' => array(
'text', $this->
getSubject())
1294 array(
'thr_pk' => array(
'integer', $this->
getId()))
1305 $ilDB = $DIC->database();
1308 'SELECT thr_date FROM frm_threads WHERE thr_pk = %s',
1310 array((
int) $thread_id)
1315 return $row[
'thr_date'] ?
$row[
'thr_date'] :
'0000-00-00 00:00:00';
1331 $this->last_post =
$post;
insert()
Inserts the object data into database.
static _lookupDate($thread_id)
updateVisits()
Updates the visit counter of the current topic.
static _lookupObjIdForForumId($a_for_id)
unmakeSticky()
Sets the current topic non-sticky.
isNotificationEnabled($a_user_id)
Check whether a user's notification about new posts in a thread is enabled (result > 0) or not (resul...
setOrderDirection($direction)
setUserNotificationEnabled($user_notification_enabled)
setOrderField($a_order_field)
getFirstPostId()
Fetches the primary key of the first post node of the current topic from database and returns it...
__construct($a_id=0, $a_is_moderator=false, $preventImplicitRead=false)
Constructor.
setAverageRating($average_rating)
getLastActivePost()
Fetches and returns an object of the last active post in the current topic.
movePosts($old_obj_id, $old_pk, $new_obj_id, $new_pk)
Moves all posts within the current thread to a new forum.
setNumNewPosts($num_new_posts)
static $possibleOrderDirections
update()
Updates an existing topic.
countActivePosts($ignoreRoot=false)
Fetches and returns the number of active posts for the given user id.
setNumUnreadPosts($num_unread_posts)
setCreateDate($a_createdate)
getNestedSetPostChildren($pos_id=null, $levels=null)
setThrAuthorId($thr_author_id)
getLastPostForThreadOverview()
static getInstance($a_obj_id=0)
makeSticky()
Sets the current topic sticky.
getUserNotificationEnabled()
close()
Closes the current topic.
foreach($_POST as $key=> $value) $res
getFirstPostNode($isModerator=false, $preventImplicitRead=false)
Fetches and returns an object of the first post in the current topic.
setDisplayUserId($a_user_id)
setLastPostString($a_last_post)
setChangeDate($a_changedate)
getLastPost()
Fetches and returns an object of the last post in the current topic.
countPosts($ignoreRoot=false)
Fetches and returns the number of posts for the given user 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.
setUserAlias($a_user_alias)
setNumPosts($a_num_posts)
disableNotification($a_user_id)
Disable a user's notification about new posts in a thread.
setLastPostForThreadOverview(ilForumPost $post)
This class handles all operations on files for the forum object.
reopen()
Reopens the current topic.
getPostTree(ilForumPost $a_post_node)
Fetches and returns an array of posts from the post tree, starting with the node object passed by the...
static _lookupTitle($a_topic_id)
Looks up the title/subject of a topic/thread.
read()
Reads the data of the current object id from database and loads it into the object.
reload()
Calls the private method read() to load the topic data from database into the object.
enableNotification($a_user_id)
Enable a user's notification about new posts in a thread.
manipulateF($query, $types, $values)
setImportName($a_import_name)
static lookupForumIdByTopicId($a_topic_id)
Class to report exception.