exports: fix activity DateAggregator; add customs DQL Date/Time functions

This commit is contained in:
2022-08-24 15:44:18 +02:00
parent 52902e905a
commit 7173e4be4a
5 changed files with 145 additions and 16 deletions

View File

@@ -0,0 +1,47 @@
<?php
namespace Chill\MainBundle\Doctrine\DQL;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\AST\PathExpression;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
/**
* Extract postgresql function
* https://www.postgresql.org/docs/current/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT
*
* Usage : EXTRACT(field FROM value)
*/
class Extract extends FunctionNode
{
private string $field;
private PathExpression $value;
public function getSql(SqlWalker $sqlWalker)
{
return sprintf(
'EXTRACT(%s FROM %s)',
$this->field,
$this->value->dispatch($sqlWalker)
);
}
public function parse(Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(Lexer::T_IDENTIFIER);
$this->field = $parser->getLexer()->token['value'];
$parser->match(Lexer::T_FROM);
$this->value = $parser->ScalarExpression();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
}