4require_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;
 
   78        $this->db = 
$DIC->database();
 
   79        $this->
user = $DIC->user();
 
   82        if (!$preventImplicitRead) {
 
  102        $this->
setSticky((
int) $data[
'is_sticky']);
 
  103        $this->
setClosed((
int) $data[
'is_closed']);
 
  122        if ($this->forum_id) {
 
  123            $nextId = $this->db->nextId(
'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            $this->db->manipulateF(
 
  172                array(
'integer', 
'text',
'timestamp', 
'integer', 
'text', 
'float', 
'integer'),
 
  173                array(  $this->forum_id,
 
  178                        $this->last_post_string,
 
  179                        $this->average_rating,
 
  200            $res = $this->db->queryf(
 
  202                                SELECT frm_threads.*, top_frm_fk frm_obj_id 
  204                                INNER JOIN frm_data ON top_pk = thr_top_fk 
  212            if (is_object(
$row)) {
 
  213                $this->thr_pk           = 
$row->pos_pk;   
 
  214                $this->forum_id         = 
$row->thr_top_fk;
 
  215                $this->display_user_id  = 
$row->thr_display_user_id;
 
  216                $this->user_alias       = 
$row->thr_usr_alias;
 
  217                $this->subject          = html_entity_decode(
$row->thr_subject);
 
  218                $this->createdate       = 
$row->thr_date;
 
  219                $this->changedate       = 
$row->thr_update;
 
  220                $this->import_name      = 
$row->import_name;
 
  221                $this->num_posts        = 
$row->thr_num_posts;
 
  222                $this->last_post_string = 
$row->thr_last_post;
 
  223                $this->visits           = 
$row->visits;
 
  224                $this->is_sticky        = 
$row->is_sticky;
 
  225                $this->is_closed        = 
$row->is_closed;
 
  226                $this->frm_obj_id       = 
$row->frm_obj_id;
 
  227                $this->average_rating   = 
$row->avg_rating;
 
  228                $this->thr_author_id    = 
$row->thr_author_id;
 
  247        return $this->
read();
 
  258        $res = $this->db->queryf(
 
  260                        SELECT * FROM frm_posts_tree  
  262                        AND parent_pos = %s',
 
  263            array(
'integer', 
'integer'),
 
  264            array($this->
id, 
'1')
 
  269        return $row->pos_fk ? 
$row->pos_fk : 0;
 
  279        $checkTime = time() - (60 * 60);
 
  281        if (
$_SESSION[
'frm_visit_frm_threads_' . $this->
id] < $checkTime) {
 
  284            $this->db->manipulateF(
 
  287                                SET     visits = visits + 1 
  306        $res = $this->db->queryf(
 
  310                        WHERE pos_thr_fk = %s',
 
  329        $res = $this->db->queryf(
 
  333                        WHERE (pos_status = %s 
  334                                 OR (pos_status = %s AND pos_display_user_id = %s)) 
  335                        AND pos_thr_fk = %s',
 
  336            array(
'integer', 
'integer', 
'integer', 
'integer'),
 
  337            array(
'1', 
'0', $this->
user->getId(), $this->id)
 
  353        $res = $this->db->queryf(
 
  357                        INNER JOIN frm_posts_tree ON pos_fk = pos_pk 
  358                        WHERE parent_pos = %s 
  360            array(
'integer', 
'integer'),
 
  361            array(
'0', $this->
id)
 
  378            $this->db->setLimit(1);
 
  379            $res = $this->db->queryf(
 
  383                                WHERE pos_thr_fk = %s                             
  384                                ORDER BY pos_date DESC',
 
  406            $this->db->setLimit(1);
 
  407            $res = $this->db->queryf(
 
  411                                WHERE pos_thr_fk = %s            
  412                                AND (pos_status = %s OR  
  413                                        (pos_status = %s AND pos_display_user_id = %s))                                                   
  414                                ORDER BY pos_date DESC',
 
  415                array(
'integer', 
'integer', 
'integer', 
'integer'),
 
  416                array($this->
id, 
'1', 
'0', $this->
user->getId())
 
  432            $res = $this->db->queryf(
 
  436                                WHERE pos_thr_fk = %s',
 
  446        return is_array($posts) ? $posts : array();
 
  462        $data_types = array();
 
  465                        SELECT                  is_author_moderator, pos_author_id, pos_pk, fpt_date, rgt, pos_top_fk, pos_thr_fk,  
  466                                                        pos_display_user_id, pos_usr_alias, pos_subject, 
  467                                                        pos_status, pos_message, pos_date, pos_update, 
  468                                                        update_user, pos_cens, pos_cens_com, notify, 
  469                                                        import_name, fpt_pk, parent_pos, lft, depth, 
  471                                                        WHEN fur.post_id IS NULL ' .
 
  472                                ($this->
user->getId() == ANONYMOUS_USER_ID ? 
' AND 1 = 2 ' : 
'') . 
' 
  476                                                        firstname, lastname, title, login 
  484                                ON                      pos_display_user_id  = usr_id 
  486                        LEFT JOIN               frm_user_read fur 
  487                                ON                      fur.thread_id = pos_thr_fk 
  488                                AND                     fur.post_id = pos_pk 
  491                        WHERE                   lft BETWEEN %s AND %s  
  494        array_push($data_types, 
'integer', 
'integer', 
'integer', 
'integer');
 
  497        if ($this->orderField != 
"") {
 
  505        $deactivated = array();
 
  506        while (
$row = $this->db->fetchAssoc(
$res)) {
 
  508            $tmp_object->assignData(
$row);
 
  510            if (!$this->is_moderator) {
 
  511                if (!$tmp_object->isActivated() && $tmp_object->getDisplayUserId() != $this->user->getId()) {
 
  512                    $deactivated[] = $tmp_object;
 
  517                foreach ($deactivated as $deactivated_node) {
 
  518                    if ($deactivated_node->getLft() < $tmp_object->getLft() && $deactivated_node->getRgt() > $tmp_object->getLft()) {
 
  519                        $deactivated[] = $tmp_object;
 
  526            if ((
int) 
$row[
'pos_display_user_id']) {
 
  527                $usr_ids[] = (int) 
$row[
'pos_display_user_id'];
 
  529            if ((
int) 
$row[
'update_user']) {
 
  530                $usr_ids[] = (int) 
$row[
'update_user'];
 
  533            $posts[] = $tmp_object;
 
  538        require_once 
'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
 
  554    public function movePosts($old_obj_id, $old_pk, $new_obj_id, $new_pk)
 
  558            if (is_array($nodes)) {
 
  559                $postsMoved = array();
 
  562                    foreach ($nodes as $node) {
 
  563                        $file_obj = 
new ilFileDataForum((
int) $old_obj_id, (
int) $node->pos_pk);
 
  564                        $moved = $file_obj->moveFilesOfPost((
int) $new_obj_id);
 
  566                        if (
true === $moved) {
 
  567                            $postsMoved[] = array(
 
  568                                'from' => $old_obj_id,
 
  570                                'position_id' => (
int) $node->pos_pk
 
  577                    foreach ($postsMoved as $postedInformation) {
 
  578                        $file_obj = 
new ilFileDataForum($postedInformation[
'to'], $postedInformation[
'position_id']);
 
  579                        $file_obj->moveFilesOfPost($postedInformation[
'from']);
 
  588            $ilAtomQuery = $this->db->buildAtomQuery();
 
  589            $ilAtomQuery->addTableLock(
'frm_user_read');
 
  590            $ilAtomQuery->addTableLock(
'frm_thread_access');
 
  592            $ilAtomQuery->addQueryCallable(
function (
ilDBInterface $ilDB) use ($new_obj_id, $current_id) {
 
  595                                DELETE FROM frm_user_read 
  596                                WHERE obj_id = %s AND thread_id =%s',
 
  597                    array(
'integer', 
'integer'),
 
  598                    array($new_obj_id, $current_id)
 
  605                                WHERE thread_id = %s',
 
  606                    array(
'integer', 
'integer'),
 
  607                    array($new_obj_id, $current_id)
 
  612                                DELETE FROM frm_thread_access 
  613                                WHERE obj_id = %s AND thread_id =%s',
 
  614                    array(
'integer', 
'integer'),
 
  615                    array($new_obj_id, $current_id)
 
  620                                UPDATE frm_thread_access 
  622                                WHERE thread_id =%s',
 
  623                    array(
'integer', 
'integer'),
 
  624                    array($new_obj_id, $current_id)
 
  630            $this->db->manipulateF(
 
  634                                WHERE pos_thr_fk = %s',
 
  635                array(
'integer', 
'integer'),
 
  636                array($new_pk, $this->
id)
 
  640            $posts = $this->db->queryf(
 
  642                                SELECT * FROM frm_posts WHERE pos_thr_fk = %s',
 
  652                include_once(
"./Services/News/classes/class.ilNewsItem.php");
 
  660                $news_item->setContextObjId($new_obj_id);
 
  661                $news_item->update();
 
  665            return count($nodes);
 
  675        $is_post_activation_enabled = $objProperties->isPostActivationEnabled();
 
  677        if ($pos_id !== 
null) {
 
  678            $res = $this->db->queryF(
 
  680                                SELECT          lft, rgt, depth 
  684                array(
'integer', 
'integer'),
 
  685                array($pos_id, $this->
id)
 
  701                                                        fp.pos_display_user_id, 
  705                                                        fp.is_author_moderator, 
  708                                                        WHEN fur.post_id IS NULL ' .
 
  709                                ($this->
user->getId() == ANONYMOUS_USER_ID ? 
' AND 1 = 2 ' : 
'') . 
' 
  713                                                        COUNT(fpt2.pos_fk) children 
  715                        FROM                    frm_posts_tree fpt 
  717                        INNER JOIN              frm_posts fp 
  718                                ON                      fp.pos_pk = fpt.pos_fk 
  720                        LEFT JOIN               frm_posts_tree fpt2 
  721                                 ON         fpt2.lft BETWEEN fpt.lft AND fpt.rgt 
  722                                 AND            fpt.thr_fk = fpt2.thr_fk 
  723                                 AND            fpt.pos_fk != fpt2.pos_fk ';
 
  727                        LEFT JOIN               frm_user_read fur 
  728                                ON                      fur.thread_id = fp.pos_thr_fk 
  729                                AND                     fur.post_id = fp.pos_pk 
  730                                AND                     fur.usr_id = ' . $this->db->quote($this->
user->getId(), 
'integer') . 
' 
  732                        LEFT JOIN               usr_data ud 
  733                                ON                      ud.usr_id = fp.pos_display_user_id 
  735                        WHERE                   fpt.thr_fk = ' . $this->db->quote($this->id, 
'integer');
 
  738            $query .= 
'         AND fpt.lft > ' . $this->db->quote(
$data[
'lft'], 
'integer') .
 
  739                    '           AND fpt.lft < ' . $this->db->quote(
$data[
'rgt'], 
'integer') . 
' ';
 
  741        if ($is_post_activation_enabled && !$this->is_moderator) {
 
  742            $query .= 
' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_display_user_id = ' . $this->db->quote($this->
user->getId(), 
'integer') . 
') ';
 
  745        if (
$data && is_numeric($levels)) {
 
  746            $query .= 
' AND fpt.depth <= ' . $this->db->quote(
$data[
'depth'] + $levels, 
'integer') . 
' ';
 
  749        $query .= 
' GROUP BY fpt.depth, 
  758                                                        fp.pos_display_user_id, 
  762                                                        fp.is_author_moderator, 
  764                                        ORDER BY fpt.rgt DESC 
  769                        FROM                    frm_posts_tree fpt 
  770                        INNER JOIN              frm_posts fp 
  771                                ON                      fp.pos_pk = fpt.pos_fk 
  772                        WHERE                   fpt.thr_fk = ' . $this->db->quote($this->
id, 
'integer');
 
  774        if ($is_post_activation_enabled && !$this->is_moderator) {
 
  775            $queryCounter .= 
' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_display_user_id = ' . $this->db->quote($this->
user->getId(), 
'integer') . 
') ';
 
  777        $queryCounter .= 
' ORDER BY fpt.rgt DESC';
 
  779        $resCounter = $this->db->query($queryCounter);
 
  782        while (
$row = $this->db->fetchAssoc($resCounter)) {
 
  789        while (
$row = $this->db->fetchAssoc(
$res)) {
 
  790            if ((
int) 
$row[
'pos_display_user_id']) {
 
  791                $usr_ids[] = (int) 
$row[
'pos_display_user_id'];
 
  798        require_once 
'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
 
  812        if ($this->
id && $a_user_id) {
 
  815                                SELECT COUNT(notification_id) cnt FROM frm_notification  
  816                                WHERE user_id = %s AND thread_id = %s',
 
  817                array(
'integer', 
'integer'),
 
  818                array($a_user_id, $this->
id)
 
  821            while ($record = $this->db->fetchAssoc(
$result)) {
 
  822                return (
bool) $record[
'cnt'];
 
  839        if ($this->
id && $a_user_id) {
 
  841                $nextId = $this->db->nextId(
'frm_notification');
 
  842                $this->db->manipulateF(
 
  844                                        INSERT INTO frm_notification 
  850                    array(
'integer', 
'integer', 
'integer'),
 
  851                    array($nextId, $a_user_id, $this->
id)
 
  870        if ($this->
id && $a_user_id) {
 
  871            $this->db->manipulateF(
 
  873                                DELETE FROM frm_notification 
  876                array(
'integer', 
'integer'),
 
  877                array($a_user_id, $this->
id)
 
  894        if ($this->
id && !$this->is_sticky) {
 
  895            $this->db->manipulateF(
 
  900                array(
'integer', 
'integer'),
 
  901                array(
'1', $this->
id)
 
  904            $this->is_sticky = 1;
 
  920        if ($this->
id && $this->is_sticky) {
 
  921            $this->db->manipulateF(
 
  926                array(
'integer', 
'integer'),
 
  927                array(
'0', $this->
id)
 
  930            $this->is_sticky = 0;
 
  946        if ($this->
id && !$this->is_closed) {
 
  947            $this->db->manipulateF(
 
  952                array(
'integer', 
'integer'),
 
  953                array(
'1', $this->
id)
 
  956            $this->is_closed = 1;
 
  972        if ($this->
id && $this->is_closed) {
 
  973            $this->db->manipulateF(
 
  978                array(
'integer', 
'integer'),
 
  979                array(
'0', $this->
id)
 
  982            $this->is_closed = 0;
 
 1016        $this->forum_id = $a_forum_id;
 
 1024        $this->display_user_id = $a_user_id;
 
 1032        $this->user_alias = $a_user_alias;
 
 1040        $this->subject = $a_subject;
 
 1048        $this->createdate = $a_createdate;
 
 1056        if ($a_changedate == 
'0000-00-00 00:00:00') {
 
 1057            $this->changedate = 
null;
 
 1059            $this->changedate = $a_changedate;
 
 1068        $this->import_name = $a_import_name;
 
 1076        if ($a_last_post == 
'') {
 
 1077            $a_last_post = 
null;
 
 1080        $this->last_post_string = $a_last_post;
 
 1088        $this->visits = $a_visits;
 
 1096        $this->is_sticky = $a_sticky;
 
 1100        return $this->is_sticky == 1 ? true : 
false;
 
 1104        $this->is_closed = $a_closed;
 
 1108        return $this->is_closed == 1 ? true : 
false;
 
 1112        $this->orderField = $a_order_field;
 
 1120        $this->is_moderator = $bool;
 
 1170        if (is_object(
$row)) {
 
 1171            return $row->thr_subject;
 
 1181            array(
'thr_subject' => array(
'text',$this->
getSubject())),
 
 1182            array(
'thr_pk'=> array(
'integer', $this->
getId()))
 
 1192        $this->num_posts = $a_num_posts;
 
 1210        $this->num_new_posts = $num_new_posts;
 
 1219        return $this->num_new_posts;
 
 1228        $this->num_unread_posts = $num_unread_posts;
 
 1237        return $this->num_unread_posts;
 
 1246        $this->user_notification_enabled = $user_notification_enabled;
 
 1255        return $this->user_notification_enabled;
 
 1260        if (!in_array(strtoupper($direction), self::$possibleOrderDirections)) {
 
 1261            $direction = current(self::$possibleOrderDirections);
 
 1264        $this->orderDirection = $direction;
 
 1280        $this->last_post = 
$post;
 
 1289            'SELECT thr_top_fk FROM frm_threads WHERE thr_pk = %s',
 
 1296        return $row[
'thr_top_fk'];
 
 1301        return $this->thread_sorting;
 
 1308                'thr_num_posts' => array(
'integer', $this->
getNumPosts()),
 
 1309                'visits'                => array(
'integer', $this->
getVisits()),
 
 1311                'thr_subject'           => array(
'text', $this->
getSubject())
 
 1313            array(
'thr_pk' => array(
'integer', $this->
getId()))
 
 1320        $DIC->database()->manipulateF(
 
 1321            'DELETE FROM frm_threads WHERE thr_pk = %s',
 
 1338            'SELECT thr_date FROM frm_threads WHERE thr_pk = %s',
 
 1340            array((
int) $thread_id)
 
 1345        return $row[
'thr_date'] ? 
$row[
'thr_date'] : 
'0000-00-00 00:00:00';
 
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
An exception for terminatinating execution or to throw for unit testing.
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...
static deleteByThreadId($thr_id)
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...
getFirstPostNode()
Fetches and returns an object of the first post in the current topic.
setOrderDirection($direction)
getUserNotificationEnabled()
setChangeDate($a_changedate)
updateVisits()
Updates the visit counter of the current topic.
setNumPosts($a_num_posts)
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)
setImportName($a_import_name)
getFirstPostId()
Fetches the primary key of the first post node of the current topic from database and returns it.
countActivePosts()
Fetches and returns the number of active posts for the given user id.
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.
countPosts()
Fetches and returns the number of posts for the given user id.
static $possibleOrderDirections
getLastActivePost()
Fetches and returns an object of the last active post in the current topic.
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.
foreach($_POST as $key=> $value) $res