Public Member Functions | Private Member Functions | Private Attributes

ilForumTopic Class Reference
[Modules/Forum]

Public Member Functions

 __construct ($a_id=0, $a_is_moderator=false)
 Constructor.
 insert ()
 Inserts the object data into database.
 update ()
 Updates an existing topic.
 reload ()
 Calls the private method read() to load the topic data from database into the object.
 getFirstPostId ()
 Fetches the primary key of the first post node of the current topic from database and returns it.
 updateVisits ()
 Updates the visit counter of the current topic.
 getLastThreadAccess ($a_user_id)
 Fetches and returns a timestamp of the last topic access.
 countPosts ()
 Fetches and returns the number of posts for the given user id.
 countActivePosts ()
 Fetches and returns the number of active posts for the given user id.
 countReadPosts ($a_user_id)
 Fetches and returns the number of read posts for the given user id.
 countReadActivePosts ($a_user_id)
 Fetches and returns the number of read active posts for the given user id.
 countNewPosts ($a_user_id)
 Fetches and returns the number of new posts for the given user id.
 countNewActivePosts ($a_user_id)
 Fetches and returns the number of new active posts for the given user id.
 getFirstPostNode ()
 Fetches and returns an object of the first post in the current topic.
 getLastPost ()
 Fetches and returns an object of the last post in the current topic.
 getLastActivePost ()
 Fetches and returns an object of the last active post in the current topic.
 getAllPosts ()
 getPostTree (ilForumPost $a_post_node)
 Fetches and returns an array of posts from the post tree, starting with the node object passed by the first paramter.
 movePosts ($old_obj_id, $old_pk, $new_obj_id, $new_pk)
 Moves all posts within the current thread to a new forum.
 getPostChilds ($a_node_id, $type= '')
 Fetches and returns an array of posts from the post tree, starting with the node id passed by the first paramter.
 isNotificationEnabled ($a_user_id)
 Check whether a user's notification about new posts in a thread is enabled (result > 0) or not (result == 0).
 enableNotification ($a_user_id)
 Enable a user's notification about new posts in a thread.
 disableNotification ($a_user_id)
 Disable a user's notification about new posts in a thread.
 makeSticky ()
 Sets the current topic sticky.
 unmakeSticky ()
 Sets the current topic non-sticky.
 close ()
 Closes the current topic.
 reopen ()
 Reopens the current topic.
 setId ($a_id)
 getId ()
 setForumId ($a_forum_id)
 getForumId ()
 setUserId ($a_user_id)
 getUserId ()
 setUserAlias ($a_user_alias)
 getUserAlias ()
 setSubject ($a_subject)
 getSubject ()
 setCreateDate ($a_createdate)
 getCreateDate ()
 setChangeDate ($a_changedate)
 getChangeDate ()
 setImportName ($a_import_name)
 getImportName ()
 setNumPosts ($a_num_posts)
 getNumPosts ()
 setLastPostString ($a_last_post)
 getLastPostString ()
 setVisits ($a_visits)
 getVisits ()
 setSticky ($a_sticky)
 isSticky ()
 setClosed ($a_closed)
 isClosed ()
 setOrderField ($a_order_field)
 getOrderField ()
 setModeratorRight ($bool)
 getModeratorRight ()
 getFrmObjId ()

Private Member Functions

 read ()
 Reads the data of the current object id from database and loads it into the object.

Private Attributes

 $id = 0
 $forum_id = 0
 $frm_obj_id = 0
 $user_id = 0
 $user_alias = ''
 $subject = ''
 $createdate = '0000-00-00 00:00:00'
 $changedate = '0000-00-00 00:00:00'
 $num_posts = 0
 $last_post_string = ''
 $visits = 0
 $import_name = ''
 $is_sticky = 0
 $is_closed = 0
 $orderField = ''
 $posts = array()
 $db = null
 $is_moderator = false

Detailed Description

Author:
Michael Jansen <mjansen@databay.de>
Version:
$Id$

Definition at line 32 of file class.ilForumTopic.php.


Constructor & Destructor Documentation

ilForumTopic::__construct ( a_id = 0,
a_is_moderator = false 
)

Constructor.

Returns an object of a forum topic. The constructor calls the private method read() to load the topic data from database into the object.

Parameters:
integer $a_id primary key of a forum topic (optional)
bool $a_is_moderator moderator-status of the current user (optional)

public

Definition at line 81 of file class.ilForumTopic.php.

References read().

        {
                global $ilDB;

                $this->is_moderator = $a_is_moderator;
                $this->db = $ilDB;
                $this->id = $a_id;
                $this->read();
        }

Here is the call graph for this function:


Member Function Documentation

ilForumTopic::close (  ) 

Closes the current topic.

