Get sub pages recursive

@param $rootPageId

@return array
160787
private function getSubPagesRecursive($rootPageId)
    {
        $pages = $this->getSubPages($rootPageId);
        foreach ($pages as $page) {
            if (false === $this->isPageTreeLeaf($page)) {
                ArrayUtility::mergeRecursiveWithOverrule(
                    $pages,
                    $this->getSubPagesRecursive($page['uid'])
                );
            }
        }

        return $pages;
    }
1252004
public function findByPageIdAndByLanguageId($pageId, $languageId)
    {
        try {
            $this->initializeSearch($pageId, $languageId);
            $pageQuery = $this->queryBuilder->buildPageQuery($pageId);
            $response = $this->search->search($pageQuery, 0, 10000);
        } catch (NoSolrConnectionFoundException $exception) {
            return [];
        } catch (SolrCommunicationException $exception) {
            return [];
        }
        $data = $response->getParsedData();
        return $this->documentEscapeService->applyHtmlSpecialCharsOnAllFields($data->response->docs ?? []);
    }
837405
public function getParentByPageId($pageId)
    {
        $data = array();
        $success = 0;

        $treeSite = $this->getServiceLocator()->get('MelisSiteTree');

        if($treeSite){
            $data  = $treeSite->getParentByPageId($pageId);
        }


        return $data;
    }
638802
public function sitemapCommand($rootPageId)
    {
        $rootPageId = $this->getRootPageIdFromId($rootPageId);

        if ($rootPageId !== null) {
            $domain = RootPageUtility::getDomain($rootPageId);

            $query   = 'SELECT page_url
                          FROM tx_metaseo_sitemap
                         WHERE page_rootpid = ' . DatabaseUtility::quote($rootPageId, 'tx_metaseo_sitemap') . '
                           AND is_blacklisted = 0';
            $urlList = DatabaseUtility::getCol($query);

            foreach ($urlList as $url) {
                if ($domain) {
                    $url = GeneralUtility::fullUrl($url, $domain);
                }

                ConsoleUtility::writeLine($url);
            }
        } else {
            ConsoleUtility::writeErrorLine('No such root page found');
            ConsoleUtility::terminate(1);
        }
    }
