public function lookForChildContainersRecursively($containerIds, array &$possibleContainers)
    {
        if (!$containerIds) {
            return;
        }
        $containerIds = GeneralUtility::intExplode(',', $containerIds);
        $queryBuilder = $this->getQueryBuilder();
        $childrenOnNextLevel = $queryBuilder
            ->select('uid', 'tx_gridelements_container')
            ->from('tt_content')
            ->where(
                $queryBuilder->expr()->andX(
                    $queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('gridelements_pi1')),
                    $queryBuilder->expr()->in(
                        'tx_gridelements_container',
                        $queryBuilder->createNamedParameter($containerIds, Connection::PARAM_INT_ARRAY)
                    )
                )
            )
            ->execute()
            ->fetchAll();

        if (!empty($childrenOnNextLevel) && !empty($possibleContainers)) {
            $containerIds = '';

            foreach ($childrenOnNextLevel as $childOnNextLevel) {
                if (isset($possibleContainers[$childOnNextLevel['uid']])) {
                    unset($possibleContainers[$childOnNextLevel['uid']]);
                }

                $containerIds .= $containerIds ? ',' . (int)$childOnNextLevel['uid'] : (int)$childOnNextLevel['uid'];

                if ($containerIds !== '') {
                    $this->lookForChildContainersRecursively($containerIds, $possibleContainers);
                }
            }
        }
    }
public function lookForChildContainersRecursively($containerIds, array &$possibleContainers)
    {
        if (!$containerIds) {
            return;
        }
        $containerIds = GeneralUtility::intExplode(',', $containerIds);
        $queryBuilder = $this->getQueryBuilder();
        $childrenOnNextLevel = $queryBuilder
            ->select('uid', 'tx_gridelements_container')
            ->from('tt_content')
            ->where(
                $queryBuilder->expr()->andX(
                    $queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('gridelements_pi1')),
                    $queryBuilder->expr()->in(
                        'tx_gridelements_container',
                        $queryBuilder->createNamedParameter($containerIds, Connection::PARAM_INT_ARRAY)
                    )
                )
            )
            ->execute()
            ->fetchAll();

        if (!empty($childrenOnNextLevel) && !empty($possibleContainers)) {
            $containerIds = '';

            foreach ($childrenOnNextLevel as $childOnNextLevel) {
                if (isset($possibleContainers[$childOnNextLevel['uid']])) {
                    unset($possibleContainers[$childOnNextLevel['uid']]);
                }

                $containerIds .= $containerIds ? ',' . (int)$childOnNextLevel['uid'] : (int)$childOnNextLevel['uid'];

                if ($containerIds !== '') {
                    $this->lookForChildContainersRecursively($containerIds, $possibleContainers);
                }
            }
        }
    }
public function lookForChildContainersRecursively ( $ containerIds , array & $ possibleContainers ) { if ( ! $ containerIds ) { return ; } $ containerIds = GeneralUtility :: intExplode ( ',' , $ containerIds ) ; $ queryBuilder = $ this -> getQueryBuilder ( ) ; $ childrenOnNextLevel = $ queryBuilder -> select ( 'uid' , 'tx_gridelements_container' ) -> from ( 'tt_content' ) -> where ( $ queryBuilder -> expr ( ) -> andX ( $ queryBuilder -> expr ( ) -> eq ( 'CType' , $ queryBuilder -> createNamedParameter ( 'gridelements_pi1' ) ) , $ queryBuilder -> expr ( ) -> in ( 'tx_gridelements_container' , $ queryBuilder -> createNamedParameter ( $ containerIds , Connection :: PARAM_INT_ARRAY ) ) ) ) -> execute ( ) -> fetchAll ( ) ; if ( ! empty ( $ childrenOnNextLevel ) && ! empty ( $ possibleContainers ) ) { $ containerIds = '' ; foreach ( $ childrenOnNextLevel as $ childOnNextLevel ) { if ( isset ( $ possibleContainers [ $ childOnNextLevel [ 'uid' ] ] ) ) { unset ( $ possibleContainers [ $ childOnNextLevel [ 'uid' ] ] ) ; } $ containerIds .= $ containerIds ? ',' . ( int ) $ childOnNextLevel [ 'uid' ] : ( int ) $ childOnNextLevel [ 'uid' ] ; if ( $ containerIds !== '' ) { $ this -> lookForChildContainersRecursively ( $ containerIds , $ possibleContainers ) ; } } } }
Recursive function to remove any container from the list of possible containers
that is already a subcontainer on any level of the current container

@param string $containerIds : A list determining containers that should be checked
@param array $possibleContainers : The result list containing the remaining containers after the check
Recursive function to remove any container from the list of possible containers that is already a subcontainer on any level of the current container