Returns:
bool true in case of success, false in case of failure public

Definition at line 851 of file class.ilForumTopic.php.

        {
                if ($this->id && !$this->is_closed)
                {
                        $query = "UPDATE frm_threads 
                                      SET is_closed = '1'
                                          WHERE 1 
                                          AND thr_pk = ".$this->db->quote($this->id)." ";
                        
                        $this->db->query($query);
                        
                        $this->is_closed = 1;
                        
                        return true;
                }
                
                return false;
        }

ilForumTopic::countActivePosts (  ) 

Fetches and returns the number of active posts for the given user id.

Parameters:
integer $a_user_id user id
Returns:
integer number of active posts public

Definition at line 304 of file class.ilForumTopic.php.

References $res.

        {
                global $ilUser;
                
                $query = "SELECT COUNT(*) AS cnt
                                  FROM frm_posts
                                  WHERE 1                                
                                  AND (pos_status = '1' OR (pos_status = '0' AND pos_usr_id = ".$this->db->quote($ilUser->getId())."))
                                  AND pos_thr_fk = ".$this->db->quote($this->id)." ";

                $res = $this->db->query($query);
                
                $rec = $res->fetchRow(DB_FETCHMODE_ASSOC);
                        
                return $rec['cnt'];
        }

ilForumTopic::countNewActivePosts ( a_user_id  ) 

Fetches and returns the number of new active posts for the given user id.

Parameters:
integer $a_user_id user id
Returns:
integer number of new active posts public

Definition at line 404 of file class.ilForumTopic.php.

References $res, and getLastThreadAccess().

        {
                global $ilUser;
                
                $timest = $this->getLastThreadAccess($a_user_id);
                
                $query = "SELECT COUNT(pos_pk) AS cnt
                                  FROM frm_posts
                                  LEFT JOIN frm_user_read ON post_id = pos_pk AND usr_id = ".$this->db->quote($a_user_id)." 
                                  WHERE 1
                                  AND pos_thr_fk = ".$this->db->quote($this->id)."
                                  AND (pos_date > '".date('Y-m-d H:i:s', $timest)."' OR pos_update > '".date('Y-m-d H:i:s', $timest)."') 
                                  AND pos_usr_id != ".$this->db->quote($a_user_id)." 
                                  AND (pos_status = '1' OR (pos_status = '0' AND pos_usr_id = ".$this->db->quote($ilUser->getId())."))
                                  AND usr_id IS NULL ";
                
                $res = $this->db->query($query);
                
                $rec = $res->fetchRow(DB_FETCHMODE_ASSOC);
                        
                return $rec['cnt'];
        }       

Here is the call graph for this function:

ilForumTopic::countNewPosts ( a_user_id  ) 

Fetches and returns the number of new posts for the given user id.

Parameters:
integer $a_user_id user id
Returns:
integer number of new posts public

Definition at line 377 of file class.ilForumTopic.php.

References $res, and getLastThreadAccess().

        {
                $timest = $this->getLastThreadAccess($a_user_id);
                
                $query = "SELECT COUNT(pos_pk) AS cnt
                                  FROM frm_posts
                                  LEFT JOIN frm_user_read ON post_id = pos_pk AND usr_id = ".$this->db->quote($a_user_id)." 
                                  WHERE 1
                                  AND pos_thr_fk = ".$this->db->quote($this->id)."
                                  AND (pos_date > '".date('Y-m-d H:i:s', $timest)."' OR pos_update > '".date('Y-m-d H:i:s', $timest)."') 
                                  AND pos_usr_id != ".$this->db->quote($a_user_id)." 
                                  AND usr_id IS NULL ";
                
                $res = $this->db->query($query);
                
                $rec = $res->fetchRow(DB_FETCHMODE_ASSOC);
                        
                return $rec['cnt'];
        }

Here is the call graph for this function:

ilForumTopic::countPosts (  ) 

Fetches and returns the number of posts for the given user id.

Parameters:
integer $a_user_id user id
Returns:
integer number of posts public

Definition at line 283 of file class.ilForumTopic.php.

References $res.

        {
                $query = "SELECT COUNT(*) AS cnt
                                  FROM frm_posts
                                  WHERE 1                                 
                                  AND pos_thr_fk = ".$this->db->quote($this->id)." ";

                $res = $this->db->query($query);
                
                $rec = $res->fetchRow(DB_FETCHMODE_ASSOC);
                        
                return $rec['cnt'];
        }

ilForumTopic::countReadActivePosts ( a_user_id  ) 

Fetches and returns the number of read active posts for the given user id.

Parameters:
integer $a_user_id user id
Returns:
integer number of read active posts public

Definition at line 351 of file class.ilForumTopic.php.

