4 require_once
'./Modules/Forum/classes/class.ilForumPost.php';
66 public function __construct($a_id = 0, $a_is_moderator =
false, $preventImplicitRead =
false)
70 $this->is_moderator = $a_is_moderator;
74 if(!$preventImplicitRead)
88 $this->
setUserId((
int) $data[
'thr_usr_id']);
95 $this->
setSticky((
int) $data[
'is_sticky']);
96 $this->
setClosed((
int) $data[
'is_closed']);
115 $nextId = $this->db->nextId(
'frm_threads');
116 $statement = $this->db->manipulateF(
' 117 INSERT INTO frm_threads 131 VALUES(%s,%s,%s,%s,%s,%s,%s,%s, %s, %s,%s,%s)',
151 $this->last_post_string,
176 $statement = $this->db->manipulateF(
' 184 array(
'integer',
'text',
'timestamp',
'integer',
'text',
'integer'),
185 array( $this->forum_id,
190 $this->last_post_string,
212 $res = $this->db->queryf(
' 213 SELECT frm_threads.*, top_frm_fk frm_obj_id 215 INNER JOIN frm_data ON top_pk = thr_top_fk 217 array(
'integer'), array($this->
id));
224 $this->thr_pk =
$row->pos_pk;
225 $this->forum_id =
$row->thr_top_fk;
226 $this->user_id =
$row->thr_usr_id;
227 $this->user_alias =
$row->thr_usr_alias;
228 $this->subject = html_entity_decode(
$row->thr_subject);
229 $this->createdate =
$row->thr_date;
230 $this->changedate =
$row->thr_update;
231 $this->import_name =
$row->import_name;
232 $this->num_posts =
$row->thr_num_posts;
233 $this->last_post_string =
$row->thr_last_post;
234 $this->visits =
$row->visits;
235 $this->is_sticky =
$row->is_sticky;
236 $this->is_closed =
$row->is_closed;
237 $this->frm_obj_id =
$row->frm_obj_id;
256 return $this->
read();
267 $res = $this->db->queryf(
' 268 SELECT * FROM frm_posts_tree 270 AND parent_pos = %s',
271 array(
'integer',
'integer'), array($this->
id,
'1'));
275 return $row->pos_fk ?
$row->pos_fk : 0;
285 $checkTime = time() - (60 * 60);
287 if (
$_SESSION[
'frm_visit_frm_threads_'.$this->
id] < $checkTime)
289 $_SESSION[
'frm_visit_frm_threads_'.$this->id] = time();
291 $statement = $this->db->manipulateF(
' 293 SET visits = visits + 1 295 array(
'integer'), array($this->
id));
310 $res = $this->db->queryf(
' 313 WHERE pos_thr_fk = %s',
314 array(
'integer'), array($this->
id));
332 $res = $this->db->queryf(
' 335 WHERE (pos_status = %s 336 OR (pos_status = %s AND pos_usr_id = %s)) 337 AND pos_thr_fk = %s',
338 array(
'integer',
'integer',
'integer',
'integer'), array(
'1',
'0', $ilUser->getId(),
$this->id));
353 $res = $this->db->queryf(
' 356 INNER JOIN frm_posts_tree ON pos_fk = pos_pk 357 WHERE parent_pos = %s 359 array(
'integer',
'integer'),
360 array(
'0', $this->
id));
377 $this->db->setLimit(1);
378 $res = $this->db->queryf(
' 381 WHERE pos_thr_fk = %s 382 ORDER BY pos_date DESC',
383 array(
'integer'), array($this->
id));
405 $this->db->setLimit(1);
406 $res = $this->db->queryf(
' 409 WHERE pos_thr_fk = %s 410 AND (pos_status = %s OR 411 (pos_status = %s AND pos_usr_id = %s)) 412 ORDER BY pos_date DESC',
413 array(
'integer',
'integer',
'integer',
'integer'),
414 array($this->
id,
'1',
'0', $ilUser->getId()));
430 $res = $this->db->queryf(
' 433 WHERE pos_thr_fk = %s',
461 $data_types = array();
464 SELECT pos_pk, fpt_date, rgt, pos_top_fk, pos_thr_fk, 465 pos_usr_id, pos_usr_alias, pos_subject, 466 pos_status, pos_message, pos_date, pos_update, 467 update_user, pos_cens, pos_cens_com, notify, 468 import_name, fpt_pk, parent_pos, lft, depth, 470 WHEN fur.post_id IS NULL '.
471 ($ilUser->getId() == ANONYMOUS_USER_ID ?
' AND 1 = 2 ' :
'').
' 475 firstname, lastname, title, login 483 ON pos_usr_id = usr_id 485 LEFT JOIN frm_user_read fur 486 ON fur.thread_id = pos_thr_fk 487 AND fur.post_id = pos_pk 490 WHERE lft BETWEEN %s AND %s 493 array_push($data_types,
'integer',
'integer',
'integer',
'integer');
496 if($this->orderField !=
"")
505 $deactivated = array();
506 while(
$row = $this->db->fetchAssoc(
$res) )
509 $tmp_object->assignData(
$row);
511 if (!$this->is_moderator)
513 if (!$tmp_object->isActivated() && $tmp_object->getUserId() != $ilUser->getId())
515 $deactivated[] = $tmp_object;
520 foreach ($deactivated as $deactivated_node)
522 if ($deactivated_node->getLft() < $tmp_object->getLft() && $deactivated_node->getRgt() > $tmp_object->getLft())
524 $deactivated[] = $tmp_object;
531 if((
int)
$row[
'pos_usr_id'])
533 $usr_ids[] = (int)$row[
'pos_usr_id'];
535 if((
int)$row[
'update_user'])
537 $usr_ids[] = (int)$row[
'update_user'];
545 require_once
'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
546 ilForumAuthorInformationCache::preloadUserObjects(array_unique($usr_ids));
561 public function movePosts($old_obj_id, $old_pk, $new_obj_id, $new_pk)
571 foreach($nodes as $node)
574 $file_obj->moveFilesOfPost((
int)$new_obj_id);
579 $this->db->lockTables(
586 $this->db->manipulateF(
' 587 DELETE FROM frm_user_read 588 WHERE obj_id = %s AND thread_id =%s',
589 array(
'integer',
'integer'),
590 array($new_obj_id, $this->
id));
592 $this->db->manipulateF(
' 595 WHERE thread_id = %s',
596 array(
'integer',
'integer'),
597 array($new_obj_id, $this->
id));
599 $this->db->manipulateF(
' 600 DELETE FROM frm_thread_access 601 WHERE obj_id = %s AND thread_id =%s',
602 array(
'integer',
'integer'),
603 array($new_obj_id, $this->
id));
605 $this->db->manipulateF(
' 606 UPDATE frm_thread_access 608 WHERE thread_id =%s',
609 array(
'integer',
'integer'),
610 array($new_obj_id, $this->
id));
612 $this->db->unlockTables();
614 $this->db->manipulateF(
' 617 WHERE pos_thr_fk = %s',
618 array(
'integer',
'integer'),
619 array($new_pk, $this->
id));
623 SELECT * FROM frm_posts WHERE pos_thr_fk = %s',
624 array(
'integer'), array($this->
id));
632 include_once(
"./Services/News/classes/class.ilNewsItem.php");
634 "frm", $post[
"pos_pk"],
"pos");
636 $news_item->setContextObjId($new_obj_id);
637 $news_item->update();
641 return count($nodes);
653 if( $pos_id !== null )
655 $res = $this->db->queryF(
" 660 array(
'integer',
'integer'),
661 array($pos_id, $this->
id)
682 WHEN fur.post_id IS NULL '.
683 ($ilUser->getId() == ANONYMOUS_USER_ID ?
' AND 1 = 2 ' :
'').
' 687 COUNT(fpt2.pos_fk) children 689 FROM frm_posts_tree fpt 691 INNER JOIN frm_posts fp 692 ON fp.pos_pk = fpt.pos_fk 694 LEFT JOIN frm_posts_tree fpt2 695 ON fpt2.lft BETWEEN fpt.lft AND fpt.rgt 696 AND fpt.thr_fk = fpt2.thr_fk 697 AND fpt.pos_fk != fpt2.pos_fk ';
701 LEFT JOIN frm_user_read fur 702 ON fur.thread_id = fp.pos_thr_fk 703 AND fur.post_id = fp.pos_pk 704 AND fur.usr_id = '.$this->db->quote($ilUser->getId(),
'integer').
' 706 LEFT JOIN usr_data ud 707 ON ud.usr_id = fp.pos_usr_id 709 WHERE fpt.thr_fk = '.$this->db->quote($this->id,
'integer');
713 $query .=
' AND fpt.lft > '.$this->db->quote(
$data[
'lft'],
'integer').
714 ' AND fpt.lft < '.$this->db->quote(
$data[
'rgt'],
'integer').
' ';
717 if( !$this->is_moderator )
719 $query .=
' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_usr_id = '.
720 $this->db->quote($ilUser->getId(),
'integer').
') ';
725 $query .=
' AND '.$this->db->in(
'fpt.parent_pos', $expandedNodes,
false,
'integer').
' ';
729 $query .=
' GROUP BY fpt.depth, 742 ORDER BY fpt.rgt DESC 747 FROM frm_posts_tree fpt 748 INNER JOIN frm_posts fp 749 ON fp.pos_pk = fpt.pos_fk 750 WHERE fpt.thr_fk = '.$this->db->quote($this->
id,
'integer');
751 if( !$this->is_moderator )
753 $queryCounter .=
' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_usr_id = '.
754 $this->db->quote($ilUser->getId(),
'integer').
') ';
756 $queryCounter .=
' ORDER BY fpt.rgt DESC';
758 $resCounter = $this->db->query($queryCounter);
761 while(
$row = $this->db->fetchAssoc($resCounter) )
763 $counter[
$row[
'pos_fk']] = $i++;
769 while(
$row = $this->db->fetchAssoc(
$res) )
771 if((
int)
$row[
'pos_usr_id'])
773 $usr_ids[] = (int)
$row[
'pos_usr_id'];
776 $row[
'counter'] = $counter[
$row[
'pos_pk']];
780 require_once
'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
781 ilForumAuthorInformationCache::preloadUserObjects(array_unique($usr_ids));
794 if ($this->
id && $a_user_id)
797 SELECT COUNT(notification_id) cnt FROM frm_notification 798 WHERE user_id = %s AND thread_id = %s',
799 array(
'integer',
'integer'),
800 array($a_user_id, $this->
id));
802 while($record = $this->db->fetchAssoc(
$result))
804 return (
bool)$record[
'cnt'];
821 if ($this->
id && $a_user_id)
825 $nextId = $this->db->nextId(
'frm_notification');
826 $statement = $this->db->manipulateF(
' 827 INSERT INTO frm_notification 833 array(
'integer',
'integer',
'integer'),
834 array($nextId, $a_user_id, $this->
id));
852 if ($this->
id && $a_user_id)
854 $statement = $this->db->manipulateF(
' 855 DELETE FROM frm_notification 858 array(
'integer',
'integer'),
859 array($a_user_id, $this->
id));
875 if ($this->
id && !$this->is_sticky)
877 $statement = $this->db->manipulateF(
' 881 array(
'integer',
'integer'),
882 array(
'1', $this->
id));
884 $this->is_sticky = 1;
900 if ($this->
id && $this->is_sticky)
902 $statement = $this->db->manipulateF(
' 906 array(
'integer',
'integer'),
907 array(
'0', $this->
id));
909 $this->is_sticky = 0;
925 if ($this->
id && !$this->is_closed)
927 $statement = $this->db->manipulateF(
' 931 array(
'integer',
'integer'),
932 array(
'1', $this->
id));
934 $this->is_closed = 1;
950 if ($this->
id && $this->is_closed)
952 $statement = $this->db->manipulateF(
' 956 array(
'integer',
'integer'),
957 array(
'0', $this->
id));
959 $this->is_closed = 0;
977 $this->forum_id = $a_forum_id;
985 $this->user_id = $a_user_id;
993 $this->user_alias = $a_user_alias;
1001 $this->subject = $a_subject;
1009 $this->createdate = $a_createdate;
1017 if($a_changedate ==
'0000-00-00 00:00:00')
1018 $this->changedate = NULL;
1020 $this->changedate = $a_changedate;
1028 $this->import_name = $a_import_name;
1036 if($a_last_post ==
'') $a_last_post = NULL;
1038 $this->last_post_string = $a_last_post;
1046 $this->visits = $a_visits;
1054 $this->is_sticky = $a_sticky;
1058 return $this->is_sticky == 1 ? true :
false;
1062 $this->is_closed = $a_closed;
1066 return $this->is_closed == 1 ? true :
false;
1070 $this->orderField = $a_order_field;
1078 $this->is_moderator = $bool;
1101 $res = $ilDB->queryf(
' 1105 array(
'integer'), array($a_topic_id));
1110 return $row->thr_subject;
1120 $ilDB->update(
'frm_threads',
1121 array(
'thr_subject' => array(
'text',$this->
getSubject())),
1122 array(
'thr_pk'=> array(
'integer', $this->
getId()))
1132 $this->num_posts = $a_num_posts;
1150 $this->num_new_posts = $num_new_posts;
1159 return $this->num_new_posts;
1168 $this->num_unread_posts = $num_unread_posts;
1177 return $this->num_unread_posts;
1186 $this->user_notification_enabled = $user_notification_enabled;
1195 return $this->user_notification_enabled;
1200 if(!in_array(strtoupper($direction), self::$possibleOrderDirections))
1202 $direction = current(self::$possibleOrderDirections);
1205 $this->orderDirection = $direction;
1218 $res = $ilDB->queryF(
'SELECT thr_top_fk FROM frm_threads WHERE thr_pk = %s',
1219 array(
'integer'), array($a_topic_id));
1223 return $row[
'thr_top_fk'];
1228 return $this->thread_sorting;
1234 $ilDB->update(
'frm_threads',
1236 'thr_num_posts' => array(
'integer', $this->
getNumPosts()),
1237 'visits' => array(
'integer', $this->
getVisits()),
1239 'thr_subject' => array(
'text', $this->
getSubject())
1241 array(
'thr_pk' => array(
'integer', $this->
getId())));
1248 $ilDB->manipulateF(
'DELETE FROM frm_threads WHERE thr_pk = %s',
1249 array(
'integer'), array($thr_id));
1261 $res = $ilDB->queryF(
'SELECT thr_date FROM frm_threads WHERE thr_pk = %s',
1262 array(
'integer'), array((
int)$thread_id));
1266 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.
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)
fetchAssoc($a_set)
Fetch row as associative array from result set.
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.
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.
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
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)