namespace Acme\SimpleBundle\DQL; use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\AST\Functions\FunctionNode; class Round extends FunctionNode { protected $roundExp; protected $roundPrecission; public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { return 'ROUND(' . $sqlWalker->walkArithmeticExpression($this->roundExp) . ','. $sqlWalker->walkArithmeticExpression($this->roundPrecission) .')'; } /** * parse - allows DQL to breakdown the DQL string into a processable structure * @param \Doctrine\ORM\Query\Parser $parser */ public function parse(\Doctrine\ORM\Query\Parser $parser) { $parser->match(Lexer::T_IDENTIFIER); $parser->match(Lexer::T_OPEN_PARENTHESIS); $this->roundExp = $parser->ArithmeticExpression(); // $parser->match(Lexer::T_COMMA); // $this->roundPrecission = $parser->ArithmeticExpression(); // $parser->match(Lexer::T_CLOSE_PARENTHESIS); } }
protected $roundExp; protected $roundPrecission; // round(roundExp, roundPrecission)
doctrine: dbal: driver: %database_driver% host: %database_host% port: %database_port% dbname: %database_name% user: %database_user% password: %database_password% charset: UTF8 orm: auto_generate_proxy_classes: %kernel.debug% auto_mapping: true dql: string_functions: unix_timestamp: \Acme\SimpleBundle\DQL\UnixTimestamp numeric_functions: round: \Acme\SimpleBundle\DQL\Round
$queryBuilder->andWhere("ROUND (sum) , 1) = :condition");
namespace Acme\SimpleBundle\DQL; use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\AST\Functions\FunctionNode; class Round extends FunctionNode { protected $arithmeticExprt; public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { return 'UNIX_TIMESTAMP(' . $sqlWalker->walkArithmeticExpression($this->arithmeticExprt) .')'; } /** * parse - allows DQL to breakdown the DQL string into a processable structure * @param \Doctrine\ORM\Query\Parser $parser */ public function parse(\Doctrine\ORM\Query\Parser $parser) { $parser->match(Lexer::T_IDENTIFIER); $parser->match(Lexer::T_OPEN_PARENTHESIS); $this->arithmeticExprt = $parser->ArithmeticExpression(); // $parser->match(Lexer::T_CLOSE_PARENTHESIS); } }
Source: https://habr.com/ru/post/209870/
All Articles