예제 #1
0
    /**
     * Fetches and returns an array of posts from the post tree, starting with the node object passed by
     * the first paramter.
     * 
     * @param    ilForumPost	$a_post_node	node-object of a post
     * @return	array		array of post objects
     * @access	public
     */
    public function getPostTree(ilForumPost $a_post_node)
    {
        global $ilUser;
        $posts = array();
        $data = array();
        $data_types = array();
        $query = '
			SELECT 			is_author_moderator, pos_author_id, pos_pk, fpt_date, rgt, pos_top_fk, pos_thr_fk, 
							pos_display_user_id, pos_usr_alias, pos_subject,
							pos_status, pos_message, pos_date, pos_update,
							update_user, pos_cens, pos_cens_com, notify,
							import_name, fpt_pk, parent_pos, lft, depth,
							(CASE
							WHEN fur.post_id IS NULL ' . ($ilUser->getId() == ANONYMOUS_USER_ID ? ' AND 1 = 2 ' : '') . '
							THEN 0
							ELSE 1
							END) post_read,
							firstname, lastname, title, login
							 
			FROM 			frm_posts_tree
			 
			INNER JOIN 		frm_posts 
				ON 			pos_fk = pos_pk
				
			LEFT JOIN		usr_data
				ON			pos_display_user_id  = usr_id
				
			LEFT JOIN		frm_user_read fur
				ON			fur.thread_id = pos_thr_fk
				AND			fur.post_id = pos_pk
				AND			fur.usr_id = %s
				 
			WHERE 			lft BETWEEN %s AND %s 
				AND 		thr_fk = %s';
        array_push($data_types, 'integer', 'integer', 'integer', 'integer');
        array_push($data, $ilUser->getId(), $a_post_node->getLft(), $a_post_node->getRgt(), $a_post_node->getThreadId());
        if ($this->orderField != "") {
            $query .= " ORDER BY " . $this->orderField . " " . $this->getOrderDirection();
        }
        $res = $this->db->queryf($query, $data_types, $data);
        $usr_ids = array();
        $deactivated = array();
        while ($row = $this->db->fetchAssoc($res)) {
            $tmp_object = new ilForumPost($row['pos_pk'], false, true);
            $tmp_object->assignData($row);
            if (!$this->is_moderator) {
                if (!$tmp_object->isActivated() && $tmp_object->getDisplayUserId() != $ilUser->getId()) {
                    $deactivated[] = $tmp_object;
                    unset($tmp_object);
                    continue;
                }
                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 2;
                    }
                }
            }
            if ((int) $row['pos_display_user_id']) {
                $usr_ids[] = (int) $row['pos_display_user_id'];
            }
            if ((int) $row['update_user']) {
                $usr_ids[] = (int) $row['update_user'];
            }
            $posts[] = $tmp_object;
            unset($tmp_object);
        }
        require_once 'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
        ilForumAuthorInformationCache::preloadUserObjects(array_unique($usr_ids));
        return $posts;
    }