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)
681 WHEN fur.post_id IS NULL '.
682 ($ilUser->getId() == ANONYMOUS_USER_ID ?
' AND 1 = 2 ' :
'').
'
686 COUNT(fpt2.pos_fk) children
688 FROM frm_posts_tree fpt
690 INNER JOIN frm_posts fp
691 ON fp.pos_pk = fpt.pos_fk
693 LEFT JOIN frm_posts_tree fpt2
694 ON fpt2.lft BETWEEN fpt.lft AND fpt.rgt
695 AND fpt.thr_fk = fpt2.thr_fk
696 AND fpt.pos_fk != fpt2.pos_fk ';
700 LEFT JOIN frm_user_read fur
701 ON fur.thread_id = fp.pos_thr_fk
702 AND fur.post_id = fp.pos_pk
703 AND fur.usr_id = '.$this->db->quote($ilUser->getId(),
'integer').
'
705 LEFT JOIN usr_data ud
706 ON ud.usr_id = fp.pos_usr_id
708 WHERE fpt.thr_fk = '.$this->db->quote($this->id,
'integer');
712 $query .=
' AND fpt.lft > '.$this->db->quote(
$data[
'lft'],
'integer').
713 ' AND fpt.lft < '.$this->db->quote(
$data[
'rgt'],
'integer').
' ';
716 if( !$this->is_moderator )
718 $query .=
' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_usr_id = '.
719 $this->db->quote($ilUser->getId(),
'integer').
') ';
724 $query .=
' AND '.$this->db->in(
'fpt.parent_pos', $expandedNodes,
false,
'integer').
' ';
728 $query .=
' GROUP BY fpt.depth,
740 ORDER BY fpt.rgt DESC
745 FROM frm_posts_tree fpt
746 INNER JOIN frm_posts fp
747 ON fp.pos_pk = fpt.pos_fk
748 WHERE fpt.thr_fk = '.$this->db->quote($this->
id,
'integer');
749 if( !$this->is_moderator )
751 $queryCounter .=
' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_usr_id = '.
752 $this->db->quote($ilUser->getId(),
'integer').
') ';
754 $queryCounter .=
' ORDER BY fpt.rgt DESC';
756 $resCounter = $this->db->query($queryCounter);
759 while(
$row = $this->db->fetchAssoc($resCounter) )
761 $counter[
$row[
'pos_fk']] = $i++;
767 while(
$row = $this->db->fetchAssoc(
$res) )
769 if((
int)
$row[
'pos_usr_id'])
771 $usr_ids[] = (int)
$row[
'pos_usr_id'];
774 $row[
'counter'] = $counter[
$row[
'pos_pk']];
778 require_once
'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
779 ilForumAuthorInformationCache::preloadUserObjects(array_unique($usr_ids));
792 if ($this->
id && $a_user_id)
795 SELECT COUNT(notification_id) cnt FROM frm_notification
796 WHERE user_id = %s AND thread_id = %s',
797 array(
'integer',
'integer'),
798 array($a_user_id, $this->
id));
800 while($record = $this->db->fetchAssoc(
$result))
802 return (
bool)$record[
'cnt'];
819 if ($this->
id && $a_user_id)
823 $nextId = $this->db->nextId(
'frm_notification');
824 $statement = $this->db->manipulateF(
'
825 INSERT INTO frm_notification
831 array(
'integer',
'integer',
'integer'),
832 array($nextId, $a_user_id, $this->
id));
850 if ($this->
id && $a_user_id)
852 $statement = $this->db->manipulateF(
'
853 DELETE FROM frm_notification
856 array(
'integer',
'integer'),
857 array($a_user_id, $this->
id));
873 if ($this->
id && !$this->is_sticky)
875 $statement = $this->db->manipulateF(
'
879 array(
'integer',
'integer'),
880 array(
'1', $this->
id));
882 $this->is_sticky = 1;
898 if ($this->
id && $this->is_sticky)
900 $statement = $this->db->manipulateF(
'
904 array(
'integer',
'integer'),
905 array(
'0', $this->
id));
907 $this->is_sticky = 0;
923 if ($this->
id && !$this->is_closed)
925 $statement = $this->db->manipulateF(
'
929 array(
'integer',
'integer'),
930 array(
'1', $this->
id));
932 $this->is_closed = 1;
948 if ($this->
id && $this->is_closed)
950 $statement = $this->db->manipulateF(
'
954 array(
'integer',
'integer'),
955 array(
'0', $this->
id));
957 $this->is_closed = 0;
975 $this->forum_id = $a_forum_id;
983 $this->user_id = $a_user_id;
991 $this->user_alias = $a_user_alias;
999 $this->subject = $a_subject;
1007 $this->createdate = $a_createdate;
1015 if($a_changedate ==
'0000-00-00 00:00:00')
1016 $this->changedate = NULL;
1018 $this->changedate = $a_changedate;
1026 $this->import_name = $a_import_name;
1034 if($a_last_post ==
'') $a_last_post = NULL;
1036 $this->last_post_string = $a_last_post;
1044 $this->visits = $a_visits;
1052 $this->is_sticky = $a_sticky;
1056 return $this->is_sticky == 1 ?
true :
false;
1060 $this->is_closed = $a_closed;
1064 return $this->is_closed == 1 ?
true :
false;
1068 $this->orderField = $a_order_field;
1076 $this->is_moderator = $bool;
1099 $res = $ilDB->queryf(
'
1103 array(
'integer'), array($a_topic_id));
1108 return $row->thr_subject;
1118 $ilDB->update(
'frm_threads',
1119 array(
'thr_subject' => array(
'text',$this->
getSubject())),
1120 array(
'thr_pk'=> array(
'integer', $this->
getId()))
1130 $this->num_posts = $a_num_posts;
1148 $this->num_new_posts = $num_new_posts;
1157 return $this->num_new_posts;
1166 $this->num_unread_posts = $num_unread_posts;
1175 return $this->num_unread_posts;
1184 $this->user_notification_enabled = $user_notification_enabled;
1193 return $this->user_notification_enabled;
1198 if(!in_array(strtoupper($direction), self::$possibleOrderDirections))
1200 $direction = current(self::$possibleOrderDirections);
1203 $this->orderDirection = $direction;