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 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)
280 $statement = $this->db->manipulateF(
' 282 SET visits = visits + 1 299 $res = $this->db->queryf(
' 302 WHERE pos_thr_fk = %s',
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',
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);
570 $ilAtomQuery = $ilDB->buildAtomQuery();
571 $ilAtomQuery->addTableLock(
'frm_user_read');
572 $ilAtomQuery->addTableLock(
'frm_thread_access');
574 $ilAtomQuery->addQueryCallable(
function (
ilDBInterface $ilDB) use ($new_obj_id, $current_id) {
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));
584 WHERE thread_id = %s',
585 array(
'integer',
'integer'),
586 array($new_obj_id, $current_id));
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));
595 UPDATE frm_thread_access 597 WHERE thread_id =%s',
598 array(
'integer',
'integer'),
599 array($new_obj_id, $current_id));
604 $this->db->manipulateF(
' 607 WHERE pos_thr_fk = %s',
608 array(
'integer',
'integer'),
609 array($new_pk, $this->
id));
613 SELECT * FROM frm_posts WHERE pos_thr_fk = %s',
622 include_once(
"./Services/News/classes/class.ilNewsItem.php");
624 "frm", $post[
"pos_pk"],
"pos");
626 $news_item->setContextObjId($new_obj_id);
627 $news_item->update();
631 return count($nodes);
643 $is_post_activation_enabled = $objProperties->isPostActivationEnabled();
645 if( $pos_id !== null )
647 $res = $this->db->queryF(
" 648 SELECT lft, rgt, depth 652 array(
'integer',
'integer'),
653 array($pos_id, $this->
id)
669 fp.pos_display_user_id, 673 fp.is_author_moderator, 676 WHEN fur.post_id IS NULL '.
677 ($ilUser->getId() == ANONYMOUS_USER_ID ?
' AND 1 = 2 ' :
'').
' 681 COUNT(fpt2.pos_fk) children 683 FROM frm_posts_tree fpt 685 INNER JOIN frm_posts fp 686 ON fp.pos_pk = fpt.pos_fk 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 ';
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').
' 700 LEFT JOIN usr_data ud 701 ON ud.usr_id = fp.pos_display_user_id 703 WHERE fpt.thr_fk = '.$this->db->quote($this->id,
'integer');
707 $query .=
' AND fpt.lft > '.$this->db->quote(
$data[
'lft'],
'integer').
708 ' AND fpt.lft < '.$this->db->quote(
$data[
'rgt'],
'integer').
' ';
710 if($is_post_activation_enabled && !$this->is_moderator)
712 $query .=
' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_display_user_id = ' . $this->db->quote($ilUser->getId(),
'integer') .
') ';
715 if(
$data && is_numeric($levels) )
717 $query .=
' AND fpt.depth <= '.$this->db->quote(
$data[
'depth'] + $levels,
'integer').
' ';
720 $query .=
' GROUP BY fpt.depth, 729 fp.pos_display_user_id, 733 fp.is_author_moderator, 735 ORDER BY fpt.rgt DESC 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');
745 if($is_post_activation_enabled && !$this->is_moderator)
747 $queryCounter .=
' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_display_user_id = ' . $this->db->quote($ilUser->getId(),
'integer') .
') ';
749 $queryCounter .=
' ORDER BY fpt.rgt DESC';
751 $resCounter = $this->db->query($queryCounter);
754 while(
$row = $this->db->fetchAssoc($resCounter) )
762 while(
$row = $this->db->fetchAssoc(
$res) )
764 if((
int)
$row[
'pos_display_user_id'])
766 $usr_ids[] = (int)
$row[
'pos_display_user_id'];
773 require_once
'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
774 ilForumAuthorInformationCache::preloadUserObjects(array_unique($usr_ids));
787 if ($this->
id && $a_user_id)
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));
795 while($record = $this->db->fetchAssoc(
$result))
797 return (
bool)$record[
'cnt'];
814 if ($this->
id && $a_user_id)
818 $nextId = $this->db->nextId(
'frm_notification');
819 $statement = $this->db->manipulateF(
' 820 INSERT INTO frm_notification 826 array(
'integer',
'integer',
'integer'),
827 array($nextId, $a_user_id, $this->
id));
845 if ($this->
id && $a_user_id)
847 $statement = $this->db->manipulateF(
' 848 DELETE FROM frm_notification 851 array(
'integer',
'integer'),
852 array($a_user_id, $this->
id));
868 if ($this->
id && !$this->is_sticky)
870 $statement = $this->db->manipulateF(
' 874 array(
'integer',
'integer'),
875 array(
'1', $this->
id));
877 $this->is_sticky = 1;
893 if ($this->
id && $this->is_sticky)
895 $statement = $this->db->manipulateF(
' 899 array(
'integer',
'integer'),
900 array(
'0', $this->
id));
902 $this->is_sticky = 0;
918 if ($this->
id && !$this->is_closed)
920 $statement = $this->db->manipulateF(
' 924 array(
'integer',
'integer'),
925 array(
'1', $this->
id));
927 $this->is_closed = 1;
943 if ($this->
id && $this->is_closed)
945 $statement = $this->db->manipulateF(
' 949 array(
'integer',
'integer'),
950 array(
'0', $this->
id));
952 $this->is_closed = 0;
986 $this->forum_id = $a_forum_id;
994 $this->display_user_id = $a_user_id;
1002 $this->user_alias = $a_user_alias;
1010 $this->subject = $a_subject;
1018 $this->createdate = $a_createdate;
1026 if($a_changedate ==
'0000-00-00 00:00:00')
1027 $this->changedate = NULL;
1029 $this->changedate = $a_changedate;
1037 $this->import_name = $a_import_name;
1045 if($a_last_post ==
'') $a_last_post = NULL;
1047 $this->last_post_string = $a_last_post;
1055 $this->visits = $a_visits;
1063 $this->is_sticky = $a_sticky;
1067 return $this->is_sticky == 1 ? true :
false;
1071 $this->is_closed = $a_closed;
1075 return $this->is_closed == 1 ? true :
false;
1079 $this->orderField = $a_order_field;
1087 $this->is_moderator = $bool;
1126 $res = $ilDB->queryf(
' 1135 return $row->thr_subject;
1145 $ilDB->update(
'frm_threads',
1157 $this->num_posts = $a_num_posts;
1175 $this->num_new_posts = $num_new_posts;
1184 return $this->num_new_posts;
1193 $this->num_unread_posts = $num_unread_posts;
1202 return $this->num_unread_posts;
1211 $this->user_notification_enabled = $user_notification_enabled;
1220 return $this->user_notification_enabled;
1225 if(!in_array(strtoupper($direction), self::$possibleOrderDirections))
1227 $direction = current(self::$possibleOrderDirections);
1230 $this->orderDirection = $direction;
1243 $res = $ilDB->queryF(
'SELECT thr_top_fk FROM frm_threads WHERE thr_pk = %s',
1248 return $row[
'thr_top_fk'];
1253 return $this->thread_sorting;
1259 $ilDB->update(
'frm_threads',
1273 $ilDB->manipulateF(
'DELETE FROM frm_threads WHERE thr_pk = %s',
1286 $res = $ilDB->queryF(
'SELECT thr_date FROM frm_threads WHERE thr_pk = %s',
1291 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.
setNumNewPosts($num_new_posts)
static $possibleOrderDirections
update()
Updates an existing topic.
setNumUnreadPosts($num_unread_posts)
setCreateDate($a_createdate)
getNestedSetPostChildren($pos_id=null, $levels=null)
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.
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
setDisplayUserId($a_user_id)
setLastPostString($a_last_post)
Create styles array
The data for the language used.
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...
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
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.
manipulateF($query, $types, $values)
setImportName($a_import_name)
static lookupForumIdByTopicId($a_topic_id)