4 require_once
'./Modules/Forum/classes/class.ilForumPost.php';
73 public function __construct($a_id = 0, $a_is_moderator =
false, $preventImplicitRead =
false)
77 $this->is_moderator = $a_is_moderator;
81 if(!$preventImplicitRead)
102 $this->
setSticky((
int) $data[
'is_sticky']);
103 $this->
setClosed((
int) $data[
'is_closed']);
124 $nextId = $this->db->nextId(
'frm_threads');
126 $this->db->insert(
'frm_threads',
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)
162 $statement = $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,
200 $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 205 array(
'integer'), array($this->
id));
211 $this->thr_pk =
$row->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;
245 return $this->
read();
256 $res = $this->db->queryf(
' 257 SELECT * FROM frm_posts_tree 259 AND parent_pos = %s',
260 array(
'integer',
'integer'), array($this->
id,
'1'));
264 return $row->pos_fk ?
$row->pos_fk : 0;
274 $checkTime = time() - (60 * 60);
276 if (
$_SESSION[
'frm_visit_frm_threads_'.$this->
id] < $checkTime)
278 $_SESSION[
'frm_visit_frm_threads_'.$this->id] = time();
280 $statement = $this->db->manipulateF(
' 282 SET visits = visits + 1 284 array(
'integer'), array($this->
id));
299 $res = $this->db->queryf(
' 302 WHERE pos_thr_fk = %s',
303 array(
'integer'), array($this->
id));
321 $res = $this->db->queryf(
' 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));
342 $res = $this->db->queryf(
' 345 INNER JOIN frm_posts_tree ON pos_fk = pos_pk 346 WHERE parent_pos = %s 348 array(
'integer',
'integer'),
349 array(
'0', $this->
id));
366 $this->db->setLimit(1);
367 $res = $this->db->queryf(
' 370 WHERE pos_thr_fk = %s 371 ORDER BY pos_date DESC',
372 array(
'integer'), array($this->
id));
394 $this->db->setLimit(1);
395 $res = $this->db->queryf(
' 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()));
419 $res = $this->db->queryf(
' 422 WHERE pos_thr_fk = %s',
450 $data_types = array();
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, 459 WHEN fur.post_id IS NULL '.
460 ($ilUser->getId() == ANONYMOUS_USER_ID ?
' AND 1 = 2 ' :
'').
' 464 firstname, lastname, title, login 472 ON pos_display_user_id = usr_id 474 LEFT JOIN frm_user_read fur 475 ON fur.thread_id = pos_thr_fk 476 AND fur.post_id = pos_pk 479 WHERE lft BETWEEN %s AND %s 482 array_push($data_types,
'integer',
'integer',
'integer',
'integer');
485 if($this->orderField !=
"")
494 $deactivated = array();
495 while(
$row = $this->db->fetchAssoc(
$res) )
498 $tmp_object->assignData(
$row);
500 if (!$this->is_moderator)
502 if (!$tmp_object->isActivated() && $tmp_object->getDisplayUserId() != $ilUser->getId())
504 $deactivated[] = $tmp_object;
509 foreach ($deactivated as $deactivated_node)
511 if ($deactivated_node->getLft() < $tmp_object->getLft() && $deactivated_node->getRgt() > $tmp_object->getLft())
513 $deactivated[] = $tmp_object;
520 if((
int)
$row[
'pos_display_user_id'])
522 $usr_ids[] = (int)$row[
'pos_display_user_id'];
524 if((
int)$row[
'update_user'])
526 $usr_ids[] = (int)$row[
'update_user'];
534 require_once
'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
535 ilForumAuthorInformationCache::preloadUserObjects(array_unique($usr_ids));
550 public function movePosts($old_obj_id, $old_pk, $new_obj_id, $new_pk)
560 foreach($nodes as $node)
563 $file_obj->moveFilesOfPost((
int)$new_obj_id);
568 $this->db->lockTables(
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));
581 $this->db->manipulateF(
' 584 WHERE thread_id = %s',
585 array(
'integer',
'integer'),
586 array($new_obj_id, $this->
id));
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));
594 $this->db->manipulateF(
' 595 UPDATE frm_thread_access 597 WHERE thread_id =%s',
598 array(
'integer',
'integer'),
599 array($new_obj_id, $this->
id));
601 $this->db->unlockTables();
603 $this->db->manipulateF(
' 606 WHERE pos_thr_fk = %s',
607 array(
'integer',
'integer'),
608 array($new_pk, $this->
id));
612 SELECT * FROM frm_posts WHERE pos_thr_fk = %s',
613 array(
'integer'), array($this->
id));
621 include_once(
"./Services/News/classes/class.ilNewsItem.php");
623 "frm", $post[
"pos_pk"],
"pos");
625 $news_item->setContextObjId($new_obj_id);
626 $news_item->update();
630 return count($nodes);
642 $is_post_activation_enabled = $objProperties->isPostActivationEnabled();
644 if( $pos_id !== null )
646 $res = $this->db->queryF(
" 651 array(
'integer',
'integer'),
652 array($pos_id, $this->
id)
668 fp.pos_display_user_id, 672 fp.is_author_moderator, 675 WHEN fur.post_id IS NULL '.
676 ($ilUser->getId() == ANONYMOUS_USER_ID ?
' AND 1 = 2 ' :
'').
' 680 COUNT(fpt2.pos_fk) children 682 FROM frm_posts_tree fpt 684 INNER JOIN frm_posts fp 685 ON fp.pos_pk = fpt.pos_fk 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 ';
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').
' 699 LEFT JOIN usr_data ud 700 ON ud.usr_id = fp.pos_display_user_id 702 WHERE fpt.thr_fk = '.$this->db->quote($this->id,
'integer');
706 $query .=
' AND fpt.lft > '.$this->db->quote(
$data[
'lft'],
'integer').
707 ' AND fpt.lft < '.$this->db->quote(
$data[
'rgt'],
'integer').
' ';
709 if($is_post_activation_enabled && !$this->is_moderator)
711 $query .=
' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_display_user_id = ' . $this->db->quote($ilUser->getId(),
'integer') .
') ';
716 $query .=
' AND '.$this->db->in(
'fpt.parent_pos', $expandedNodes,
false,
'integer').
' ';
719 $query .=
' GROUP BY fpt.depth, 728 fp.pos_display_user_id, 732 fp.is_author_moderator, 734 ORDER BY fpt.rgt DESC 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');
744 if($is_post_activation_enabled && !$this->is_moderator)
746 $queryCounter .=
' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_display_user_id = ' . $this->db->quote($ilUser->getId(),
'integer') .
') ';
748 $queryCounter .=
' ORDER BY fpt.rgt DESC';
750 $resCounter = $this->db->query($queryCounter);
753 while(
$row = $this->db->fetchAssoc($resCounter) )
755 $counter[
$row[
'pos_fk']] = $i++;
761 while(
$row = $this->db->fetchAssoc(
$res) )
763 if((
int)
$row[
'pos_display_user_id'])
765 $usr_ids[] = (int)
$row[
'pos_display_user_id'];
768 $row[
'counter'] = $counter[
$row[
'pos_pk']];
772 require_once
'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
773 ilForumAuthorInformationCache::preloadUserObjects(array_unique($usr_ids));
786 if ($this->
id && $a_user_id)
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));
794 while($record = $this->db->fetchAssoc(
$result))
796 return (
bool)$record[
'cnt'];
813 if ($this->
id && $a_user_id)
817 $nextId = $this->db->nextId(
'frm_notification');
818 $statement = $this->db->manipulateF(
' 819 INSERT INTO frm_notification 825 array(
'integer',
'integer',
'integer'),
826 array($nextId, $a_user_id, $this->
id));
844 if ($this->
id && $a_user_id)
846 $statement = $this->db->manipulateF(
' 847 DELETE FROM frm_notification 850 array(
'integer',
'integer'),
851 array($a_user_id, $this->
id));
867 if ($this->
id && !$this->is_sticky)
869 $statement = $this->db->manipulateF(
' 873 array(
'integer',
'integer'),
874 array(
'1', $this->
id));
876 $this->is_sticky = 1;
892 if ($this->
id && $this->is_sticky)
894 $statement = $this->db->manipulateF(
' 898 array(
'integer',
'integer'),
899 array(
'0', $this->
id));
901 $this->is_sticky = 0;
917 if ($this->
id && !$this->is_closed)
919 $statement = $this->db->manipulateF(
' 923 array(
'integer',
'integer'),
924 array(
'1', $this->
id));
926 $this->is_closed = 1;
942 if ($this->
id && $this->is_closed)
944 $statement = $this->db->manipulateF(
' 948 array(
'integer',
'integer'),
949 array(
'0', $this->
id));
951 $this->is_closed = 0;
985 $this->forum_id = $a_forum_id;
993 $this->display_user_id = $a_user_id;
1001 $this->user_alias = $a_user_alias;
1009 $this->subject = $a_subject;
1017 $this->createdate = $a_createdate;
1025 if($a_changedate ==
'0000-00-00 00:00:00')
1026 $this->changedate = NULL;
1028 $this->changedate = $a_changedate;
1036 $this->import_name = $a_import_name;
1044 if($a_last_post ==
'') $a_last_post = NULL;
1046 $this->last_post_string = $a_last_post;
1054 $this->visits = $a_visits;
1062 $this->is_sticky = $a_sticky;
1066 return $this->is_sticky == 1 ? true :
false;
1070 $this->is_closed = $a_closed;
1074 return $this->is_closed == 1 ? true :
false;
1078 $this->orderField = $a_order_field;
1086 $this->is_moderator = $bool;
1125 $res = $ilDB->queryf(
' 1129 array(
'integer'), array($a_topic_id));
1134 return $row->thr_subject;
1144 $ilDB->update(
'frm_threads',
1145 array(
'thr_subject' => array(
'text',$this->
getSubject())),
1146 array(
'thr_pk'=> array(
'integer', $this->
getId()))
1156 $this->num_posts = $a_num_posts;
1174 $this->num_new_posts = $num_new_posts;
1183 return $this->num_new_posts;
1192 $this->num_unread_posts = $num_unread_posts;
1201 return $this->num_unread_posts;
1210 $this->user_notification_enabled = $user_notification_enabled;
1219 return $this->user_notification_enabled;
1224 if(!in_array(strtoupper($direction), self::$possibleOrderDirections))
1226 $direction = current(self::$possibleOrderDirections);
1229 $this->orderDirection = $direction;
1242 $res = $ilDB->queryF(
'SELECT thr_top_fk FROM frm_threads WHERE thr_pk = %s',
1243 array(
'integer'), array($a_topic_id));
1247 return $row[
'thr_top_fk'];
1252 return $this->thread_sorting;
1258 $ilDB->update(
'frm_threads',
1260 'thr_num_posts' => array(
'integer', $this->
getNumPosts()),
1261 'visits' => array(
'integer', $this->
getVisits()),
1263 'thr_subject' => array(
'text', $this->
getSubject())
1265 array(
'thr_pk' => array(
'integer', $this->
getId())));
1272 $ilDB->manipulateF(
'DELETE FROM frm_threads WHERE thr_pk = %s',
1273 array(
'integer'), array($thr_id));
1285 $res = $ilDB->queryF(
'SELECT thr_date FROM frm_threads WHERE thr_pk = %s',
1286 array(
'integer'), array((
int)$thread_id));
1290 return $row[
'thr_date'] ?
$row[
'thr_date'] :
'0000-00-00 00:00:00';
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)
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.
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.
getNestedSetPostChildren($pos_id=null, $expandedNodes=array())
setNumNewPosts($num_new_posts)
static $possibleOrderDirections
update()
Updates an existing topic.
const DB_FETCHMODE_OBJECT
setNumUnreadPosts($num_unread_posts)
setCreateDate($a_createdate)
setThrAuthorId($thr_author_id)
static getInstance($a_obj_id=0)
makeSticky()
Sets the current topic sticky.
getUserNotificationEnabled()
close()
Closes the current topic.
countActivePosts()
Fetches and returns the number of active posts for the given user id.
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.
getFirstPostNode()
Fetches and returns an object of the first post in the current topic.
setUserAlias($a_user_alias)
setNumPosts($a_num_posts)
static deleteByThreadId($thr_id)
disableNotification($a_user_id)
Disable a user's notification about new posts in a thread.
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...
countPosts()
Fetches and returns the number of posts for the given user id.
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.
setImportName($a_import_name)
static lookupForumIdByTopicId($a_topic_id)