References $res.

        {
                global $ilUser;
                
                $query = "SELECT COUNT(*) AS cnt                                  
                                  FROM frm_user_read
                                  INNER JOIN frm_posts ON pos_pk = post_id
                                  WHERE 1                         
                                  AND usr_id = ".$this->db->quote($a_user_id)."
                                  AND thread_id = ".$this->db->quote($this->id)."                                 
                                  AND (pos_status = '1' OR (pos_status = '0' AND pos_usr_id = ".$this->db->quote($ilUser->getId())."))";

                $res = $this->db->query($query);
                
                $rec = $res->fetchRow(DB_FETCHMODE_ASSOC);
                        
                return $rec['cnt'];
        }

ilForumTopic::countReadPosts ( a_user_id  ) 

Fetches and returns the number of read posts for the given user id.

Parameters:
integer $a_user_id user id
Returns:
integer number of read posts public

Definition at line 328 of file class.ilForumTopic.php.

References $res.

        {
                $query = "SELECT COUNT(*) AS cnt                                  
                                  FROM frm_user_read
                                  INNER JOIN frm_posts ON pos_pk = post_id
                                  WHERE 1                         
                                  AND usr_id = ".$this->db->quote($a_user_id)."
                                  AND thread_id = ".$this->db->quote($this->id)." ";

                $res = $this->db->query($query);
                
                $rec = $res->fetchRow(DB_FETCHMODE_ASSOC);
                        
                return $rec['cnt'];
        }       

ilForumTopic::disableNotification ( a_user_id  ) 

Disable a user's notification about new posts in a thread.

Parameters:
integer $a_user_id id of an user
Returns:
bool true in case of success, false in case of failure public

Definition at line 778 of file class.ilForumTopic.php.

        {
                if ($this->id && $a_user_id)
                {                       
                        $query = "DELETE FROM frm_notification
                                          WHERE 1 
                                          AND user_id = ".$this->db->quote($a_user_id)." 
                                          AND thread_id = ".$this->db->quote($this->id)." ";
                        
                        $this->db->query($query);
                        
                        return false;
                }               
                
                return false;
        }

ilForumTopic::enableNotification ( a_user_id  ) 

Enable a user's notification about new posts in a thread.

Parameters:
integer $a_user_id id of an user
Returns:
bool true in case of success, false in case of failure public

Definition at line 752 of file class.ilForumTopic.php.

References isNotificationEnabled().

        {
                if ($this->id && $a_user_id)
                {
                        if (!$this->isNotificationEnabled($a_user_id))
                        {
                                $query = "INSERT INTO frm_notification (user_id, thread_id) VALUES (
                                                 ".$this->db->quote($a_user_id).", ".$this->db->quote($this->id).")";
                                
                                $this->db->query($query);
                                
                                return true;
                        }
                        
                        return false;
                }
                
                return false;
        }

Here is the call graph for this function:

ilForumTopic::getAllPosts (  ) 

Definition at line 506 of file class.ilForumTopic.php.

References $posts, and $res.

Referenced by movePosts().

        {                               
            $posts = array();
                
                if($this->id)
                {
                        $query = "SELECT pos_pk
                                          FROM frm_posts                                
                                          WHERE 1 
                                          AND pos_thr_fk = ".$this->db->quote($this->id);
                        
                        $res = $this->db->query($query);                
                        while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
                        {
                                $posts[$row->pos_pk] = $row;
                        }
                }
                
                return is_array($posts) ? $posts : array();
        }

Here is the caller graph for this function:

ilForumTopic::getChangeDate (  ) 

Definition at line 947 of file class.ilForumTopic.php.

        {
                return $this->changedate;
        }       

ilForumTopic::getCreateDate (  ) 

Definition at line 939 of file class.ilForumTopic.php.

        {
                return $this->createdate;
        }

ilForumTopic::getFirstPostId (  ) 

Fetches the primary key of the first post node of the current topic from database and returns it.

Returns:
integer primary key of the first post node public

Definition at line 211 of file class.ilForumTopic.php.

References $res.

        {
                $query = "SELECT *
                                  FROM frm_posts_tree 
                              WHERE 1
                                  AND thr_fk = ".$this->db->quote($this->id)." 
                              AND parent_pos = '0' ";
                $res = $this->db->query($query);
                $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
                
                return $row->pos_fk ? $row->pos_fk : 0;
        }

ilForumTopic::getFirstPostNode (  ) 

Fetches and returns an object of the first post in the current topic.

Returns:
ilForumPost object of a post public

Definition at line 433 of file class.ilForumTopic.php.

References $res.

        {               
                $query = "SELECT pos_pk
                                  FROM frm_posts 
                                  INNER JOIN frm_posts_tree ON pos_fk = pos_pk
                                  WHERE 1                                
                                  AND parent_pos = '0'
                                  AND thr_fk = ".$this->db->quote($this->id)." ";

                $res = $this->db->query($query);
                
                $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
                
                return new ilForumPost($row->pos_pk);
        }

