/**
  * Return data row as array
  *
  * @return array
  */
 public function fetchRow()
 {
     return $this->connection->sql_fetch_assoc($this->resource);
 }
 /**
  * @param $selectConf
  * @return array
  */
 function getArchiveMenuRange($selectConf)
 {
     $range = array('minval' => 0, 'maxval' => 0);
     if ($this->conf['amenuStart']) {
         $range['minval'] = strtotime($this->conf['amenuStart']);
     }
     if ($this->conf['amenuEnd']) {
         $eTime = strtotime($this->conf['amenuEnd']);
         if ($eTime > $range['minval']) {
             $range['maxval'] = $eTime;
         }
     }
     if (!($range['minval'] && $range['maxval'])) {
         // find minval and/or maxval automatically
         $selectConf['selectFields'] = '';
         if (!$range['minval']) {
             $selectConf['selectFields'] .= 'MIN(tt_news.datetime) AS minval';
             if ($this->conf['ignoreNewsWithoutDatetimeInAmenu']) {
                 $selectConf['where'] .= ' AND tt_news.datetime > 0';
             }
         }
         if (!$range['maxval']) {
             $selectConf['selectFields'] .= ($selectConf['selectFields'] ? ', ' : '') . 'MAX(tt_news.datetime) AS maxval';
         }
         $res = $this->exec_getQuery('tt_news', $selectConf);
         $range = $this->db->sql_fetch_assoc($res);
     }
     return $range;
 }
    /**
     * 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;
    }