/**
  * @return array
  */
 public function fetchAll()
 {
     $rows = array();
     while (($a_row = $this->connection->sql_fetch_assoc($this->resource)) == true) {
         $rows[] = $a_row;
     }
     $this->connection->sql_free_result($this->resource);
     return $rows;
 }
 /**
  * fills the internal array '$this->langArr' with the available syslanguages
  *
  * @return	void
  */
 function initLanguages()
 {
     $lres = $this->db->exec_SELECTquery('*', 'sys_language', '1=1' . $this->getEnableFields('sys_language'));
     $this->langArr = array();
     $this->langArr[0] = array('title' => $this->conf['defLangLabel'], 'flag' => $this->conf['defLangImage']);
     while ($row = $this->db->sql_fetch_assoc($lres)) {
         $this->langArr[$row['uid']] = $row;
     }
     $this->db->sql_free_result($lres);
 }
    /**
     * Get tree data
     *
     * @param integer $uid
     * @param string $subLevelId
     *
     * @return array
     */
    protected function getTreeData($uid, $subLevelId)
    {
        // Filter the results by preference and access
        $clauseExludePidList = '';
        if ($pidList = $GLOBALS['BE_USER']->getTSConfigVal('options.hideRecords.pages')) {
            if ($pidList = $this->databaseHandle->cleanIntList($pidList)) {
                $clauseExludePidList = ' AND pages.uid NOT IN (' . $pidList . ')';
            }
        }
        $clause = ' AND ' . $GLOBALS['BE_USER']->getPagePermsClause(1) . ' ' . $clauseExludePidList;
        /**
         * We want a page tree with all the excluded pages in there. This means
         * all pages that have the exclude flag set and also all pages that have the
         * excludeBranch flag set, including their children.
         *
         * 1). First fetch the page id's that have any exclusion options set
         */
        $result = $this->databaseHandle->sql_query('
			SELECT GROUP_CONCAT(uid) AS uids
			FROM pages
			WHERE
				tx_tablecleaner_exclude = 1 AND
				deleted = 0 ' . $clause . ';
		');
        $row = $this->databaseHandle->sql_fetch_assoc($result);
        $excludePages = array();
        if ($row['uids'] !== NULL) {
            $excludePages = explode(',', $row['uids']);
        }
        $this->databaseHandle->sql_free_result($result);
        $result = $this->databaseHandle->sql_query('
			SELECT GROUP_CONCAT(uid) AS uids
			FROM pages
			WHERE
				tx_tablecleaner_exclude_branch = 1 AND
				deleted = 0 ' . $clause . ';
		');
        $row = $this->databaseHandle->sql_fetch_assoc($result);
        $excludeBranchPages = array();
        if ($row['uids'] !== NULL) {
            $excludeBranchPages = explode(',', $row['uids']);
        }
        $this->databaseHandle->sql_free_result($result);
        /**
         * 2). Fetch the id's up to the 'current root' page.
         * To build a complete page tree, we also need the parents of the
         * excluded pages. So we merge the found pages and fetch the rootlines for
         * all those pages.
         */
        $allExcludedPages = array_merge($excludePages, $excludeBranchPages);
        $allExcludedPages = array_unique($allExcludedPages);
        $allUids = array();
        foreach ($allExcludedPages as $pageId) {
            // Don't fetch the rootline if the pageId is already in the list
            if (!in_array($pageId, $allUids)) {
                // Get the rootline up to the starting uid
                $rootLine = t3lib_BEfunc::BEgetRootLine($pageId, ' AND NOT uid = ' . $uid . $clause);
                foreach ($rootLine as $record) {
                    $allUids[] = $record['uid'];
                }
            }
        }
        /**
         * 3). Include self
         */
        $allUids[] = $uid;
        /**
         * 4). Fetch all the children of the pages that have exclude_branch set.
         */
        foreach ($excludeBranchPages as $pageId) {
            $allUids = array_merge($allUids, Tx_Tablecleaner_Utility_Base::fetchChildPages($pageId));
        }
        $allUids = array_unique($allUids);
        $foundPages = $this->pageRepository->findByUids($allUids);
        $allPages = array();
        foreach ($foundPages as $page) {
            $allPages[$page['uid']] = $page;
        }
        $tree = $this->reassembleTree($allPages, $uid, $subLevelId);
        $rootElement[$uid] = $allPages[$uid];
        $rootElement[$uid][$subLevelId] = $tree;
        return $rootElement;
    }