ilForumTopic::getForumId (  ) 

Definition at line 907 of file class.ilForumTopic.php.

        {
                return $this->forum_id;
        }       

ilForumTopic::getFrmObjId (  ) 

Definition at line 1015 of file class.ilForumTopic.php.

        {
                return $this->frm_obj_id;
        }

ilForumTopic::getId (  ) 

Definition at line 899 of file class.ilForumTopic.php.

Referenced by ilForumExplorer::ilForumExplorer().

        {
                return $this->id;
        }

Here is the caller graph for this function:

ilForumTopic::getImportName (  ) 

Definition at line 955 of file class.ilForumTopic.php.

        {
                return $this->import_name;
        }       

ilForumTopic::getLastActivePost (  ) 

Fetches and returns an object of the last active post in the current topic.

Returns:
ilForumPost object of the last active post public

Definition at line 482 of file class.ilForumTopic.php.

References $res.

        {
                global $ilUser;
                
                if ($this->id)
                {
                        $query = "SELECT pos_pk
                                          FROM frm_posts 
                                          WHERE 1
                                          AND pos_thr_fk = ".$this->db->quote($this->id)."                               
                                          AND (pos_status = '1' OR (pos_status = '0' AND pos_usr_id = ".$this->db->quote($ilUser->getId())."))                                     
                                          ORDER BY pos_date DESC
                                          LIMIT 1";
        
                        $res = $this->db->query($query);
                        
                        $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
                        
                        return new ilForumPost($row->pos_pk);
                }
                
                return false;
        }

ilForumTopic::getLastPost (  ) 

Fetches and returns an object of the last post in the current topic.

Returns:
ilForumPost object of the last post public

Definition at line 455 of file class.ilForumTopic.php.

References $res.

        {
                if ($this->id)
                {
                        $query = "SELECT pos_pk
                                          FROM frm_posts 
                                          WHERE 1
                                          AND pos_thr_fk = ".$this->db->quote($this->id)."                               
                                          ORDER BY pos_date DESC
                                          LIMIT 1";
        
                        $res = $this->db->query($query);
                        
                        $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
                        
                        return new ilForumPost($row->pos_pk);
                }
                
                return false;
        }

ilForumTopic::getLastPostString (  ) 

Definition at line 971 of file class.ilForumTopic.php.

        {
                return $this->last_post_string;
        }

ilForumTopic::getLastThreadAccess ( a_user_id  ) 

Fetches and returns a timestamp of the last topic access.

Parameters:
integer $a_user_id user id
Returns:
integer timestamp of last thread access public

Definition at line 255 of file class.ilForumTopic.php.

References $res.

Referenced by countNewActivePosts(), and countNewPosts().

        {               
                $query = "SELECT * 
                                  FROM frm_thread_access 
                                  WHERE 1
                                  AND thread_id = ".$this->db->quote($this->id)." 
                                  AND usr_id = ".$this->db->quote($a_user_id)." ";

                $res = $this->db->query($query);
                while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
                {
                        $last_access = $row->access_old;
                }
                if (!$last_access)
                {                       
                        $last_access = NEW_DEADLINE;
                }
                
                return $last_access;
        }

Here is the caller graph for this function:

ilForumTopic::getModeratorRight (  ) 

Definition at line 1011 of file class.ilForumTopic.php.

        {
                return $this->orderField;
        }

ilForumTopic::getNumPosts (  ) 

Definition at line 963 of file class.ilForumTopic.php.

        {
                return $this->num_posts;
        }

ilForumTopic::getOrderField (  ) 

Definition at line 1003 of file class.ilForumTopic.php.

        {
                return $this->orderField;
        }

ilForumTopic::getPostChilds ( a_node_id,
type = '' 
)

Fetches and returns an array of posts from the post tree, starting with the node id passed by the first paramter.

If the second parameter $type is set to 'explorer', the data will be returned different because of compatibility issues in explorer view.

Parameters:
integer $a_node_id id of starting node
string $type 'explorer' or '' (optional)
Returns:
array array of posts public