1057653
private function getPagesDatas($rootPages)
	{
		$idPage = $this->params()->fromQuery('nodeId', -1);

		if ($idPage == MelisCmsRightsService::MELISCMS_PREFIX_PAGES . '_root')
			$idPage = -1;
		else
			$idPage = str_replace(MelisCmsRightsService::MELISCMS_PREFIX_PAGES . '_', '', $idPage);

		$pageMelisKey = 'meliscms_page';
		$melisAppConfig =$this->getServiceLocator()->get('MelisCoreConfig');
		$appsConfig = $melisAppConfig->getItem($pageMelisKey);

		if (!empty($appsConfig['conf']['id']))
			$zoneId = $appsConfig['conf']['id'];
		else
			$zoneId = 'id_meliscms_page';


		// Get the children
		$melisTree = $this->serviceLocator->get('MelisEngineTree');
		if (!empty($rootPages))
		{
			if ($rootPages[0] == -1 || $idPage != -1)
			{
				$children = $melisTree->getPageChildren($idPage);
				$children = $children->toArray();
			}
			else
			{
				$children = array();
				$tablePageTree = $this->getServiceLocator()->get('MelisEngineTablePageTree');
				foreach ($rootPages as $idPage)
				{
					$pageDetails = $tablePageTree->getFullDatasPage($idPage, '');
					$pageDetails = $pageDetails->toArray();
					$children = array_merge($children, $pageDetails);
				}
			}
		}
		else
		{
			return array();
		}


		// Making a new array with one unique page from published or save
		$final = array();
		foreach($children as $page)
		{
			$data_page_id = $page['tree_page_id'];

			/**
			 * Check which table must be used depending on if there's data
			 * in saved or published table.
			 * Saved results come withe same column name prefixed by s_
			 */
			if (!empty($page['s_page_id']))
			{
				$has_saved_version = 1;
				$prefixTable = 's_';
			}
			else
			{
				$has_saved_version = 0;
				$prefixTable = '';
			}

			// Prefix the id with the pageId
			$zoneIdTmp = $data_page_id . '_' . $zoneId;

			// Check if node has children
			$has_children = false;
			$childrenTmp = $melisTree->getPageChildren($data_page_id);
			if ($childrenTmp)
			{
				$childrenTmp = $childrenTmp->toArray();
				if (count($childrenTmp) > 0)
					$has_children = true;
			}

			// Check if the publish page is online to know for our result
			$is_online = 0;
			if (!empty($page['page_status']) && $page['page_status'] == 1)
				$is_online = 1;

			// Type of page is in table defined previously
			$data_page_type = $page[$prefixTable . 'page_type'];

			// We show always published name in tree, saved if no published
			if (!empty($page['page_name']))
				$data_page_name = $page['page_name'];
			else
			{
				if (!empty($page['s_page_name']))
					$data_page_name = $page['s_page_name'];
				else
					$data_page_name = $page['page_name'];
			}

			switch ($data_page_type) {
				case 'PAGE': 
					$data_icon = 'fa fa-file-o';
					break;
				case 'SITE': 
					$data_icon = 'fa fa-home';
					break;
				case 'FOLDER': 
					$data_icon = 'fa fa-folder-open-o';
					break;
				case 'NEWSLETTER': 
					$data_icon = 'fa fa-newspaper-o';
					break;
				default: 
					$data_icon = '';
					break;
			}

			$newpage = array(
				// These datas are common to all treeviews
				'item_zoneid' => $zoneIdTmp,
				'item_melisKey' => $pageMelisKey,
				'item_name' => $data_page_id . ' - ' . $data_page_name,
				'item_is_on' => $is_online,
				'item_has_version' => $has_saved_version,
				'item_icon' => $data_icon,
				'item_has_children' => $has_children,
				'item_dragdrop' => $this->isAllowedDragDrop(),

				// These datas are added and will be sent back when calling the view from the melisKey
				'item_datas' => array(
					'page_title' => $data_page_name,
					'page_id' => $data_page_id,
					'page_has_saved_version' => $has_saved_version,
					'page_is_online' => $is_online,
					'page_type' => $data_page_type,
					'item_zoneid' => $zoneIdTmp,
					'item_melisKey' => $pageMelisKey,
				)
			);

			array_push($final, $newpage);
		}

		return $final;
	}
1022114
public function getSubPagesRecursively($pageUid, array &$subPages)
    {
        $queryBuilder = $this->getQueryBuilder('pages');
        $childPages = $queryBuilder
            ->select('uid', 'backend_layout', 'backend_layout_next_level')
            ->from('pages')
            ->where(
                $queryBuilder->expr()->eq(
                    'pid',
                    $queryBuilder->createNamedParameter((int)$pageUid, \PDO::PARAM_INT)
                )
            )
            ->execute()
            ->fetchAll();

        if (!empty($childPages)) {
            foreach ($childPages as $page) {
                if (empty($page['backend_layout'])) {
                    $subPages[] = $page;
                }
                if (empty($page['backend_layout_next_level'])) {
                    $this->getSubPagesRecursively($page['uid'], $subPages);
                }
            }
        }
    }
751356
public function resolvePageLayout($pageId, $themeId = null)
    {
        /** @var $site \PageBuilder\Entity\Site */
        /** @var $parent \PageBuilder\Entity\Page */
        /** @var $page \PageBuilder\Entity\Page */
        /** @var $templateObj \PageBuilder\Entity\Template */
        /** @var PageModel $pageModel */

        $layout    = [];
        $pageModel = $this->getServiceLocator()->get('pagebuilder\model\page');
        $page      = $pageModel->getMainPageById($pageId);

        if ($page['layout']) {
            return $page['layout'];
        } elseif ($page['parentId']) {
            $parentPage = $pageModel->getMainPageById($page['parentId']);
            if ($parentPage['layout']) {
                return $parentPage['layout'];
            }
        }

        if (is_object($page) and $templateObj = $page->getTemplate()) {
            if ($layout = $templateObj->getLayout()) {
                return $layout;
            }
        }

        //get the sites default template's layout
        if ($site = $this->getServiceLocator()->get('active\site')) {
            if ($templateObj = $site->getDefaultTemplate()) {
                return $templateObj->getLayout();
            }
        }

        return $layout;
    }
