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 $this->db->setLimit(1);
258 $res = $this->db->queryf(
260 SELECT * FROM frm_posts_tree
265 array(
'integer',
'integer',
'integer'),
266 array($this->
id,
'0', 2)
271 return $row->pos_fk ? $row->pos_fk : 0;
281 $checkTime = time() - (60 * 60);
283 if (
$_SESSION[
'frm_visit_frm_threads_' . $this->
id] < $checkTime) {
286 $this->db->manipulateF(
289 SET visits = visits + 1
308 $res = $this->db->queryf(
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 ' :
''),
332 $res = $this->db->queryf(
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)
357 $res = $this->db->queryF(
361 INNER JOIN frm_posts_tree ON pos_fk = pos_pk
362 WHERE parent_pos = %s
364 array(
'integer',
'integer'),
368 $row = $this->db->fetchAssoc(
$res);
370 $post =
new ilForumPost($row[
'pos_pk'], $isModerator, $preventImplicitRead);
371 $post->assignData($row);
385 $this->db->setLimit(1);
386 $res = $this->db->queryf(
390 WHERE pos_thr_fk = %s
391 ORDER BY pos_date DESC',
413 $this->db->setLimit(1);
414 $res = $this->db->queryf(
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())
439 $res = $this->db->queryf(
443 WHERE pos_thr_fk = %s',
449 $posts[$row->pos_pk] = $row;
453 return is_array($posts) ? $posts : array();
469 $data_types = array();
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,
478 WHEN fur.post_id IS NULL ' .
483 firstname, lastname, title, login
491 ON pos_display_user_id = usr_id
493 LEFT JOIN frm_user_read fur
494 ON fur.thread_id = pos_thr_fk
495 AND fur.post_id = pos_pk
498 WHERE lft > %s AND lft < %s
501 array_push($data_types,
'integer',
'integer',
'integer',
'integer');
504 if ($this->orderField !=
"") {
511 while ($row = $this->db->fetchAssoc(
$res)) {
512 $post =
new ilForumPost($row[
'pos_pk'],
false,
true);
513 $post->assignData($row);
515 if (!$this->is_moderator) {
516 if (!$post->isActivated() && $post->getPosAuthorId() != $this->user->getId()) {
521 if ((
int) $row[
'pos_display_user_id']) {
522 $usr_ids[(int) $row[
'pos_display_user_id']] = (
int) $row[
'pos_display_user_id'];
524 if ((
int) $row[
'update_user']) {
525 $usr_ids[(int) $row[
'update_user']] = (
int) $row[
'update_user'];
546 public function movePosts($old_obj_id, $old_pk, $new_obj_id, $new_pk)
550 if (is_array($nodes)) {
551 $postsMoved = array();
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);
558 if (
true === $moved) {
559 $postsMoved[] = array(
560 'from' => $old_obj_id,
562 'position_id' => (
int) $node->pos_pk
569 foreach ($postsMoved as $postedInformation) {
570 $file_obj =
new ilFileDataForum($postedInformation[
'to'], $postedInformation[
'position_id']);
571 $file_obj->moveFilesOfPost($postedInformation[
'from']);
580 $ilAtomQuery = $this->db->buildAtomQuery();
581 $ilAtomQuery->addTableLock(
'frm_user_read');
582 $ilAtomQuery->addTableLock(
'frm_thread_access');
584 $ilAtomQuery->addQueryCallable(
function (
ilDBInterface $ilDB) use ($new_obj_id, $current_id) {
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)
597 WHERE thread_id = %s',
598 array(
'integer',
'integer'),
599 array($new_obj_id, $current_id)
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)
612 UPDATE frm_thread_access
614 WHERE thread_id =%s',
615 array(
'integer',
'integer'),
616 array($new_obj_id, $current_id)
622 $this->db->manipulateF(
626 WHERE pos_thr_fk = %s',
627 array(
'integer',
'integer'),
628 array($new_pk, $this->
id)
632 $posts = $this->db->queryf(
634 SELECT * FROM frm_posts WHERE pos_thr_fk = %s',
651 $news_item->setContextObjId($new_obj_id);
652 $news_item->update();
655 return count($nodes);
665 $is_post_activation_enabled = $objProperties->isPostActivationEnabled();
667 if ($pos_id !==
null) {
668 $res = $this->db->queryF(
670 SELECT lft, rgt, depth
674 array(
'integer',
'integer'),
675 array($pos_id, $this->
id)
691 fp.pos_display_user_id,
695 fp.is_author_moderator,
698 WHEN fur.post_id IS NULL ' .
703 COUNT(fpt2.pos_fk) children
705 FROM frm_posts_tree fpt
707 INNER JOIN frm_posts fp
708 ON fp.pos_pk = fpt.pos_fk
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 ';
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') .
'
722 LEFT JOIN usr_data ud
723 ON ud.usr_id = fp.pos_display_user_id
725 WHERE fpt.thr_fk = ' . $this->db->quote($this->id,
'integer');
728 $query .=
' AND fpt.lft > ' . $this->db->quote(
$data[
'lft'],
'integer') .
729 ' AND fpt.lft < ' . $this->db->quote(
$data[
'rgt'],
'integer') .
' ';
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') .
') ';
735 if (
$data && is_numeric($levels)) {
736 $query .=
' AND fpt.depth <= ' . $this->db->quote(
$data[
'depth'] + $levels,
'integer') .
' ';
739 $query .=
' GROUP BY fpt.depth,
748 fp.pos_display_user_id,
752 fp.is_author_moderator,
754 ORDER BY fpt.rgt DESC
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');
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') .
') ';
767 $queryCounter .=
' ORDER BY fpt.rgt DESC';
769 $resCounter = $this->db->query($queryCounter);
772 while ($row = $this->db->fetchAssoc($resCounter)) {
773 $counter[$row[
'pos_fk']] =
$i++;
779 while ($row = $this->db->fetchAssoc(
$res)) {
780 if ((
int) $row[
'pos_display_user_id']) {
781 $usr_ids[] = (int) $row[
'pos_display_user_id'];
784 $row[
'counter'] = $counter[$row[
'pos_pk']];
801 if ($this->
id && $a_user_id) {
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)
810 while ($record = $this->db->fetchAssoc(
$result)) {
811 return (
bool) $record[
'cnt'];
828 if ($this->
id && $a_user_id) {
830 $nextId = $this->db->nextId(
'frm_notification');
831 $this->db->manipulateF(
833 INSERT INTO frm_notification
839 array(
'integer',
'integer',
'integer'),
840 array($nextId, $a_user_id, $this->
id)
859 if ($this->
id && $a_user_id) {
860 $this->db->manipulateF(
862 DELETE FROM frm_notification
865 array(
'integer',
'integer'),
866 array($a_user_id, $this->
id)
883 if ($this->
id && !$this->is_sticky) {
884 $this->db->manipulateF(
889 array(
'integer',
'integer'),
890 array(
'1', $this->
id)
893 $this->is_sticky = 1;
909 if ($this->
id && $this->is_sticky) {
910 $this->db->manipulateF(
915 array(
'integer',
'integer'),
916 array(
'0', $this->
id)
919 $this->is_sticky = 0;
935 if ($this->
id && !$this->is_closed) {
936 $this->db->manipulateF(
941 array(
'integer',
'integer'),
942 array(
'1', $this->
id)
945 $this->is_closed = 1;
961 if ($this->
id && $this->is_closed) {
962 $this->db->manipulateF(
967 array(
'integer',
'integer'),
968 array(
'0', $this->
id)
971 $this->is_closed = 0;
1005 $this->forum_id = $a_forum_id;
1013 $this->display_user_id = $a_user_id;
1021 $this->user_alias = $a_user_alias;
1029 $this->subject = $a_subject;
1037 $this->createdate = $a_createdate;
1045 if ($a_changedate ==
'0000-00-00 00:00:00') {
1046 $this->changedate =
null;
1048 $this->changedate = $a_changedate;
1057 $this->import_name = $a_import_name;
1065 if ($a_last_post ==
'') {
1066 $a_last_post =
null;
1069 $this->last_post_string = $a_last_post;
1077 $this->visits = $a_visits;
1085 $this->is_sticky = $a_sticky;
1089 return $this->is_sticky == 1 ?
true :
false;
1093 $this->is_closed = $a_closed;
1097 return $this->is_closed == 1 ?
true :
false;
1101 $this->orderField = $a_order_field;
1109 $this->is_moderator = $bool;
1159 if (is_object($row)) {
1160 return $row->thr_subject;
1170 array(
'thr_subject' => array(
'text',$this->
getSubject())),
1171 array(
'thr_pk' => array(
'integer', $this->
getId()))
1175 $first_node->setSubject($this->
getSubject());
1176 $first_node->update();
1185 $this->num_posts = $a_num_posts;
1203 $this->num_new_posts = $num_new_posts;
1212 return $this->num_new_posts;
1221 $this->num_unread_posts = $num_unread_posts;
1230 return $this->num_unread_posts;
1239 $this->user_notification_enabled = $user_notification_enabled;
1248 return $this->user_notification_enabled;
1253 if (!in_array(strtoupper($direction), self::$possibleOrderDirections)) {
1254 $direction = current(self::$possibleOrderDirections);
1257 $this->orderDirection = $direction;
1272 'SELECT thr_top_fk FROM frm_threads WHERE thr_pk = %s',
1279 return $row[
'thr_top_fk'];
1284 return $this->thread_sorting;
1291 'thr_num_posts' => array(
'integer', $this->
getNumPosts()),
1292 'visits' => array(
'integer', $this->
getVisits()),
1294 'thr_subject' => array(
'text', $this->
getSubject())
1296 array(
'thr_pk' => array(
'integer', $this->
getId()))
1310 'SELECT thr_date FROM frm_threads WHERE thr_pk = %s',
1312 array((
int) $thread_id)
1317 return $row[
'thr_date'] ? $row[
'thr_date'] :
'0000-00-00 00:00:00';
1333 $this->last_post = $post;
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)
getUserNotificationEnabled()
setChangeDate($a_changedate)
updateVisits()
Updates the visit counter of the current topic.
setNumPosts($a_num_posts)
countPosts($ignoreRoot=false)
Fetches and returns the number of posts for the given user id.
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.
getLastPostForThreadOverview()
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
foreach($_POST as $key=> $value) $res