Definition at line 676 of file class.ilForumTopic.php.

        {
                global $ilUser;
                
                $childs = array();

                $count = 0;

                $query = "SELECT pos_pk 
                                  FROM frm_posts_tree 
                                  INNER JOIN frm_posts ON frm_posts.pos_pk = frm_posts_tree.pos_fk 
                                  WHERE 1
                                  AND frm_posts_tree.parent_pos = ".$this->db->quote($a_node_id)." 
                                  AND frm_posts_tree.thr_fk = ".$this->db->quote($this->id)." 
                                  ORDER BY frm_posts_tree.lft DESC";
                $r = $this->db->query($query);

                $count = $r->numRows();

                if ($count > 0)
                {
                        $active_count = 0;
                        
                        while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
                        {
                                $tmp_obj = new ilForumPost($row->pos_pk);
                                
                                if ($this->is_moderator || 
                                   ($tmp_obj->isActivated() || (!$tmp_obj->isActivated() && $tmp_obj->getUserId() == $ilUser->getId())))
                                {
                                        $childs[] = ($type == 'explorer' ? $tmp_obj->getDataAsArrayForExplorer() : $tmp_obj->getDataAsArray());
                                        ++$active_count;
                                }
                                
                                unset($tmp_obj);
                        }

                        // mark the last child node (important for display)
                        if ($active_count > 0) $childs[$active_count - 1]['last'] = true;

                        return $childs;
                }
                else
                {
                        return $childs;
                }
        }       

ilForumTopic::getPostTree ( ilForumPost a_post_node  ) 

Fetches and returns an array of posts from the post tree, starting with the node object passed by the first paramter.

Parameters:
ilForumPost $a_post_node node-object of a post
Returns:
array array of post objects public

Definition at line 535 of file class.ilForumTopic.php.

References $res, ilForumPost::getLft(), ilForumPost::getRgt(), and ilForumPost::getThreadId().

        {
                global $ilUser;
                
            $this->posts = array();

                $query = "SELECT pos_pk
                                  FROM frm_posts_tree 
                                  INNER JOIN frm_posts ON pos_fk = pos_pk 
                                  WHERE 1 
                                  AND lft BETWEEN ".$this->db->quote($a_post_node->getLft())." AND ".$this->db->quote($a_post_node->getRgt())." 
                                  AND thr_fk = ".$this->db->quote($a_post_node->getThreadId());
                if ($this->orderField == "frm_posts_tree.date")
                {
                        $query .= " ORDER BY ".$this->orderField." ASC";
                }
                else if ($this->orderField != "")
                {
                        $query .= " ORDER BY ".$this->orderField." DESC";
                }

                $res = $this->db->query($query);
                
                $deactivated = array();
                while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
                {
                        $tmp_object = new ilForumPost($row->pos_pk);

                        if (!$this->is_moderator)
                        {
                                if (!$tmp_object->isActivated() && $tmp_object->getUserId() != $ilUser->getId())
                                {
                                        $deactivated[] = $tmp_object;
                                        unset($tmp_object);
                                        continue;                               
                                }
                         
                                $continue = false;
                                foreach ($deactivated as $deactivated_node)
                                {
                                        if ($deactivated_node->getLft() < $tmp_object->getLft() && 
                                                $deactivated_node->getRgt() > $tmp_object->getLft())
                                        {
                                                $deactivated[] = $tmp_object;
                                                unset($tmp_object);
                                                $continue = true;
                                                break;
                                        }
                                }
                         
                                if ($continue) continue;
                        }
                         
                        $this->posts[] = $tmp_object;
                         
                        unset($tmp_object);
                }

                return $this->posts;
        }

Here is the call graph for this function:

ilForumTopic::getSubject (  ) 

Definition at line 931 of file class.ilForumTopic.php.

        {
                return $this->subject;
        }       

ilForumTopic::getUserAlias (  ) 

Definition at line 923 of file class.ilForumTopic.php.

        {
                return $this->user_alias;
        }

ilForumTopic::getUserId (  ) 

Definition at line 915 of file class.ilForumTopic.php.

        {
                return $this->user_id;
        }

ilForumTopic::getVisits (  ) 

Definition at line 979 of file class.ilForumTopic.php.

        {
                return $this->visits;
        }

ilForumTopic::insert (  ) 

Inserts the object data into database.

Returns:
bool true in case of success, false in case of failure public

Definition at line 97 of file class.ilForumTopic.php.

        {                       
                if ($this->forum_id)
                {       
                        $query = "INSERT INTO frm_threads "
                                        ."SET "
                                        ."thr_top_fk = " . $this->db->quote($this->forum_id). ", "
                                        ."thr_usr_id = " . $this->db->quote($this->user_id). ", "
                                        ."thr_usr_alias = " . $this->db->quote($this->user_alias). ", "
                                        ."thr_subject = " . $this->db->quote($this->subject). ", "
                                        ."thr_date = " . $this->db->quote($this->createdate). ", "                                      
                                        ."thr_update = " . $this->db->quote($this->changedate). ", "
                                        ."thr_num_posts = " . $this->db->quote($this->num_posts). ", "
                                        ."thr_last_post = " . $this->db->quote($this->last_post_string). ", "
                                        ."is_sticky = " . $this->db->quote($this->is_sticky). ", "
                                        ."is_closed = " . $this->db->quote($this->is_closed). ", "
                                        ."import_name = " . $this->db->quote($this->import_name). " ";
                        $this->db->query($query);
                        
                        $this->id = $this->db->getLastInsertId();
                        
                        return true;
                }
                
                return false;   
        }