1194855
public function getSeoKeywordsByPageId($pageId)
    {
        $pageId = $this->params()->fromRoute('idPage', $this->params()->fromQuery('idPage', ''));
        $data = array();

        $seoKeywords = $pageId->getSeoKeywords($pageId);
        $data        = $seoKeywords;

        return $data;
    }
598157
public function getPages()
    {
        $pages = array();

        foreach ($this->children as $child) {
            if ($child instanceof SwatNoteBookChild) {
                $pages = array_merge($pages, $child->getPages());
            }
        }

        return $pages;
    }
1312463
protected function getAnchorsInPage($id)
    {
        $page = SiteTree::get()->byID($id);

        if (!$page || !$page->canView()) {
            return [];
        }

        return $page->getAnchorsOnPage();
    }
579270
public function getCollectionPages($collectionId)
    {
        $pageMapper = ($this->container->dataMapper)('PageMapper');

        // Page Collection
        $data = $pageMapper->findCollectionPagesById($collectionId);

        return $data;
    }
574774
private function getChildren($parentID)
    {
        $tmp = [];
        $count = 0;
        foreach($this->existingMenuLinks as $key => $menuLink){
            if ($menuLink['parent'] == $parentID) {
                $tmp[$count] = $menuLink;
                $count++;
            }
        }
        return $tmp;
    }
80624
public function getEditionLogOfPageEditionById($pageId)
    {
        $data = array();

        $pageEdition = $this->getServiceLocator()->get('MelisEnginePage');
        $dataLogs    = $pageEdition->getEditionLogsOfPage($pageId);

        $data = $dataLogs;

        return $data;
    }
683923
protected function listCalcDepth($pageUid, array $rootLineRaw, $depth = null)
    {
        if ($depth === null) {
            $depth = 1;
        }

        if (empty($rootLineRaw[$pageUid])) {
            // found root page
            return $depth;
        }

        // we must be at least in the first depth
        ++$depth;

        $pagePid = $rootLineRaw[$pageUid];

        if (!empty($pagePid)) {
            // recursive
            $depth = $this->listCalcDepth($pagePid, $rootLineRaw, $depth);
        }

        return $depth;
    }
735529
public function getPageContent($pageId)
    {
        // Retrieve cache version if front mode to avoid multiple calls
        $melisEngineCacheSystem = $this->getServiceLocator()->get('MelisEngineCacheSystem');
        $pageContent = $melisEngineCacheSystem->getCacheByKey($this->cachekey.$pageId, $this->cacheConfig, true);
        
        return $pageContent;
    }
687767
public function get(
        $root = null,
        $siteId = null,
        $pages = null,
        $pageType = null,
        $pageName = null
    ) {
        if (empty($root)) {
            $root = self::RESOURCE_SITES;
        }

        if (empty($siteId)) {
            return $root;
        }

        if (empty($pages)) {
            return $root . '.' . $siteId;
        }

        if (empty($pageType) || empty($pageName)) {
            return $root . '.' . $siteId . '.' . $pages;
        }

        return $root . '.' . $siteId . '.' . $pages . '.' . $pageType . '.' . $pageName;
    }
597965
public function buildPageQuery($pageId)
    {
        $siteRepository = GeneralUtility::makeInstance(SiteRepository::class);
        $site = $siteRepository->getSiteByPageId($pageId);

        return $this->newSearchQuery('')
            ->useQueryString('*:*')
            ->useFilter('(type:pages AND uid:' . $pageId . ') OR (*:* AND pid:' . $pageId . ' NOT type:pages)', 'type')
            ->useFilter('siteHash:' . $site->getSiteHash(), 'siteHash')
            ->useReturnFields(ReturnFields::fromString('*'))
            ->useSortings(Sortings::fromString('type asc, title asc'))
            ->useQueryType('standard')
            ->getQuery();
    }