Вход Регистрация
Файл: onlinepoisk.wm-scripts.ru/vendor/Pagerfanta/Adapter/DoctrineORM/CountWalker.php
Строк: 71
<?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;

class 
CountWalker extends TreeWalkerAdapter
{
    
/**
     * Walks down a SelectStatement AST node, modifying it to retrieve a COUNT
     *
     * @param SelectStatement $AST
     * @return void
     */
    
public function walkSelectStatement(SelectStatement $AST)
    {
        
$parent null;
        
$parentName null;

        foreach (
$this->_getQueryComponents() as $dqlAlias => $qComp) {
            if (
array_key_exists('parent'$qComp) && $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;

        
$AST->selectClause->selectExpressions = array(
            new 
SelectExpression(
                new 
AggregateExpression('count'$pathExpressiontrue), null
            
)
        );

        
// ORDER BY is not needed, only increases query execution through unnecessary sorting.
        
$AST->orderByClause null;
    }

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