ilForumTopic::isClosed (  ) 

Definition at line 995 of file class.ilForumTopic.php.

        {
                return $this->is_closed == 1 ? true : false;
        }

ilForumTopic::isNotificationEnabled ( a_user_id  ) 

Check whether a user's notification about new posts in a thread is enabled (result > 0) or not (result == 0).

Parameters:
integer $a_user_id id of an user
Returns:
bool true in case of success, false in case of failure public

Definition at line 730 of file class.ilForumTopic.php.

Referenced by enableNotification().

        {
                if ($this->id && $a_user_id)
                {                       
                        $query = "SELECT COUNT(*) 
                                          FROM frm_notification 
                                          WHERE 1
                                          AND user_id = ".$this->db->quote($a_user_id)."  
                                          AND thread_id = ".$this->db->quote($this->id)." ";
                        
                        return ($this->db->getOne($query)) ? true : false;
                }
                
                return false;           
        }

Here is the caller graph for this function:

ilForumTopic::isSticky (  ) 

Definition at line 987 of file class.ilForumTopic.php.

        {
                return $this->is_sticky == 1 ? true : false;
        }

ilForumTopic::makeSticky (  ) 

Sets the current topic sticky.

Returns:
bool true in case of success, false in case of failure public

Definition at line 801 of file class.ilForumTopic.php.

        {
                if ($this->id && !$this->is_sticky)
                {
                        $query = "UPDATE frm_threads 
                                      SET is_sticky = '1'
                                          WHERE 1 
                                          AND thr_pk = ".$this->db->quote($this->id)." ";
                        
                        $this->db->query($query);
                        
                        $this->is_sticky = 1;
                        
                        return true;
                }
                
                return false;
        }

ilForumTopic::movePosts ( old_obj_id,
old_pk,
new_obj_id,
new_pk 
)

Moves all posts within the current thread to a new forum.

Parameters:
integer $old_obj_id object id of the current forum
integer $old_pk primary key of old forum
integer $new_obj_id object id of the new forum
integer $new_pk primary key of new forum
Returns:
integer number of afffected rows by updating posts public

Definition at line 606 of file class.ilForumTopic.php.

References $posts, $res, ilForum::_lookupObjIdForForumId(), getAllPosts(), and ilNewsItem::getFirstNewsIdForContext().

        {
                global $ilDB;
                
                require_once './Modules/Forum/classes/class.ilFileDataForum.php';
                
                if ($this->id)
                {
                        if(is_array($nodes = $this->getAllPosts()))
                        {
                                // Move attachments
                                foreach($nodes as $node)
                                {
                                        $file_obj = new ilFileDataForum((int)$old_obj_id, (int)$node->pos_pk);
                                        $file_obj->moveFilesOfPost((int)$new_obj_id);
                                        unset($file_obj);
                                }
                        }
                                                
                        $query = "UPDATE frm_user_read
                                          SET obj_id = ".$ilDB->quote($new_obj_id)."
                                          WHERE 1
                                          AND thread_id = ".$ilDB->quote($this->id)." ";                                         
                        $res = $ilDB->query($query);
                        
                        $query = "UPDATE frm_thread_access
                                          SET obj_id = ".$ilDB->quote($new_obj_id)."
                                          WHERE 1
                                          AND thread_id = ".$ilDB->quote($this->id)." ";                                         
                        $res = $ilDB->query($query);
                        
                        $query = "UPDATE frm_posts
                                          SET pos_top_fk = ".$ilDB->quote($new_pk)."
                                          WHERE 1
                                          AND pos_thr_fk = ".$ilDB->quote($this->id)." ";                                        
                        $res = $ilDB->query($query);
                        $ar = $ilDB->affectedRows();
                        
                        // update all related news
                        $posts = $ilDB->query("SELECT * FROM frm_posts ".
                                " WHERE pos_thr_fk = ".$ilDB->quote($this->id));
                        $old_obj_id = ilForum::_lookupObjIdForForumId($old_pk);
                        $new_obj_id = ilForum::_lookupObjIdForForumId($new_pk);
                        while($post = $posts->fetchRow(DB_FETCHMODE_ASSOC))
                        {
                                include_once("./Services/News/classes/class.ilNewsItem.php");
                                $news_id = ilNewsItem::getFirstNewsIdForContext($old_obj_id,
                                        "frm", $post["pos_pk"], "pos");
                                $news_item = new ilNewsItem($news_id);
                                $news_item->setContextObjId($new_obj_id);
                                $news_item->update();
                                //echo "<br>-".$post["pos_pk"]."-".$old_obj_id."-".$new_obj_id."-";
                        }
                        
                        return $ar;
                }
                
                return 0;
        }

