public function getNestedSetPostChildren($pos_id = null, $expandedNodes = array())
    {
        global $ilUser;
        $data = null;
        $objProperties = ilForumProperties::getInstance($this->getFrmObjId());
        $is_post_activation_enabled = $objProperties->isPostActivationEnabled();
        if ($pos_id !== null) {
            $res = $this->db->queryF("\n\t\t\t\tSELECT\t\tlft, rgt\n\t\t\t\tFROM\t\tfrm_posts_tree\n\t\t\t\tWHERE\t\tpos_fk = %s\n\t\t\t\tAND\t\t\tthr_fk = %s", array('integer', 'integer'), array($pos_id, $this->id));
            $data = $this->db->fetchAssoc($res);
        }
        $query = '
			SELECT			fpt.depth,
							fpt.rgt,
							fpt.parent_pos,
							fp.pos_pk,
							fp.pos_subject,
							fp.pos_usr_alias,
							fp.pos_date,
							fp.pos_update,
							fp.pos_status,
							fp.pos_display_user_id,
							fp.pos_usr_alias,
							fp.import_name,
							fp.pos_author_id,
							fp.is_author_moderator,
							fur.post_id,
							(CASE
							WHEN fur.post_id IS NULL ' . ($ilUser->getId() == ANONYMOUS_USER_ID ? ' AND 1 = 2 ' : '') . '
							THEN 0
							ELSE 1
							END) post_read,
							COUNT(fpt2.pos_fk) children	

			FROM			frm_posts_tree fpt

			INNER JOIN		frm_posts fp
				ON			fp.pos_pk = fpt.pos_fk
				
			LEFT JOIN		frm_posts_tree fpt2
				 ON         fpt2.lft BETWEEN fpt.lft AND fpt.rgt
				 AND		fpt.thr_fk = fpt2.thr_fk
				 AND		fpt.pos_fk != fpt2.pos_fk ';
        $query .= '
			LEFT JOIN		frm_user_read fur
				ON			fur.thread_id = fp.pos_thr_fk
				AND			fur.post_id = fp.pos_pk
				AND			fur.usr_id = ' . $this->db->quote($ilUser->getId(), 'integer') . '

			LEFT JOIN		usr_data ud
				ON			ud.usr_id = fp.pos_display_user_id
		
			WHERE			fpt.thr_fk = ' . $this->db->quote($this->id, 'integer');
        if ($data) {
            $query .= '		AND fpt.lft > ' . $this->db->quote($data['lft'], 'integer') . '		AND fpt.lft < ' . $this->db->quote($data['rgt'], 'integer') . ' ';
        }
        if ($is_post_activation_enabled && !$this->is_moderator) {
            $query .= ' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_display_user_id = ' . $this->db->quote($ilUser->getId(), 'integer') . ') ';
        }
        if ($expandedNodes) {
            $query .= ' AND ' . $this->db->in('fpt.parent_pos', $expandedNodes, false, 'integer') . ' ';
        }
        $query .= ' GROUP BY fpt.depth,
							fpt.rgt,
							fpt.parent_pos,
							fp.pos_pk,
							fp.pos_subject,
							fp.pos_usr_alias,
							fp.pos_date,
							fp.pos_update,
							fp.pos_status,
							fp.pos_display_user_id,
							fp.pos_usr_alias,
							fp.import_name,
							fp.pos_author_id,
							fp.is_author_moderator,
							fur.post_id
					ORDER BY fpt.rgt DESC
		';
        $queryCounter = '
			SELECT			pos_fk
			FROM			frm_posts_tree fpt
			INNER JOIN		frm_posts fp
				ON			fp.pos_pk = fpt.pos_fk
			WHERE			fpt.thr_fk = ' . $this->db->quote($this->id, 'integer');
        if ($is_post_activation_enabled && !$this->is_moderator) {
            $queryCounter .= ' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_display_user_id = ' . $this->db->quote($ilUser->getId(), 'integer') . ') ';
        }
        $queryCounter .= ' ORDER BY fpt.rgt DESC';
        $resCounter = $this->db->query($queryCounter);
        $counter = array();
        $i = 0;
        while ($row = $this->db->fetchAssoc($resCounter)) {
            $counter[$row['pos_fk']] = $i++;
        }
        $res = $this->db->query($query);
        $children = array();
        $usr_ids = array();
        while ($row = $this->db->fetchAssoc($res)) {
            if ((int) $row['pos_display_user_id']) {
                $usr_ids[] = (int) $row['pos_display_user_id'];
            }
            $row['counter'] = $counter[$row['pos_pk']];
            $children[] = $row;
        }
        require_once 'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
        ilForumAuthorInformationCache::preloadUserObjects(array_unique($usr_ids));
        return $children;
    }
 /**
  * @return ilForumTopicTableGUI
  */
 public function fetchData()
 {
     $this->determineOffsetAndOrder();
     $excluded_ids = array();
     if ($this->parent_cmd == 'mergeThreads' && $this->getSelectedThread() instanceof ilForumTopic) {
         $excluded_ids[] = $this->getSelectedThread()->getId();
     }
     $params = array('is_moderator' => $this->getIsModerator(), 'excluded_ids' => $excluded_ids);
     $data = $this->getMapper()->getAllThreads($this->topicData['top_pk'], $params, (int) $this->getLimit(), (int) $this->getOffset());
     if (!count($data['items']) && $this->getOffset() > 0) {
         $this->resetOffset();
         $data = $this->getMapper()->getAllThreads($this->topicData['top_pk'], $params, (int) $this->getLimit(), (int) $this->getOffset());
     }
     $this->setMaxCount($data['cnt']);
     $this->setData($data['items']);
     // Collect user ids for preloading user objects
     $thread_ids = array();
     $user_ids = array();
     foreach ($data['items'] as $thread) {
         /**
          * @var $thread ilForumTopic
          */
         $thread_ids[] = (int) $thread->getId();
         if ($thread->getUserId() > 0) {
             $user_ids[$thread->getUserId()] = (int) $thread->getUserId();
         }
     }
     $user_ids = array_merge(ilObjForum::getUserIdsOfLastPostsByRefIdAndThreadIds($this->getRefId(), $thread_ids), $user_ids);
     ilForumAuthorInformationCache::preloadUserObjects(array_unique($user_ids));
     return $this;
 }