Вход Регистрация
Файл: onlinepoisk.wm-scripts.ru/vendor/Pagerfanta/Adapter/DoctrineORM/LimitSubqueryWalker.php
Строк: 102
<?php

/*
 * This file is part of the Pagerfanta package.
 *
 * (c) Pablo Díez <pablodip@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace PagerfantaAdapterDoctrineORM;

use 
DoctrineORMQueryTreeWalkerAdapter,
    
DoctrineORMQueryASTSelectStatement,
    
DoctrineORMQueryASTSelectExpression,
    
DoctrineORMQueryASTPathExpression,
    
DoctrineORMQueryASTAggregateExpression;

/**
 * Replaces the selectClause of the AST with a SELECT DISTINCT root.id equivalent
 *
 * @category    DoctrineExtensions
 * @package     DoctrineExtensionsPaginate
 * @author      David Abdemoulaie <dave@hobodave.com>
 * @copyright   Copyright (c) 2010 David Abdemoulaie (http://hobodave.com/)
 * @license     http://hobodave.com/license.txt New BSD License
 */
class LimitSubqueryWalker extends TreeWalkerAdapter
{
    private 
$aliasCounter 0;

    
/**
     * Walks down a SelectStatement AST node, modifying it to retrieve DISTINCT ids
     * of the root Entity
     *
     * @param SelectStatement $AST
     * @return void
     */
    
public function walkSelectStatement(SelectStatement $AST)
    {
        
$parent null;
        
$parentName null;
        
$selectExpressions = array();

        foreach (
$this->_getQueryComponents() AS $dqlAlias => $qComp) {
            
// skip mixed data in query
            
if (isset($qComp['resultVariable'])) {
                
$selectExpressions[] = new SelectExpression($qComp['resultVariable'], $dqlAlias);
                continue;
            }

            if (
$qComp['parent'] === null && $qComp['nestingLevel'] == 0) {
                
$parent $qComp;
                
$parentName $dqlAlias;
                break;
            }
        }

        
$pathExpression = new PathExpression(
            
PathExpression::TYPE_STATE_FIELD PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION$parentName,
            
$parent['metadata']->getSingleIdentifierFieldName()
        );
        
$pathExpression->type PathExpression::TYPE_STATE_FIELD;

        
array_unshift($selectExpressions, new SelectExpression($pathExpression'_dctrn_id'));
        
$AST->selectClause->selectExpressions $selectExpressions;

        if (isset(
$AST->orderByClause)) {
            foreach (
$AST->orderByClause->orderByItems as $item) {
                if (
$item->expression instanceof PathExpression) {
                    
$pathExpression = new PathExpression(
                        
PathExpression::TYPE_STATE_FIELD PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION,
                        
$item->expression->identificationVariable,
                        
$item->expression->field
                    
);
                    
$pathExpression->type PathExpression::TYPE_STATE_FIELD;
                    
$AST->selectClause->selectExpressions[] = new SelectExpression($pathExpression'_dctrn_ord'.$this->aliasCounter++);
                }
            }
        }

        
$AST->selectClause->isDistinct true;
    }

}
Онлайн: 1
Реклама