Here is the call graph for this function:

ilForumTopic::read (  )  [private]

Reads the data of the current object id from database and loads it into the object.

Returns:
bool true in case of success, false in case of failure

private

Definition at line 157 of file class.ilForumTopic.php.

Referenced by __construct(), and reload().

        {
                if ($this->id)
                {
                        $query = "SELECT frm_threads.*, top_frm_fk AS frm_obj_id
                                          FROM frm_threads
                                          INNER JOIN frm_data ON top_pk = thr_top_fk
                                          WHERE 1
                                          AND thr_pk = " . $this->db->quote($this->id) . " ";
                        $row = $this->db->getrow($query);
        
                        if (is_object($row))
                        {
                                $this->thr_pk = $row->pos_pk;
                                $this->forum_id = $row->thr_top_fk;
                                $this->user_id = $row->thr_usr_id;
                                $this->user_alias = $row->thr_usr_alias;        
                                $this->subject = $row->thr_subject;
                                $this->createdate = $row->thr_date;     
                                $this->changedate = $row->thr_update;
                                $this->import_name = $row->import_name;
                                $this->num_posts = $row->thr_num_posts;
                                $this->last_post_string = $row->thr_last_post;
                                $this->visits = $row->visits;
                                $this->is_sticky = $row->is_sticky;
                                $this->is_closed = $row->is_closed;
                                $this->frm_obj_id = $row->frm_obj_id;
                                
                                return true;
                        }
                        
                        return false;
                }
                
                return false;
        }

Here is the caller graph for this function:

ilForumTopic::reload (  ) 

Calls the private method read() to load the topic data from database into the object.

Returns:
bool true in case of success, false in case of failure public

Definition at line 200 of file class.ilForumTopic.php.

References read().

        {
                return $this->read();
        }

Here is the call graph for this function:

ilForumTopic::reopen (  ) 

Reopens the current topic.

Returns:
bool true in case of success, false in case of failure public

Definition at line 876 of file class.ilForumTopic.php.

        {
                if ($this->id && $this->is_closed)
                {
                        $query = "UPDATE frm_threads 
                                      SET is_closed = '0'
                                          WHERE 1 
                                          AND thr_pk = ".$this->db->quote($this->id)." ";
                        
                        $this->db->query($query);
                        
                        $this->is_closed = 0;
                        
                        return true;
                }
                
                return false;
        }

ilForumTopic::setChangeDate ( a_changedate  ) 

Definition at line 943 of file class.ilForumTopic.php.

        {
                $this->changedate = $a_changedate;
        }

ilForumTopic::setClosed ( a_closed  ) 

Definition at line 991 of file class.ilForumTopic.php.

        {
                $this->is_closed = $a_closed;
        }

ilForumTopic::setCreateDate ( a_createdate  ) 

Definition at line 935 of file class.ilForumTopic.php.

        {
                $this->createdate = $a_createdate;
        }

ilForumTopic::setForumId ( a_forum_id  ) 

Definition at line 903 of file class.ilForumTopic.php.

        {
                $this->forum_id = $a_forum_id;
        }

ilForumTopic::setId ( a_id  ) 

Definition at line 895 of file class.ilForumTopic.php.

        {
                $this->id = $a_id;
        }

ilForumTopic::setImportName ( a_import_name  ) 

Definition at line 951 of file class.ilForumTopic.php.

        {
                $this->import_name = $a_import_name;
        }

ilForumTopic::setLastPostString ( a_last_post  ) 

Definition at line 967 of file class.ilForumTopic.php.

        {
                $this->last_post_string = $a_last_post;
        }

ilForumTopic::setModeratorRight ( bool  ) 

Definition at line 1007 of file class.ilForumTopic.php.

        {
                $this->is_moderator = $bool;
        }

ilForumTopic::setNumPosts ( a_num_posts  ) 

Definition at line 959 of file class.ilForumTopic.php.

        {
                $this->num_posts = $a_num_posts;
        }

ilForumTopic::setOrderField ( a_order_field  ) 

Definition at line 999 of file class.ilForumTopic.php.

        {
                $this->orderField = $a_order_field;
        }

ilForumTopic::setSticky ( a_sticky  ) 

Definition at line 983 of file class.ilForumTopic.php.

        {
                $this->is_sticky = $a_sticky;
        }

ilForumTopic::setSubject ( a_subject  ) 

Definition at line 927 of file class.ilForumTopic.php.

        {
                $this->subject = $a_subject;
        }

ilForumTopic::setUserAlias ( a_user_alias  ) 

Definition at line 919 of file class.ilForumTopic.php.

        {
                $this->user_alias = $a_user_alias;
        }

ilForumTopic::setUserId ( a_user_id  ) 

Definition at line 911 of file class.ilForumTopic.php.

        {
                $this->user_id = $a_user_id;            
        }

ilForumTopic::setVisits ( a_visits  ) 

Definition at line 975 of file class.ilForumTopic.php.

        {
                $this->visits = $a_visits;
        }

ilForumTopic::unmakeSticky (  ) 

Sets the current topic non-sticky.

Returns:
bool true in case of success, false in case of failure public

Definition at line 826 of file class.ilForumTopic.php.

        {
                if ($this->id && $this->is_sticky)
                {
                        $query = "UPDATE frm_threads 
                                      SET is_sticky = '0'
                                          WHERE 1 
                                          AND thr_pk = ".$this->db->quote($this->id)." ";
                        
                        $this->db->query($query);
                        
                        $this->is_sticky = 0;
                        
                        return true;
                }
                
                return false;
        }

ilForumTopic::update (  ) 

Updates an existing topic.

Returns:
bool true in case of success, false in case of failure public

Definition at line 130 of file class.ilForumTopic.php.

        {
                if ($this->id)
                {               
                        $query = "UPDATE frm_threads "
                                        ."SET "
                                        ."thr_top_fk = " . $this->db->quote($this->forum_id). ", "
                                        ."thr_subject = " . $this->db->quote($this->subject). ", "
                                        ."thr_update = " . $this->db->quote($this->changedate). ", "
                                        ."thr_num_posts = " . $this->db->quote($this->num_posts). ", "
                                        ."thr_last_post = " . $this->db->quote($this->last_post_string). " "
                                        ."WHERE thr_pk = ". $this->db->quote($this->id) ." ";
                        $this->db->query($query);

                        return true;
                }
                
                return false;
        }

ilForumTopic::updateVisits (  ) 

Updates the visit counter of the current topic.

public

Definition at line 229 of file class.ilForumTopic.php.

References $_SESSION.

        {
                $checkTime = time() - (60 * 60);
                
                if ($_SESSION['frm_visit_frm_threads_'.$this->id] < $checkTime)
                {
                        $_SESSION['frm_visit_frm_threads_'.$this->id] = time();         
                
                        $query = "UPDATE frm_threads
                                          SET 
                                          visits = visits + 1
                                          WHERE thr_pk = ".$this->db->quote($this->id)." ";                     
                        
                        $this->db->query($query);
                }
                
                return true;
        }


Field Documentation

ilForumTopic::$changedate = '0000-00-00 00:00:00' [private]

Definition at line 48 of file class.ilForumTopic.php.

ilForumTopic::$createdate = '0000-00-00 00:00:00' [private]

Definition at line 46 of file class.ilForumTopic.php.

ilForumTopic::$db = null [private]

Definition at line 66 of file class.ilForumTopic.php.

ilForumTopic::$forum_id = 0 [private]

Definition at line 36 of file class.ilForumTopic.php.

ilForumTopic::$frm_obj_id = 0 [private]

Definition at line 38 of file class.ilForumTopic.php.

ilForumTopic::$id = 0 [private]

Definition at line 34 of file class.ilForumTopic.php.

ilForumTopic::$import_name = '' [private]

Definition at line 56 of file class.ilForumTopic.php.

ilForumTopic::$is_closed = 0 [private]

Definition at line 60 of file class.ilForumTopic.php.

ilForumTopic::$is_moderator = false [private]

Definition at line 68 of file class.ilForumTopic.php.

ilForumTopic::$is_sticky = 0 [private]

Definition at line 58 of file class.ilForumTopic.php.

ilForumTopic::$last_post_string = '' [private]

Definition at line 52 of file class.ilForumTopic.php.

ilForumTopic::$num_posts = 0 [private]

Definition at line 50 of file class.ilForumTopic.php.

ilForumTopic::$orderField = '' [private]

Definition at line 62 of file class.ilForumTopic.php.

ilForumTopic::$posts = array() [private]

Definition at line 64 of file class.ilForumTopic.php.

Referenced by getAllPosts(), and movePosts().

ilForumTopic::$subject = '' [private]

Definition at line 44 of file class.ilForumTopic.php.

ilForumTopic::$user_alias = '' [private]

Definition at line 42 of file class.ilForumTopic.php.

ilForumTopic::$user_id = 0 [private]

Definition at line 40 of file class.ilForumTopic.php.

ilForumTopic::$visits = 0 [private]

Definition at line 54 of file class.ilForumTopic.php.


The documentation for this class was generated from the following file: